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:
parent
9948f33a4f
commit
8219707dc3
@ -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 string MessageChunk { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
@ -161,13 +163,29 @@ namespace OBD.NET.Common.Devices
|
||||
|
||||
protected override object ProcessMessage(string message)
|
||||
{
|
||||
if (message == null) return null;
|
||||
|
||||
DateTime timestamp = DateTime.Now;
|
||||
|
||||
RawDataReceived?.Invoke(this, new RawDataReceivedEventArgs(message, timestamp));
|
||||
|
||||
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();
|
||||
if (mode == (byte)Mode)
|
||||
|
||||
@ -55,7 +55,7 @@ namespace OBD.NET.Common.OBDData
|
||||
{
|
||||
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));
|
||||
|
||||
_rawData = new byte[_length];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user