//----------------------------------------------------------------------- // // 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.Special { using System; using System.Windows.Forms; using global::DeviceApi; using global::Protocol; using global::SharedObjects; using global::SharedObjects.Api; using global::SharedObjects.Protocol; /* * From a Swedish Volvo Forum: * ============================ * Ville bara meddela att jag hittat sekvensen nu. * Det är bara att skicka följande 7 byte över K-lina så får man tillgång till CAN-nätet. * * De är presenterade hexadecimalt nedan: * 84 40 13 b2 f0 03 7c * * Använde mig av en vanlig USB -> RS232 omvandlare. * Skapade en omvandlare för att göra om RS232 spänningsnivåer (+/- 10V) till K-lina (0V & +12V) * Körde ett standard terminalprogram med stöd för att skicka Hex-koder istället för Ascii. Ställde in 10400 baud med 8N1. * Nästa steg blir att skapa en enhet som automatiskt skickar det, för man måste skicka var 5:e sekund annars så stänger den bussen igen. * --- * Summary: Send the hex string above over K-Line to activate CAN in the OBD-II connector. * This shall work on Volvos before 2008(or so), since after 2008 CAN was mandatory. */ /// /// Special handling of enabling the CAN bus on Pre-2008 Volvo cars. /// public partial class VolvoForm : Form { /// /// Byte array with trig sequence. /// private static readonly byte[] ba = new byte[] { 0x84, 0x40, 0x13, 0xb2, 0xf0, 0x03, 0x7c }; /// /// Logging interface. /// private ILogging iLogging; /// /// Current device connection. /// private IPassThruConnection passThruConnection; /// /// Current protocol handler. /// private MessageHandler messageHandler; /// /// tx message instance. /// private IPassThruMsg txmsg; /// /// Message counter. /// private int count = 0; /// /// Initializes a new instance of the class. /// /// Logging interface. /// Current device connection. /// Current protocol handler. /// Current message handler. /// Current TX flags. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "2", Justification = "Reviewed, intentional.")] public VolvoForm(ILogging iLogging, IPassThruConnection passThruConnection, IProtocolHandler protocolHandler, MessageHandler messageHandler, uint txFlags) { this.iLogging = iLogging; this.passThruConnection = passThruConnection; this.messageHandler = messageHandler; this.txmsg = PassThruMsg.getMaskedMsg(protocolHandler.protocol); this.txmsg.TxFlags = (int)txFlags; this.InitializeComponent(); } /// /// Process one tick. /// /// Sending object. /// Event data. private void timer1_Tick(object sender, EventArgs e) { this.statusTB.Text = (this.count++).ToString(); // txmsg.Data for (int i = 0; i < ba.Length; i++) { this.txmsg.Data[i] = ba[i]; } this.txmsg.DataSize = ba.Length; PassThruConstants.resultCode res; if ((res = this.messageHandler.sendMessage(this.txmsg)) != 0) { this.timer1.Enabled = false; string errtext; this.iLogging.errTestConnection(this.passThruConnection, res, out errtext); if (MessageBox.Show( "An error occured when trying to send the activation message.\r\n\r\n" + errtext + "\r\n\r\nDo you want to stop the process?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { this.Close(); } else { this.timer1.Enabled = true; } } } } }