1
0
mirror of https://github.com/DarthAffe/OBD.NET.git synced 2025-12-12 16:58:30 +00:00

Merge branch 'master' into OperationCanceledException-fix

This commit is contained in:
Roman Lumetsberger 2017-08-18 16:11:01 +02:00 committed by GitHub
commit 5f296a35ca
151 changed files with 519 additions and 605 deletions

View File

@ -1,8 +1,9 @@
namespace OBD.NET.Commands namespace OBD.NET.Common.Commands
{ {
public class ATCommand public class ATCommand
{ {
#region Values #region Commands
// ReSharper disable InconsistentNaming
//TODO DarthAffe 26.06.2016: Implement all commands //TODO DarthAffe 26.06.2016: Implement all commands
@ -21,6 +22,7 @@
public static readonly ATCommand PrintVersion = new ATCommand("ATI", "^ELM327.*"); public static readonly ATCommand PrintVersion = new ATCommand("ATI", "^ELM327.*");
public static readonly ATCommand CloseProtocol = new ATCommand("ATPC"); public static readonly ATCommand CloseProtocol = new ATCommand("ATPC");
// ReSharper restore InconsistentNaming
#endregion #endregion
#region Properties & Fields #region Properties & Fields
@ -42,19 +44,13 @@
#region Methods #region Methods
public override string ToString() public override string ToString() => Command;
{
return Command;
}
#endregion #endregion
#region Operators #region Operators
public static implicit operator string(ATCommand command) public static implicit operator string(ATCommand command) => command.ToString();
{
return command.ToString();
}
#endregion #endregion
} }

View File

@ -1,8 +1,9 @@
namespace OBD.NET.Commands namespace OBD.NET.Common.Commands
{ {
public class STCommand public class STCommand
{ {
#region Values #region Values
// ReSharper disable InconsistentNaming
//TODO DarthAffe 19.03.2017: Implement all commands //TODO DarthAffe 19.03.2017: Implement all commands
@ -15,6 +16,7 @@
internal static readonly STCommand Monitor = new STCommand("STM"); internal static readonly STCommand Monitor = new STCommand("STM");
internal static readonly STCommand MonitorAll = new STCommand("STMA"); internal static readonly STCommand MonitorAll = new STCommand("STMA");
// ReSharper restore InconsistentNaming
#endregion #endregion
#region Properties & Fields #region Properties & Fields
@ -34,19 +36,13 @@
#region Methods #region Methods
public override string ToString() public override string ToString() => Command;
{
return Command;
}
#endregion #endregion
#region Operators #region Operators
public static implicit operator string(STCommand command) public static implicit operator string(STCommand command) => command.ToString();
{
return command.ToString();
}
#endregion #endregion
} }

View File

@ -3,8 +3,24 @@
/// <summary> /// <summary>
/// Event args for receiving serial data /// Event args for receiving serial data
/// </summary> /// </summary>
public class DataReceivedEventArgs:System.EventArgs public class DataReceivedEventArgs : System.EventArgs
{ {
#region Properties & Fields
/// <summary>
/// Count of valid data bytes in the buffer
/// </summary>
public int Count { get; }
/// <summary>
/// Data buffer holding the bytes
/// </summary>
public byte[] Data { get; }
#endregion
#region Constructors
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DataReceivedEventArgs"/> class. /// Initializes a new instance of the <see cref="DataReceivedEventArgs"/> class.
/// </summary> /// </summary>
@ -12,18 +28,10 @@
/// <param name="data">The data.</param> /// <param name="data">The data.</param>
public DataReceivedEventArgs(int count, byte[] data) public DataReceivedEventArgs(int count, byte[] data)
{ {
Count = count; this.Count = count;
Data = data; this.Data = data;
} }
/// <summary> #endregion
/// Count of valid data bytes in the buffer
/// </summary>
public int Count { get; private set; }
/// <summary>
/// Data buffer holding the bytes
/// </summary>
public byte[] Data { get; private set; }
} }
} }

View File

@ -1,8 +1,8 @@
using OBD.NET.Common.Communication.EventArgs; using System;
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using OBD.NET.Common.Communication.EventArgs;
namespace OBD.NET.Communication namespace OBD.NET.Common.Communication
{ {
/// <summary> /// <summary>
/// Serial connection interface /// Serial connection interface
@ -42,18 +42,17 @@ namespace OBD.NET.Communication
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
Task ConnectAsync(); Task ConnectAsync();
/// <summary> /// <summary>
/// Writes the specified data to the serial connection /// Writes the specified data to the serial connection
/// </summary> /// </summary>
/// <param name="text">The text.</param> /// <param name="data">The data.</param>
void Write(byte[] data); void Write(byte[] data);
/// <summary> /// <summary>
/// Writes the specified data to the serial connection asynchronous /// Writes the specified data to the serial connection asynchronous
/// </summary> /// </summary>
/// <param name="text">The text.</param> /// <param name="data">The data.</param>
Task WriteAsync(byte[] data); Task WriteAsync(byte[] data);
} }
} }

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Count : GenericData public class Count : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Degree : GenericData public class Degree : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class DegreeCelsius : GenericData public class DegreeCelsius : GenericData
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public abstract class GenericData public abstract class GenericData
{ {
@ -17,7 +17,7 @@ namespace OBD.NET.DataTypes
#region Constructors #region Constructors
public GenericData(double value, double minValue, double maxValue) protected GenericData(double value, double minValue, double maxValue)
{ {
this.Value = value; this.Value = value;
this.MinValue = minValue; this.MinValue = minValue;
@ -25,7 +25,7 @@ namespace OBD.NET.DataTypes
this.IsFloatingPointValue = true; this.IsFloatingPointValue = true;
} }
public GenericData(int value, int minValue, int maxValue) protected GenericData(int value, int minValue, int maxValue)
{ {
this.Value = value; this.Value = value;
this.MinValue = minValue; this.MinValue = minValue;
@ -37,24 +37,15 @@ namespace OBD.NET.DataTypes
#region Operators #region Operators
public static implicit operator double(GenericData p) public static implicit operator double(GenericData p) => p.Value;
{
return p.Value;
}
public static implicit operator int(GenericData p) public static implicit operator int(GenericData p) => (int)Math.Round(p.Value);
{
return (int)Math.Round(p.Value);
}
#endregion #endregion
#region Methods #region Methods
public override string ToString() public override string ToString() => (IsFloatingPointValue ? Value.ToString("0.00") : Value.ToString()) + (Unit == null ? string.Empty : (" " + Unit));
{
return (IsFloatingPointValue ? Value.ToString("0.00") : Value.ToString()) + (Unit == null ? string.Empty : (" " + Unit));
}
#endregion #endregion
} }

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class GramPerSec : GenericData public class GramPerSec : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Kilometre : GenericData public class Kilometre : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class KilometrePerHour : GenericData public class KilometrePerHour : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Kilopascal : GenericData public class Kilopascal : GenericData
{ {
@ -22,10 +22,7 @@
#region Operators #region Operators
public static explicit operator Pascal(Kilopascal pa) public static explicit operator Pascal(Kilopascal pa) => new Pascal(pa.Value / 1000.0, pa.MinValue / 1000.0, pa.MaxValue / 1000.0);
{
return new Pascal(pa.Value / 1000.0, pa.MinValue / 1000.0, pa.MaxValue / 1000.0);
}
#endregion #endregion
} }

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class LitresPerHour : GenericData public class LitresPerHour : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Milliampere : GenericData public class Milliampere : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Minute : GenericData public class Minute : GenericData
{ {
@ -22,12 +22,9 @@
#region Operators #region Operators
public static explicit operator Second(Minute m) public static explicit operator Second(Minute m) => m.IsFloatingPointValue
{ ? new Second(m.Value * 60, m.MinValue * 60, m.MaxValue * 60)
return m.IsFloatingPointValue : new Second((int)(m.Value * 60), (int)(m.MinValue * 60), (int)(m.MaxValue * 60));
? new Second(m.Value * 60, m.MinValue * 60, m.MaxValue * 60)
: new Second((int)(m.Value * 60), (int)(m.MinValue * 60), (int)(m.MaxValue * 60));
}
#endregion #endregion
} }

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class NewtonMetre : GenericData public class NewtonMetre : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Pascal : GenericData public class Pascal : GenericData
{ {
@ -22,12 +22,9 @@
#region Operators #region Operators
public static explicit operator Kilopascal(Pascal pa) public static explicit operator Kilopascal(Pascal pa) => pa.IsFloatingPointValue
{ ? new Kilopascal(pa.Value * 1000, pa.MinValue * 1000, pa.MaxValue * 1000)
return pa.IsFloatingPointValue : new Kilopascal((int)(pa.Value * 1000), (int)(pa.MinValue * 1000), (int)(pa.MaxValue * 1000));
? new Kilopascal(pa.Value * 1000, pa.MinValue * 1000, pa.MaxValue * 1000)
: new Kilopascal((int)(pa.Value * 1000), (int)(pa.MinValue * 1000), (int)(pa.MaxValue * 1000));
}
#endregion #endregion
} }

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Percent : GenericData public class Percent : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Ratio : GenericData public class Ratio : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class RevolutionsPerMinute : GenericData public class RevolutionsPerMinute : GenericData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Second : GenericData public class Second : GenericData
{ {
@ -22,10 +22,7 @@
#region Operators #region Operators
public static explicit operator Minute(Second s) public static explicit operator Minute(Second s) => new Minute(s.Value / 60.0, s.MinValue / 60.0, s.MaxValue / 60.0);
{
return new Minute(s.Value / 60.0, s.MinValue / 60.0, s.MaxValue / 60.0);
}
#endregion #endregion
} }

View File

@ -1,4 +1,4 @@
namespace OBD.NET.DataTypes namespace OBD.NET.Common.DataTypes
{ {
public class Volt : GenericData public class Volt : GenericData
{ {

View File

@ -1,27 +1,27 @@
using System; namespace OBD.NET.Common.Devices
using System.Collections.Generic;
using System.Text;
namespace OBD.NET.Common.Devices
{ {
/// <summary> /// <summary>
/// Class used for queued command /// Class used for queued command
/// </summary> /// </summary>
public class QueuedCommand public class QueuedCommand
{ {
#region Properties & Fields
/// <summary> public string CommandText { get; private set; }
/// Initializes a new instance
/// </summary>
/// <param name="commandText"></param>
public QueuedCommand(string commandText)
{
CommandResult = new CommandResult();
CommandText = commandText;
}
public string CommandText { get; set; }
public CommandResult CommandResult { get; } public CommandResult CommandResult { get; }
#endregion
#region Constructors
public QueuedCommand(string commandText)
{
this.CommandText = commandText;
CommandResult = new CommandResult();
}
#endregion
} }
} }

View File

@ -1,18 +1,23 @@
using System; using OBD.NET.Common.Util;
using System.Collections.Generic;
using System.Text;
using OBD.NET.Util;
namespace OBD.NET.Common.Devices namespace OBD.NET.Common.Devices
{ {
public class CommandResult public class CommandResult
{ {
#region Properties & Fields
public object Result { get; set; }
public AsyncManualResetEvent WaitHandle { get; }
#endregion
#region Constructors
public CommandResult() public CommandResult()
{ {
WaitHandle = new AsyncManualResetEvent(); WaitHandle = new AsyncManualResetEvent();
} }
public object Result { get; set; } #endregion
public AsyncManualResetEvent WaitHandle { get; }
} }
} }

View File

@ -1,29 +1,28 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using OBD.NET.Commands;
using OBD.NET.Communication;
using OBD.NET.Enums;
using OBD.NET.Events;
using OBD.NET.Events.EventArgs;
using OBD.NET.Extensions;
using OBD.NET.Logging;
using OBD.NET.OBDData;
using System.Threading.Tasks; using System.Threading.Tasks;
using OBD.NET.Common.Commands;
using OBD.NET.Common.Communication;
using OBD.NET.Common.Enums;
using OBD.NET.Common.Events;
using OBD.NET.Common.Events.EventArgs;
using OBD.NET.Common.Extensions;
using OBD.NET.Common.Logging;
using OBD.NET.Common.OBDData;
namespace OBD.NET.Devices namespace OBD.NET.Common.Devices
{ {
public class ELM327 : SerialDevice public class ELM327 : SerialDevice
{ {
#region Properties & Fields #region Properties & Fields
protected Dictionary<Type, IDataEventManager> _dataReceivedEventHandlers = new Dictionary<Type, IDataEventManager>(); protected readonly Dictionary<Type, IDataEventManager> DataReceivedEventHandlers = new Dictionary<Type, IDataEventManager>();
protected static Dictionary<Type, byte> PidCache { get; } = new Dictionary<Type, byte>(); protected static Dictionary<Type, byte> PidCache { get; } = new Dictionary<Type, byte>();
protected static Dictionary<byte, Type> DataTypeCache { get; } = new Dictionary<byte, Type>(); protected static Dictionary<byte, Type> DataTypeCache { get; } = new Dictionary<byte, Type>();
protected Mode Mode { get; set; } = Mode.ShowCurrentData; //TODO DarthAffe 26.06.2016: Implement different modes protected Mode Mode { get; set; } = Mode.ShowCurrentData; //TODO DarthAffe 26.06.2016: Implement different modes
#endregion #endregion
#region Events #region Events
@ -89,16 +88,12 @@ namespace OBD.NET.Devices
throw; throw;
} }
} }
/// <summary> /// <summary>
/// Sends the AT command. /// Sends the AT command.
/// </summary> /// </summary>
/// <param name="command">The command.</param> /// <param name="command">The command.</param>
public virtual void SendCommand(ATCommand command) public virtual void SendCommand(ATCommand command) => SendCommand(command.Command);
{
SendCommand(command.Command);
}
/// <summary> /// <summary>
/// Requests the data and calls the handler /// Requests the data and calls the handler
@ -130,14 +125,12 @@ namespace OBD.NET.Devices
Logger?.WriteLine("Requesting Type " + typeof(T).Name + " ...", OBDLogLevel.Debug); Logger?.WriteLine("Requesting Type " + typeof(T).Name + " ...", OBDLogLevel.Debug);
byte pid = ResolvePid<T>(); byte pid = ResolvePid<T>();
Logger?.WriteLine("Requesting PID " + pid.ToString("X2") + " ...", OBDLogLevel.Debug); Logger?.WriteLine("Requesting PID " + pid.ToString("X2") + " ...", OBDLogLevel.Debug);
var result = SendCommand(((byte)Mode).ToString("X2") + pid.ToString("X2")); CommandResult result = SendCommand(((byte)Mode).ToString("X2") + pid.ToString("X2"));
await result.WaitHandle.WaitAsync(); await result.WaitHandle.WaitAsync();
return result.Result as T; return result.Result as T;
} }
protected override object ProcessMessage(string message) protected override object ProcessMessage(string message)
{ {
DateTime timestamp = DateTime.Now; DateTime timestamp = DateTime.Now;
@ -145,21 +138,19 @@ namespace OBD.NET.Devices
RawDataReceived?.Invoke(this, new RawDataReceivedEventArgs(message, timestamp)); RawDataReceived?.Invoke(this, new RawDataReceivedEventArgs(message, timestamp));
if (message.Length > 4) if (message.Length > 4)
{ {
if (message[0] == '4') if (message[0] == '4')
{ {
byte mode = (byte)message[1].GetHexVal(); byte mode = (byte)message[1].GetHexVal();
if (mode == (byte)Mode) if (mode == (byte)Mode)
{ {
byte pid = (byte)message.Substring(2, 2).GetHexVal(); byte pid = (byte)message.Substring(2, 2).GetHexVal();
Type dataType; if (DataTypeCache.TryGetValue(pid, out Type dataType))
if (DataTypeCache.TryGetValue(pid, out dataType))
{ {
IOBDData obdData = (IOBDData)Activator.CreateInstance(dataType); IOBDData obdData = (IOBDData)Activator.CreateInstance(dataType);
obdData.Load(message.Substring(4, message.Length - 4)); obdData.Load(message.Substring(4, message.Length - 4));
IDataEventManager dataEventManager; if (DataReceivedEventHandlers.TryGetValue(dataType, out IDataEventManager dataEventManager))
if (_dataReceivedEventHandlers.TryGetValue(dataType, out dataEventManager))
dataEventManager.RaiseEvent(this, obdData, timestamp); dataEventManager.RaiseEvent(this, obdData, timestamp);
return obdData; return obdData;
@ -173,8 +164,7 @@ namespace OBD.NET.Devices
protected virtual byte ResolvePid<T>() protected virtual byte ResolvePid<T>()
where T : class, IOBDData, new() where T : class, IOBDData, new()
{ {
byte pid; if (!PidCache.TryGetValue(typeof(T), out byte pid))
if (!PidCache.TryGetValue(typeof(T), out pid))
{ {
T data = Activator.CreateInstance<T>(); T data = Activator.CreateInstance<T>();
pid = data.PID; pid = data.PID;
@ -185,40 +175,33 @@ namespace OBD.NET.Devices
return pid; return pid;
} }
public override void Dispose() public override void Dispose() => Dispose(true);
{
Dispose(true);
}
public void Dispose(bool sendCloseProtocol) public void Dispose(bool sendCloseProtocol)
{ {
try try
{ {
if (sendCloseProtocol) if (sendCloseProtocol)
{
SendCommand(ATCommand.CloseProtocol); SendCommand(ATCommand.CloseProtocol);
}
} }
catch { } catch { /* Well at least we tried ... */ }
_dataReceivedEventHandlers.Clear(); DataReceivedEventHandlers.Clear();
base.Dispose(); base.Dispose();
} }
public void SubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData public void SubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData
{ {
IDataEventManager eventManager; if (!DataReceivedEventHandlers.TryGetValue(typeof(T), out IDataEventManager eventManager))
if (!_dataReceivedEventHandlers.TryGetValue(typeof(T), out eventManager)) DataReceivedEventHandlers.Add(typeof(T), (eventManager = new GenericDataEventManager<T>()));
_dataReceivedEventHandlers.Add(typeof(T), (eventManager = new GenericDataEventManager<T>()));
((GenericDataEventManager<T>)eventManager).DataReceived += eventHandler; ((GenericDataEventManager<T>)eventManager).DataReceived += eventHandler;
} }
public void UnsubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData public void UnsubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData
{ {
IDataEventManager eventManager; if (DataReceivedEventHandlers.TryGetValue(typeof(T), out IDataEventManager eventManager))
if (_dataReceivedEventHandlers.TryGetValue(typeof(T), out eventManager))
((GenericDataEventManager<T>)eventManager).DataReceived -= eventHandler; ((GenericDataEventManager<T>)eventManager).DataReceived -= eventHandler;
} }

View File

@ -1,12 +1,11 @@
using OBD.NET.Communication; using OBD.NET.Common.Commands;
using OBD.NET.Logging; using OBD.NET.Common.Communication;
using OBD.NET.Common.Logging;
namespace OBD.NET.Devices namespace OBD.NET.Common.Devices
{ {
public class STN1170 : ELM327 // Fully compatible device public class STN1170 : ELM327 // Fully compatible device
{ {
//TODO DarthAffe 26.06.2016: Add ST-Commands and stuff
#region Constructors #region Constructors
public STN1170(ISerialConnection connection, IOBDLogger logger = null) public STN1170(ISerialConnection connection, IOBDLogger logger = null)
@ -14,5 +13,15 @@ namespace OBD.NET.Devices
{ } { }
#endregion #endregion
#region Methods
/// <summary>
/// Sends the ST command.
/// </summary>
/// <param name="command">The command.</param>
public virtual void SendCommand(STCommand command) => SendCommand(command.Command);
#endregion
} }
} }

View File

@ -1,59 +1,37 @@
using System; using System;
using OBD.NET.Communication; using System.Collections.Concurrent;
using OBD.NET.Exceptions;
using OBD.NET.Logging;
using System.Threading.Tasks;
using OBD.NET.Common.Communication.EventArgs;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Collections.Concurrent; using System.Threading.Tasks;
using OBD.NET.Common.Devices; using OBD.NET.Common.Communication;
using OBD.NET.Common.Communication.EventArgs;
using OBD.NET.Common.Exceptions;
using OBD.NET.Common.Logging;
namespace OBD.NET.Devices namespace OBD.NET.Common.Devices
{ {
/// <summary> /// <summary>
/// Base class used for communicating with the device /// Base class used for communicating with the device
/// </summary> /// </summary>
public abstract class SerialDevice : IDisposable public abstract class SerialDevice : IDisposable
{ {
private BlockingCollection<QueuedCommand> commandQueue; #region Properties & Fields
private readonly BlockingCollection<QueuedCommand> _commandQueue = new BlockingCollection<QueuedCommand>();
private readonly StringBuilder _lineBuffer = new StringBuilder(); private readonly StringBuilder _lineBuffer = new StringBuilder();
private readonly AutoResetEvent _commandFinishedEvent = new AutoResetEvent(false);
private Task _commandWorkerTask;
private CancellationTokenSource _commandCancellationToken;
private readonly AutoResetEvent commandFinishedEvent = new AutoResetEvent(false); protected QueuedCommand CurrentCommand;
private Task commandWorkerTask;
private CancellationTokenSource commandCancellationToken;
protected QueuedCommand currentCommand;
/// <summary>
/// Logger instance
/// </summary>
protected IOBDLogger Logger { get; } protected IOBDLogger Logger { get; }
/// <summary>
/// Low level connection
/// </summary>
protected ISerialConnection Connection { get; } protected ISerialConnection Connection { get; }
/// <summary>
/// Terminator of the protocol message
/// </summary>
protected char Terminator { get; set; } protected char Terminator { get; set; }
#endregion
#region Constructors #region Constructors
/// <summary>
/// Prevents a default instance of the <see cref="SerialDevice"/> class from being created.
/// </summary>
private SerialDevice()
{
commandQueue = new BlockingCollection<QueuedCommand>();
}
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="SerialDevice"/> class. /// Initializes a new instance of the <see cref="SerialDevice"/> class.
/// </summary> /// </summary>
@ -61,21 +39,18 @@ namespace OBD.NET.Devices
/// <param name="terminator">terminator used for terminating the command message</param> /// <param name="terminator">terminator used for terminating the command message</param>
/// <param name="logger">logger instance</param> /// <param name="logger">logger instance</param>
protected SerialDevice(ISerialConnection connection, char terminator = '\r', IOBDLogger logger = null) protected SerialDevice(ISerialConnection connection, char terminator = '\r', IOBDLogger logger = null)
:this()
{ {
Connection = connection; this.Connection = connection;
Terminator = terminator; this.Terminator = terminator;
Logger = logger; this.Logger = logger;
connection.DataReceived += OnDataReceived; connection.DataReceived += OnDataReceived;
} }
#endregion #endregion
#region Methods #region Methods
/// <summary> /// <summary>
/// Initializes the device /// Initializes the device
/// </summary> /// </summary>
@ -105,13 +80,11 @@ namespace OBD.NET.Devices
Logger?.WriteLine("Failed to open Serial-Connection.", OBDLogLevel.Error); Logger?.WriteLine("Failed to open Serial-Connection.", OBDLogLevel.Error);
throw new SerialException("Failed to open Serial-Connection."); throw new SerialException("Failed to open Serial-Connection.");
} }
else
{
Logger?.WriteLine("Opened Serial-Connection!", OBDLogLevel.Debug);
}
commandCancellationToken = new CancellationTokenSource(); Logger?.WriteLine("Opened Serial-Connection!", OBDLogLevel.Debug);
commandWorkerTask = Task.Factory.StartNew(CommandWorker);
_commandCancellationToken = new CancellationTokenSource();
_commandWorkerTask = Task.Factory.StartNew(CommandWorker);
} }
@ -123,19 +96,17 @@ namespace OBD.NET.Devices
protected virtual CommandResult SendCommand(string command) protected virtual CommandResult SendCommand(string command)
{ {
if (!Connection.IsOpen) if (!Connection.IsOpen)
{
throw new InvalidOperationException("Not connected"); throw new InvalidOperationException("Not connected");
}
command = PrepareCommand(command); command = PrepareCommand(command);
Logger?.WriteLine("Queuing Command: '" + command.Replace('\r', '\'') + "'", OBDLogLevel.Verbose); Logger?.WriteLine("Queuing Command: '" + command.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
var cmd = new QueuedCommand(command); QueuedCommand cmd = new QueuedCommand(command);
commandQueue.Add(cmd); _commandQueue.Add(cmd);
return cmd.CommandResult; return cmd.CommandResult;
} }
/// <summary> /// <summary>
/// Prepares the command /// Prepares the command
/// </summary> /// </summary>
@ -168,8 +139,8 @@ namespace OBD.NET.Devices
break; break;
case '>': case '>':
currentCommand.CommandResult.WaitHandle.Set(); CurrentCommand.CommandResult.WaitHandle.Set();
commandFinishedEvent.Set(); _commandFinishedEvent.Set();
break; break;
case '\n': case '\n':
@ -203,8 +174,8 @@ namespace OBD.NET.Devices
/// <param name="message">The message.</param> /// <param name="message">The message.</param>
private void InternalProcessMessage(string message) private void InternalProcessMessage(string message)
{ {
var data = ProcessMessage(message); object data = ProcessMessage(message);
currentCommand.CommandResult.Result = data; CurrentCommand.CommandResult.Result = data;
} }
/// <summary> /// <summary>
@ -219,7 +190,7 @@ namespace OBD.NET.Devices
/// </summary> /// </summary>
private async void CommandWorker() private async void CommandWorker()
{ {
while (!commandCancellationToken.IsCancellationRequested) while (!_commandCancellationToken.IsCancellationRequested)
{ {
currentCommand = null; currentCommand = null;
try try
@ -229,14 +200,9 @@ namespace OBD.NET.Devices
Logger?.WriteLine("Writing Command: '" + currentCommand.CommandText.Replace('\r', '\'') + "'", OBDLogLevel.Verbose); Logger?.WriteLine("Writing Command: '" + currentCommand.CommandText.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
if (Connection.IsAsync) if (Connection.IsAsync)
{
await Connection.WriteAsync(Encoding.ASCII.GetBytes(currentCommand.CommandText)); await Connection.WriteAsync(Encoding.ASCII.GetBytes(currentCommand.CommandText));
}
else else
{
Connection.Write(Encoding.ASCII.GetBytes(currentCommand.CommandText)); Connection.Write(Encoding.ASCII.GetBytes(currentCommand.CommandText));
}
//wait for command to finish //wait for command to finish
commandFinishedEvent.WaitOne(); commandFinishedEvent.WaitOne();
} }

View File

@ -1,4 +1,4 @@
namespace OBD.NET.Enums namespace OBD.NET.Common.Enums
{ {
/// <summary> /// <summary>
/// https://en.wikipedia.org/wiki/OBD-II_PIDs#Modes /// https://en.wikipedia.org/wiki/OBD-II_PIDs#Modes

View File

@ -1,7 +1,7 @@
using System; using System;
using OBD.NET.OBDData; using OBD.NET.Common.OBDData;
namespace OBD.NET.Events.EventArgs namespace OBD.NET.Common.Events.EventArgs
{ {
public class DataReceivedEventArgs<T> where T : IOBDData public class DataReceivedEventArgs<T> where T : IOBDData
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
namespace OBD.NET.Events.EventArgs namespace OBD.NET.Common.Events.EventArgs
{ {
public class RawDataReceivedEventArgs public class RawDataReceivedEventArgs
{ {

View File

@ -1,32 +1,22 @@
using System; using System;
using OBD.NET.Devices; using OBD.NET.Common.Devices;
using OBD.NET.Events.EventArgs; using OBD.NET.Common.Events.EventArgs;
using OBD.NET.OBDData; using OBD.NET.Common.OBDData;
namespace OBD.NET.Events namespace OBD.NET.Common.Events
{ {
public class GenericDataEventManager<T> : IDataEventManager where T : IOBDData public class GenericDataEventManager<T> : IDataEventManager
where T : IOBDData
{ {
#region Properties & Fields
#endregion
#region Events #region Events
internal event ELM327.DataReceivedEventHandler<T> DataReceived; internal event ELM327.DataReceivedEventHandler<T> DataReceived;
#endregion #endregion
#region Constructors
#endregion
#region Methods #region Methods
public void RaiseEvent(object sender, IOBDData data, DateTime timestamp) public void RaiseEvent(object sender, IOBDData data, DateTime timestamp) => DataReceived?.Invoke(sender, new DataReceivedEventArgs<T>((T)data, timestamp));
{
DataReceived?.Invoke(sender, new DataReceivedEventArgs<T>((T)data, timestamp));
}
#endregion #endregion
} }

View File

@ -1,7 +1,7 @@
using System; using System;
using OBD.NET.OBDData; using OBD.NET.Common.OBDData;
namespace OBD.NET.Events namespace OBD.NET.Common.Events
{ {
public interface IDataEventManager public interface IDataEventManager
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
namespace OBD.NET.Exceptions namespace OBD.NET.Common.Exceptions
{ {
public class SerialException : Exception public class SerialException : Exception
{ {
@ -16,7 +16,7 @@ namespace OBD.NET.Exceptions
public SerialException(string message, Exception innerException) public SerialException(string message, Exception innerException)
: base(message, innerException) : base(message, innerException)
{ } { }
#endregion #endregion
} }

View File

@ -1,6 +1,6 @@
using System; using System;
namespace OBD.NET.Exceptions namespace OBD.NET.Common.Exceptions
{ {
public class UnexpectedResultException : Exception public class UnexpectedResultException : Exception
{ {
@ -14,7 +14,7 @@ namespace OBD.NET.Exceptions
#region Constructors #region Constructors
public UnexpectedResultException(string result, string expectedResult) public UnexpectedResultException(string result, string expectedResult)
:this($"Unexpected result '{result}'. Expected was '{expectedResult}'", result, expectedResult) : this($"Unexpected result '{result}'. Expected was '{expectedResult}'", result, expectedResult)
{ {
this.Result = result; this.Result = result;
this.ExpectedResult = expectedResult; this.ExpectedResult = expectedResult;
@ -33,7 +33,6 @@ namespace OBD.NET.Exceptions
this.Result = result; this.Result = result;
this.ExpectedResult = expectedResult; this.ExpectedResult = expectedResult;
} }
#endregion #endregion
} }

View File

@ -1,24 +1,22 @@
using System; using System;
using System.Linq;
namespace OBD.NET.Extensions namespace OBD.NET.Common.Extensions
{ {
public static class HexExtension public static class HexExtension
{ {
public static int GetHexVal(this char hex) #region Methods
{
return hex - (hex < 58 ? 48 : (hex < 97 ? 55 : 87)); public static int GetHexVal(this char hex) => hex - (hex < 58 ? 48 : (hex < 97 ? 55 : 87));
}
public static int GetHexVal(this string hex) public static int GetHexVal(this string hex)
{ {
if ((hex.Length % 2) == 1) if ((hex.Length % 2) == 1)
throw new ArgumentException("The binary key cannot have an odd number of digits"); throw new ArgumentException("The binary key cannot have an odd number of digits");
int result = 0; return hex.Aggregate(0, (current, c) => (current << 4) + (GetHexVal(c)));
foreach (char c in hex)
result = (result << 4) + (GetHexVal(c));
return result;
} }
#endregion
} }
} }

View File

@ -1,4 +1,4 @@
namespace OBD.NET.Logging namespace OBD.NET.Common.Logging
{ {
public interface IOBDLogger public interface IOBDLogger
{ {

View File

@ -1,17 +1,17 @@
using OBD.NET.Logging; using System.Diagnostics;
using System.Diagnostics;
namespace OBD.NET.Common.Logging namespace OBD.NET.Common.Logging
{ {
/// <summary> /// <summary>
/// Simple debug logger /// Simple debug logger
/// </summary> /// </summary>
/// <seealso cref="OBD.NET.Logging.IOBDLogger" /> /// <seealso cref="IOBDLogger" />
public class OBDDebugLogger : IOBDLogger public class OBDDebugLogger : IOBDLogger
{ {
public void WriteLine(string text, OBDLogLevel level) #region Methods
{
Debug.WriteLine($"{level}: {text}"); public void WriteLine(string text, OBDLogLevel level) => Debug.WriteLine($"{level}: {text}");
}
#endregion
} }
} }

View File

@ -1,4 +1,4 @@
namespace OBD.NET.Logging namespace OBD.NET.Common.Logging
{ {
public enum OBDLogLevel public enum OBDLogLevel
{ {

View File

@ -1,10 +1,10 @@
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class AuxiliaryInputStatus : AbstractOBDData public class AuxiliaryInputStatus : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public bool PowerTakeOffStatus => (A & 1 << 0) != 0; public bool PowerTakeOffStatus => (A & (1 << 0)) != 0;
#endregion #endregion

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class CalculatedEngineLoad : AbstractOBDData public class CalculatedEngineLoad : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class CommandedSecondaryAirStatus : AbstractOBDData public class CommandedSecondaryAirStatus : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class EngineCoolantTemperature : AbstractOBDData public class EngineCoolantTemperature : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class EngineRPM : AbstractOBDData public class EngineRPM : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class FuelPressure : AbstractOBDData public class FuelPressure : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using System; using System;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class FuelSystemStatus : AbstractOBDData public class FuelSystemStatus : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class IntakeAirTemperature : AbstractOBDData public class IntakeAirTemperature : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class IntakeManifoldAbsolutePressure : AbstractOBDData public class IntakeManifoldAbsolutePressure : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class LongTermFuelTrimBank1 : AbstractOBDData public class LongTermFuelTrimBank1 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class LongTermFuelTrimBank2 : AbstractOBDData public class LongTermFuelTrimBank2 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class MAFAirFlowRate : AbstractOBDData public class MAFAirFlowRate : AbstractOBDData
{ {

View File

@ -1,4 +1,4 @@
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OBDStandards : AbstractOBDData public class OBDStandards : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor1FuelTrim : AbstractOBDData public class OxygenSensor1FuelTrim : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor2FuelTrim : AbstractOBDData public class OxygenSensor2FuelTrim : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor3FuelTrim : AbstractOBDData public class OxygenSensor3FuelTrim : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor4FuelTrim : AbstractOBDData public class OxygenSensor4FuelTrim : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor5FuelTrim : AbstractOBDData public class OxygenSensor5FuelTrim : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor6FuelTrim : AbstractOBDData public class OxygenSensor6FuelTrim : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor7FuelTrim : AbstractOBDData public class OxygenSensor7FuelTrim : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor8FuelTrim : AbstractOBDData public class OxygenSensor8FuelTrim : AbstractOBDData
{ {

View File

@ -1,17 +1,17 @@
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensorPresent : AbstractOBDData public class OxygenSensorPresent : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public bool IsSensor1Present => (A & 1 << 0) != 0; public bool IsSensor1Present => (A & (1 << 0)) != 0;
public bool IsSensor2Present => (A & 1 << 1) != 0; public bool IsSensor2Present => (A & (1 << 1)) != 0;
public bool IsSensor3Present => (A & 1 << 2) != 0; public bool IsSensor3Present => (A & (1 << 2)) != 0;
public bool IsSensor4Present => (A & 1 << 3) != 0; public bool IsSensor4Present => (A & (1 << 3)) != 0;
public bool IsSensor5Present => (A & 1 << 4) != 0; public bool IsSensor5Present => (A & (1 << 4)) != 0;
public bool IsSensor6Present => (A & 1 << 5) != 0; public bool IsSensor6Present => (A & (1 << 5)) != 0;
public bool IsSensor7Present => (A & 1 << 6) != 0; public bool IsSensor7Present => (A & (1 << 6)) != 0;
public bool IsSensor8Present => (A & 1 << 7) != 0; public bool IsSensor8Present => (A & (1 << 7)) != 0;
#endregion #endregion

View File

@ -1,17 +1,17 @@
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensorPresent2 : AbstractOBDData public class OxygenSensorPresent2 : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public bool IsSensor1Present => (A & 1 << 0) != 0; public bool IsSensor1Present => (A & (1 << 0)) != 0;
public bool IsSensor2Present => (A & 1 << 1) != 0; public bool IsSensor2Present => (A & (1 << 1)) != 0;
public bool IsSensor3Present => (A & 1 << 2) != 0; public bool IsSensor3Present => (A & (1 << 2)) != 0;
public bool IsSensor4Present => (A & 1 << 3) != 0; public bool IsSensor4Present => (A & (1 << 3)) != 0;
public bool IsSensor5Present => (A & 1 << 4) != 0; public bool IsSensor5Present => (A & (1 << 4)) != 0;
public bool IsSensor6Present => (A & 1 << 5) != 0; public bool IsSensor6Present => (A & (1 << 5)) != 0;
public bool IsSensor7Present => (A & 1 << 6) != 0; public bool IsSensor7Present => (A & (1 << 6)) != 0;
public bool IsSensor8Present => (A & 1 << 7) != 0; public bool IsSensor8Present => (A & (1 << 7)) != 0;
#endregion #endregion

View File

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class PidsSupported01_20 : AbstractOBDData public class PidsSupported01_20 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class RunTimeSinceEngineStart : AbstractOBDData public class RunTimeSinceEngineStart : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class ShortTermFuelTrimBank1 : AbstractOBDData public class ShortTermFuelTrimBank1 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class ShortTermFuelTrimBank2 : AbstractOBDData public class ShortTermFuelTrimBank2 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class ThrottlePosition : AbstractOBDData public class ThrottlePosition : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class TimingAdvance : AbstractOBDData public class TimingAdvance : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class VehicleSpeed : AbstractOBDData public class VehicleSpeed : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class AbsoluteBarometricPressure : AbstractOBDData public class AbsoluteBarometricPressure : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class CatalystTemperatureBank1Sensor1 : AbstractOBDData public class CatalystTemperatureBank1Sensor1 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class CatalystTemperatureBank1Sensor2 : AbstractOBDData public class CatalystTemperatureBank1Sensor2 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class CatalystTemperatureBank2Sensor1 : AbstractOBDData public class CatalystTemperatureBank2Sensor1 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class CatalystTemperatureBank2Sensor2 : AbstractOBDData public class CatalystTemperatureBank2Sensor2 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class CommandedEGR : AbstractOBDData public class CommandedEGR : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class CommandedEvaporativePurge : AbstractOBDData public class CommandedEvaporativePurge : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class DistanceTraveledSinceCodesCleared : AbstractOBDData public class DistanceTraveledSinceCodesCleared : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class DistanceTraveledWithMILOn : AbstractOBDData public class DistanceTraveledWithMILOn : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class EGRError : AbstractOBDData public class EGRError : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class EvapSystemVaporPressure : AbstractOBDData public class EvapSystemVaporPressure : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class FuelRailGaugePressure : AbstractOBDData public class FuelRailGaugePressure : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class FuelRailPressure : AbstractOBDData public class FuelRailPressure : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class FuelTankLevelInput : AbstractOBDData public class FuelTankLevelInput : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor1FuelAir : AbstractOBDData public class OxygenSensor1FuelAir : AbstractOBDData
{ {

View File

@ -1,13 +1,13 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor1FuelAir2 : AbstractOBDData public class OxygenSensor1FuelAir2 : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon); public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon);
public Milliampere Current => new Milliampere(C + (D / 256.0) - 128, -128, 128 - double.Epsilon); public Milliampere Current => new Milliampere((C + (D / 256.0)) - 128, -128, 128 - double.Epsilon);
#endregion #endregion

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor2FuelAir : AbstractOBDData public class OxygenSensor2FuelAir : AbstractOBDData
{ {

View File

@ -1,13 +1,13 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor2FuelAir2 : AbstractOBDData public class OxygenSensor2FuelAir2 : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon); public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon);
public Milliampere Current => new Milliampere(C + (D / 256.0) - 128, -128, 128 - double.Epsilon); public Milliampere Current => new Milliampere((C + (D / 256.0)) - 128, -128, 128 - double.Epsilon);
#endregion #endregion

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor3FuelAir : AbstractOBDData public class OxygenSensor3FuelAir : AbstractOBDData
{ {

View File

@ -1,13 +1,13 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor3FuelAir2 : AbstractOBDData public class OxygenSensor3FuelAir2 : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon); public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon);
public Milliampere Current => new Milliampere(C + (D / 256.0) - 128, -128, 128 - double.Epsilon); public Milliampere Current => new Milliampere((C + (D / 256.0)) - 128, -128, 128 - double.Epsilon);
#endregion #endregion

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor4FuelAir : AbstractOBDData public class OxygenSensor4FuelAir : AbstractOBDData
{ {

View File

@ -1,13 +1,13 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor4FuelAir2 : AbstractOBDData public class OxygenSensor4FuelAir2 : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon); public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon);
public Milliampere Current => new Milliampere(C + (D / 256.0) - 128, -128, 128 - double.Epsilon); public Milliampere Current => new Milliampere((C + (D / 256.0)) - 128, -128, 128 - double.Epsilon);
#endregion #endregion

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor5FuelAir : AbstractOBDData public class OxygenSensor5FuelAir : AbstractOBDData
{ {

View File

@ -1,13 +1,13 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor5FuelAir2 : AbstractOBDData public class OxygenSensor5FuelAir2 : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon); public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon);
public Milliampere Current => new Milliampere(C + (D / 256.0) - 128, -128, 128 - double.Epsilon); public Milliampere Current => new Milliampere((C + (D / 256.0)) - 128, -128, 128 - double.Epsilon);
#endregion #endregion

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor6FuelAir : AbstractOBDData public class OxygenSensor6FuelAir : AbstractOBDData
{ {

View File

@ -1,13 +1,13 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor6FuelAir2 : AbstractOBDData public class OxygenSensor6FuelAir2 : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon); public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon);
public Milliampere Current => new Milliampere(C + (D / 256.0) - 128, -128, 128 - double.Epsilon); public Milliampere Current => new Milliampere((C + (D / 256.0)) - 128, -128, 128 - double.Epsilon);
#endregion #endregion

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor7FuelAir : AbstractOBDData public class OxygenSensor7FuelAir : AbstractOBDData
{ {

View File

@ -1,13 +1,13 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor7FuelAir2 : AbstractOBDData public class OxygenSensor7FuelAir2 : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon); public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon);
public Milliampere Current => new Milliampere(C + (D / 256.0) - 128, -128, 128 - double.Epsilon); public Milliampere Current => new Milliampere((C + (D / 256.0)) - 128, -128, 128 - double.Epsilon);
#endregion #endregion

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor8FuelAir : AbstractOBDData public class OxygenSensor8FuelAir : AbstractOBDData
{ {

View File

@ -1,13 +1,13 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class OxygenSensor8FuelAir2 : AbstractOBDData public class OxygenSensor8FuelAir2 : AbstractOBDData
{ {
#region Properties & Fields #region Properties & Fields
public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon); public Ratio FuelAirEquivalenceRatio => new Ratio((2.0 / 25536.0) * ((256 * A) + B), 0, 2 - double.Epsilon);
public Milliampere Current => new Milliampere(C + (D / 256.0) - 128, -128, 128 - double.Epsilon); public Milliampere Current => new Milliampere((C + (D / 256.0)) - 128, -128, 128 - double.Epsilon);
#endregion #endregion

View File

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class PidsSupported21_40 : AbstractOBDData public class PidsSupported21_40 : AbstractOBDData
{ {

View File

@ -1,6 +1,6 @@
using OBD.NET.DataTypes; using OBD.NET.Common.DataTypes;
namespace OBD.NET.OBDData namespace OBD.NET.Common.OBDData
{ {
public class WarmUpsSinceCodesCleared : AbstractOBDData public class WarmUpsSinceCodesCleared : AbstractOBDData
{ {

Some files were not shown because too many files have changed in this diff Show More