//-----------------------------------------------------------------------
//
// 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::DataMgmt;
using global::SharedObjects.Api;
using global::SharedObjects.Misc;
///
/// Connection flags component.
///
public partial class ConnectionFlags : UserControl
{
///
/// Current device connection.
///
private IPassThruConnection passThruConnection;
///
/// Current vehicle.
///
private XmlClass.vehicle vehicle;
///
/// Gets the flags.
///
public uint flags { get; private set; }
///
/// Base flags for protocol.
///
private uint baseFlags;
///
/// Initializes a new instance of the class.
///
public ConnectionFlags()
{
this.InitializeComponent();
}
///
/// Initializes the component.
///
/// Current device connection.
/// Current vehicle.
/// Base connection flags based on protocol.
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "baseFlags", Justification = "Reviewed, intentional.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "vehicle", Justification = "Reviewed, intentional.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "passThruConnection", Justification = "Reviewed, intentional.")]
public void init(IPassThruConnection passThruConnection, XmlClass.vehicle vehicle, uint baseFlags)
{
this.passThruConnection = passThruConnection;
this.vehicle = vehicle;
this.baseFlags = baseFlags;
this.flags = baseFlags;
this.updateConnFlags();
this.setToolTips();
}
///
/// Set tool tips.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "CanApp.CustomToolTip", Justification = "Reviewed, intentional.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Reviewed, intentional.")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Reviewed.")]
private void setToolTips()
{
this.toolTip1.SetToolTip(
this.connFlagsLB,
"Connection flags to be used when connecting to the vehicle.\r\n"
+ "Different vehicles requires different flags.");
}
///
/// Update connection flags for vehicle.
///
private void updateConnFlags()
{
this.flags = this.baseFlags;
foreach (XmlClass.vehicle.flags flag in this.vehicle.connflags)
{
foreach (CanFlags cf in VehiclesManager.connFlags)
{
if (cf.name.Equals(flag.flag))
{
this.flags |= cf.id;
}
}
}
this.connFlagsLB.Items.Clear();
CanFlags[] cfa = this.passThruConnection.getConnFlags();
for (int i = 0; i < cfa.Length; i++)
{
this.connFlagsLB.Items.Add(cfa[i].name);
if ((cfa[i].id & this.flags) != 0)
{
this.connFlagsLB.SetItemChecked(i, true);
}
}
}
///
/// Handle item checked event.
///
/// Sending object.
/// Event data.
private void connFlagsLB_ItemCheck(object sender, ItemCheckEventArgs e)
{
int ix = e.Index;
CheckState cs = e.NewValue;
CanFlags[] msgFlags = this.passThruConnection.getConnFlags();
if (cs == CheckState.Checked)
{
this.flags |= msgFlags[ix].id;
}
else
{
this.flags &= ~msgFlags[ix].id;
}
}
}
}