diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2012-08-12 12:58:34 +0400 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2012-08-12 12:58:34 +0400 |
commit | e906b67f900cef0d2c8a167a4a88203a988ed7a9 (patch) | |
tree | 0b206ae0ce3a76b4341dec9233049a265132c143 | |
parent | c15648e44efd68f26df6b84240e99fe10c66d0c1 (diff) | |
parent | 4aaf5dd3cf3d1b089bb168ffdb2ed8f75e2899c6 (diff) | |
download | trackermap-server-e906b67f900cef0d2c8a167a4a88203a988ed7a9.tar.gz trackermap-server-e906b67f900cef0d2c8a167a4a88203a988ed7a9.tar.bz2 trackermap-server-e906b67f900cef0d2c8a167a4a88203a988ed7a9.zip |
Merge https://github.com/williamchitto/traccar
Conflicts:
test.sh
-rw-r--r-- | README_MAVEN.txt | 42 | ||||
-rw-r--r-- | src/org/traccar/protocol/ST210ProtocolDecoder.java | 198 | ||||
-rw-r--r-- | test/org/traccar/protocol/ST210ProtocolDecoderTest.java | 111 |
3 files changed, 210 insertions, 141 deletions
diff --git a/README_MAVEN.txt b/README_MAVEN.txt new file mode 100644 index 000000000..0f0ed8eb7 --- /dev/null +++ b/README_MAVEN.txt @@ -0,0 +1,42 @@ +----------------ECLIPSE------------------------- +If you use Eclipse for Jave EE, you can simply import the generated +project into Eclipse. We've tested against Eclipse 3.6. Later versions +will likely also work, earlier versions may not. + +Eclipse users will need to install the following plugin components: +======= +- m2eclipse Core +- Maven Integration for WTP (in m2eclipse extras) + Instructions for installing the maven plugins can be found here: + http://m2eclipse.sonatype.org/installing-m2eclipse.html + +Ensure Eclipse is configured to use Java 1.6 as this sample uses +AppEngine. + +In Eclipse, go to the File menu and choose: + + File -> Import... -> Existing Maven Projects into Workspace + + Select the directory containing this file. + + Click Finish. + +You can now browse the project in Eclipse. + +To compile your project for deployment, just type 'mvn package'. + +--------------NETBEANS----------------- + +From the NetBeans IDE, install the Maven plugin. To do this, select Tools->Plugins, select Maven, click Install, and follow the prompts. + +Configure Maven in NetBeans IDE. To do this, select Tools->Options, select Miscellaneous from the top panel, then select the Maven tab. + +For the External Maven Home field, browse to your Maven installation. + +If the option is available, check Always use external Maven for building projects. Close the dialog. + +From the NetBeans IDE, select File->Open Project, and then browse to the location of the project you'd like to open. + +Check Open as Main Project, then click Open Project. + +Right-click the project and select Run. diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 230dd5505..f503fead6 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -1,6 +1,7 @@ package org.traccar.protocol; import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; @@ -15,40 +16,38 @@ import org.traccar.model.DataManager; import org.traccar.model.Position; public class ST210ProtocolDecoder extends GenericProtocolDecoder { + - /** - * Initialize - */ public ST210ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - super(dataManager, resetDelay); - } - - private enum ST210FIELDS { - HDR_STATUS("SA200STT;", "Status Report"), HDR_EMERGENCY("SA200EMG;", - "Emergency Report"), HDR_EVENT("SA200EVT;", "Event Report"), HDR_ALERT( - "SA200ALT;", "Alert Report"), HDR_ALIVE("SA200ALV;", - "Alive Report"), DEV_ID("(\\d+);", "Device ID"), SW_VER( - "(\\d{3});", "Software Release Version"), DATE("(\\d+);", - "GPS date (yyyymmdd) Year + Month + Day"), TIME( - "(\\d{2}:\\d{2}:\\d{2});", - "GPS time (hh:mm:ss) Hour : Minute : Second"), CELL( - "(\\d{2}\\w\\d{2});", - "Location Code ID (3 digits hex) + Serving Cell BSIC(2 digits decimal)"), LAT( - "(-\\d{2}.\\d+);", "Latitude (+/-xx.xxxxxx)"), LON( - "(-\\d{3}.\\d+);", "Longitude (+/-xxx.xxxxxx)"), SPD( - "(\\d{3}.\\d{3});", - "Speed in km/h - This value returns to 0 when it is over than 200,000Km"), CRS( - "(\\d{3}.\\d{2});", "Course over ground in degree"), SATT( - "(\\d+);", "Number of satellites"), FIX("(\\d);", - "GPS is fixed(1)\n" + "GPS is not fixed(0)"), DIST("(\\d+);", - "Traveled ddistance in meter"), PWR_VOLT("(\\d{2}.\\d{2});", - "Voltage value of main power"), IO("(\\d+);", - "Current I/O status of inputs and outputs."), MODE("(\\d);", - "1 = Idle mode (Parking)\n" + "2 = Active Mode (Driving)"), MSG_NUM( - "(\\d{4})", - "Message number - After 9999 is reported, message number returns to 0000"), EMG_ID( - "(\\d);", "Emergency type"), EVT_ID("(\\d);", "Event type"), ALERT_ID( - "(\\d);", "Alert type"); + super(dataManager, resetDelay); + } + + private enum ST210FIELDS { + HDR_STATUS("SA200STT;", + "Status Report"), + HDR_EMERGENCY("SA200EMG;","Emergency Report"), + HDR_EVENT("SA200EVT;", "Event Report"), + HDR_ALERT("SA200ALT;","Alert Report"), + HDR_ALIVE("SA200ALV;","Alive Report"), + DEV_ID("(\\d+);", "Device ID"), + SW_VER("(\\d{3});", "Software Release Version"), + DATE("(\\d+);","GPS date (yyyymmdd) Year + Month + Day"), + TIME("(\\d{2}:\\d{2}:\\d{2});","GPS time (hh:mm:ss) Hour : Minute : Second"), + CELL("(\\d{2}\\w\\d{2});","Location Code ID (3 digits hex) + Serving Cell BSIC(2 digits decimal)"), + LAT("(-\\d{2}.\\d+);", "Latitude (+/-xx.xxxxxx)"), + LON("(-\\d{3}.\\d+);", "Longitude (+/-xxx.xxxxxx)"), + SPD("(\\d{3}.\\d{3});","Speed in km/h - This value returns to 0 when it is over than 200,000Km"), + CRS("(\\d{3}.\\d{2});", "Course over ground in degree"), + SATT("(\\d+);", "Number of satellites"), + FIX("(\\d);","GPS is fixed(1)\n" + "GPS is not fixed(0)"), + DIST("(\\d+);","Traveled ddistance in meter"), + PWR_VOLT("(\\d+.\\d{2});","Voltage value of main power"), + IO("(\\d+);","Current I/O status of inputs and outputs."), + MODE("(\\d);","1 = Idle mode (Parking)\n" + "2 = Active Mode (Driving)"), + MSG_NUM("(\\d{4})","Message number - After 9999 is reported, message number returns to 0000"), + EMG_ID("(\\d)", "Emergency type"), + EVT_ID("(\\d);", "Event type"), + ALERT_ID("(\\d);", "Alert type"); private String pattern; @@ -99,34 +98,41 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case DATE: { // Date - Calendar time = Calendar.getInstance(TimeZone - .getTimeZone("UTC")); + Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); - time.set(Calendar.YEAR, Integer.valueOf(Integer - .valueOf(groupValue.substring(0, 4)))); - time.set(Calendar.MONTH, Integer.valueOf(Integer - .valueOf(groupValue.substring(4, 6)))); - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer - .valueOf(groupValue.substring(6, 8)))); - position.setTime(time.getTime()); + time.set(Calendar.YEAR, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 4)))); + time.set(Calendar.MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(4, 6))-1)); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8)))); + + Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + + ret.setTimeInMillis(time.getTimeInMillis() + + TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) - + TimeZone.getDefault().getOffset(time.getTimeInMillis())); + + position.setTime(ret.getTime()); + break; } case TIME: { - Calendar time = Calendar.getInstance(TimeZone - .getTimeZone("UTC")); + Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); time.setTime(position.getTime()); - - time.set(Calendar.HOUR, Integer.valueOf(Integer - .valueOf(groupValue.substring(0, 2)))); - time.set(Calendar.MINUTE, Integer.valueOf(Integer - .valueOf(groupValue.substring(3, 5)))); - time.set(Calendar.SECOND, Integer.valueOf(Integer - .valueOf(groupValue.substring(6, 8)))); - - position.setTime(time.getTime()); + + time.set(Calendar.HOUR_OF_DAY, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 2)))); + time.set(Calendar.MINUTE, Integer.valueOf(Integer.valueOf(groupValue.substring(3, 5)))); + time.set(Calendar.SECOND, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8)))); + + Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + + ret.setTimeInMillis(time.getTimeInMillis() + + TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) - + TimeZone.getDefault().getOffset(time.getTimeInMillis())); + + position.setTime(ret.getTime()); + break; } @@ -169,7 +175,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 0: return NOT_FIXED; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -206,16 +212,16 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 2: return DRIVING; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } private enum FIELD_EMG_ID_VALUE { - PANIC(1, "Emergency by panic button"), PARKING(2, - "Emergency by parking lock"), MAIN_POWER(3, - "Emergency by removing main power"), ANTI_THEFT(5, - "Emergency by anti-theft"); + PANIC(1, "Emergency by panic button"), + PARKING(2,"Emergency by parking lock"), + MAIN_POWER(3,"Emergency by removing main power"), + ANTI_THEFT(5,"Emergency by anti-theft"); private int value; @@ -250,18 +256,18 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 5: return ANTI_THEFT; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } private enum FIELD_EVT_ID_VALUE { - INPUT1_GROUND(1, "Input1 goes to ground state"), INPUT1_OPEN(2, - "Input1 goes to open state"), INPUT2_GROUND(3, - "Input2 goes to ground state"), INPUT2_OPEN(4, - "Input2 goes to open state"), INPUT3_GROUND(5, - "Input3 goes to ground state"), INPUT3_OPEN(6, - "Input3 goes to open state"); + INPUT1_GROUND(1, "Input1 goes to ground state"), + INPUT1_OPEN(2,"Input1 goes to open state"), + INPUT2_GROUND(3,"Input2 goes to ground state"), + INPUT2_OPEN(4,"Input2 goes to open state"), + INPUT3_GROUND(5,"Input3 goes to ground state"), + INPUT3_OPEN(6,"Input3 goes to open state"); private int value; @@ -283,7 +289,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { public FIELD_EVT_ID_VALUE getValueOf(String indiceStr) { int indice = Integer.valueOf(indiceStr); return getValueOf(indice); - } + } public FIELD_EVT_ID_VALUE getValueOf(int indice) { switch (indice) { @@ -300,27 +306,27 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 6: return INPUT3_OPEN; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } private enum FIELD_ALERT_ID_VALUE { - DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), OVER_SPPED( - 2, "Ended over speed condition"), DISCON_GPS(3, - "Disconnected GPS antenna"), RECON_GPS(4, - "Reconnected GPS antenna after disconnected"), OUT_GEO_FENCE(5, - "The vehicle went out from the geo-fence that has following ID"), INTO_GEO_FENCE( - 6, - "The vehicle entered into the geo-fence that has following ID"), SHORTED_GPS( - 8, "Shorted GPS antenna"), DEEP_SLEEP_ON(9, - "Enter to deep sleep mode"), DEEP_SLEEP_OFF(10, - "Exite from deep sleep mode"), BKP_BATTERY(13, - "Backup battery error"), BATTERY_DOWN(14, - "Vehicle battery goes down to so low level"), SHOCKED(15, - "Shocked"), COLLISION(16, "Occurred some collision"), DEVIATE_ROUT( - 18, "Deviate from predefined rout"), ENTER_ROUT(19, - "Enter into predefined rout"); + DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), + OVER_SPPED(2, "Ended over speed condition"), + DISCON_GPS(3,"Disconnected GPS antenna"), + RECON_GPS(4,"Reconnected GPS antenna after disconnected"), + OUT_GEO_FENCE(5,"The vehicle went out from the geo-fence that has following ID"), + INTO_GEO_FENCE(6,"The vehicle entered into the geo-fence that has following ID"), + SHORTED_GPS(8, "Shorted GPS antenna"), + DEEP_SLEEP_ON(9,"Enter to deep sleep mode"), + DEEP_SLEEP_OFF(10,"Exite from deep sleep mode"), + BKP_BATTERY(13,"Backup battery error"), + BATTERY_DOWN(14,"Vehicle battery goes down to so low level"), + SHOCKED(15,"Shocked"), + COLLISION(16, "Occurred some collision"), + DEVIATE_ROUT(18, "Deviate from predefined rout"), + ENTER_ROUT(19,"Enter into predefined rout"); private int value; @@ -377,7 +383,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 19: return ENTER_ROUT; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -594,13 +600,21 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { }; @Override - public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - if (channel != null) { - channel.write("OI AMIGO do decoder"); - } + public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) { String sentence = (String) msg; - return decodeMsg(sentence); + Log.info("Msg: " + msg); + + Position position = null; + + try{ + position = decodeMsg(sentence); + Log.info("MESSAGE DECODED WITH SUCCESS!"); + } + catch(Exception e){ + Log.info("ERROR WHILE DECODING MESSAGE: " + e.getMessage()); + } + + return position; } public Position decodeMsg(String msg) throws Exception { @@ -611,13 +625,10 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { Pattern protocolPattern = report.getProtocolPattern(); - Log.info("Protocol Pattern: " + protocolPattern.toString()); - Log.info("Msg: " + msg); - // Parse message Matcher parser = protocolPattern.matcher(msg); if (!parser.matches()) { - return null; + throw new Exception("Pattern no match: " + protocolPattern.toString()); } // Create new position @@ -637,4 +648,5 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { return position; } + } diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java index cf5b0b8e6..88ad9f306 100644 --- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java @@ -10,64 +10,79 @@ import org.junit.BeforeClass; import org.junit.Test; import org.traccar.Server; import org.traccar.helper.Log; -//import org.traccar.server.SocketCliente; +import org.traccar.server.SocketCliente; public class ST210ProtocolDecoderTest { - /*@BeforeClass - public static void UpServer() { - final Server service = new Server(); - String[] args = new String[1]; - args[0] = "setup\\windows\\windows.cfg"; - try { - service.init(args); + /* + @BeforeClass + public static void UpServer() { + final Server service = new Server(); + String[] args = new String[1]; + args[0] = "setup\\windows\\windows.cfg"; + try { + service.init(args); - Log.info("starting server..."); - service.start(); + Log.info("starting server..."); + service.start(); - // Shutdown server properly - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - Log.info("shutting down server..."); - service.stop(); - } - }); + // Shutdown server properly + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + Log.info("shutting down server..."); + service.stop(); + } + }); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } - @Test - public void testClienteMsg() throws Exception { + @Test + public void testClienteMsg() throws Exception { - SocketCliente cliente = new SocketCliente(); - cliente.SendMSG( - "localhost", - 5010, - "SA200STT;317652;042;20120718;15:37:12;16d41;-15.618755;-056.083241;000.024;000.00;8;1;41548;12.17;100000;2;1979"); + SocketCliente cliente = new SocketCliente(); + cliente.SendMSG( + "localhost", + 5010, + "SA200STT;317652;042;20120718;15:37:12;16d41;-15.618755;-056.083241;000.024;000.00;8;1;41548;12.17;100000;2;1979"); + } - }*/ +*/ + + @Test + public void testDecode() throws Exception { -/* @Test - public void testDecode() throws Exception { + ST210ProtocolDecoder decoder = new ST210ProtocolDecoder( + new TestDataManager(), 0); - ST210ProtocolDecoder decoder = new ST210ProtocolDecoder( - new TestDataManager(), 0); + assertNotNull(decoder + .decode(null, + null, + "SA200STT;317652;042;20120718;15:37:12;16d41;-15.618755;-056.083241;000.024;000.00;8;1;41548;12.17;100000;2;1979")); + assertNotNull(decoder + .decode(null, + null, + "SA200STT;317652;042;20120721;19:04:30;16d41;-15.618743;-056.083221;000.001;000.00;12;1;41557;12.21;000000;1;3125")); + assertNotNull(decoder + .decode(null, + null, + "SA200STT;317652;042;20120722;00:24:23;16d41;-15.618767;-056.083214;000.011;000.00;11;1;41557;12.21;000000;1;3205")); + assertNotNull(decoder + .decode(null, + null, + "SA200STT;315198;042;20120808;20:37:34;42948;-15.618731;-056.083216;000.007;000.00;12;1;48;0.00;000000;1;0127")); + assertNotNull(decoder + .decode(null, + null, + "SA200STT;315198;042;20120809;13:43:34;16d41;-15.618709;-056.083223;000.025;000.00;8;1;49;12.10;100000;2;0231")); + assertNotNull(decoder + .decode(null, + null, + "SA200EMG;317652;042;20120718;15:35:41;16d41;-15.618740;-056.083252;000.034;000.00;8;1;41548;12.17;110000;1")); + } - assertNotNull(decoder - .decode(null, - null, - "SA200STT;317652;042;20120718;15:37:12;16d41;-15.618755;-056.083241;000.024;000.00;8;1;41548;12.17;100000;2;1979")); - assertNotNull(decoder - .decode(null, - null, - "SA200STT;317652;042;20120721;19:04:30;16d41;-15.618743;-056.083221;000.001;000.00;12;1;41557;12.21;000000;1;3125")); - assertNotNull(decoder - .decode(null, - null, - "SA200STT;317652;042;20120722;00:24:23;16d41;-15.618767;-056.083214;000.011;000.00;11;1;41557;12.21;000000;1;3205")); - }*/ } |