//----------------------------------------------------------------------- // // 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.OBD { using System; using System.Collections.Generic; using System.Windows.Forms; using global::Protocol.OBD; using global::SharedObjects; using global::SharedObjects.DataMgmt; using global::SharedObjects.GUI; using global::SharedObjects.Misc; using global::SharedObjects.Protocol; using global::SharedObjects.Protocol.OBD; using global::UserInterface.GUI.Objects; /// /// Panel for inspecting Freeze Frame data. /// public partial class FfDataPanel : AbstractUserControl, IDataPresentation { /// /// Gets OBD data panel instance. /// public ObdDataPanel obdDataPanel { get { return this.obdDataPanel1; } } /// /// Messaging instance. /// private IMessaging iMessaging; /// /// Freeze Frame number. /// private byte frameNumber = 0; /// /// Data requester instance. /// private DataRequester dataRequester; /// /// Initializes a new instance of the class. /// /// Logging instance. /// Application tree instance. /// Messaging instance. /// Data source interface. /// Vehicle instance. /// Data requester instance. /// Data file directory path. public FfDataPanel( ILogging iLogging, IApplicationTree applicationTree, IMessaging iMessaging, IDataSource iDataSource, XmlClass.vehicle vehicle, DataRequester dataRequester, string dataFileDir) : base(iLogging, vehicle, applicationTree) { this.iMessaging = iMessaging; this.dataRequester = dataRequester; this.InitializeComponent(); this.obdDataPanel1.init( iLogging, iMessaging, applicationTree, 0x02, iDataSource, vehicle, dataFileDir); 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))); this.frameNumberUd.Value = this.frameNumber; } /// /// (re) Initialize the instance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic", Justification = "Reviewed")] public void init() { // this.timer1.Start(); } /// /// Trig a get data event. /// public override void getDataEvent() { IList selectedDataItems = this.obdDataPanel1.getSelectedItems(); this.dataRequester.prepareRequestData(); foreach (PidItemWrapper item in selectedDataItems) { this.dataRequester.handlePid( item.addrList, (byte)(item.actualMode & 0xff), this.frameNumber, item.pidMode, item.pidItem, item.pidItem.pid_int); } this.dataRequester.finishPrepareDataRequest(); this.dataRequester.requestSelectedPids(); } /// /// Add data to the simple data table. /// /// Presentation data wrapper. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Reviewed, intentional.")] public void simpleDataAdd(IPresentationData presentationData) { if ((presentationData.mode & 0xbf) == 0x02) { EcuDataPanel ecuDataPanel = getDataPanelByAddress(presentationData.sourceAddress, this.frameNumber); ecuDataPanel.simpleDataAdd(presentationData); } } /// /// Add an item of the type Control. /// /// ECU source address for data. /// Which parameter mode that is selected. /// Item to add. public void add(uint sourceAddress, byte mode, Control control) { if ((mode & 0xbf) == 0x02) { EcuDataPanel ecuDataPanel = getDataPanelByAddress(sourceAddress, this.frameNumber); ecuDataPanel.add(sourceAddress, mode, control); } } /// /// The frame number has changed. /// /// Sending object. /// Event data. private void frameNumberUd_ValueChanged(object sender, EventArgs e) { this.frameNumber = (byte)this.frameNumberUd.Value; this.obdDataPanel1.clear(); this.getFfPids(); } /// /// Refresh button has been clicked. /// /// Sending object. /// Event data. private void refreshButton_Click(object sender, EventArgs e) { this.obdDataPanel1.clear(); this.getFfPids(); } /// /// Request Freeze Frame data. /// /// Sending object. /// Event data. private void getFfDataButton_Click(object sender, EventArgs e) { this.clearOldData(); this.getDataEvent(); } /// /// Clear old data from display pages. /// private void clearOldData() { foreach (PanelTreeNode node in this.owningNode.Nodes) { if (node.Nodes != null) { foreach (PanelTreeNode node1 in node.Nodes) { if (node1.userControl is EcuDataPanel && node.frameNumber == this.frameNumber) { EcuDataPanel ecuDataPanel = (EcuDataPanel)node1.userControl; ecuDataPanel.clear(); } } } } } /// /// Clear the current set of sub-panels. /// /// Sending object. /// Event data. private void clearButton_Click(object sender, EventArgs e) { if (MessageBox.Show( "Do you want to discard the current set of sub-panels?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { foreach (PanelTreeNode node in this.owningNode.Nodes) { if (node.Nodes != null) { foreach (PanelTreeNode node1 in node.Nodes) { EcuDataPanel ecuDataPanel = (EcuDataPanel)node1.userControl; ecuDataPanel.clear(); } node.Nodes.Clear(); } } this.owningNode.Nodes.Clear(); this.ecuData.Clear(); } } /// /// Delayed request for data. /// /// Sending object. /// Event data. private void timer1_Tick(object sender, EventArgs e) { this.timer1.Stop(); this.getFfPids(); } /// /// Do a request for FreezeFrame PIDs. /// private void getFfPids() { byte[] ba = TxMsg.GET_FREEZEFRAME_PIDS; ba[2] = this.frameNumber; this.iMessaging.queueMsg(null, new TxMsg(ba)); this.iMessaging.sendMsg(); } } }