Skip to content

Commit

Permalink
Support Castel response messages
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed May 2, 2018
1 parent d28bad4 commit ff1f4cc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/org/traccar/protocol/CastelProtocolDecoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public CastelProtocolDecoder(CastelProtocol protocol) {
public static final short MSG_SC_GPS_SLEEP = 0x4009;
public static final short MSG_SC_FUEL = 0x400E;
public static final short MSG_SC_AGPS_REQUEST = 0x5101;
public static final short MSG_SC_QUERY_RESPONSE = (short) 0xA002;
public static final short MSG_SC_CURRENT_LOCATION = (short) 0xB001;

public static final short MSG_CC_LOGIN = 0x4001;
Expand Down Expand Up @@ -272,7 +273,7 @@ private void decodeAlarm(Position position, int alarm) {

private Object decodeSc(
Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
int version, ChannelBuffer id, short type, DeviceSession deviceSession) {

if (type == MSG_SC_HEARTBEAT) {

Expand Down Expand Up @@ -395,14 +396,36 @@ private Object decodeSc(

return position;

} else if (type == MSG_SC_QUERY_RESPONSE) {

Position position = createPosition(deviceSession);

buf.readUnsignedShort(); // index
buf.readUnsignedByte(); // response count
buf.readUnsignedByte(); // response index

int failureCount = buf.readUnsignedByte();
for (int i = 0; i < failureCount; i++) {
buf.readUnsignedShort(); // tag
}

int successCount = buf.readUnsignedByte();
for (int i = 0; i < successCount; i++) {
buf.readUnsignedShort(); // tag
position.set(Position.KEY_RESULT,
buf.readBytes(buf.readUnsignedShort()).toString(StandardCharsets.US_ASCII));
}

return position;

}

return null;
}

private Object decodeCc(
Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
int version, ChannelBuffer id, short type, DeviceSession deviceSession) {

if (type == MSG_CC_HEARTBEAT) {

Expand Down Expand Up @@ -459,7 +482,7 @@ private Object decodeCc(

private Object decodeMpip(
Channel channel, SocketAddress remoteAddress, ChannelBuffer buf,
int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
int version, ChannelBuffer id, short type, DeviceSession deviceSession) {

if (type == 0x4001) {

Expand Down Expand Up @@ -513,7 +536,7 @@ protected Object decode(
}

ChannelBuffer id = buf.readBytes(20);
int type = ChannelBuffers.swapShort(buf.readShort());
short type = ChannelBuffers.swapShort(buf.readShort());

DeviceSession deviceSession = getDeviceSession(
channel, remoteAddress, id.toString(StandardCharsets.US_ASCII).trim());
Expand Down
3 changes: 3 additions & 0 deletions test/org/traccar/protocol/CastelProtocolDecoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public void testDecode() throws Exception {

CastelProtocolDecoder decoder = new CastelProtocolDecoder(new CastelProtocol());

verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"40403a00043231335750323031373030363135360000000000a00200000100000101201100344a474446364545374a4230373632363056ff0d0a"));

verifyAttributes(decoder, binary(ByteOrder.LITTLE_ENDIAN,
"4040560004323133474c3230313630303033363400000000004002a122a05a5423a05abe0f2a000000000007f1f90014000000040001640011170003001e000505210b210c210d210f2101062b58ef02001a25950d0a"));

Expand Down

0 comments on commit ff1f4cc

Please sign in to comment.