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

Added experimental support for splitted responses

This commit is contained in:
Darth Affe 2020-08-15 00:29:40 +02:00
parent 9948f33a4f
commit 8219707dc3
2 changed files with 21 additions and 3 deletions

View File

@ -25,6 +25,8 @@ namespace OBD.NET.Common.Devices
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
protected string MessageChunk { get; set; }
#endregion #endregion
#region Events #region Events
@ -161,13 +163,29 @@ namespace OBD.NET.Common.Devices
protected override object ProcessMessage(string message) protected override object ProcessMessage(string message)
{ {
if (message == null) return null;
DateTime timestamp = DateTime.Now; DateTime timestamp = DateTime.Now;
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') // DarthAffe 15.08.2020: Splitted messages are prefixed with 0: (first chunk) and 1: (second chunk)
// DarthAffe 15.08.2020: They also seem to be always preceded by a '009'-message, but since that's to short to be processed it should be safe to ignore.
// DarthAffe 15.08.2020: Since that behavior isn't really documented (at least I wasn't able to find it) that's all trial and error and might not work for all pids with long results.
if (message[1] == ':')
{
if (message[0] == '0')
MessageChunk = message.Substring(2, message.Length - 2);
else if (message[0] == '1')
{
string fullMessage = MessageChunk + message.Substring(2, message.Length - 2);
MessageChunk = null;
return ProcessMessage(fullMessage);
}
}
else if (message[0] == '4')
{ {
byte mode = (byte)message[1].GetHexVal(); byte mode = (byte)message[1].GetHexVal();
if (mode == (byte)Mode) if (mode == (byte)Mode)

View File

@ -22,7 +22,7 @@ namespace OBD.NET.Common.OBDData
_rawData = value; _rawData = value;
} }
} }
public bool IsValid => RawData.Length == _length; public bool IsValid => RawData.Length == _length;
protected byte A => RawData.Length > 0 ? RawData[0] : default(byte); protected byte A => RawData.Length > 0 ? RawData[0] : default(byte);
@ -55,7 +55,7 @@ namespace OBD.NET.Common.OBDData
{ {
try try
{ {
if (((data.Length % 2) == 1) || ((data.Length / 2) != _length)) if (((data.Length % 2) != 0) || ((data.Length / 2) < _length))
throw new ArgumentException("The provided data is not valid", nameof(data)); throw new ArgumentException("The provided data is not valid", nameof(data));
_rawData = new byte[_length]; _rawData = new byte[_length];