diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2012-11-02 23:22:25 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2012-11-02 23:22:25 +1300 |
commit | 119b1a9562aee0072c034017405df4cc94feaf35 (patch) | |
tree | 5f2f1faf98f598fdd5f5f014e01ca489f7119e9f | |
parent | 73f1943342354f5a3922561ca7ebefad239ce153 (diff) | |
download | trackermap-server-119b1a9562aee0072c034017405df4cc94feaf35.tar.gz trackermap-server-119b1a9562aee0072c034017405df4cc94feaf35.tar.bz2 trackermap-server-119b1a9562aee0072c034017405df4cc94feaf35.zip |
Add PT502 protocol (fix #75)
-rw-r--r-- | default.cfg | 4 | ||||
-rw-r--r-- | src/org/traccar/Server.java | 27 | ||||
-rwxr-xr-x | test.sh | 3 | ||||
-rw-r--r-- | test/org/traccar/protocol/Pt502ProtocolDecoderTest.java | 18 |
4 files changed, 52 insertions, 0 deletions
diff --git a/default.cfg b/default.cfg index de0301dae..c8186a358 100644 --- a/default.cfg +++ b/default.cfg @@ -160,4 +160,8 @@ <entry key="v680.enable">true</entry> <entry key="v680.port">5016</entry> + <!-- PT502 server configuration --> + <entry key="pt502.enable">true</entry> + <entry key="pt502.port">5017</entry> + </properties> diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 8dd55431f..051d040b9 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -103,6 +103,7 @@ public class Server { initJt600Server(properties); initEv603Server(properties); initV680Server(properties); + initPt502Server(properties); // Initialize web server if (Boolean.valueOf(properties.getProperty("http.enable"))) { @@ -625,4 +626,30 @@ public class Server { serverList.add(server); } } + + /** + * Init PT502 server + */ + private void initPt502Server(Properties properties) throws SQLException { + + String protocol = "pt502"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), resetDelay, geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + byte delimiter[] = { (byte) '\r', (byte) '\n' }; + pipeline.addLast("frameDecoder", + new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new Pt502ProtocolDecoder(getDataManager())); + } + }); + + serverList.add(server); + } + } } @@ -59,3 +59,6 @@ echo "15. ev603" echo "16. v680" (echo -n -e "#123456789012345#1000#0#1000#AUT#1#66830FFB#13000.0000,E,6000.0000,N,001.41,259#010112#121600##";) | nc -v localhost 5016 + +echo "17. pt502" +(echo -n -e "\$POS,123456,121700.000,A,6000.0000,N,13000.0000,E,0.0,0.0,010112,,,A/00000,00000/0/23895000//\r\n";) | nc -v localhost 5017 diff --git a/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java new file mode 100644 index 000000000..8b8881bd8 --- /dev/null +++ b/test/org/traccar/protocol/Pt502ProtocolDecoderTest.java @@ -0,0 +1,18 @@ +package org.traccar.protocol; + +import static org.junit.Assert.assertNotNull; +import org.junit.Test; + +public class Pt502ProtocolDecoderTest { + + @Test + public void testDecode() throws Exception { + + Pt502ProtocolDecoder decoder = new Pt502ProtocolDecoder(new TestDataManager()); + + assertNotNull(decoder.decode(null, null, + "$POS,6094,205523.000,A,1013.6223,N,06728.4248,W,0.0,99.3,011112,,,A/00000,00000/0/23895000//")); + + } + +} |