aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/ST210ProtocolDecoder.java198
1 files changed, 105 insertions, 93 deletions
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;
}
+
}