88 lines
1.9 KiB
Java
88 lines
1.9 KiB
Java
|
package com.safemobile.lib;
|
||
|
|
||
|
import com.safemobile.lib.SM;
|
||
|
|
||
|
public class TCPmsg
|
||
|
{
|
||
|
public boolean OK;
|
||
|
public int msgLen;
|
||
|
public String seqID;
|
||
|
public int opCode;
|
||
|
public String data;
|
||
|
public String error;
|
||
|
public String allData;
|
||
|
|
||
|
public String leftOver="";
|
||
|
|
||
|
private char[] _rawdata;
|
||
|
private int _len;
|
||
|
public TCPmsg(char[] rawdata, int len)
|
||
|
{
|
||
|
_rawdata = rawdata;
|
||
|
_len = len;
|
||
|
OK = Parse();
|
||
|
}
|
||
|
|
||
|
public TCPmsg(TCPmsg tcp)
|
||
|
{
|
||
|
_rawdata =tcp._rawdata;
|
||
|
_len = tcp._len;
|
||
|
OK = Parse();
|
||
|
}
|
||
|
|
||
|
public TCPmsg(char[] msg)
|
||
|
{
|
||
|
_rawdata = msg;
|
||
|
_len = msg.length;
|
||
|
OK = Parse();
|
||
|
}
|
||
|
|
||
|
private boolean Parse()
|
||
|
{
|
||
|
char[] temp = new char[_len];
|
||
|
for(int i=0;i<_len;i++) temp[i] = _rawdata[i];
|
||
|
data =new String(temp);
|
||
|
//SM.Debug("multi RX: " + data);
|
||
|
this.allData = data;
|
||
|
|
||
|
String[] tempArr = data.split("#");
|
||
|
if ((tempArr.length == 0) || (tempArr.length == 1))
|
||
|
{
|
||
|
SM.Debug("incorect messagebuss message=" + data);
|
||
|
return false;
|
||
|
}
|
||
|
//get msg len
|
||
|
int messLen = -1;
|
||
|
try
|
||
|
{
|
||
|
messLen = Integer.parseInt(tempArr[1]);
|
||
|
} catch (Exception e) {
|
||
|
SM.Debug("incorect msg len =" + tempArr[1]);
|
||
|
return false;
|
||
|
}
|
||
|
//messLen not int
|
||
|
if(messLen ==-1) return false;
|
||
|
|
||
|
if (_len != messLen)
|
||
|
{
|
||
|
SM.Debug("message length("+messLen+") != actual length("+_len+")");
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
seqID = tempArr[2];
|
||
|
opCode = Integer.parseInt(tempArr[3]);
|
||
|
data = "";
|
||
|
for (int i = 4; i < tempArr.length; i++)
|
||
|
{
|
||
|
if(tempArr[i] !="")
|
||
|
data += tempArr[i]+"#";
|
||
|
}
|
||
|
|
||
|
// add sequence ID to data when ack message
|
||
|
if(opCode == OperationCodes.TM_ACK || opCode == OperationCodes.TM_ACK_SD)
|
||
|
data+= seqID + "#";
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
}
|