mirror of
https://github.com/DarthAffe/OBD.NET.git
synced 2025-12-12 08:48:30 +00:00
Applied consistend code-style; Changed target of desktop parts to 4.6.1
This commit is contained in:
parent
ea2ac35046
commit
27fd4aba40
@ -1,8 +1,9 @@
|
||||
namespace OBD.NET.Commands
|
||||
namespace OBD.NET.Common.Commands
|
||||
{
|
||||
public class ATCommand
|
||||
{
|
||||
#region Values
|
||||
#region Commands
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
//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 CloseProtocol = new ATCommand("ATPC");
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
@ -42,19 +44,13 @@
|
||||
|
||||
#region Methods
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Command;
|
||||
}
|
||||
public override string ToString() => Command;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
public static implicit operator string(ATCommand command)
|
||||
{
|
||||
return command.ToString();
|
||||
}
|
||||
public static implicit operator string(ATCommand command) => command.ToString();
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
namespace OBD.NET.Commands
|
||||
namespace OBD.NET.Common.Commands
|
||||
{
|
||||
public class STCommand
|
||||
{
|
||||
#region Values
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
//TODO DarthAffe 19.03.2017: Implement all commands
|
||||
|
||||
@ -15,6 +16,7 @@
|
||||
internal static readonly STCommand Monitor = new STCommand("STM");
|
||||
internal static readonly STCommand MonitorAll = new STCommand("STMA");
|
||||
|
||||
// ReSharper restore InconsistentNaming
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
@ -34,19 +36,13 @@
|
||||
|
||||
#region Methods
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Command;
|
||||
}
|
||||
public override string ToString() => Command;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
public static implicit operator string(STCommand command)
|
||||
{
|
||||
return command.ToString();
|
||||
}
|
||||
public static implicit operator string(STCommand command) => command.ToString();
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -3,8 +3,24 @@
|
||||
/// <summary>
|
||||
/// Event args for receiving serial data
|
||||
/// </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>
|
||||
/// Initializes a new instance of the <see cref="DataReceivedEventArgs"/> class.
|
||||
/// </summary>
|
||||
@ -12,18 +28,10 @@
|
||||
/// <param name="data">The data.</param>
|
||||
public DataReceivedEventArgs(int count, byte[] data)
|
||||
{
|
||||
Count = count;
|
||||
Data = data;
|
||||
this.Count = count;
|
||||
this.Data = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
using OBD.NET.Common.Communication.EventArgs;
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using OBD.NET.Common.Communication.EventArgs;
|
||||
|
||||
namespace OBD.NET.Communication
|
||||
namespace OBD.NET.Common.Communication
|
||||
{
|
||||
/// <summary>
|
||||
/// Serial connection interface
|
||||
@ -42,18 +42,17 @@ namespace OBD.NET.Communication
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task ConnectAsync();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified data to the serial connection
|
||||
/// </summary>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
void Write(byte[] data);
|
||||
|
||||
/// <summary>
|
||||
/// Writes the specified data to the serial connection asynchronous
|
||||
/// </summary>
|
||||
/// <param name="text">The text.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
Task WriteAsync(byte[] data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Count : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Degree : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class DegreeCelsius : GenericData
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public abstract class GenericData
|
||||
{
|
||||
@ -17,7 +17,7 @@ namespace OBD.NET.DataTypes
|
||||
|
||||
#region Constructors
|
||||
|
||||
public GenericData(double value, double minValue, double maxValue)
|
||||
protected GenericData(double value, double minValue, double maxValue)
|
||||
{
|
||||
this.Value = value;
|
||||
this.MinValue = minValue;
|
||||
@ -25,7 +25,7 @@ namespace OBD.NET.DataTypes
|
||||
this.IsFloatingPointValue = true;
|
||||
}
|
||||
|
||||
public GenericData(int value, int minValue, int maxValue)
|
||||
protected GenericData(int value, int minValue, int maxValue)
|
||||
{
|
||||
this.Value = value;
|
||||
this.MinValue = minValue;
|
||||
@ -37,24 +37,15 @@ namespace OBD.NET.DataTypes
|
||||
|
||||
#region Operators
|
||||
|
||||
public static implicit operator double(GenericData p)
|
||||
{
|
||||
return p.Value;
|
||||
}
|
||||
public static implicit operator double(GenericData p) => p.Value;
|
||||
|
||||
public static implicit operator int(GenericData p)
|
||||
{
|
||||
return (int)Math.Round(p.Value);
|
||||
}
|
||||
public static implicit operator int(GenericData p) => (int)Math.Round(p.Value);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return (IsFloatingPointValue ? Value.ToString("0.00") : Value.ToString()) + (Unit == null ? string.Empty : (" " + Unit));
|
||||
}
|
||||
public override string ToString() => (IsFloatingPointValue ? Value.ToString("0.00") : Value.ToString()) + (Unit == null ? string.Empty : (" " + Unit));
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class GramPerSec : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Kilometre : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class KilometrePerHour : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Kilopascal : GenericData
|
||||
{
|
||||
@ -22,10 +22,7 @@
|
||||
|
||||
#region Operators
|
||||
|
||||
public static explicit operator Pascal(Kilopascal pa)
|
||||
{
|
||||
return new Pascal(pa.Value / 1000.0, pa.MinValue / 1000.0, pa.MaxValue / 1000.0);
|
||||
}
|
||||
public static explicit operator Pascal(Kilopascal pa) => new Pascal(pa.Value / 1000.0, pa.MinValue / 1000.0, pa.MaxValue / 1000.0);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class LitresPerHour : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Milliampere : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Minute : GenericData
|
||||
{
|
||||
@ -22,12 +22,9 @@
|
||||
|
||||
#region Operators
|
||||
|
||||
public static explicit operator Second(Minute m)
|
||||
{
|
||||
return m.IsFloatingPointValue
|
||||
? 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));
|
||||
}
|
||||
public static explicit operator Second(Minute m) => m.IsFloatingPointValue
|
||||
? 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
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class NewtonMetre : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Pascal : GenericData
|
||||
{
|
||||
@ -22,12 +22,9 @@
|
||||
|
||||
#region Operators
|
||||
|
||||
public static explicit operator Kilopascal(Pascal pa)
|
||||
{
|
||||
return pa.IsFloatingPointValue
|
||||
? 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));
|
||||
}
|
||||
public static explicit operator Kilopascal(Pascal pa) => pa.IsFloatingPointValue
|
||||
? 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
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Percent : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Ratio : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class RevolutionsPerMinute : GenericData
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Second : GenericData
|
||||
{
|
||||
@ -22,10 +22,7 @@
|
||||
|
||||
#region Operators
|
||||
|
||||
public static explicit operator Minute(Second s)
|
||||
{
|
||||
return new Minute(s.Value / 60.0, s.MinValue / 60.0, s.MaxValue / 60.0);
|
||||
}
|
||||
public static explicit operator Minute(Second s) => new Minute(s.Value / 60.0, s.MinValue / 60.0, s.MaxValue / 60.0);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.DataTypes
|
||||
namespace OBD.NET.Common.DataTypes
|
||||
{
|
||||
public class Volt : GenericData
|
||||
{
|
||||
|
||||
@ -1,27 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OBD.NET.Common.Devices
|
||||
namespace OBD.NET.Common.Devices
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used for queued command
|
||||
/// </summary>
|
||||
public class QueuedCommand
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance
|
||||
/// </summary>
|
||||
/// <param name="commandText"></param>
|
||||
public QueuedCommand(string commandText)
|
||||
{
|
||||
CommandResult = new CommandResult();
|
||||
CommandText = commandText;
|
||||
}
|
||||
|
||||
public string CommandText { get; set; }
|
||||
public string CommandText { get; private set; }
|
||||
|
||||
public CommandResult CommandResult { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public QueuedCommand(string commandText)
|
||||
{
|
||||
this.CommandText = commandText;
|
||||
|
||||
CommandResult = new CommandResult();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,18 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using OBD.NET.Util;
|
||||
using OBD.NET.Common.Util;
|
||||
|
||||
namespace OBD.NET.Common.Devices
|
||||
{
|
||||
public class CommandResult
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public object Result { get; set; }
|
||||
public AsyncManualResetEvent WaitHandle { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public CommandResult()
|
||||
{
|
||||
WaitHandle = new AsyncManualResetEvent();
|
||||
}
|
||||
|
||||
public object Result { get; set; }
|
||||
public AsyncManualResetEvent WaitHandle { get; }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,29 +1,28 @@
|
||||
using System;
|
||||
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 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
|
||||
{
|
||||
#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<byte, Type> DataTypeCache { get; } = new Dictionary<byte, Type>();
|
||||
|
||||
protected Mode Mode { get; set; } = Mode.ShowCurrentData; //TODO DarthAffe 26.06.2016: Implement different modes
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
@ -89,16 +88,12 @@ namespace OBD.NET.Devices
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Sends the AT command.
|
||||
/// </summary>
|
||||
/// <param name="command">The command.</param>
|
||||
public virtual void SendCommand(ATCommand command)
|
||||
{
|
||||
SendCommand(command.Command);
|
||||
}
|
||||
public virtual void SendCommand(ATCommand command) => SendCommand(command.Command);
|
||||
|
||||
/// <summary>
|
||||
/// Requests the data and calls the handler
|
||||
@ -130,14 +125,12 @@ namespace OBD.NET.Devices
|
||||
Logger?.WriteLine("Requesting Type " + typeof(T).Name + " ...", OBDLogLevel.Debug);
|
||||
byte pid = ResolvePid<T>();
|
||||
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();
|
||||
return result.Result as T;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected override object ProcessMessage(string message)
|
||||
{
|
||||
DateTime timestamp = DateTime.Now;
|
||||
@ -145,21 +138,19 @@ namespace OBD.NET.Devices
|
||||
RawDataReceived?.Invoke(this, new RawDataReceivedEventArgs(message, timestamp));
|
||||
|
||||
if (message.Length > 4)
|
||||
{
|
||||
{
|
||||
if (message[0] == '4')
|
||||
{
|
||||
byte mode = (byte)message[1].GetHexVal();
|
||||
if (mode == (byte)Mode)
|
||||
{
|
||||
byte pid = (byte)message.Substring(2, 2).GetHexVal();
|
||||
Type dataType;
|
||||
if (DataTypeCache.TryGetValue(pid, out dataType))
|
||||
if (DataTypeCache.TryGetValue(pid, out Type dataType))
|
||||
{
|
||||
IOBDData obdData = (IOBDData)Activator.CreateInstance(dataType);
|
||||
obdData.Load(message.Substring(4, message.Length - 4));
|
||||
|
||||
IDataEventManager dataEventManager;
|
||||
if (_dataReceivedEventHandlers.TryGetValue(dataType, out dataEventManager))
|
||||
|
||||
if (DataReceivedEventHandlers.TryGetValue(dataType, out IDataEventManager dataEventManager))
|
||||
dataEventManager.RaiseEvent(this, obdData, timestamp);
|
||||
|
||||
return obdData;
|
||||
@ -173,8 +164,7 @@ namespace OBD.NET.Devices
|
||||
protected virtual byte ResolvePid<T>()
|
||||
where T : class, IOBDData, new()
|
||||
{
|
||||
byte pid;
|
||||
if (!PidCache.TryGetValue(typeof(T), out pid))
|
||||
if (!PidCache.TryGetValue(typeof(T), out byte pid))
|
||||
{
|
||||
T data = Activator.CreateInstance<T>();
|
||||
pid = data.PID;
|
||||
@ -185,40 +175,33 @@ namespace OBD.NET.Devices
|
||||
return pid;
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
}
|
||||
public override void Dispose() => Dispose(true);
|
||||
|
||||
public void Dispose(bool sendCloseProtocol)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sendCloseProtocol)
|
||||
{
|
||||
SendCommand(ATCommand.CloseProtocol);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
catch { /* Well at least we tried ... */ }
|
||||
|
||||
_dataReceivedEventHandlers.Clear();
|
||||
DataReceivedEventHandlers.Clear();
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public void SubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData
|
||||
{
|
||||
IDataEventManager eventManager;
|
||||
if (!_dataReceivedEventHandlers.TryGetValue(typeof(T), out eventManager))
|
||||
_dataReceivedEventHandlers.Add(typeof(T), (eventManager = new GenericDataEventManager<T>()));
|
||||
if (!DataReceivedEventHandlers.TryGetValue(typeof(T), out IDataEventManager eventManager))
|
||||
DataReceivedEventHandlers.Add(typeof(T), (eventManager = new GenericDataEventManager<T>()));
|
||||
|
||||
((GenericDataEventManager<T>)eventManager).DataReceived += eventHandler;
|
||||
}
|
||||
|
||||
public void UnsubscribeDataReceived<T>(DataReceivedEventHandler<T> eventHandler) where T : IOBDData
|
||||
{
|
||||
IDataEventManager eventManager;
|
||||
if (_dataReceivedEventHandlers.TryGetValue(typeof(T), out eventManager))
|
||||
if (DataReceivedEventHandlers.TryGetValue(typeof(T), out IDataEventManager eventManager))
|
||||
((GenericDataEventManager<T>)eventManager).DataReceived -= eventHandler;
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
using OBD.NET.Communication;
|
||||
using OBD.NET.Logging;
|
||||
using OBD.NET.Common.Commands;
|
||||
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
|
||||
{
|
||||
//TODO DarthAffe 26.06.2016: Add ST-Commands and stuff
|
||||
|
||||
#region Constructors
|
||||
|
||||
public STN1170(ISerialConnection connection, IOBDLogger logger = null)
|
||||
@ -14,5 +13,15 @@ namespace OBD.NET.Devices
|
||||
{ }
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,59 +1,37 @@
|
||||
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.Collections.Concurrent;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Collections.Concurrent;
|
||||
using OBD.NET.Common.Devices;
|
||||
using System.Threading.Tasks;
|
||||
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>
|
||||
/// Base class used for communicating with the device
|
||||
/// </summary>
|
||||
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 AutoResetEvent _commandFinishedEvent = new AutoResetEvent(false);
|
||||
private Task _commandWorkerTask;
|
||||
private CancellationTokenSource _commandCancellationToken;
|
||||
|
||||
private readonly AutoResetEvent commandFinishedEvent = new AutoResetEvent(false);
|
||||
|
||||
private Task commandWorkerTask;
|
||||
|
||||
private CancellationTokenSource commandCancellationToken;
|
||||
|
||||
protected QueuedCommand currentCommand;
|
||||
|
||||
/// <summary>
|
||||
/// Logger instance
|
||||
/// </summary>
|
||||
protected QueuedCommand CurrentCommand;
|
||||
protected IOBDLogger Logger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Low level connection
|
||||
/// </summary>
|
||||
protected ISerialConnection Connection { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Terminator of the protocol message
|
||||
/// </summary>
|
||||
protected char Terminator { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Prevents a default instance of the <see cref="SerialDevice"/> class from being created.
|
||||
/// </summary>
|
||||
private SerialDevice()
|
||||
{
|
||||
commandQueue = new BlockingCollection<QueuedCommand>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SerialDevice"/> class.
|
||||
/// </summary>
|
||||
@ -61,21 +39,18 @@ namespace OBD.NET.Devices
|
||||
/// <param name="terminator">terminator used for terminating the command message</param>
|
||||
/// <param name="logger">logger instance</param>
|
||||
protected SerialDevice(ISerialConnection connection, char terminator = '\r', IOBDLogger logger = null)
|
||||
:this()
|
||||
{
|
||||
Connection = connection;
|
||||
Terminator = terminator;
|
||||
Logger = logger;
|
||||
this.Connection = connection;
|
||||
this.Terminator = terminator;
|
||||
this.Logger = logger;
|
||||
|
||||
connection.DataReceived += OnDataReceived;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Methods
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the device
|
||||
/// </summary>
|
||||
@ -105,13 +80,11 @@ namespace OBD.NET.Devices
|
||||
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);
|
||||
Logger?.WriteLine("Opened Serial-Connection!", OBDLogLevel.Debug);
|
||||
|
||||
_commandCancellationToken = new CancellationTokenSource();
|
||||
_commandWorkerTask = Task.Factory.StartNew(CommandWorker);
|
||||
}
|
||||
|
||||
|
||||
@ -123,19 +96,17 @@ namespace OBD.NET.Devices
|
||||
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);
|
||||
QueuedCommand cmd = new QueuedCommand(command);
|
||||
_commandQueue.Add(cmd);
|
||||
|
||||
return cmd.CommandResult;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Prepares the command
|
||||
/// </summary>
|
||||
@ -168,8 +139,8 @@ namespace OBD.NET.Devices
|
||||
break;
|
||||
|
||||
case '>':
|
||||
currentCommand.CommandResult.WaitHandle.Set();
|
||||
commandFinishedEvent.Set();
|
||||
CurrentCommand.CommandResult.WaitHandle.Set();
|
||||
_commandFinishedEvent.Set();
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
@ -203,8 +174,8 @@ namespace OBD.NET.Devices
|
||||
/// <param name="message">The message.</param>
|
||||
private void InternalProcessMessage(string message)
|
||||
{
|
||||
var data = ProcessMessage(message);
|
||||
currentCommand.CommandResult.Result = data;
|
||||
object data = ProcessMessage(message);
|
||||
CurrentCommand.CommandResult.Result = data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -219,24 +190,20 @@ namespace OBD.NET.Devices
|
||||
/// </summary>
|
||||
private async void CommandWorker()
|
||||
{
|
||||
while (!commandCancellationToken.IsCancellationRequested)
|
||||
while (!_commandCancellationToken.IsCancellationRequested)
|
||||
{
|
||||
currentCommand = null;
|
||||
if(commandQueue.TryTake(out currentCommand, Timeout.Infinite, commandCancellationToken.Token))
|
||||
CurrentCommand = null;
|
||||
if (_commandQueue.TryTake(out CurrentCommand, Timeout.Infinite, _commandCancellationToken.Token))
|
||||
{
|
||||
Logger?.WriteLine("Writing Command: '" + currentCommand.CommandText.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
|
||||
Logger?.WriteLine("Writing Command: '" + CurrentCommand.CommandText.Replace('\r', '\'') + "'", OBDLogLevel.Verbose);
|
||||
|
||||
if (Connection.IsAsync)
|
||||
{
|
||||
await Connection.WriteAsync(Encoding.ASCII.GetBytes(currentCommand.CommandText));
|
||||
}
|
||||
await Connection.WriteAsync(Encoding.ASCII.GetBytes(CurrentCommand.CommandText));
|
||||
else
|
||||
{
|
||||
Connection.Write(Encoding.ASCII.GetBytes(currentCommand.CommandText));
|
||||
Connection.Write(Encoding.ASCII.GetBytes(CurrentCommand.CommandText));
|
||||
|
||||
}
|
||||
//wait for command to finish
|
||||
commandFinishedEvent.WaitOne();
|
||||
_commandFinishedEvent.WaitOne();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,8 +213,9 @@ namespace OBD.NET.Devices
|
||||
/// </summary>
|
||||
public virtual void Dispose()
|
||||
{
|
||||
commandCancellationToken?.Cancel();
|
||||
commandWorkerTask?.Wait();
|
||||
_commandCancellationToken?.Cancel();
|
||||
_commandWorkerTask?.Wait();
|
||||
|
||||
Connection?.Dispose();
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.Enums
|
||||
namespace OBD.NET.Common.Enums
|
||||
{
|
||||
/// <summary>
|
||||
/// https://en.wikipedia.org/wiki/OBD-II_PIDs#Modes
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
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
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace OBD.NET.Events.EventArgs
|
||||
namespace OBD.NET.Common.Events.EventArgs
|
||||
{
|
||||
public class RawDataReceivedEventArgs
|
||||
{
|
||||
|
||||
@ -1,32 +1,22 @@
|
||||
using System;
|
||||
using OBD.NET.Devices;
|
||||
using OBD.NET.Events.EventArgs;
|
||||
using OBD.NET.OBDData;
|
||||
using OBD.NET.Common.Devices;
|
||||
using OBD.NET.Common.Events.EventArgs;
|
||||
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
|
||||
|
||||
internal event ELM327.DataReceivedEventHandler<T> DataReceived;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public void RaiseEvent(object sender, IOBDData data, DateTime timestamp)
|
||||
{
|
||||
DataReceived?.Invoke(sender, new DataReceivedEventArgs<T>((T)data, timestamp));
|
||||
}
|
||||
public void RaiseEvent(object sender, IOBDData data, DateTime timestamp) => DataReceived?.Invoke(sender, new DataReceivedEventArgs<T>((T)data, timestamp));
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using OBD.NET.OBDData;
|
||||
using OBD.NET.Common.OBDData;
|
||||
|
||||
namespace OBD.NET.Events
|
||||
namespace OBD.NET.Common.Events
|
||||
{
|
||||
public interface IDataEventManager
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace OBD.NET.Exceptions
|
||||
namespace OBD.NET.Common.Exceptions
|
||||
{
|
||||
public class SerialException : Exception
|
||||
{
|
||||
@ -16,7 +16,7 @@ namespace OBD.NET.Exceptions
|
||||
public SerialException(string message, Exception innerException)
|
||||
: base(message, innerException)
|
||||
{ }
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace OBD.NET.Exceptions
|
||||
namespace OBD.NET.Common.Exceptions
|
||||
{
|
||||
public class UnexpectedResultException : Exception
|
||||
{
|
||||
@ -14,7 +14,7 @@ namespace OBD.NET.Exceptions
|
||||
#region Constructors
|
||||
|
||||
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.ExpectedResult = expectedResult;
|
||||
@ -33,7 +33,6 @@ namespace OBD.NET.Exceptions
|
||||
this.Result = result;
|
||||
this.ExpectedResult = expectedResult;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,24 +1,22 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace OBD.NET.Extensions
|
||||
namespace OBD.NET.Common.Extensions
|
||||
{
|
||||
public static class HexExtension
|
||||
{
|
||||
public static int GetHexVal(this char hex)
|
||||
{
|
||||
return hex - (hex < 58 ? 48 : (hex < 97 ? 55 : 87));
|
||||
}
|
||||
#region Methods
|
||||
|
||||
public static int GetHexVal(this char hex) => hex - (hex < 58 ? 48 : (hex < 97 ? 55 : 87));
|
||||
|
||||
public static int GetHexVal(this string hex)
|
||||
{
|
||||
if ((hex.Length % 2) == 1)
|
||||
throw new ArgumentException("The binary key cannot have an odd number of digits");
|
||||
|
||||
int result = 0;
|
||||
foreach (char c in hex)
|
||||
result = (result << 4) + (GetHexVal(c));
|
||||
|
||||
return result;
|
||||
return hex.Aggregate(0, (current, c) => (current << 4) + (GetHexVal(c)));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.Logging
|
||||
namespace OBD.NET.Common.Logging
|
||||
{
|
||||
public interface IOBDLogger
|
||||
{
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
using OBD.NET.Logging;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace OBD.NET.Common.Logging
|
||||
{
|
||||
/// <summary>
|
||||
/// Simple debug logger
|
||||
/// </summary>
|
||||
/// <seealso cref="OBD.NET.Logging.IOBDLogger" />
|
||||
/// <seealso cref="IOBDLogger" />
|
||||
public class OBDDebugLogger : IOBDLogger
|
||||
{
|
||||
public void WriteLine(string text, OBDLogLevel level)
|
||||
{
|
||||
Debug.WriteLine($"{level}: {text}");
|
||||
}
|
||||
#region Methods
|
||||
|
||||
public void WriteLine(string text, OBDLogLevel level) => Debug.WriteLine($"{level}: {text}");
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.Logging
|
||||
namespace OBD.NET.Common.Logging
|
||||
{
|
||||
public enum OBDLogLevel
|
||||
{
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
namespace OBD.NET.OBDData
|
||||
namespace OBD.NET.Common.OBDData
|
||||
{
|
||||
public class AuxiliaryInputStatus : AbstractOBDData
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public bool PowerTakeOffStatus => (A & 1 << 0) != 0;
|
||||
public bool PowerTakeOffStatus => (A & (1 << 0)) != 0;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace OBD.NET.OBDData
|
||||
namespace OBD.NET.Common.OBDData
|
||||
{
|
||||
public class CommandedSecondaryAirStatus : AbstractOBDData
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace OBD.NET.OBDData
|
||||
namespace OBD.NET.Common.OBDData
|
||||
{
|
||||
public class FuelSystemStatus : AbstractOBDData
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
namespace OBD.NET.OBDData
|
||||
namespace OBD.NET.Common.OBDData
|
||||
{
|
||||
public class OBDStandards : AbstractOBDData
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
namespace OBD.NET.OBDData
|
||||
namespace OBD.NET.Common.OBDData
|
||||
{
|
||||
public class OxygenSensorPresent : AbstractOBDData
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public bool IsSensor1Present => (A & 1 << 0) != 0;
|
||||
public bool IsSensor2Present => (A & 1 << 1) != 0;
|
||||
public bool IsSensor3Present => (A & 1 << 2) != 0;
|
||||
public bool IsSensor4Present => (A & 1 << 3) != 0;
|
||||
public bool IsSensor5Present => (A & 1 << 4) != 0;
|
||||
public bool IsSensor6Present => (A & 1 << 5) != 0;
|
||||
public bool IsSensor7Present => (A & 1 << 6) != 0;
|
||||
public bool IsSensor8Present => (A & 1 << 7) != 0;
|
||||
public bool IsSensor1Present => (A & (1 << 0)) != 0;
|
||||
public bool IsSensor2Present => (A & (1 << 1)) != 0;
|
||||
public bool IsSensor3Present => (A & (1 << 2)) != 0;
|
||||
public bool IsSensor4Present => (A & (1 << 3)) != 0;
|
||||
public bool IsSensor5Present => (A & (1 << 4)) != 0;
|
||||
public bool IsSensor6Present => (A & (1 << 5)) != 0;
|
||||
public bool IsSensor7Present => (A & (1 << 6)) != 0;
|
||||
public bool IsSensor8Present => (A & (1 << 7)) != 0;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
namespace OBD.NET.OBDData
|
||||
namespace OBD.NET.Common.OBDData
|
||||
{
|
||||
public class OxygenSensorPresent2 : AbstractOBDData
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public bool IsSensor1Present => (A & 1 << 0) != 0;
|
||||
public bool IsSensor2Present => (A & 1 << 1) != 0;
|
||||
public bool IsSensor3Present => (A & 1 << 2) != 0;
|
||||
public bool IsSensor4Present => (A & 1 << 3) != 0;
|
||||
public bool IsSensor5Present => (A & 1 << 4) != 0;
|
||||
public bool IsSensor6Present => (A & 1 << 5) != 0;
|
||||
public bool IsSensor7Present => (A & 1 << 6) != 0;
|
||||
public bool IsSensor8Present => (A & 1 << 7) != 0;
|
||||
public bool IsSensor1Present => (A & (1 << 0)) != 0;
|
||||
public bool IsSensor2Present => (A & (1 << 1)) != 0;
|
||||
public bool IsSensor3Present => (A & (1 << 2)) != 0;
|
||||
public bool IsSensor4Present => (A & (1 << 3)) != 0;
|
||||
public bool IsSensor5Present => (A & (1 << 4)) != 0;
|
||||
public bool IsSensor6Present => (A & (1 << 5)) != 0;
|
||||
public bool IsSensor7Present => (A & (1 << 6)) != 0;
|
||||
public bool IsSensor8Present => (A & (1 << 7)) != 0;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OBD.NET.OBDData
|
||||
namespace OBD.NET.Common.OBDData
|
||||
{
|
||||
public class PidsSupported01_20 : AbstractOBDData
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace OBD.NET.OBDData
|
||||
namespace OBD.NET.Common.OBDData
|
||||
{
|
||||
public class PidsSupported21_40 : AbstractOBDData
|
||||
{
|
||||
|
||||
@ -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
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user