SafeDispatch/AndroidLIB/MSG.cs

58 lines
1.6 KiB
C#
Raw Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AndroidLIB
{
public class MSG
{
public bool OK;
public int msgLen;
public string seqID;
public int opCode;
public string data;
public string error;
public string allData;
public byte[] b_allData;
public byte[] _rawdata;
public int _len;
public MSG(byte[] rawdata, int len)
{
_rawdata = rawdata;
b_allData = rawdata;
_len = len;
OK = Parse();
}
private bool Parse()
{
string dataTemp = System.Text.Encoding.ASCII.GetString(_rawdata, 0, _len);
SMd.Debug("multi RX: " + dataTemp.Trim());
this.allData = dataTemp;
string[] tempArr = dataTemp.Split('#');
if ((tempArr.Length == 0) || (tempArr.Length == 1))
{
SMd.Debug("incorect messagebuss message=" + data);
return false;
}
int messLen = Convert.ToInt32(tempArr[1]);
if (_len != messLen)
{
Console.WriteLine("message length({0}) != actual length({1})", messLen, _len);
return false;
}
seqID = tempArr[2];
opCode = Convert.ToInt32(tempArr[3]);
data = "";
int idx = 1+tempArr[1].Length + 1 + tempArr[2].Length + 1 + tempArr[3].Length + 1;
data = allData.Substring(idx);
return true;
}
}
}