diff --git a/OBD.NET/OBD.NET/Commands/ATCommand.cs b/OBD.NET/OBD.NET.Common/Commands/ATCommand.cs similarity index 100% rename from OBD.NET/OBD.NET/Commands/ATCommand.cs rename to OBD.NET/OBD.NET.Common/Commands/ATCommand.cs diff --git a/OBD.NET/OBD.NET/Commands/STCommand.cs b/OBD.NET/OBD.NET.Common/Commands/STCommand.cs similarity index 100% rename from OBD.NET/OBD.NET/Commands/STCommand.cs rename to OBD.NET/OBD.NET.Common/Commands/STCommand.cs diff --git a/OBD.NET/OBD.NET.Common/Communication/EventArgs/DataReceivedEventArgs.cs b/OBD.NET/OBD.NET.Common/Communication/EventArgs/DataReceivedEventArgs.cs new file mode 100644 index 0000000..bff6c57 --- /dev/null +++ b/OBD.NET/OBD.NET.Common/Communication/EventArgs/DataReceivedEventArgs.cs @@ -0,0 +1,29 @@ +namespace OBD.NET.Common.Communication.EventArgs +{ + /// + /// Event args for receiving serial data + /// + public class DataReceivedEventArgs:System.EventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// The count. + /// The data. + public DataReceivedEventArgs(int count, byte[] data) + { + Count = count; + Data = data; + } + + /// + /// Count of valid data bytes in the buffer + /// + public int Count { get; private set; } + + /// + /// Data buffer holding the bytes + /// + public byte[] Data { get; private set; } + } +} diff --git a/OBD.NET/OBD.NET.Common/Communication/ISerialConnection.cs b/OBD.NET/OBD.NET.Common/Communication/ISerialConnection.cs new file mode 100644 index 0000000..6b2ea8e --- /dev/null +++ b/OBD.NET/OBD.NET.Common/Communication/ISerialConnection.cs @@ -0,0 +1,59 @@ +using OBD.NET.Common.Communication.EventArgs; +using System; +using System.Threading.Tasks; + +namespace OBD.NET.Communication +{ + /// + /// Serial connection interface + /// + /// + public interface ISerialConnection : IDisposable + { + /// + /// Gets a value indicating whether this instance is open. + /// + /// + /// true if this instance is open; otherwise, false. + /// + bool IsOpen { get; } + + /// + /// Gets a value indicating whether this instance uses asynchronous IO + /// + /// + /// Has to be set to true if asynchronous IO is supported. + /// If true async methods have to be implemented + /// + bool IsAsync { get; } + + /// + /// Occurs when a full line was received + /// + event EventHandler DataReceived; + + /// + /// Connects the serial port. + /// + void Connect(); + + /// + /// Connects the serial port asynchronous + /// + /// + Task ConnectAsync(); + + /// + /// Writes the specified data to the serial connection + /// + /// The text. + void Write(byte[] data); + + /// + /// Writes the specified data to the serial connection asynchronous + /// + /// The text. + Task WriteAsync(byte[] data); + + } +} diff --git a/OBD.NET/OBD.NET/DataTypes/Count.cs b/OBD.NET/OBD.NET.Common/DataTypes/Count.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Count.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Count.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Degree.cs b/OBD.NET/OBD.NET.Common/DataTypes/Degree.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Degree.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Degree.cs diff --git a/OBD.NET/OBD.NET/DataTypes/DegreeCelsius.cs b/OBD.NET/OBD.NET.Common/DataTypes/DegreeCelsius.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/DegreeCelsius.cs rename to OBD.NET/OBD.NET.Common/DataTypes/DegreeCelsius.cs diff --git a/OBD.NET/OBD.NET/DataTypes/GenericData.cs b/OBD.NET/OBD.NET.Common/DataTypes/GenericData.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/GenericData.cs rename to OBD.NET/OBD.NET.Common/DataTypes/GenericData.cs diff --git a/OBD.NET/OBD.NET/DataTypes/GramPerSec.cs b/OBD.NET/OBD.NET.Common/DataTypes/GramPerSec.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/GramPerSec.cs rename to OBD.NET/OBD.NET.Common/DataTypes/GramPerSec.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Kilometre.cs b/OBD.NET/OBD.NET.Common/DataTypes/Kilometre.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Kilometre.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Kilometre.cs diff --git a/OBD.NET/OBD.NET/DataTypes/KilometrePerHour.cs b/OBD.NET/OBD.NET.Common/DataTypes/KilometrePerHour.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/KilometrePerHour.cs rename to OBD.NET/OBD.NET.Common/DataTypes/KilometrePerHour.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Kilopascal.cs b/OBD.NET/OBD.NET.Common/DataTypes/Kilopascal.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Kilopascal.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Kilopascal.cs diff --git a/OBD.NET/OBD.NET/DataTypes/LitresPerHour.cs b/OBD.NET/OBD.NET.Common/DataTypes/LitresPerHour.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/LitresPerHour.cs rename to OBD.NET/OBD.NET.Common/DataTypes/LitresPerHour.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Milliampere.cs b/OBD.NET/OBD.NET.Common/DataTypes/Milliampere.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Milliampere.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Milliampere.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Minute.cs b/OBD.NET/OBD.NET.Common/DataTypes/Minute.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Minute.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Minute.cs diff --git a/OBD.NET/OBD.NET/DataTypes/NewtonMetre.cs b/OBD.NET/OBD.NET.Common/DataTypes/NewtonMetre.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/NewtonMetre.cs rename to OBD.NET/OBD.NET.Common/DataTypes/NewtonMetre.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Pascal.cs b/OBD.NET/OBD.NET.Common/DataTypes/Pascal.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Pascal.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Pascal.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Percent.cs b/OBD.NET/OBD.NET.Common/DataTypes/Percent.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Percent.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Percent.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Ratio.cs b/OBD.NET/OBD.NET.Common/DataTypes/Ratio.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Ratio.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Ratio.cs diff --git a/OBD.NET/OBD.NET/DataTypes/RevolutionsPerMinute.cs b/OBD.NET/OBD.NET.Common/DataTypes/RevolutionsPerMinute.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/RevolutionsPerMinute.cs rename to OBD.NET/OBD.NET.Common/DataTypes/RevolutionsPerMinute.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Second.cs b/OBD.NET/OBD.NET.Common/DataTypes/Second.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Second.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Second.cs diff --git a/OBD.NET/OBD.NET/DataTypes/Volt.cs b/OBD.NET/OBD.NET.Common/DataTypes/Volt.cs similarity index 100% rename from OBD.NET/OBD.NET/DataTypes/Volt.cs rename to OBD.NET/OBD.NET.Common/DataTypes/Volt.cs diff --git a/OBD.NET/OBD.NET.Common/Devices/Command.cs b/OBD.NET/OBD.NET.Common/Devices/Command.cs new file mode 100644 index 0000000..c3b306c --- /dev/null +++ b/OBD.NET/OBD.NET.Common/Devices/Command.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OBD.NET.Common.Devices +{ + /// + /// Class used for queued command + /// + public class QueuedCommand + { + + /// + /// Initializes a new instance + /// + /// + public QueuedCommand(string commandText) + { + CommandResult = new CommandResult(); + CommandText = commandText; + } + + public string CommandText { get; set; } + + public CommandResult CommandResult { get; } + } +} diff --git a/OBD.NET/OBD.NET.Common/Devices/CommandResult.cs b/OBD.NET/OBD.NET.Common/Devices/CommandResult.cs new file mode 100644 index 0000000..7352301 --- /dev/null +++ b/OBD.NET/OBD.NET.Common/Devices/CommandResult.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OBD.NET.Util; + +namespace OBD.NET.Common.Devices +{ + public class CommandResult + { + public CommandResult() + { + WaitHandle = new AsyncManualResetEvent(); + } + + public object Result { get; set; } + public AsyncManualResetEvent WaitHandle { get; } + } +} diff --git a/OBD.NET/OBD.NET/Devices/ELM327.cs b/OBD.NET/OBD.NET.Common/Devices/ELM327.cs similarity index 78% rename from OBD.NET/OBD.NET/Devices/ELM327.cs rename to OBD.NET/OBD.NET.Common/Devices/ELM327.cs index ca7e445..170f561 100644 --- a/OBD.NET/OBD.NET/Devices/ELM327.cs +++ b/OBD.NET/OBD.NET.Common/Devices/ELM327.cs @@ -9,6 +9,7 @@ using OBD.NET.Events.EventArgs; using OBD.NET.Extensions; using OBD.NET.Logging; using OBD.NET.OBDData; +using System.Threading.Tasks; namespace OBD.NET.Devices { @@ -22,7 +23,7 @@ namespace OBD.NET.Devices protected static Dictionary DataTypeCache { get; } = new Dictionary(); protected Mode Mode { get; set; } = Mode.ShowCurrentData; //TODO DarthAffe 26.06.2016: Implement different modes - + #endregion #region Events @@ -36,7 +37,7 @@ namespace OBD.NET.Devices #region Constructors - public ELM327(SerialConnection connection, IOBDLogger logger = null) + public ELM327(ISerialConnection connection, IOBDLogger logger = null) : base(connection, logger: logger) { } @@ -44,17 +45,26 @@ namespace OBD.NET.Devices #region Methods + public override async Task InitializeAsync() + { + await base.InitializeAsync(); + InternalInitialize(); + } + public override void Initialize() { base.Initialize(); + InternalInitialize(); + } + private void InternalInitialize() + { Logger?.WriteLine("Initializing ...", OBDLogLevel.Debug); try { Logger?.WriteLine("Resetting Device ...", OBDLogLevel.Debug); SendCommand(ATCommand.ResetDevice); - Thread.Sleep(1000); Logger?.WriteLine("Turning Echo Off ...", OBDLogLevel.Debug); SendCommand(ATCommand.EchoOff); @@ -71,7 +81,6 @@ namespace OBD.NET.Devices Logger?.WriteLine("Setting the Protocol to 'Auto' ...", OBDLogLevel.Debug); SendCommand(ATCommand.SetProtocolAuto); - Thread.Sleep(1000); } // DarthAffe 21.02.2017: This seems to happen sometimes, i don't know why - just retry. catch @@ -81,11 +90,20 @@ namespace OBD.NET.Devices } } + + /// + /// Sends the AT command. + /// + /// The command. public virtual void SendCommand(ATCommand command) { SendCommand(command.Command); } + /// + /// Requests the data and calls the handler + /// + /// public virtual void RequestData() where T : class, IOBDData, new() { @@ -101,13 +119,33 @@ namespace OBD.NET.Devices SendCommand(((byte)Mode).ToString("X2") + pid.ToString("X2")); } - protected override void ProcessMessage(string message) + /// + /// Requests the data asynchronous and return the data when available + /// + /// + /// + public virtual async Task RequestDataAsync() + where T : class, IOBDData, new() + { + Logger?.WriteLine("Requesting Type " + typeof(T).Name + " ...", OBDLogLevel.Debug); + byte pid = ResolvePid(); + Logger?.WriteLine("Requesting PID " + pid.ToString("X2") + " ...", OBDLogLevel.Debug); + var result = SendCommand(((byte)Mode).ToString("X2") + pid.ToString("X2")); + + await result.WaitHandle.WaitAsync(); + return result.Result as T; + } + + + + protected override object ProcessMessage(string message) { DateTime timestamp = DateTime.Now; RawDataReceived?.Invoke(this, new RawDataReceivedEventArgs(message, timestamp)); if (message.Length > 4) + { if (message[0] == '4') { byte mode = (byte)message[1].GetHexVal(); @@ -119,13 +157,17 @@ namespace OBD.NET.Devices { IOBDData obdData = (IOBDData)Activator.CreateInstance(dataType); obdData.Load(message.Substring(4, message.Length - 4)); - + IDataEventManager dataEventManager; if (_dataReceivedEventHandlers.TryGetValue(dataType, out dataEventManager)) dataEventManager.RaiseEvent(this, obdData, timestamp); + + return obdData; } } } + } + return null; } protected virtual byte ResolvePid() @@ -155,12 +197,11 @@ namespace OBD.NET.Devices if (sendCloseProtocol) { SendCommand(ATCommand.CloseProtocol); - Thread.Sleep(500); } } catch { } - _dataReceivedEventHandlers = null; + _dataReceivedEventHandlers.Clear(); base.Dispose(); } diff --git a/OBD.NET/OBD.NET/Devices/STN1170.cs b/OBD.NET/OBD.NET.Common/Devices/STN1170.cs similarity index 80% rename from OBD.NET/OBD.NET/Devices/STN1170.cs rename to OBD.NET/OBD.NET.Common/Devices/STN1170.cs index 8439124..af35037 100644 --- a/OBD.NET/OBD.NET/Devices/STN1170.cs +++ b/OBD.NET/OBD.NET.Common/Devices/STN1170.cs @@ -9,7 +9,7 @@ namespace OBD.NET.Devices #region Constructors - public STN1170(SerialConnection connection, IOBDLogger logger = null) + public STN1170(ISerialConnection connection, IOBDLogger logger = null) : base(connection, logger) { } diff --git a/OBD.NET/OBD.NET.Common/Devices/SerialDevice.cs b/OBD.NET/OBD.NET.Common/Devices/SerialDevice.cs new file mode 100644 index 0000000..d9c8dcc --- /dev/null +++ b/OBD.NET/OBD.NET.Common/Devices/SerialDevice.cs @@ -0,0 +1,256 @@ +using System; +using OBD.NET.Communication; +using OBD.NET.Exceptions; +using OBD.NET.Logging; +using System.Threading.Tasks; +using OBD.NET.Common.Communication.EventArgs; +using System.Text; +using System.Threading; +using System.Collections.Concurrent; +using OBD.NET.Common.Devices; + +namespace OBD.NET.Devices +{ + /// + /// Base class used for communicating with the device + /// + public abstract class SerialDevice : IDisposable + { + private BlockingCollection commandQueue; + + private readonly StringBuilder _lineBuffer = new StringBuilder(); + + private readonly AutoResetEvent commandFinishedEvent = new AutoResetEvent(false); + + private Task commandWorkerTask; + + private CancellationTokenSource commandCancellationToken; + + protected QueuedCommand currentCommand; + + /// + /// Logger instance + /// + protected IOBDLogger Logger { get; } + + /// + /// Low level connection + /// + protected ISerialConnection Connection { get; } + + /// + /// Terminator of the protocol message + /// + protected char Terminator { get; set; } + + + #region Constructors + + /// + /// Prevents a default instance of the class from being created. + /// + private SerialDevice() + { + commandQueue = new BlockingCollection(); + } + + /// + /// Initializes a new instance of the class. + /// + /// connection. + /// terminator used for terminating the command message + /// logger instance + protected SerialDevice(ISerialConnection connection, char terminator = '\r', IOBDLogger logger = null) + :this() + { + Connection = connection; + Terminator = terminator; + Logger = logger; + + connection.DataReceived += OnDataReceived; + } + + + #endregion + + #region Methods + + + /// + /// Initializes the device + /// + public virtual void Initialize() + { + Connection.Connect(); + CheckConnectionAndStartWorker(); + } + + /// + /// Initializes the device + /// + public virtual async Task InitializeAsync() + { + await Connection.ConnectAsync(); + CheckConnectionAndStartWorker(); + } + + /// + /// Checks the connection and starts background worker which is sending the commands + /// + /// Failed to open Serial-Connection. + private void CheckConnectionAndStartWorker() + { + if (!Connection.IsOpen) + { + Logger?.WriteLine("Failed to open Serial-Connection.", OBDLogLevel.Error); + throw new SerialException("Failed to open Serial-Connection."); + } + else + { + Logger?.WriteLine("Opened Serial-Connection!", OBDLogLevel.Debug); + } + + commandCancellationToken = new CancellationTokenSource(); + commandWorkerTask = Task.Factory.StartNew(CommandWorker); + } + + + /// + /// Sends the command. + /// + /// command string + /// Not connected + protected virtual CommandResult SendCommand(string command) + { + if (!Connection.IsOpen) + { + throw new InvalidOperationException("Not connected"); + } + + + command = PrepareCommand(command); + Logger?.WriteLine("Queuing Command: '" + command.Replace('\r', '\'') + "'", OBDLogLevel.Verbose); + + var cmd = new QueuedCommand(command); + commandQueue.Add(cmd); + return cmd.CommandResult; + } + + /// + /// Prepares the command + /// + /// + /// + protected virtual string PrepareCommand(string command) + { + if (command == null) throw new ArgumentNullException(nameof(command)); + + if (!command.EndsWith(Terminator.ToString(), StringComparison.Ordinal)) + command += Terminator; + + return command; + } + + /// + /// Called when data is received from the serial device + /// + /// The sender. + /// The instance containing the event data. + private void OnDataReceived(object sender, DataReceivedEventArgs e) + { + for (int i = 0; i < e.Count; i++) + { + char c = (char)e.Data[i]; + switch (c) + { + case '\r': + FinishLine(); + break; + + case '>': + currentCommand.CommandResult.WaitHandle.Set(); + commandFinishedEvent.Set(); + break; + + case '\n': + case (char)0x00: + break; // ignore + + default: + _lineBuffer.Append(c); + break; + } + } + } + + /// + /// Signals a final message + /// + private void FinishLine() + { + string line = _lineBuffer.ToString().Trim(); + _lineBuffer.Clear(); + + if (string.IsNullOrWhiteSpace(line)) return; + Logger?.WriteLine("Response: '" + line + "'", OBDLogLevel.Verbose); + + InternalProcessMessage(line); + } + + /// + /// Process message and sets the result + /// + /// The message. + private void InternalProcessMessage(string message) + { + var data = ProcessMessage(message); + currentCommand.CommandResult.Result = data; + } + + /// + /// Processes the message. + /// + /// message received + /// result data + protected abstract object ProcessMessage(string message); + + /// + /// Worker method for sending commands + /// + private async void CommandWorker() + { + while (!commandCancellationToken.IsCancellationRequested) + { + currentCommand = null; + if(commandQueue.TryTake(out currentCommand, Timeout.Infinite, commandCancellationToken.Token)) + { + Logger?.WriteLine("Writing Command: '" + currentCommand.CommandText.Replace('\r', '\'') + "'", OBDLogLevel.Verbose); + + if (Connection.IsAsync) + { + await Connection.WriteAsync(Encoding.ASCII.GetBytes(currentCommand.CommandText)); + } + else + { + Connection.Write(Encoding.ASCII.GetBytes(currentCommand.CommandText)); + + } + //wait for command to finish + commandFinishedEvent.WaitOne(); + } + } + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public virtual void Dispose() + { + commandCancellationToken?.Cancel(); + commandWorkerTask?.Wait(); + Connection?.Dispose(); + } + + #endregion + } +} diff --git a/OBD.NET/OBD.NET/Enums/Mode.cs b/OBD.NET/OBD.NET.Common/Enums/Mode.cs similarity index 100% rename from OBD.NET/OBD.NET/Enums/Mode.cs rename to OBD.NET/OBD.NET.Common/Enums/Mode.cs diff --git a/OBD.NET/OBD.NET/Events/EventArgs/DataReceivedEventArgs.cs b/OBD.NET/OBD.NET.Common/Events/EventArgs/DataReceivedEventArgs.cs similarity index 100% rename from OBD.NET/OBD.NET/Events/EventArgs/DataReceivedEventArgs.cs rename to OBD.NET/OBD.NET.Common/Events/EventArgs/DataReceivedEventArgs.cs diff --git a/OBD.NET/OBD.NET/Events/EventArgs/RawDataReceivedEventArgs.cs b/OBD.NET/OBD.NET.Common/Events/EventArgs/RawDataReceivedEventArgs.cs similarity index 100% rename from OBD.NET/OBD.NET/Events/EventArgs/RawDataReceivedEventArgs.cs rename to OBD.NET/OBD.NET.Common/Events/EventArgs/RawDataReceivedEventArgs.cs diff --git a/OBD.NET/OBD.NET/Events/GenericDataEventManager.cs b/OBD.NET/OBD.NET.Common/Events/GenericDataEventManager.cs similarity index 100% rename from OBD.NET/OBD.NET/Events/GenericDataEventManager.cs rename to OBD.NET/OBD.NET.Common/Events/GenericDataEventManager.cs diff --git a/OBD.NET/OBD.NET/Events/IDataEventManager.cs b/OBD.NET/OBD.NET.Common/Events/IDataEventManager.cs similarity index 100% rename from OBD.NET/OBD.NET/Events/IDataEventManager.cs rename to OBD.NET/OBD.NET.Common/Events/IDataEventManager.cs diff --git a/OBD.NET/OBD.NET/Exceptions/SerialException.cs b/OBD.NET/OBD.NET.Common/Exceptions/SerialException.cs similarity index 71% rename from OBD.NET/OBD.NET/Exceptions/SerialException.cs rename to OBD.NET/OBD.NET.Common/Exceptions/SerialException.cs index 74413e7..d6fc529 100644 --- a/OBD.NET/OBD.NET/Exceptions/SerialException.cs +++ b/OBD.NET/OBD.NET.Common/Exceptions/SerialException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace OBD.NET.Exceptions { @@ -17,10 +16,7 @@ namespace OBD.NET.Exceptions public SerialException(string message, Exception innerException) : base(message, innerException) { } - - protected SerialException(SerializationInfo info, StreamingContext context) - : base(info, context) - { } + #endregion } diff --git a/OBD.NET/OBD.NET/Exceptions/UnexpectedResultException.cs b/OBD.NET/OBD.NET.Common/Exceptions/UnexpectedResultException.cs similarity index 78% rename from OBD.NET/OBD.NET/Exceptions/UnexpectedResultException.cs rename to OBD.NET/OBD.NET.Common/Exceptions/UnexpectedResultException.cs index d6b4f82..5c6dab5 100644 --- a/OBD.NET/OBD.NET/Exceptions/UnexpectedResultException.cs +++ b/OBD.NET/OBD.NET.Common/Exceptions/UnexpectedResultException.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.Serialization; namespace OBD.NET.Exceptions { @@ -34,13 +33,7 @@ namespace OBD.NET.Exceptions this.Result = result; this.ExpectedResult = expectedResult; } - - protected UnexpectedResultException(SerializationInfo info, StreamingContext context, string result, string expectedResult) - : base(info, context) - { - this.Result = result; - this.ExpectedResult = expectedResult; - } + #endregion } diff --git a/OBD.NET/OBD.NET/Extensions/HexExtension.cs b/OBD.NET/OBD.NET.Common/Extensions/HexExtension.cs similarity index 100% rename from OBD.NET/OBD.NET/Extensions/HexExtension.cs rename to OBD.NET/OBD.NET.Common/Extensions/HexExtension.cs diff --git a/OBD.NET/OBD.NET/Logging/IOBDLogger.cs b/OBD.NET/OBD.NET.Common/Logging/IOBDLogger.cs similarity index 100% rename from OBD.NET/OBD.NET/Logging/IOBDLogger.cs rename to OBD.NET/OBD.NET.Common/Logging/IOBDLogger.cs diff --git a/OBD.NET/OBD.NET.Common/Logging/OBDDebugLogger.cs b/OBD.NET/OBD.NET.Common/Logging/OBDDebugLogger.cs new file mode 100644 index 0000000..949c490 --- /dev/null +++ b/OBD.NET/OBD.NET.Common/Logging/OBDDebugLogger.cs @@ -0,0 +1,17 @@ +using OBD.NET.Logging; +using System.Diagnostics; + +namespace OBD.NET.Common.Logging +{ + /// + /// Simple debug logger + /// + /// + public class OBDDebugLogger : IOBDLogger + { + public void WriteLine(string text, OBDLogLevel level) + { + Debug.WriteLine($"{level}: {text}"); + } + } +} diff --git a/OBD.NET/OBD.NET/Logging/OBDLogLevel.cs b/OBD.NET/OBD.NET.Common/Logging/OBDLogLevel.cs similarity index 100% rename from OBD.NET/OBD.NET/Logging/OBDLogLevel.cs rename to OBD.NET/OBD.NET.Common/Logging/OBDLogLevel.cs diff --git a/OBD.NET/OBD.NET.Common/OBD.NET.Common.csproj b/OBD.NET/OBD.NET.Common/OBD.NET.Common.csproj new file mode 100644 index 0000000..f82f963 --- /dev/null +++ b/OBD.NET/OBD.NET.Common/OBD.NET.Common.csproj @@ -0,0 +1,17 @@ + + + + netstandard1.4 + Wyrez / Roman Lumetsberger + - + OBD.NET + C#-Library to read/write data from/to a car through an ELM327-/STN1170-Adapter + True + 1.1.0 + + + + + + + \ No newline at end of file diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/AuxiliaryInputStatus.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/AuxiliaryInputStatus.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/AuxiliaryInputStatus.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/AuxiliaryInputStatus.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/CalculatedEngineLoad.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/CalculatedEngineLoad.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/CalculatedEngineLoad.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/CalculatedEngineLoad.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/CommandedSecondaryAirStatus.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/CommandedSecondaryAirStatus.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/CommandedSecondaryAirStatus.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/CommandedSecondaryAirStatus.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/EngineCoolantTemperature.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/EngineCoolantTemperature.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/EngineCoolantTemperature.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/EngineCoolantTemperature.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/EngineRPM.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/EngineRPM.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/EngineRPM.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/EngineRPM.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/FuelPressure.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/FuelPressure.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/FuelPressure.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/FuelPressure.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/FuelSystemStatus.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/FuelSystemStatus.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/FuelSystemStatus.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/FuelSystemStatus.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/IntakeAirTemperature.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/IntakeAirTemperature.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/IntakeAirTemperature.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/IntakeAirTemperature.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/IntakeManifoldAbsolutePressure.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/IntakeManifoldAbsolutePressure.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/IntakeManifoldAbsolutePressure.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/IntakeManifoldAbsolutePressure.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/LongTermFuelTrimBank1.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/LongTermFuelTrimBank1.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/LongTermFuelTrimBank1.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/LongTermFuelTrimBank1.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/LongTermFuelTrimBank2.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/LongTermFuelTrimBank2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/LongTermFuelTrimBank2.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/LongTermFuelTrimBank2.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/MAFAirFlowRate.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/MAFAirFlowRate.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/MAFAirFlowRate.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/MAFAirFlowRate.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OBDStandards.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OBDStandards.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OBDStandards.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OBDStandards.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor1FuelTrim.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor1FuelTrim.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor1FuelTrim.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor1FuelTrim.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor2FuelTrim.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor2FuelTrim.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor2FuelTrim.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor2FuelTrim.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor3FuelTrim.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor3FuelTrim.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor3FuelTrim.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor3FuelTrim.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor4FuelTrim.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor4FuelTrim.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor4FuelTrim.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor4FuelTrim.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor5FuelTrim.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor5FuelTrim.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor5FuelTrim.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor5FuelTrim.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor6FuelTrim.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor6FuelTrim.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor6FuelTrim.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor6FuelTrim.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor7FuelTrim.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor7FuelTrim.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor7FuelTrim.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor7FuelTrim.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor8FuelTrim.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor8FuelTrim.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensor8FuelTrim.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensor8FuelTrim.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensorPresent.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensorPresent.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensorPresent.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensorPresent.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensorsPresent2.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensorsPresent2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/OxygenSensorsPresent2.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/OxygenSensorsPresent2.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/PidsSupported01_20.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/PidsSupported01_20.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/PidsSupported01_20.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/PidsSupported01_20.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/RunTimeSinceEngineStart.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/RunTimeSinceEngineStart.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/RunTimeSinceEngineStart.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/RunTimeSinceEngineStart.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/ShortTermFuelTrimBank1.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/ShortTermFuelTrimBank1.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/ShortTermFuelTrimBank1.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/ShortTermFuelTrimBank1.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/ShortTermFuelTrimBank2.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/ShortTermFuelTrimBank2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/ShortTermFuelTrimBank2.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/ShortTermFuelTrimBank2.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/ThrottlePosition.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/ThrottlePosition.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/ThrottlePosition.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/ThrottlePosition.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/TimingAdvance.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/TimingAdvance.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/TimingAdvance.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/TimingAdvance.cs diff --git a/OBD.NET/OBD.NET/OBDData/00-1F/VehicleSpeed.cs b/OBD.NET/OBD.NET.Common/OBDData/00-1F/VehicleSpeed.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/00-1F/VehicleSpeed.cs rename to OBD.NET/OBD.NET.Common/OBDData/00-1F/VehicleSpeed.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/AbsoluteBarometricPressure.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/AbsoluteBarometricPressure.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/AbsoluteBarometricPressure.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/AbsoluteBarometricPressure.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/CatalystTemperatureBank1Sensor1.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/CatalystTemperatureBank1Sensor1.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/CatalystTemperatureBank1Sensor1.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/CatalystTemperatureBank1Sensor1.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/CatalystTemperatureBank1Sensor2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/CatalystTemperatureBank1Sensor2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/CatalystTemperatureBank1Sensor2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/CatalystTemperatureBank1Sensor2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/CatalystTemperatureBank2Sensor1.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/CatalystTemperatureBank2Sensor1.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/CatalystTemperatureBank2Sensor1.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/CatalystTemperatureBank2Sensor1.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/CatalystTemperatureBank2Sensor2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/CatalystTemperatureBank2Sensor2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/CatalystTemperatureBank2Sensor2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/CatalystTemperatureBank2Sensor2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/CommandedEGR.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/CommandedEGR.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/CommandedEGR.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/CommandedEGR.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/CommandedEvaporativePurge.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/CommandedEvaporativePurge.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/CommandedEvaporativePurge.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/CommandedEvaporativePurge.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/DistanceTraveledSinceCodesCleared.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/DistanceTraveledSinceCodesCleared.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/DistanceTraveledSinceCodesCleared.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/DistanceTraveledSinceCodesCleared.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/DistanceTraveledWithMILOn.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/DistanceTraveledWithMILOn.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/DistanceTraveledWithMILOn.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/DistanceTraveledWithMILOn.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/EGRError.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/EGRError.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/EGRError.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/EGRError.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/EvapSystemVaporPressure.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/EvapSystemVaporPressure.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/EvapSystemVaporPressure.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/EvapSystemVaporPressure.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/FuelRailGaugePressure.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/FuelRailGaugePressure.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/FuelRailGaugePressure.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/FuelRailGaugePressure.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/FuelRailPressure.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/FuelRailPressure.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/FuelRailPressure.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/FuelRailPressure.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/FuelTankLevelInput.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/FuelTankLevelInput.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/FuelTankLevelInput.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/FuelTankLevelInput.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor1FuelAir.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor1FuelAir.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor1FuelAir.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor1FuelAir.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor1FuelAir2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor1FuelAir2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor1FuelAir2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor1FuelAir2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor2FuelAir.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor2FuelAir.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor2FuelAir.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor2FuelAir.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor2FuelAir2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor2FuelAir2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor2FuelAir2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor2FuelAir2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor3FuelAir.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor3FuelAir.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor3FuelAir.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor3FuelAir.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor3FuelAir2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor3FuelAir2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor3FuelAir2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor3FuelAir2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor4FuelAir.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor4FuelAir.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor4FuelAir.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor4FuelAir.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor4FuelAir2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor4FuelAir2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor4FuelAir2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor4FuelAir2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor5FuelAir.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor5FuelAir.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor5FuelAir.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor5FuelAir.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor5FuelAir2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor5FuelAir2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor5FuelAir2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor5FuelAir2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor6FuelAir.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor6FuelAir.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor6FuelAir.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor6FuelAir.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor6FuelAir2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor6FuelAir2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor6FuelAir2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor6FuelAir2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor7FuelAir.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor7FuelAir.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor7FuelAir.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor7FuelAir.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor7FuelAir2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor7FuelAir2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor7FuelAir2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor7FuelAir2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor8FuelAir.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor8FuelAir.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor8FuelAir.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor8FuelAir.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor8FuelAir2.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor8FuelAir2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/OxygenSensor8FuelAir2.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/OxygenSensor8FuelAir2.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/PidsSupported21_40.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/PidsSupported21_40.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/PidsSupported21_40.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/PidsSupported21_40.cs diff --git a/OBD.NET/OBD.NET/OBDData/20-3F/WarmUpsSinceCodesCleared.cs b/OBD.NET/OBD.NET.Common/OBDData/20-3F/WarmUpsSinceCodesCleared.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/20-3F/WarmUpsSinceCodesCleared.cs rename to OBD.NET/OBD.NET.Common/OBDData/20-3F/WarmUpsSinceCodesCleared.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/AbsoluteEvapSystemVaporPressure.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/AbsoluteEvapSystemVaporPressure.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/AbsoluteEvapSystemVaporPressure.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/AbsoluteEvapSystemVaporPressure.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/AbsoluteLoadValue.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/AbsoluteLoadValue.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/AbsoluteLoadValue.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/AbsoluteLoadValue.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/AbsoluteThrottlePositionB.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/AbsoluteThrottlePositionB.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/AbsoluteThrottlePositionB.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/AbsoluteThrottlePositionB.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/AbsoluteThrottlePositionC.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/AbsoluteThrottlePositionC.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/AbsoluteThrottlePositionC.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/AbsoluteThrottlePositionC.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/AcceleratorPedalPositionD.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/AcceleratorPedalPositionD.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/AcceleratorPedalPositionD.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/AcceleratorPedalPositionD.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/AcceleratorPedalPositionE.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/AcceleratorPedalPositionE.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/AcceleratorPedalPositionE.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/AcceleratorPedalPositionE.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/AcceleratorPedalPositionF.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/AcceleratorPedalPositionF.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/AcceleratorPedalPositionF.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/AcceleratorPedalPositionF.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/AmbientAirTemperature.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/AmbientAirTemperature.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/AmbientAirTemperature.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/AmbientAirTemperature.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/CommandedThrottleActuator.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/CommandedThrottleActuator.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/CommandedThrottleActuator.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/CommandedThrottleActuator.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/ControlModuleVoltage.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/ControlModuleVoltage.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/ControlModuleVoltage.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/ControlModuleVoltage.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/EngineFuelRate.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/EngineFuelRate.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/EngineFuelRate.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/EngineFuelRate.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/EngineOilTemperature.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/EngineOilTemperature.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/EngineOilTemperature.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/EngineOilTemperature.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/EthanolFuel.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/EthanolFuel.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/EthanolFuel.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/EthanolFuel.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/EvapSystemVaporPressure2.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/EvapSystemVaporPressure2.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/EvapSystemVaporPressure2.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/EvapSystemVaporPressure2.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/FuelAirCommandedEquivalenceRatio.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/FuelAirCommandedEquivalenceRatio.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/FuelAirCommandedEquivalenceRatio.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/FuelAirCommandedEquivalenceRatio.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/FuelInjectionTiming.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/FuelInjectionTiming.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/FuelInjectionTiming.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/FuelInjectionTiming.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/FuelRailAbsolutePressure.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/FuelRailAbsolutePressure.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/FuelRailAbsolutePressure.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/FuelRailAbsolutePressure.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/FuelType.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/FuelType.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/FuelType.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/FuelType.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/HybridBatteryPackRemainingLife.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/HybridBatteryPackRemainingLife.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/HybridBatteryPackRemainingLife.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/HybridBatteryPackRemainingLife.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/LongTermSecondaryOxygenSensorTrimBank13.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/LongTermSecondaryOxygenSensorTrimBank13.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/LongTermSecondaryOxygenSensorTrimBank13.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/LongTermSecondaryOxygenSensorTrimBank13.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/LongTermSecondaryOxygenSensorTrimBank24.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/LongTermSecondaryOxygenSensorTrimBank24.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/LongTermSecondaryOxygenSensorTrimBank24.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/LongTermSecondaryOxygenSensorTrimBank24.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/MaximumValueForAirFlowRate.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/MaximumValueForAirFlowRate.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/MaximumValueForAirFlowRate.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/MaximumValueForAirFlowRate.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/MaximumValues.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/MaximumValues.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/MaximumValues.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/MaximumValues.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/MonitorStatusThisDriveCycle.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/MonitorStatusThisDriveCycle.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/MonitorStatusThisDriveCycle.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/MonitorStatusThisDriveCycle.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/PidsSupported41_60.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/PidsSupported41_60.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/PidsSupported41_60.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/PidsSupported41_60.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/RelativeAcceleratorPedalPosition.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/RelativeAcceleratorPedalPosition.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/RelativeAcceleratorPedalPosition.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/RelativeAcceleratorPedalPosition.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/RelativeThrottlePosition.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/RelativeThrottlePosition.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/RelativeThrottlePosition.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/RelativeThrottlePosition.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/ShortTermSecondaryOxygenSensorTrimBank13.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/ShortTermSecondaryOxygenSensorTrimBank13.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/ShortTermSecondaryOxygenSensorTrimBank13.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/ShortTermSecondaryOxygenSensorTrimBank13.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/ShortTermSecondaryOxygenSensorTrimBank24.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/ShortTermSecondaryOxygenSensorTrimBank24.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/ShortTermSecondaryOxygenSensorTrimBank24.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/ShortTermSecondaryOxygenSensorTrimBank24.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/TimeRunWithMILOn.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/TimeRunWithMILOn.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/TimeRunWithMILOn.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/TimeRunWithMILOn.cs diff --git a/OBD.NET/OBD.NET/OBDData/40-5F/TimeSinceTroubleCodesCleared.cs b/OBD.NET/OBD.NET.Common/OBDData/40-5F/TimeSinceTroubleCodesCleared.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/40-5F/TimeSinceTroubleCodesCleared.cs rename to OBD.NET/OBD.NET.Common/OBDData/40-5F/TimeSinceTroubleCodesCleared.cs diff --git a/OBD.NET/OBD.NET/OBDData/60-7F/ActualEnginePercentTorque.cs b/OBD.NET/OBD.NET.Common/OBDData/60-7F/ActualEnginePercentTorque.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/60-7F/ActualEnginePercentTorque.cs rename to OBD.NET/OBD.NET.Common/OBDData/60-7F/ActualEnginePercentTorque.cs diff --git a/OBD.NET/OBD.NET/OBDData/60-7F/DriversDemandEnginePercentTorque.cs b/OBD.NET/OBD.NET.Common/OBDData/60-7F/DriversDemandEnginePercentTorque.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/60-7F/DriversDemandEnginePercentTorque.cs rename to OBD.NET/OBD.NET.Common/OBDData/60-7F/DriversDemandEnginePercentTorque.cs diff --git a/OBD.NET/OBD.NET/OBDData/60-7F/EnginePercentTorqueData.cs b/OBD.NET/OBD.NET.Common/OBDData/60-7F/EnginePercentTorqueData.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/60-7F/EnginePercentTorqueData.cs rename to OBD.NET/OBD.NET.Common/OBDData/60-7F/EnginePercentTorqueData.cs diff --git a/OBD.NET/OBD.NET/OBDData/60-7F/EngineReferenceTorque.cs b/OBD.NET/OBD.NET.Common/OBDData/60-7F/EngineReferenceTorque.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/60-7F/EngineReferenceTorque.cs rename to OBD.NET/OBD.NET.Common/OBDData/60-7F/EngineReferenceTorque.cs diff --git a/OBD.NET/OBD.NET/OBDData/60-7F/PidsSupported61_80.cs b/OBD.NET/OBD.NET.Common/OBDData/60-7F/PidsSupported61_80.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/60-7F/PidsSupported61_80.cs rename to OBD.NET/OBD.NET.Common/OBDData/60-7F/PidsSupported61_80.cs diff --git a/OBD.NET/OBD.NET/OBDData/80-9F/PidsSupported81_A0.cs b/OBD.NET/OBD.NET.Common/OBDData/80-9F/PidsSupported81_A0.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/80-9F/PidsSupported81_A0.cs rename to OBD.NET/OBD.NET.Common/OBDData/80-9F/PidsSupported81_A0.cs diff --git a/OBD.NET/OBD.NET/OBDData/A0-BF/PidsSupportedA1_C0.cs b/OBD.NET/OBD.NET.Common/OBDData/A0-BF/PidsSupportedA1_C0.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/A0-BF/PidsSupportedA1_C0.cs rename to OBD.NET/OBD.NET.Common/OBDData/A0-BF/PidsSupportedA1_C0.cs diff --git a/OBD.NET/OBD.NET/OBDData/AbstractOBDData.cs b/OBD.NET/OBD.NET.Common/OBDData/AbstractOBDData.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/AbstractOBDData.cs rename to OBD.NET/OBD.NET.Common/OBDData/AbstractOBDData.cs diff --git a/OBD.NET/OBD.NET/OBDData/C0-DF/PidsSupportedC1_E0.cs b/OBD.NET/OBD.NET.Common/OBDData/C0-DF/PidsSupportedC1_E0.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/C0-DF/PidsSupportedC1_E0.cs rename to OBD.NET/OBD.NET.Common/OBDData/C0-DF/PidsSupportedC1_E0.cs diff --git a/OBD.NET/OBD.NET/OBDData/IOBDData.cs b/OBD.NET/OBD.NET.Common/OBDData/IOBDData.cs similarity index 100% rename from OBD.NET/OBD.NET/OBDData/IOBDData.cs rename to OBD.NET/OBD.NET.Common/OBDData/IOBDData.cs diff --git a/OBD.NET/OBD.NET.Common/Util/AsyncManulResetEvent.cs b/OBD.NET/OBD.NET.Common/Util/AsyncManulResetEvent.cs new file mode 100644 index 0000000..4f8f34f --- /dev/null +++ b/OBD.NET/OBD.NET.Common/Util/AsyncManulResetEvent.cs @@ -0,0 +1,48 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace OBD.NET.Util +{ + /// + /// Notifies one or more waiting awaiters that an event has occurred + /// + public class AsyncManualResetEvent + { + private volatile TaskCompletionSource _tcs = new TaskCompletionSource(); + + /// + /// Waits the async. + /// + /// + public Task WaitAsync() + { + return _tcs.Task; + } + + //public void Set() { m_tcs.TrySetResult(true); } + /// + /// Sets the state of the event to signaled, allowing one or more waiting awaiters to proceed. + /// + public void Set() + { + var tcs = _tcs; + Task.Factory.StartNew(s => ((TaskCompletionSource)s).TrySetResult(true), + tcs, CancellationToken.None, TaskCreationOptions.PreferFairness, TaskScheduler.Default); + tcs.Task.Wait(); + } + + /// + /// Sets the state of the event to nonsignaled, causing awaiters to block. + /// + public void Reset() + { + while (true) + { + var tcs = _tcs; + if (!tcs.Task.IsCompleted || + Interlocked.CompareExchange(ref _tcs, new TaskCompletionSource(), tcs) == tcs) + return; + } + } + } +} \ No newline at end of file diff --git a/OBD.NET/OBD.NET.Universal/Communication/BluetoothSerialConnection.cs b/OBD.NET/OBD.NET.Universal/Communication/BluetoothSerialConnection.cs new file mode 100644 index 0000000..dbb7401 --- /dev/null +++ b/OBD.NET/OBD.NET.Universal/Communication/BluetoothSerialConnection.cs @@ -0,0 +1,170 @@ +using System; +using System.Runtime.InteropServices.WindowsRuntime; +using System.Threading; +using System.Threading.Tasks; +using OBD.NET.Common.Communication.EventArgs; +using Windows.Devices.Bluetooth.Rfcomm; +using Windows.Networking.Sockets; +using Windows.Storage.Streams; +using System.Linq; + +namespace OBD.NET.Communication +{ + /// + /// Bluetooth OBD serial implementation + /// + /// + public class BluetoothSerialConnection : ISerialConnection + { + + private StreamSocket _socket; + private DataWriter _writer; + + private readonly byte[] _readBuffer = new byte[1024]; + + private CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); + private Task _readerTask; + + private string device; + + /// + /// Initializes a new instance of the class. + /// + public BluetoothSerialConnection() + { + device = null; + } + + /// + /// Initializes a new instance of the class. + /// + /// Name of the device. + /// The logger. + public BluetoothSerialConnection(string deviceName) + { + device = deviceName; + } + + + /// + /// Gets a value indicating whether this instance is open. + /// + /// + /// true if this instance is open; otherwise, false. + /// + public bool IsOpen { get; private set; } + + /// + /// Gets a value indicating whether this instance uses asynchronous IO + /// + /// + /// Has to be set to true if asynchronous IO is supported. + /// If true async methods have to be implemented + /// + public bool IsAsync => true; + + /// + /// Occurs when a full line was received + /// + public event EventHandler DataReceived; + + /// + /// Connects the serial port. + /// + /// Synchronous operations not supported + public void Connect() + { + throw new NotSupportedException("Synchronous operations not supported on UWP platform"); + } + + /// + /// Connects the serial port asynchronously + /// + /// + public async Task ConnectAsync() + { + var services = await Windows.Devices.Enumeration.DeviceInformation + .FindAllAsync(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort)); + + //use first serial service + if (services.Count > 0) + { + var id = services[0].Id; + + //use predefined device from constructor + if (!string.IsNullOrWhiteSpace(device)) + { + id = services.Where(x => x.Name.Equals(device, StringComparison.OrdinalIgnoreCase)) + .Select(x => x.Id).FirstOrDefault(); + + if (id == null) + { + throw new InvalidOperationException($"Device {device} not found"); + } + } + + // Initialize the target Bluetooth device + var service = await RfcommDeviceService.FromIdAsync(id); + + // Check that the service meets this App's minimum requirement + + _socket = new StreamSocket(); + await _socket.ConnectAsync(service.ConnectionHostName, + service.ConnectionServiceName); + _writer = new DataWriter(_socket.OutputStream); + _readerTask = StartReader(); + IsOpen = true; + } + } + + /// + /// Writes the specified text to the serial connection + /// + /// The text. + /// Synchronous operations not supported + public void Write(byte[] data) + { + throw new NotImplementedException("Synchronous operations not supported on UWP platform"); + } + + /// + /// Writes the specified text to the serial connection asynchronously + /// + /// The text. + /// + public async Task WriteAsync(byte[] data) + { + _writer.WriteBytes(data); + await _writer.StoreAsync(); + await _writer.FlushAsync(); + } + + private Task StartReader() + { + return Task.Factory.StartNew(async () => + { + + var buffer = _readBuffer.AsBuffer(); + while (!_cancellationTokenSource.IsCancellationRequested) + { + var readData = await _socket.InputStream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.Partial); + SerialPortOnDataReceived(readData); + } + }, _cancellationTokenSource.Token); + } + + private void SerialPortOnDataReceived(IBuffer buffer) + { + DataReceived?.Invoke(this, new DataReceivedEventArgs((int)buffer.Length, _readBuffer)); + } + + + public void Dispose() + { + _cancellationTokenSource?.Cancel(); + _readerTask?.Wait(); + _socket?.Dispose(); + } + + } +} diff --git a/OBD.NET/OBD.NET.Universal/OBD.NET.Universal.csproj b/OBD.NET/OBD.NET.Universal/OBD.NET.Universal.csproj new file mode 100644 index 0000000..f35a990 --- /dev/null +++ b/OBD.NET/OBD.NET.Universal/OBD.NET.Universal.csproj @@ -0,0 +1,138 @@ + + + + + Debug + AnyCPU + {E0EAFF82-C514-4827-8F49-F1928EBA8E73} + Library + Properties + OBD.NET.Universal + OBD.NET.Universal + en-US + UAP + 10.0.15063.0 + 10.0.10586.0 + 14 + 512 + {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + prompt + 4 + + + x86 + true + bin\x86\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x86 + false + prompt + + + x86 + bin\x86\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x86 + false + prompt + + + ARM + true + bin\ARM\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + ARM + false + prompt + + + ARM + bin\ARM\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + ARM + false + prompt + + + x64 + true + bin\x64\Debug\ + DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP + ;2008 + full + x64 + false + prompt + + + x64 + bin\x64\Release\ + TRACE;NETFX_CORE;WINDOWS_UWP + true + ;2008 + pdbonly + x64 + false + prompt + + + PackageReference + + + + + + + + + 5.2.3 + + + + + {d985b70e-cdf3-4cf1-ab5d-8d19c7fe7b31} + OBD.NET.Common + + + + + + + 14.0 + + + + \ No newline at end of file diff --git a/OBD.NET/OBD.NET.Universal/OBD.NET.Universal.nuspec b/OBD.NET/OBD.NET.Universal/OBD.NET.Universal.nuspec new file mode 100644 index 0000000..5fcc230 --- /dev/null +++ b/OBD.NET/OBD.NET.Universal/OBD.NET.Universal.nuspec @@ -0,0 +1,15 @@ + + + + $id$ + $version$ + $title$ + $author$ + $author$ + https://github.com/romanlum/OBD.NET + false + $description$ + Initial release. + Copyright 2017 + + \ No newline at end of file diff --git a/OBD.NET/OBD.NET.Universal/Properties/AssemblyInfo.cs b/OBD.NET/OBD.NET.Universal/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..483f8d8 --- /dev/null +++ b/OBD.NET/OBD.NET.Universal/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OBD.NET.Universal")] +[assembly: AssemblyDescription("C#-Library to read/write data from/to a car through an ELM327-/STN1170-Adapter on UWP")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Roman Lumetsberger")] +[assembly: AssemblyProduct("OBD.NET")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: ComVisible(false)] \ No newline at end of file diff --git a/OBD.NET/OBD.NET.Universal/Properties/OBD.NET.Universal.rd.xml b/OBD.NET/OBD.NET.Universal/Properties/OBD.NET.Universal.rd.xml new file mode 100644 index 0000000..874b02e --- /dev/null +++ b/OBD.NET/OBD.NET.Universal/Properties/OBD.NET.Universal.rd.xml @@ -0,0 +1,33 @@ + + + + + + + + + diff --git a/OBD.NET/OBD.NET.sln b/OBD.NET/OBD.NET.sln index 0656bde..c8614b3 100644 --- a/OBD.NET/OBD.NET.sln +++ b/OBD.NET/OBD.NET.sln @@ -1,20 +1,92 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26403.7 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OBD.NET", "OBD.NET\OBD.NET.csproj", "{C97E0C5B-0571-41A3-9257-90BB48E46DCF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OBD.NET.Common", "OBD.NET.Common\OBD.NET.Common.csproj", "{D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODB.NET.Desktop", "ODB.NET.Desktop\ODB.NET.Desktop.csproj", "{14CB98E1-95DE-4923-8896-FDF5171AA49E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OBD.NET.Universal", "OBD.NET.Universal\OBD.NET.Universal.csproj", "{E0EAFF82-C514-4827-8F49-F1928EBA8E73}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ODB.NET.ConsoleClient", "ODB.NET.ConsoleClient\ODB.NET.ConsoleClient.csproj", "{8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|ARM = Debug|ARM + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|ARM = Release|ARM + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C97E0C5B-0571-41A3-9257-90BB48E46DCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C97E0C5B-0571-41A3-9257-90BB48E46DCF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C97E0C5B-0571-41A3-9257-90BB48E46DCF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C97E0C5B-0571-41A3-9257-90BB48E46DCF}.Release|Any CPU.Build.0 = Release|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Debug|ARM.ActiveCfg = Debug|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Debug|ARM.Build.0 = Debug|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Debug|x64.ActiveCfg = Debug|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Debug|x64.Build.0 = Debug|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Debug|x86.ActiveCfg = Debug|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Debug|x86.Build.0 = Debug|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Release|Any CPU.Build.0 = Release|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Release|ARM.ActiveCfg = Release|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Release|ARM.Build.0 = Release|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Release|x64.ActiveCfg = Release|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Release|x64.Build.0 = Release|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Release|x86.ActiveCfg = Release|Any CPU + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31}.Release|x86.Build.0 = Release|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Debug|ARM.ActiveCfg = Debug|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Debug|ARM.Build.0 = Debug|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Debug|x64.ActiveCfg = Debug|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Debug|x64.Build.0 = Debug|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Debug|x86.ActiveCfg = Debug|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Debug|x86.Build.0 = Debug|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|Any CPU.Build.0 = Release|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|ARM.ActiveCfg = Release|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|ARM.Build.0 = Release|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x64.ActiveCfg = Release|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x64.Build.0 = Release|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x86.ActiveCfg = Release|Any CPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E}.Release|x86.Build.0 = Release|Any CPU + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|ARM.ActiveCfg = Debug|ARM + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|ARM.Build.0 = Debug|ARM + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|x64.ActiveCfg = Debug|x64 + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|x64.Build.0 = Debug|x64 + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|x86.ActiveCfg = Debug|x86 + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Debug|x86.Build.0 = Debug|x86 + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|Any CPU.Build.0 = Release|Any CPU + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|ARM.ActiveCfg = Release|ARM + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|ARM.Build.0 = Release|ARM + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|x64.ActiveCfg = Release|x64 + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|x64.Build.0 = Release|x64 + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|x86.ActiveCfg = Release|x86 + {E0EAFF82-C514-4827-8F49-F1928EBA8E73}.Release|x86.Build.0 = Release|x86 + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|ARM.ActiveCfg = Debug|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|ARM.Build.0 = Debug|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|x64.ActiveCfg = Debug|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|x64.Build.0 = Debug|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|x86.ActiveCfg = Debug|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Debug|x86.Build.0 = Debug|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Release|Any CPU.Build.0 = Release|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Release|ARM.ActiveCfg = Release|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Release|ARM.Build.0 = Release|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Release|x64.ActiveCfg = Release|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Release|x64.Build.0 = Release|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Release|x86.ActiveCfg = Release|Any CPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/OBD.NET/OBD.NET/Devices/SerialDevice.cs b/OBD.NET/OBD.NET/Devices/SerialDevice.cs deleted file mode 100644 index 67fb3dc..0000000 --- a/OBD.NET/OBD.NET/Devices/SerialDevice.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using OBD.NET.Communication; -using OBD.NET.Exceptions; -using OBD.NET.Logging; - -namespace OBD.NET.Devices -{ - public abstract class SerialDevice : IDisposable - { - #region Properties & Fields - - protected IOBDLogger Logger { get; } - - protected SerialConnection Connection { get; } - protected char Terminator { get; set; } - - #endregion - - #region Constructors - - protected SerialDevice(SerialConnection connection, char terminator = '\r', IOBDLogger logger = null) - { - this.Connection = connection; - this.Terminator = terminator; - this.Logger = logger; - - connection.MessageReceived += SerialMessageReceived; - } - - #endregion - - #region Methods - - public virtual void Initialize() - { - Logger?.WriteLine("Opening Serial-Connection ...", OBDLogLevel.Debug); - Connection.Connect(); - - if (!Connection.IsOpen) - { - Logger?.WriteLine("Failed to open Serial-Connection.", OBDLogLevel.Error); - throw new SerialException("Failed to open Serial-Connection."); - } - else - Logger?.WriteLine("Opened Serial-Connection!", OBDLogLevel.Debug); - } - - protected virtual void SendCommand(string command) - { - if (!Connection.IsOpen) return; - - command = PrepareCommand(command); - - Logger?.WriteLine("Writing Command: '" + command.Replace('\r', '\'') + "'", OBDLogLevel.Verbose); - Connection.Write(command); - } - - protected virtual string PrepareCommand(string command) - { - if (command == null) throw new ArgumentNullException(nameof(command)); - - if (!command.EndsWith(Terminator.ToString(), StringComparison.Ordinal)) - command += Terminator; - - return command; - } - - private void SerialMessageReceived(object sender, string message) - { - if (string.IsNullOrWhiteSpace(message)) return; - - Logger?.WriteLine("Response: '" + message + "'", OBDLogLevel.Verbose); - ProcessMessage(message.Trim()); - } - - protected abstract void ProcessMessage(string message); - - public virtual void Dispose() - { - Connection?.Dispose(); - } - - #endregion - } -} diff --git a/OBD.NET/OBD.NET/OBD.NET.csproj b/OBD.NET/OBD.NET/OBD.NET.csproj deleted file mode 100644 index 0c0204a..0000000 --- a/OBD.NET/OBD.NET/OBD.NET.csproj +++ /dev/null @@ -1,197 +0,0 @@ - - - - - Debug - AnyCPU - {C97E0C5B-0571-41A3-9257-90BB48E46DCF} - Library - Properties - OBD.NET - OBD.NET - v4.5 - 512 - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OBD.NET/OBD.NET/OBD.NET.csproj.DotSettings b/OBD.NET/OBD.NET/OBD.NET.csproj.DotSettings deleted file mode 100644 index ca3a58b..0000000 --- a/OBD.NET/OBD.NET/OBD.NET.csproj.DotSettings +++ /dev/null @@ -1,8 +0,0 @@ - - True - True - True - True - True - True - True \ No newline at end of file diff --git a/OBD.NET/ODB.NET.ConsoleClient/App.config b/OBD.NET/ODB.NET.ConsoleClient/App.config new file mode 100644 index 0000000..d1428ad --- /dev/null +++ b/OBD.NET/ODB.NET.ConsoleClient/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/OBD.NET/ODB.NET.ConsoleClient/ODB.NET.ConsoleClient.csproj b/OBD.NET/ODB.NET.ConsoleClient/ODB.NET.ConsoleClient.csproj new file mode 100644 index 0000000..950d5eb --- /dev/null +++ b/OBD.NET/ODB.NET.ConsoleClient/ODB.NET.ConsoleClient.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {8F8EC5D5-94BD-47CF-9714-CA8C0198BDDC} + Exe + ODB.NET.ConsoleClient + ODB.NET.ConsoleClient + v4.5 + 512 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {D985B70E-CDF3-4CF1-AB5D-8D19C7FE7B31} + OBD.NET.Common + + + {14CB98E1-95DE-4923-8896-FDF5171AA49E} + ODB.NET.Desktop + + + + \ No newline at end of file diff --git a/OBD.NET/ODB.NET.ConsoleClient/Program.cs b/OBD.NET/ODB.NET.ConsoleClient/Program.cs new file mode 100644 index 0000000..f8f8e02 --- /dev/null +++ b/OBD.NET/ODB.NET.ConsoleClient/Program.cs @@ -0,0 +1,84 @@ +using OBD.NET.Common.Logging; +using OBD.NET.Communication; +using OBD.NET.Devices; +using OBD.NET.Logging; +using OBD.NET.OBDData; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace ODB.NET.ConsoleClient +{ + /// + /// Console test client + /// + class Program + { + static void Main(string[] args) + { + if (args.Length < 1) + { + Console.WriteLine("Parameter ComPort needed."); + return; + } + + var comPort = args[0]; + + using (SerialConnection connection = new SerialConnection(comPort)) + using (ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug))) + { + dev.SubscribeDataReceived((sender, data) => + { + Console.WriteLine("EngineRPM: " + data.Data.Rpm); + }); + + dev.SubscribeDataReceived((sender, data) => + { + Console.WriteLine("VehicleSpeed: " + data.Data.Speed); + }); + + dev.Initialize(); + dev.RequestData(); + for (int i = 0; i < 5; i++) + { + dev.RequestData(); + dev.RequestData(); + Thread.Sleep(1000); + } + Console.ReadLine(); + } + + //Async example + MainAsync(comPort).Wait(); + + } + + /// + /// Async example using new RequestDataAsync + /// + /// The COM port. + /// + public static async Task MainAsync(string comPort) + { + using (SerialConnection connection = new SerialConnection(comPort)) + using (ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug))) + { + dev.Initialize(); + var data = await dev.RequestDataAsync(); + Console.WriteLine("Data: " + data.Rpm); + data = await dev.RequestDataAsync(); + Console.WriteLine("Data: " + data.Rpm); + var data2 = await dev.RequestDataAsync(); + Console.WriteLine("Data: " + data2.Speed); + data = await dev.RequestDataAsync(); + Console.WriteLine("Data: " + data.Rpm); + + } + } + } + + +} diff --git a/OBD.NET/ODB.NET.ConsoleClient/Properties/AssemblyInfo.cs b/OBD.NET/ODB.NET.ConsoleClient/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..95594b5 --- /dev/null +++ b/OBD.NET/ODB.NET.ConsoleClient/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ODB.NET.ConsoleClient")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ODB.NET.ConsoleClient")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("8f8ec5d5-94bd-47cf-9714-ca8c0198bddc")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OBD.NET/OBD.NET/Communication/EnhancedSerialPort.cs b/OBD.NET/ODB.NET.Desktop/Communication/EnhancedSerialPort.cs similarity index 100% rename from OBD.NET/OBD.NET/Communication/EnhancedSerialPort.cs rename to OBD.NET/ODB.NET.Desktop/Communication/EnhancedSerialPort.cs diff --git a/OBD.NET/OBD.NET/Communication/SerialConnection.cs b/OBD.NET/ODB.NET.Desktop/Communication/SerialConnection.cs similarity index 60% rename from OBD.NET/OBD.NET/Communication/SerialConnection.cs rename to OBD.NET/ODB.NET.Desktop/Communication/SerialConnection.cs index 3c8aed7..6f8b161 100644 --- a/OBD.NET/OBD.NET/Communication/SerialConnection.cs +++ b/OBD.NET/ODB.NET.Desktop/Communication/SerialConnection.cs @@ -2,10 +2,12 @@ using System.IO.Ports; using System.Text; using System.Threading; +using System.Threading.Tasks; +using OBD.NET.Common.Communication.EventArgs; namespace OBD.NET.Communication { - public class SerialConnection : IDisposable + public class SerialConnection : ISerialConnection { #region Properties & Fields @@ -13,6 +15,7 @@ namespace OBD.NET.Communication private readonly int _timeout; public bool IsOpen => _serialPort?.IsOpen ?? false; + public bool IsAsync => false; private readonly byte[] _readBuffer = new byte[1024]; private readonly StringBuilder _lineBuffer = new StringBuilder(); @@ -23,7 +26,7 @@ namespace OBD.NET.Communication #region Events - public event EventHandler MessageReceived; + public event EventHandler DataReceived; #endregion @@ -51,58 +54,38 @@ namespace OBD.NET.Communication public void Connect() { _serialPort.Open(); - Thread.Sleep(5000); - Write("\r"); - } - - public void Write(string text) - { - if (!_hasPrompt.WaitOne(_timeout)) - throw new TimeoutException("No prompt received"); - - _serialPort.Write(text); } private void SerialPortOnDataReceived(object sender, SerialDataReceivedEventArgs serialDataReceivedEventArgs) { int count = _serialPort.Read(_readBuffer, 0, _serialPort.BytesToRead); - for (int i = 0; i < count; i++) - { - char c = (char)_readBuffer[i]; - switch (c) - { - case '\r': - FinishLine(); - break; - - case '>': - _hasPrompt.Set(); - break; - - case '\n': - case (char)0x00: - break; // ignore - - default: - _lineBuffer.Append(c); - break; - } - } - } - - private void FinishLine() - { - string line = _lineBuffer.ToString(); - _lineBuffer.Clear(); - - MessageReceived?.Invoke(this, line); + DataReceived?.Invoke(this,new DataReceivedEventArgs(count, _readBuffer)); } + public void Dispose() { _serialPort?.Dispose(); } + public Task ConnectAsync() + { + throw new NotSupportedException("Asynchronous operations not supported"); + } + + public Task WriteAsync(byte[] data) + { + throw new NotSupportedException("Asynchronous operations not supported"); + } + + + public void Write(byte[] data) + { + _serialPort.Write(data, 0, data.Length); + } + + + #endregion } } diff --git a/OBD.NET/ODB.NET.Desktop/Logging/ODBConsoleLogger.cs b/OBD.NET/ODB.NET.Desktop/Logging/ODBConsoleLogger.cs new file mode 100644 index 0000000..0e69e0b --- /dev/null +++ b/OBD.NET/ODB.NET.Desktop/Logging/ODBConsoleLogger.cs @@ -0,0 +1,35 @@ +using OBD.NET.Logging; +using System; +using System.Diagnostics; + +namespace OBD.NET.Common.Logging +{ + /// + /// Simple console logger + /// + /// + public class OBDConsoleLogger : IOBDLogger + { + public OBDLogLevel LogLevel { get; set; } + + public OBDConsoleLogger() + { + LogLevel = OBDLogLevel.None; + } + + public OBDConsoleLogger(OBDLogLevel level) + { + LogLevel = level; + } + + public void WriteLine(string text, OBDLogLevel level) + { + if (LogLevel == OBDLogLevel.None) return; + + if((int)level >= (int)LogLevel) + { + Console.WriteLine($"{DateTime.Now.ToString()} - {level} - {text}"); + } + } + } +} diff --git a/OBD.NET/ODB.NET.Desktop/ODB.NET.Desktop.csproj b/OBD.NET/ODB.NET.Desktop/ODB.NET.Desktop.csproj new file mode 100644 index 0000000..57966b5 --- /dev/null +++ b/OBD.NET/ODB.NET.Desktop/ODB.NET.Desktop.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {14CB98E1-95DE-4923-8896-FDF5171AA49E} + Library + Properties + ODB.NET.Desktop + ODB.NET.Desktop + v4.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + {d985b70e-cdf3-4cf1-ab5d-8d19c7fe7b31} + OBD.NET.Common + + + + + + + \ No newline at end of file diff --git a/OBD.NET/ODB.NET.Desktop/ODB.NET.Desktop.nuspec b/OBD.NET/ODB.NET.Desktop/ODB.NET.Desktop.nuspec new file mode 100644 index 0000000..4192d04 --- /dev/null +++ b/OBD.NET/ODB.NET.Desktop/ODB.NET.Desktop.nuspec @@ -0,0 +1,15 @@ + + + + $id$ + $version$ + $title$ + $author$ + $author$ + https://github.com/romanlum/OBD.NET + false + $description$ + Initial release + Copyright 2017 + + \ No newline at end of file diff --git a/OBD.NET/OBD.NET/Properties/AssemblyInfo.cs b/OBD.NET/ODB.NET.Desktop/Properties/AssemblyInfo.cs similarity index 76% rename from OBD.NET/OBD.NET/Properties/AssemblyInfo.cs rename to OBD.NET/ODB.NET.Desktop/Properties/AssemblyInfo.cs index 93aa0d4..9d5a6e1 100644 --- a/OBD.NET/OBD.NET/Properties/AssemblyInfo.cs +++ b/OBD.NET/ODB.NET.Desktop/Properties/AssemblyInfo.cs @@ -2,34 +2,34 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -// General Information about an assembly is controlled through the following +// General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("OBD.NET")] -[assembly: AssemblyDescription("C#-Library to read/write data from/to a car through an ELM327-/STN1170-Adapter")] +[assembly: AssemblyTitle("ODB.NET.Desktop")] +[assembly: AssemblyDescription("C#-Library to read/write data from/to a car through an ELM327-/STN1170-Adapter on UWP")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Wyrez")] +[assembly: AssemblyCompany("Wyrez / Roman Lumetsberger")] [assembly: AssemblyProduct("OBD.NET")] -[assembly: AssemblyCopyright("Copyright © Wyrez 2016")] +[assembly: AssemblyCopyright("Copyright © 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("c97e0c5b-0571-41a3-9257-90bb48e46dcf")] +[assembly: Guid("14cb98e1-95de-4923-8896-fdf5171aa49e")] // Version information for an assembly consists of the following four values: // // Major Version -// Minor Version +// Minor Version // Build Number // Revision // -// You can specify all the values or you can default the Build and Revision Numbers +// You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] diff --git a/README.md b/README.md index 7c9bc4f..c80138e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,79 @@ # OBD.NET C#-Library to read/write data from/to a car through an ELM327-/STN1170-Adapter + +## Projects +* OBD.NET.Common - NetStandard 1.4 Library for platform independent stuff +* OBD.NET.Desktop - Implemenation of SerialConnection on full .NET Framework +* OBD.NET.Universal - Implementation of BluetoothSerialConnection for connecting to Bluetooth Adapter on UWP +* OBD.NET.ConsoleClient - Example client application using SerialConnection on full .NET Framework + +## Usage +* Add OBD.NET.Common and OBD.NET.Desktop packages to project +```csharp +class Program +{ + static void Main(string[] args) + { + if (args.Length < 1) + { + Console.WriteLine("Parameter ComPort needed."); + return; + } + + var comPort = args[0]; + + using (SerialConnection connection = new SerialConnection(comPort)) + using (ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug))) + { + dev.SubscribeDataReceived((sender, data) => + { + Console.WriteLine("EngineRPM: " + data.Data.Rpm); + }); + + dev.SubscribeDataReceived((sender, data) => + { + Console.WriteLine("VehicleSpeed: " + data.Data.Speed); + }); + + dev.Initialize(); + dev.RequestData(); + for (int i = 0; i < 5; i++) + { + dev.RequestData(); + dev.RequestData(); + Thread.Sleep(1000); + } + Console.ReadLine(); + } + + //Async example + MainAsync(comPort).Wait(); + + } + + /// + /// Async example using new RequestDataAsync + /// + /// The COM port. + /// + public static async Task MainAsync(string comPort) + { + using (SerialConnection connection = new SerialConnection(comPort)) + using (ELM327 dev = new ELM327(connection, new OBDConsoleLogger(OBDLogLevel.Debug))) + { + dev.Initialize(); + var data = await dev.RequestDataAsync(); + Console.WriteLine("Data: " + data.Rpm); + data = await dev.RequestDataAsync(); + Console.WriteLine("Data: " + data.Rpm); + var data2 = await dev.RequestDataAsync(); + Console.WriteLine("Data: " + data2.Speed); + data = await dev.RequestDataAsync(); + Console.WriteLine("Data: " + data.Rpm); + + } + } +} +``` + + diff --git a/Tools/nuget.exe b/Tools/nuget.exe new file mode 100644 index 0000000..856263d Binary files /dev/null and b/Tools/nuget.exe differ