//-----------------------------------------------------------------------
//
// Copyright © 2012 Nils Hammar. All rights reserved.
//
//-----------------------------------------------------------------------
/*
* Software to access vehicle information via the OBD-II connector.
*
* Copyright © 2012 Nils Hammar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
* Alternative licensing is possible, see the licensing document.
*
* The above text may not be removed or modified.
*/
namespace UserInterface.GUI
{
using System.Windows.Forms;
using global::DataSource.FileAccess;
using global::SharedObjects.Api;
using global::SharedObjects.Misc;
///
/// Message flags component.
///
public partial class MessageFlags : UserControl
{
///
/// Current device connection.
///
private IPassThruConnection passThruConnection;
///
/// Current vehicle.
///
private XmlClass.vehicle vehicle;
///
/// Gets Current flags.
///
public uint flags { get; private set; }
///
/// Indicates if protocol has 29 bit addressing.
///
private bool is29bit;
///
/// Initializes a new instance of the class.
///
public MessageFlags()
{
this.InitializeComponent();
}
///
/// Initialize component.
///
/// Current device connection.
/// Current vehicle.
/// 'true' if ISO15765 29-bit.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "is29bit", Justification = "Reviewed, intentional.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "passThruConnection", Justification = "Reviewed, intentional.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "vehicle", Justification = "Reviewed, intentional.")]
public void init(IPassThruConnection passThruConnection, XmlClass.vehicle vehicle, bool is29bit)
{
this.passThruConnection = passThruConnection;
this.vehicle = vehicle;
this.is29bit = is29bit;
this.setToolTips();
this.configListBox();
this.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top
| System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
}
///
/// Configure list box.
///
private void configListBox()
{
if (this.passThruConnection != null)
{
CanFlags[] cfa = this.passThruConnection.getMessageFlags();
this.txMsgFlagsLB.Items.Clear();
this.flags = this.is29bit ? (uint)PassThruConstants.txflags.CAN_29BIT_ID : 0;
for (int i = 0; i < cfa.Length; i++)
{
this.txMsgFlagsLB.Items.Add(cfa[i].name);
if (((cfa[i].id & VehiclesFileAccess.getMsgFlags(this.vehicle)) != 0)
|| ((cfa[i].id & this.flags) != 0))
{
this.flags |= cfa[i].id;
this.txMsgFlagsLB.SetItemChecked(i, true);
}
}
}
}
///
/// Change flag state.
///
/// Sending object.
/// Event data.
private void txMsgFlagsLB_ItemCheck(object sender, ItemCheckEventArgs e)
{
int ix = e.Index;
CheckState cs = e.NewValue;
CanFlags[] msgFlags = this.passThruConnection.getMessageFlags();
if (cs == CheckState.Checked)
{
this.flags |= msgFlags[ix].id;
}
else
{
this.flags &= ~msgFlags[ix].id;
}
}
///
/// Set tool tips for items.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Reviewed.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "CanApp.CustomToolTip", Justification = "Reviewed.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Reviewed.")]
private void setToolTips()
{
this.toolTip1.SetToolTip(
this.txMsgFlagsLB,
"Default message flags for OBD filters and transmit data.\r\n"
+ "The filter data can be modified for filters and transmit data later.");
}
}
}