diff options
-rw-r--r-- | default.cfg | 8 | ||||
-rw-r--r-- | src/org/traccar/Server.java | 34 | ||||
-rw-r--r-- | src/org/traccar/model/DatabaseDataManager.java | 1 | ||||
-rw-r--r-- | src/org/traccar/protocol/ProgressProtocolDecoder.java | 51 | ||||
-rwxr-xr-x | test.sh | 11 |
5 files changed, 95 insertions, 10 deletions
diff --git a/default.cfg b/default.cfg index 74f2f390b..0feb9338b 100644 --- a/default.cfg +++ b/default.cfg @@ -180,5 +180,13 @@ <!-- Skypatrol server configuration --> <entry key="skypatrol.enable">true</entry> <entry key="skypatrol.port">5021</entry> + + <!-- GT02 server configuration --> + <entry key="gt02.enable">true</entry> + <entry key="gt02.port">5022</entry> + + <!-- GT06 server configuration --> + <entry key="gt06.enable">true</entry> + <entry key="gt06.port">5023</entry> </properties> diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 9deb271da..506513b60 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -111,6 +111,8 @@ public class Server { initNavisServer(properties); initMeitrackServer(properties); initSkypatrolServer(properties); + initGt02Server(properties); + initGt06Server(properties); // Initialize web server if (Boolean.valueOf(properties.getProperty("http.enable"))) { @@ -810,4 +812,36 @@ public class Server { serverList.add(server); } } + + /** + * Init GT02 server + */ + private void initGt02Server(Properties properties) throws SQLException { + + String protocol = "gt02"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(new ServerBootstrap()); + server.setPort(getProtocolPort(properties, protocol)); + server.setAddress(getProtocolInterface(properties, protocol)); + //server.setEndianness(ByteOrder.LITTLE_ENDIAN); + final Integer resetDelay = getProtocolResetDelay(properties, protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), resetDelay, geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(4 * 1024, 12, 2, 2, 0)); + pipeline.addLast("objectDecoder", new NavisProtocolDecoder(getDataManager())); + } + }); + + serverList.add(server); + } + } + + /** + * Init GT06 server + */ + private void initGt06Server(Properties properties) throws SQLException { + } + } diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java index f17839594..073d6ef71 100644 --- a/src/org/traccar/model/DatabaseDataManager.java +++ b/src/org/traccar/model/DatabaseDataManager.java @@ -220,6 +220,7 @@ public class DatabaseDataManager implements DataManager { queryAddPosition.prepare(); + queryAddPosition.setLong("id", position.getId()); queryAddPosition.setLong("device_id", position.getDeviceId()); queryAddPosition.setTimestamp("time", position.getTime()); queryAddPosition.setBoolean("valid", position.getValid()); diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index 0494b339f..64aca8157 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -15,9 +15,9 @@ */ package org.traccar.protocol; +import java.nio.charset.Charset; import java.util.Calendar; import java.util.TimeZone; -import java.nio.charset.Charset; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; @@ -60,6 +60,7 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { /** * Decode message */ + @Override protected Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { @@ -74,22 +75,24 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { length = buf.readUnsignedShort(); buf.skipBytes(length); length = buf.readUnsignedShort(); + buf.skipBytes(length); + length = buf.readUnsignedShort(); String imei = buf.readBytes(length).toString(Charset.defaultCharset()); try { deviceId = getDataManager().getDeviceByImei(imei).getId(); } catch(Exception error) { - Log.warning("Unknown device - " + imei); + Log.warning("Unknown device - " + imei + " (id - " + id + ")"); } } // Position - else if (type == MSG_POINT || type == MSG_ALARM) { + else if (deviceId != 0 && (type == MSG_POINT || type == MSG_ALARM)) { Position position = new Position(); StringBuilder extendedInfo = new StringBuilder("<protocol>progress</protocol>"); position.setDeviceId(deviceId); // Message index - buf.readUnsignedInt(); + position.setId(buf.readUnsignedInt()); // Time Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); @@ -114,9 +117,11 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { // Satellites int satellitesNumber = buf.readUnsignedByte(); - extendedInfo.append("<sat>"); + extendedInfo.append("<satellites>"); extendedInfo.append(satellitesNumber); - extendedInfo.append("</sat>"); + extendedInfo.append("</satellites>"); + + // Validity position.setValid(satellitesNumber >= 3); // TODO: probably wrong // Cell signal @@ -124,10 +129,35 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append(buf.readUnsignedByte()); extendedInfo.append("</gsm>"); - // TODO: process other data + // Milage + extendedInfo.append("<milage>"); + extendedInfo.append(buf.readUnsignedInt()); + extendedInfo.append("</milage>"); + + long extraFlags = buf.readLong(); + + // Analog inputs + if ((extraFlags & 0x1) == 0x1) { + int count = buf.readUnsignedShort(); + for (int i = 1; i <= count; i++) { + extendedInfo.append("<adc").append(i).append(">"); + extendedInfo.append(buf.readUnsignedShort()); + extendedInfo.append("</adc").append(i).append(">"); + } + + } - // Extended info - position.setExtendedInfo(extendedInfo.toString()); + // CAN adapter + if ((extraFlags & 0x2) == 0x2) { + int size = buf.readUnsignedShort(); + buf.skipBytes(size); + } + + // Passenger sensor + if ((extraFlags & 0x4) == 0x4) { + int size = buf.readUnsignedShort(); + buf.skipBytes(size); + } // Send response for alarm message if (type == MSG_ALARM) { @@ -137,6 +167,9 @@ public class ProgressProtocolDecoder extends GenericProtocolDecoder { extendedInfo.append("<alarm>true</alarm>"); } + // Extended info + position.setExtendedInfo(extendedInfo.toString()); + return position; } @@ -69,5 +69,14 @@ echo "18. tr20" echo "19. navis" -echo "18. tr20" +echo "20. meitrack" (echo -n -e "\$\$d138,123456789012345,AAA,35,60.000000,130.000000,120101122000,A,7,18,0,0,0,49,3800,24965,510|10|0081|4F4F,0000,000D|0010|0012|0963|0000,,*BF\r\n";) | nc -v localhost 5020 + +echo "21. skypatrol" + + +echo "22. gt02" + + +echo "23. gt06" + |