aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/KhdProtocolDecoder.java21
-rw-r--r--src/org/traccar/protocol/NoranProtocolDecoder.java32
2 files changed, 30 insertions, 23 deletions
diff --git a/src/org/traccar/protocol/KhdProtocolDecoder.java b/src/org/traccar/protocol/KhdProtocolDecoder.java
index da41daa0e..1ae192bf5 100644
--- a/src/org/traccar/protocol/KhdProtocolDecoder.java
+++ b/src/org/traccar/protocol/KhdProtocolDecoder.java
@@ -36,8 +36,14 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
private String readSerialNumber(ChannelBuffer buf) {
int b1 = buf.readUnsignedByte();
- int b2 = buf.readUnsignedByte(); if (b2 > 0x80) b2 -= 0x80;
- int b3 = buf.readUnsignedByte(); if (b3 > 0x80) b3 -= 0x80;
+ int b2 = buf.readUnsignedByte();
+ if (b2 > 0x80) {
+ b2 -= 0x80;
+ }
+ int b3 = buf.readUnsignedByte();
+ if (b3 > 0x80) {
+ b3 -= 0x80;
+ }
int b4 = buf.readUnsignedByte();
String serialNumber = String.format("%02d%02d%02d%02d", b1, b2, b3, b4);
return String.valueOf(Long.parseLong(serialNumber));
@@ -63,12 +69,8 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
int type = buf.readUnsignedByte();
buf.readUnsignedShort(); // size
- if (type == MSG_ON_DEMAND ||
- type == MSG_POSITION_UPLOAD ||
- type == MSG_POSITION_REUPLOAD ||
- type == MSG_ALARM ||
- type == MSG_REPLY ||
- type == MSG_PERIPHERAL) {
+ if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD
+ || type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) {
// Create new position
Position position = new Position();
@@ -118,7 +120,8 @@ public class KhdProtocolDecoder extends BaseProtocolDecoder {
}
- // TODO: parse extra data
+ // parse extra data
+
return position;
} else if (type == MSG_LOGIN && channel != null) {
diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java
index bca741c9f..11408b1ed 100644
--- a/src/org/traccar/protocol/NoranProtocolDecoder.java
+++ b/src/org/traccar/protocol/NoranProtocolDecoder.java
@@ -47,8 +47,7 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
@Override
protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg)
- throws Exception {
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
@@ -58,29 +57,28 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
if (type == MSG_SHAKE_HAND && channel != null) {
ChannelBuffer response = ChannelBuffers.dynamicBuffer(ByteOrder.LITTLE_ENDIAN, 13);
- response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", Charset.defaultCharset()));
+ response.writeBytes(
+ ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n*KW", Charset.defaultCharset()));
response.writeByte(0);
response.writeShort(response.capacity());
response.writeShort(MSG_SHAKE_HAND_RESPONSE);
response.writeByte(1); // status
- response.writeBytes(ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", Charset.defaultCharset()));
+ response.writeBytes(
+ ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "\r\n", Charset.defaultCharset()));
channel.write(response, remoteAddress);
- } else if (type == MSG_UPLOAD_POSITION ||
- type == MSG_UPLOAD_POSITION_NEW ||
- type == MSG_CONTROL_RESPONSE ||
- type == MSG_ALARM) {
+ } else if (type == MSG_UPLOAD_POSITION || type == MSG_UPLOAD_POSITION_NEW
+ || type == MSG_CONTROL_RESPONSE || type == MSG_ALARM) {
boolean newFormat = false;
- if (type == MSG_UPLOAD_POSITION && buf.readableBytes() == 48 ||
- type == MSG_ALARM && buf.readableBytes() == 48 ||
- type == MSG_CONTROL_RESPONSE && buf.readableBytes() == 57 ||
- type == MSG_UPLOAD_POSITION_NEW) {
+ if (type == MSG_UPLOAD_POSITION && buf.readableBytes() == 48
+ || type == MSG_ALARM && buf.readableBytes() == 48
+ || type == MSG_CONTROL_RESPONSE && buf.readableBytes() == 57
+ || type == MSG_UPLOAD_POSITION_NEW) {
newFormat = true;
}
- // Create new position
Position position = new Position();
position.setProtocol(getProtocolName());
@@ -122,7 +120,13 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder {
}
// Identification
- String id = buf.readBytes(newFormat ? 12 : 11).toString(Charset.defaultCharset()).replaceAll("[^\\p{Print}]", "");
+ ChannelBuffer rawId;
+ if (newFormat) {
+ rawId = buf.readBytes(12);
+ } else {
+ rawId = buf.readBytes(11);
+ }
+ String id = rawId.toString(Charset.defaultCharset()).replaceAll("[^\\p{Print}]", "");
if (!identify(id, channel, remoteAddress)) {
return null;
}