diff options
Diffstat (limited to 'src/org/traccar')
-rw-r--r-- | src/org/traccar/Device.java | 8 | ||||
-rw-r--r-- | src/org/traccar/GenericProtocolDecoder.java | 30 | ||||
-rw-r--r-- | src/org/traccar/Position.java | 55 | ||||
-rw-r--r-- | src/org/traccar/Server.java | 1 | ||||
-rw-r--r-- | src/org/traccar/helper/NamedParameterStatement.java | 12 | ||||
-rw-r--r-- | src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java | 58 |
6 files changed, 132 insertions, 32 deletions
diff --git a/src/org/traccar/Device.java b/src/org/traccar/Device.java index bf77d2e91..2fb6dfb4e 100644 --- a/src/org/traccar/Device.java +++ b/src/org/traccar/Device.java @@ -29,8 +29,8 @@ public class Device { return id; } - public void setId(Long newId) { - id = newId; + public void setId(Long id) { + this.id = id; } /** @@ -42,8 +42,8 @@ public class Device { return imei; } - public void setImei(String newImei) { - imei = newImei; + public void setImei(String imei) { + this.imei = imei; } } diff --git a/src/org/traccar/GenericProtocolDecoder.java b/src/org/traccar/GenericProtocolDecoder.java index 0d79818ab..c48cf6c56 100644 --- a/src/org/traccar/GenericProtocolDecoder.java +++ b/src/org/traccar/GenericProtocolDecoder.java @@ -35,9 +35,16 @@ public abstract class GenericProtocolDecoder extends OneToOneDecoder { private DataManager dataManager; /** + * Set data manager + */ + public final void setDataManager(DataManager dataManager) { + this.dataManager = dataManager; + } + + /** * Return data manager */ - public DataManager getDataManager() { + public final DataManager getDataManager() { return dataManager; } @@ -45,14 +52,27 @@ public abstract class GenericProtocolDecoder extends OneToOneDecoder { * Reset connection delay */ private Integer resetDelay; - + /** - * Initialize variables + * Set reset connection delay */ - public GenericProtocolDecoder(DataManager dataManager, Integer resetDelay) { - this.dataManager = dataManager; + public final void setResetDelay(Integer resetDelay) { this.resetDelay = resetDelay; } + + /** + * Default constructor + */ + public GenericProtocolDecoder() { + } + + /** + * Initialize + */ + public GenericProtocolDecoder(DataManager dataManager, Integer resetDelay) { + setDataManager(dataManager); + setResetDelay(resetDelay); + } /** * Disconnect channel diff --git a/src/org/traccar/Position.java b/src/org/traccar/Position.java index 79191c4d5..520b49dd2 100644 --- a/src/org/traccar/Position.java +++ b/src/org/traccar/Position.java @@ -31,8 +31,8 @@ public class Position { return id; } - public void setId(Long newId) { - id = newId; + public void setId(Long id) { + this.id = id; } /** @@ -44,8 +44,8 @@ public class Position { return deviceId; } - public void setDeviceId(Long newDeviceId) { - deviceId = newDeviceId; + public void setDeviceId(Long deviceId) { + this.deviceId = deviceId; } /** @@ -57,8 +57,8 @@ public class Position { return time; } - public void setTime(Date newTime) { - time = newTime; + public void setTime(Date time) { + this.time = time; } /** @@ -70,8 +70,8 @@ public class Position { return valid; } - public void setValid(Boolean newValid) { - valid = newValid; + public void setValid(Boolean valid) { + this.valid = valid; } /** @@ -83,8 +83,8 @@ public class Position { return latitude; } - public void setLatitude(Double newLatitude) { - latitude = newLatitude; + public void setLatitude(Double latitude) { + this.latitude = latitude; } /** @@ -96,8 +96,8 @@ public class Position { return longitude; } - public void setLongitude(Double newLongitude) { - longitude = newLongitude; + public void setLongitude(Double longitude) { + this.longitude = longitude; } /** @@ -109,8 +109,8 @@ public class Position { return altitude; } - public void setAltitude(Double newAltitude) { - altitude = newAltitude; + public void setAltitude(Double altitude) { + this.altitude = altitude; } /** @@ -122,8 +122,8 @@ public class Position { return speed; } - public void setSpeed(Double newSpeed) { - speed = newSpeed; + public void setSpeed(Double speed) { + this.speed = speed; } /** @@ -135,8 +135,8 @@ public class Position { return course; } - public void setCourse(Double newCourse) { - course = newCourse; + public void setCourse(Double course) { + this.course = course; } /** @@ -148,8 +148,21 @@ public class Position { return power; } - public void setPower(Double newPower) { - power = newPower; + public void setPower(Double power) { + this.power = power; } - + + /** + * Extended information in XML format + */ + private String extendedInfo; + + public String getExtendedInfo() { + return extendedInfo; + } + + public void setExtendedInfo(String extendedInfo) { + this.extendedInfo = extendedInfo; + } + } diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 16c26b6d6..a84f8f337 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -183,6 +183,7 @@ public class Server implements DataManager { insertPosition.setDouble("speed", position.getSpeed()); insertPosition.setDouble("course", position.getCourse()); insertPosition.setDouble("power", position.getPower()); + insertPosition.setString("extended_info", position.getExtendedInfo()); insertPosition.executeUpdate(); } diff --git a/src/org/traccar/helper/NamedParameterStatement.java b/src/org/traccar/helper/NamedParameterStatement.java index 0e84e9827..c71f7dd05 100644 --- a/src/org/traccar/helper/NamedParameterStatement.java +++ b/src/org/traccar/helper/NamedParameterStatement.java @@ -209,4 +209,16 @@ public class NamedParameterStatement { } } + public void setString(String name, String value) throws SQLException { + + List indexList = (List) indexMap.get(name); + if (indexList != null) for (Object index: indexList) { + if (value != null) { + statement.setString((Integer) index, value); + } else { + statement.setNull((Integer) index, Types.VARCHAR); + } + } + } + } diff --git a/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java b/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java index 382c9e998..4fb33f5ba 100644 --- a/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java +++ b/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java @@ -45,7 +45,7 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { static private Pattern pattern = Pattern.compile( "\\$\\$.{2}" + // Length "(\\d{15})\\|" + // IMEI - ".{2}" + // Alarm Type + "(.{2})" + // Alarm Type "\\$GPRMC," + "(\\d{2})(\\d{2})(\\d{2}).(\\d{3})," + // Time (HHMMSS.SSS) "([AV])," + // Validity @@ -55,7 +55,17 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { "([EW])," + "(\\d+.\\d{2})?," + // Speed "(\\d+.\\d{2})?," + // Course - "(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY) + "(\\d{2})(\\d{2})(\\d{2}),[^\\|]*\\|" + // Date (DDMMYY) + "(\\d+.\\d)\\|(\\d+.\\d)\\|(\\d+.\\d)\\|" + // Dilution of precision + "(\\d{12})\\|" + // Status + "(\\d{14})\\|" + // Clock + "(\\d{8})\\|" + // Voltage + "(\\d{8})\\|" + // ADC + "(.{8})\\|" + // Cell + "(.\\d{3})\\|" + // Temperature + "(\\d+.\\d{4})\\|" + // Mileage + "(\\d{4})\\|" + // Serial + "(.{10})?\\|" + // RFID ".+"); /** * Decode message @@ -73,6 +83,7 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { // Create new position Position position = new Position(); + String extendedInfo = "<protocol>avl08</protocol>"; Integer index = 1; @@ -80,6 +91,9 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { String imei = parser.group(index++); position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + // Alarm type + extendedInfo += "<alarm>" + parser.group(index++) + "</alarm>"; + // Time Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); time.clear(); @@ -123,6 +137,46 @@ public class Avl08ProtocolDecoder extends GenericProtocolDecoder { time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); position.setTime(time.getTime()); + // Dilution of precision + extendedInfo += "<pdop>" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + "</pdop>"; + extendedInfo += "<hdop>" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + "</hdop>"; + extendedInfo += "<vdop>" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + "</vdop>"; + + // Status + extendedInfo += "<status>" + parser.group(index++) + "</status>"; + + // Real time clock + extendedInfo += "<clock>" + parser.group(index++) + "</clock>"; + + // Voltage + String voltage = parser.group(index++); + position.setPower(Double.valueOf(voltage.substring(1, 4)) / 100); + extendedInfo += "<voltage>" + voltage + "</voltage>"; + + // ADC + extendedInfo += "<adc>" + parser.group(index++) + "</adc>"; + + // Cell + extendedInfo += "<cell>" + parser.group(index++) + "</cell>"; + + // Temperature + extendedInfo += "<temperature>" + parser.group(index++) + "</temperature>"; + + // Mileage + extendedInfo += "<mileage>" + parser.group(index++) + "</mileage>"; + + // Serial + extendedInfo += "<serial>" + parser.group(index++).replaceFirst ("^0*", "") + "</serial>"; + + // RFID + String rfid = parser.group(index++); + if (rfid != null) { + extendedInfo += "<rfid>" + rfid + "</rfid>"; + } + + // Extended info + position.setExtendedInfo(extendedInfo); + return position; } |