//----------------------------------------------------------------------- // // 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 SharedObjects { using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; /// /// Misc utility methods. /// public static class Utils { /// /// Constant for Carriage Return and Line Feed. /// public const string CRLF = "\r\n"; /// /// Get numeric value from combo box. /// /// Combo box instance. /// Value of selected combo box item. public static uint getNumValue(object sender) { ComboBox cb = (ComboBox)sender; uint newData = 0; try { newData = Convert.ToUInt32(cb.Text.Substring(2), 16); } catch { } return newData; } /// /// Get the list as a hex string. /// /// List of bytes. /// String with hex values. public static string listToHexString(IList response) { string rspStr = string.Empty; if (response != null) { foreach (byte b1 in response) { if (!string.IsNullOrEmpty(rspStr)) { rspStr += " "; } rspStr += b1.ToString("X2"); } } return rspStr; } /// /// Convert a byte array to a string with hex values. /// /// Raw data. /// Start position in data. /// String with hex codes. public static string arrayToString(byte[] data, uint startindex) { string inData = string.Empty; if (data != null) { uint p1 = startindex; while (p1 < data.Length) { if (!string.IsNullOrEmpty(inData)) { inData += " "; } inData += data[p1++].ToString("X2"); } } return inData; } } /// /// Log row modes. /// public enum rowMode { /// /// Log raw in data. /// transport_in, /// /// Log raw out data. /// transport_out, /// /// Log Session layer in data. /// session_in, /// /// Log Session layer out data. /// session_out, /// /// Log formatted in data. /// presentation_in, /// /// Log formatted out data. /// presentation_out, /// /// Data discarded - no response sent. /// data_discard, } }