From 02c1fb78a8b1681325ec01f49ae6ff6603825243 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 26 Apr 2012 19:34:10 +0000 Subject: --- src/org/traccar/Server.java | 18 +- src/org/traccar/protocol/Avl08ProtocolDecoder.java | 184 +++++++++++++++++++++ src/org/traccar/protocol/Gl100ProtocolDecoder.java | 120 ++++++++++++++ src/org/traccar/protocol/Gl200ProtocolDecoder.java | 113 +++++++++++++ .../traccar/protocol/Gps103ProtocolDecoder.java | 133 +++++++++++++++ src/org/traccar/protocol/T55ProtocolDecoder.java | 153 +++++++++++++++++ src/org/traccar/protocol/Tk103ProtocolDecoder.java | 126 ++++++++++++++ .../traccar/protocol/Xexun2ProtocolDecoder.java | 139 ++++++++++++++++ src/org/traccar/protocol/XexunFrameDecoder.java | 92 +++++++++++ src/org/traccar/protocol/XexunProtocolDecoder.java | 128 ++++++++++++++ .../protocol/avl08/Avl08ProtocolDecoder.java | 183 -------------------- .../protocol/gl100/Gl100ProtocolDecoder.java | 120 -------------- .../protocol/gl200/Gl200ProtocolDecoder.java | 113 ------------- .../protocol/gps103/Gps103ProtocolDecoder.java | 133 --------------- .../traccar/protocol/t55/T55ProtocolDecoder.java | 153 ----------------- .../protocol/tk103/Tk103ProtocolDecoder.java | 128 -------------- .../traccar/protocol/xexun/XexunFrameDecoder.java | 92 ----------- .../protocol/xexun/XexunProtocolDecoder.java | 128 -------------- .../protocol/xexun2/Xexun2ProtocolDecoder.java | 139 ---------------- 19 files changed, 1197 insertions(+), 1198 deletions(-) create mode 100644 src/org/traccar/protocol/Avl08ProtocolDecoder.java create mode 100644 src/org/traccar/protocol/Gl100ProtocolDecoder.java create mode 100644 src/org/traccar/protocol/Gl200ProtocolDecoder.java create mode 100644 src/org/traccar/protocol/Gps103ProtocolDecoder.java create mode 100644 src/org/traccar/protocol/T55ProtocolDecoder.java create mode 100644 src/org/traccar/protocol/Tk103ProtocolDecoder.java create mode 100644 src/org/traccar/protocol/Xexun2ProtocolDecoder.java create mode 100644 src/org/traccar/protocol/XexunFrameDecoder.java create mode 100644 src/org/traccar/protocol/XexunProtocolDecoder.java delete mode 100644 src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java delete mode 100644 src/org/traccar/protocol/gl100/Gl100ProtocolDecoder.java delete mode 100644 src/org/traccar/protocol/gl200/Gl200ProtocolDecoder.java delete mode 100644 src/org/traccar/protocol/gps103/Gps103ProtocolDecoder.java delete mode 100644 src/org/traccar/protocol/t55/T55ProtocolDecoder.java delete mode 100644 src/org/traccar/protocol/tk103/Tk103ProtocolDecoder.java delete mode 100644 src/org/traccar/protocol/xexun/XexunFrameDecoder.java delete mode 100644 src/org/traccar/protocol/xexun/XexunProtocolDecoder.java delete mode 100644 src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java (limited to 'src/org') diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index a84f8f337..b5e7acdea 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -39,12 +39,12 @@ import org.jboss.netty.handler.codec.string.StringEncoder; import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.handler.logging.LoggingHandler; -import org.traccar.protocol.xexun.XexunFrameDecoder; -import org.traccar.protocol.xexun.XexunProtocolDecoder; -import org.traccar.protocol.gps103.Gps103ProtocolDecoder; -import org.traccar.protocol.tk103.Tk103ProtocolDecoder; -import org.traccar.protocol.gl200.Gl200ProtocolDecoder; -import org.traccar.protocol.t55.T55ProtocolDecoder; +import org.traccar.protocol.XexunFrameDecoder; +import org.traccar.protocol.XexunProtocolDecoder; +import org.traccar.protocol.Gps103ProtocolDecoder; +import org.traccar.protocol.Tk103ProtocolDecoder; +import org.traccar.protocol.Gl200ProtocolDecoder; +import org.traccar.protocol.T55ProtocolDecoder; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineFactory; @@ -52,9 +52,9 @@ import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.Channels; import org.jboss.netty.channel.SimpleChannelHandler; import org.traccar.helper.AdvancedConnection; -import org.traccar.protocol.gl100.Gl100ProtocolDecoder; -import org.traccar.protocol.xexun2.Xexun2ProtocolDecoder; -import org.traccar.protocol.avl08.Avl08ProtocolDecoder; +import org.traccar.protocol.Gl100ProtocolDecoder; +import org.traccar.protocol.Xexun2ProtocolDecoder; +import org.traccar.protocol.Avl08ProtocolDecoder; /** * Server diff --git a/src/org/traccar/protocol/Avl08ProtocolDecoder.java b/src/org/traccar/protocol/Avl08ProtocolDecoder.java new file mode 100644 index 000000000..7f564af37 --- /dev/null +++ b/src/org/traccar/protocol/Avl08ProtocolDecoder.java @@ -0,0 +1,184 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.Position; +import org.traccar.DataManager; +import org.traccar.Device; // DELME +import org.traccar.GenericProtocolDecoder; + +/** + * AVL-08 tracker protocol decoder + */ +public class Avl08ProtocolDecoder extends GenericProtocolDecoder { + + /** + * Initialize + */ + public Avl08ProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + /** + * Regular expressions pattern + */ + static private Pattern pattern = Pattern.compile( + "\\$\\$.{2}" + // Length + "(\\d{15})\\|" + // IMEI + "(.{2})" + // Alarm Type + "\\$GPRMC," + + "(\\d{2})(\\d{2})(\\d{2}).(\\d{3})," + // Time (HHMMSS.SSS) + "([AV])," + // Validity + "(\\d{2})(\\d{2}.\\d{4})," + // Latitude (DDMM.MMMM) + "([NS])," + + "(\\d{3})(\\d{2}.\\d{4})," + // Longitude (DDDMM.MMMM) + "([EW])," + + "(\\d+.\\d{2})?," + // Speed + "(\\d+.\\d{2})?," + // Course + "(\\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 + ".+"); // TODO: Use non-capturing group + + /** + * Decode message + */ + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + // Parse message + String sentence = (String) msg; + Matcher parser = pattern.matcher(sentence); + if (!parser.matches()) { + return null; + } + + // Create new position + Position position = new Position(); + String extendedInfo = "avl08"; + + Integer index = 1; + + // Get device by IMEI + String imei = parser.group(index++); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + + // Alarm type + extendedInfo += "" + parser.group(index++) + ""; + + // Time + Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + time.clear(); + time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); + time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); + + // Validity + position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); + + // Latitude + Double latitude = Double.valueOf(parser.group(index++)); + latitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; + position.setLatitude(latitude); + + // Longitude + Double lonlitude = Double.valueOf(parser.group(index++)); + lonlitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; + position.setLongitude(lonlitude); + + // Altitude + position.setAltitude(0.0); + + // Speed + position.setSpeed(Double.valueOf(parser.group(index++))); + + // Course + String course = parser.group(index++); + if (course != null) { + position.setCourse(Double.valueOf(course)); + } else { + position.setCourse(0.0); + } + + // Date + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); + time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); + position.setTime(time.getTime()); + + // Dilution of precision + extendedInfo += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; + extendedInfo += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; + extendedInfo += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; + + // Status + extendedInfo += "" + parser.group(index++) + ""; + + // Real time clock + extendedInfo += "" + parser.group(index++) + ""; + + // Voltage + String voltage = parser.group(index++); + position.setPower(Double.valueOf(voltage.substring(1, 4)) / 100); + extendedInfo += "" + voltage + ""; + + // ADC + extendedInfo += "" + parser.group(index++) + ""; + + // Cell + extendedInfo += "" + parser.group(index++) + ""; + + // Temperature + extendedInfo += "" + parser.group(index++) + ""; + + // Mileage + extendedInfo += "" + parser.group(index++) + ""; + + // Serial + extendedInfo += "" + parser.group(index++).replaceFirst ("^0*", "") + ""; + + // RFID + String rfid = parser.group(index++); + if (rfid != null) { + extendedInfo += "" + rfid + ""; + } + + // Extended info + position.setExtendedInfo(extendedInfo); + + return position; + } + +} diff --git a/src/org/traccar/protocol/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/Gl100ProtocolDecoder.java new file mode 100644 index 000000000..4ec41f8c1 --- /dev/null +++ b/src/org/traccar/protocol/Gl100ProtocolDecoder.java @@ -0,0 +1,120 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.Position; +import org.traccar.DataManager; +import org.traccar.GenericProtocolDecoder; + +/** + * GL200 tracker protocol decoder + */ +public class Gl100ProtocolDecoder extends GenericProtocolDecoder { + + /** + * Initialize + */ + public Gl100ProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + /** + * Regular expressions pattern + */ + static private Pattern pattern = Pattern.compile( + "\\+RESP:GT...," + + "(\\d{15})," + // IMEI + "(?:(?:\\d+," + // Number + "\\d," + // Reserved / Geofence id + "\\d)|" + // Reserved / Geofence alert + "(?:[^,]*))," + // Calling number + "([01])," + // GPS fix + "(\\d+.\\d)," + // Speed + "(\\d+)," + // Course + "(-?\\d+.\\d)," + // Altitude + "\\d*," + // GPS accuracy + "(-?\\d+.\\d+)," + // Longitude + "(-?\\d+.\\d+)," + // Latitude + "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD) + "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) + ".*"); + + /** + * Decode message + */ + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + String sentence = (String) msg; + + // Send response + if (sentence.contains("AT+GTHBD=")) { + String response = "+RESP:GTHBD,GPRS ACTIVE,"; + response += sentence.substring(9, sentence.lastIndexOf(',')); + response += '\0'; + channel.write(response); + } + + // Parse message + Matcher parser = pattern.matcher(sentence); + if (!parser.matches()) { + return null; + } + + // Create new position + Position position = new Position(); + + Integer index = 1; + + // Get device by IMEI + String imei = parser.group(index++); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + + // Validity + position.setValid(Integer.valueOf(parser.group(index++)) == 0 ? false : true); + + // Position info + position.setSpeed(Double.valueOf(parser.group(index++))); + position.setCourse(Double.valueOf(parser.group(index++))); + position.setAltitude(Double.valueOf(parser.group(index++))); + position.setLongitude(Double.valueOf(parser.group(index++))); + position.setLatitude(Double.valueOf(parser.group(index++))); + + // Date + Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + time.clear(); + time.set(Calendar.YEAR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + + // Time + time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); + time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); + position.setTime(time.getTime()); + + return position; + } + +} diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java new file mode 100644 index 000000000..a43562eb9 --- /dev/null +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -0,0 +1,113 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.Position; +import org.traccar.DataManager; +import org.traccar.GenericProtocolDecoder; + +/** + * GL200 tracker protocol decoder + */ +public class Gl200ProtocolDecoder extends GenericProtocolDecoder { + + /** + * Initialize + */ + public Gl200ProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + /** + * Regular expressions pattern + */ + static private Pattern pattern = Pattern.compile( + "\\+RESP:GT...," + + "\\d{6}," + // Protocol version + "(\\d{15})," + // IMEI + "[^,]*," + // Device name + "(?:(?:\\d," + // Report ID / Geo mode + "\\d*," + // Report type / Geo radius + "\\d*)|" + // Number / Geo check interval + "(?:[^,]*))," + // Call number + "(\\d*)," + // GPS accuracy + "(\\d+.\\d)," + // Speed + "(\\d+)," + // Course + "(-?\\d+.\\d)," + // Altitude + "(-?\\d+.\\d+)," + // Longitude + "(-?\\d+.\\d+)," + // Latitude + "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD) + "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) + ".*"); + + /** + * Decode message + */ + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + String sentence = (String) msg; + + // Parse message + Matcher parser = pattern.matcher(sentence); + if (!parser.matches()) { + return null; + } + + // Create new position + Position position = new Position(); + + Integer index = 1; + + // Get device by IMEI + String imei = parser.group(index++); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + + // Validity + position.setValid(Integer.valueOf(parser.group(index++)) == 0 ? false : true); + + // Position info + position.setSpeed(Double.valueOf(parser.group(index++))); + position.setCourse(Double.valueOf(parser.group(index++))); + position.setAltitude(Double.valueOf(parser.group(index++))); + position.setLongitude(Double.valueOf(parser.group(index++))); + position.setLatitude(Double.valueOf(parser.group(index++))); + + // Date + Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + time.clear(); + time.set(Calendar.YEAR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + + // Time + time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); + time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); + position.setTime(time.getTime()); + + return position; + } + +} diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java new file mode 100644 index 000000000..e9c889af7 --- /dev/null +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -0,0 +1,133 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.Position; +import org.traccar.DataManager; +import org.traccar.GenericProtocolDecoder; + +/** + * Gps 103 tracker protocol decoder + */ +public class Gps103ProtocolDecoder extends GenericProtocolDecoder { + + /** + * Initialize + */ + public Gps103ProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + /** + * Regular expressions pattern + */ + static private Pattern pattern = Pattern.compile( + "imei:" + + "([\\d]+)," + // IMEI + "[^,]+," + + "(\\d{2})(\\d{2})(\\d{2})[\\d]+," + // Date + "[+]?[\\d]*," + + "[FL]," + // F - full / L - low + "([\\d]{2})([\\d]{2})([\\d]{2}).([\\d]{3})," + // Time (HHMMSS.SSS) + "([AV])," + // Validity + "([\\d]{2})([\\d]{2}.[\\d]{4})," + // Latitude (DDMM.MMMM) + "([NS])," + + "([\\d]{3})([\\d]{2}.[\\d]{4})," + // Longitude (DDDMM.MMMM) + "([EW])," + + "([\\d]+.[\\d]{2})," + // Speed + ".*"); + + /** + * Decode message + */ + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + String sentence = (String) msg; + + // Send response #1 + if (sentence.contains("##")) { + channel.write("LOAD"); + } + + // Send response #2 + if (sentence.length() == 15 && Character.isDigit(sentence.charAt(0))) { + channel.write("ON"); + } + + // Parse message + Matcher parser = pattern.matcher(sentence); + if (!parser.matches()) { + return null; + } + + // Create new position + Position position = new Position(); + + Integer index = 1; + + // Get device by IMEI + String imei = parser.group(index++); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + + // Date + Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + time.clear(); + time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); + time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + + // Time + time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); + time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); + position.setTime(time.getTime()); + + // Validity + position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); + + // Latitude + Double latitude = Double.valueOf(parser.group(index++)); + latitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; + position.setLatitude(latitude); + + // Longitude + Double lonlitude = Double.valueOf(parser.group(index++)); + lonlitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; + position.setLongitude(lonlitude); + + // Altitude + position.setAltitude(0.0); + + // Speed + position.setSpeed(Double.valueOf(parser.group(index++))); + position.setCourse(0.0); + + return position; + } + +} diff --git a/src/org/traccar/protocol/T55ProtocolDecoder.java b/src/org/traccar/protocol/T55ProtocolDecoder.java new file mode 100644 index 000000000..d1ffc7a4d --- /dev/null +++ b/src/org/traccar/protocol/T55ProtocolDecoder.java @@ -0,0 +1,153 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.Position; +import org.traccar.DataManager; +import org.traccar.GenericProtocolDecoder; + +/** + * T55 tracker protocol decoder + */ +public class T55ProtocolDecoder extends GenericProtocolDecoder { + + /** + * Device ID + */ + private Long deviceId; + + /** + * Initialize + */ + public T55ProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + /** + * Regular expressions pattern + */ + static private Pattern pattern = Pattern.compile( + "\\$GPRMC," + + "(\\d{2})(\\d{2})(\\d{2}).(\\d{3})," + // Time (HHMMSS.SSS) + "([AV])," + // Validity + "(\\d{2})(\\d{2}.\\d{4})," + // Latitude (DDMM.MMMM) + "([NS])," + + "(\\d{3})(\\d{2}.\\d{4})," + // Longitude (DDDMM.MMMM) + "([EW])," + + "(\\d+.\\d{2})?," + // Speed + "(\\d+.\\d{2})?," + // Course + "(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY) + ".+"); // Other (Checksumm) + + /** + * Decode message + */ + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + String sentence = (String) msg; + + //System.out.println(sentence); + + // Detect device ID + if (sentence.contains("$PGID")) { + String imei = sentence.substring(6, 6 + 15); + deviceId = getDataManager().getDeviceByImei(imei).getId(); + } + + // Parse message + else if (sentence.contains("$GPRMC") && deviceId != null) { + + // Send response + if (channel != null) { + channel.write("OK1\r\n"); + } + + // Parse message + Matcher parser = pattern.matcher(sentence); + if (!parser.matches()) { + return null; + } + + // Create new position + Position position = new Position(); + position.setDeviceId(deviceId); + + Integer index = 1; + + // Time + Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + time.clear(); + time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); + time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); + index += 1; // Skip milliseconds + + // Validity + position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); + + // Latitude + Double latitude = Double.valueOf(parser.group(index++)); + latitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; + position.setLatitude(latitude); + + // Longitude + Double lonlitude = Double.valueOf(parser.group(index++)); + lonlitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; + position.setLongitude(lonlitude); + + // Speed + String speed = parser.group(index++); + if (speed != null) { + position.setSpeed(Double.valueOf(speed)); + } else { + position.setSpeed(0.0); + } + + // Course + String course = parser.group(index++); + if (course != null) { + position.setCourse(Double.valueOf(course)); + } else { + position.setCourse(0.0); + } + + // Date + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); + time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); + position.setTime(time.getTime()); + + // Altitude + position.setAltitude(0.0); + + return position; + } + + return null; + } + +} diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java new file mode 100644 index 000000000..3eab4a386 --- /dev/null +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -0,0 +1,126 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.TimeZone; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.Position; +import org.traccar.DataManager; +import org.traccar.GenericProtocolDecoder; + +/** + * Gps 103 tracker protocol decoder + */ +public class Tk103ProtocolDecoder extends GenericProtocolDecoder { + + /** + * Initialize + */ + public Tk103ProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + /** + * Regular expressions pattern + */ + static private Pattern pattern = Pattern.compile( + "\\(" + + "(\\d+)" + // Device ID + "(.{4})" + // Command + "(\\d{15})" + // IMEI (?) + "(\\d{2})(\\d{2})(\\d{2})" + // Date (YYMMDD) + "([AV])" + // Validity + "(\\d{2})(\\d{2}.\\d{4})" + // Latitude (DDMM.MMMM) + "([NS])" + + "(\\d{3})(\\d{2}.\\d{4})" + // Longitude (DDDMM.MMMM) + "([EW])" + + "(\\d+.\\d)" + // Speed + "(\\d{2})(\\d{2})(\\d{2})" + // Time (HHMMSS) + "(\\d+.\\d{2})" + // Course + "(\\d+)" + // State + ".+"); // Mileage (?) + + /** + * Decode message + */ + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + String sentence = (String) msg; + + // Parse message + Matcher parser = pattern.matcher(sentence); + if (!parser.matches()) { + return null; + } + + // Create new position + Position position = new Position(); + + Integer index = 1; + index += 2; // Skip Device ID and command + + // Get device by IMEI + String imei = parser.group(index++); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + + // Date + Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + time.clear(); + time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); + time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + + // Validity + position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); + + // Latitude + Double latitude = Double.valueOf(parser.group(index++)); + latitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; + position.setLatitude(latitude); + + // Longitude + Double lonlitude = Double.valueOf(parser.group(index++)); + lonlitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; + position.setLongitude(lonlitude); + + // Altitude + position.setAltitude(0.0); + + // Speed + position.setSpeed(Double.valueOf(parser.group(index++))); + + // Time + time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); + time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); + position.setTime(time.getTime()); + + // Course + position.setCourse(Double.valueOf(parser.group(index++))); + + return position; + } + +} diff --git a/src/org/traccar/protocol/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java new file mode 100644 index 000000000..ce530785e --- /dev/null +++ b/src/org/traccar/protocol/Xexun2ProtocolDecoder.java @@ -0,0 +1,139 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.util.TimeZone; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.Position; +import org.traccar.DataManager; +import org.traccar.GenericProtocolDecoder; + +/** + * Xexun tracker protocol decoder + */ +public class Xexun2ProtocolDecoder extends GenericProtocolDecoder { + + /** + * Initialize + */ + public Xexun2ProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + /** + * Regular expressions pattern + */ + static private Pattern pattern = Pattern.compile( + "[\r\n]*" + + "\\d+," + + "\\+\\d+," + + "GPRMC," + + "(\\d{2})(\\d{2})(\\d{2}).(\\d{3})," + // Time (HHMMSS.SSS) + "([AV])," + // Validity + "(\\d{2})(\\d{2}.\\d{4})," + // Latitude (DDMM.MMMM) + "([NS])," + + "(\\d{3})(\\d{2}.\\d{4})," + // Longitude (DDDMM.MMMM) + "([EW])," + + "(\\d+.\\d+)," + // Speed + "(\\d+.\\d+)?," + // Course + "(\\d{2})(\\d{2})(\\d{2})," + // Date (DDMMYY) + ".*imei:" + + "(\\d+)," + // IMEI + "\\d+," + + "\\d+.\\d+," + + "F:(\\d+.\\d+)V," + // Power + ".*" + + "[\r\n]*"); + + /** + * Decode message + */ + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + // Parse message + String sentence = (String) msg; + Matcher parser = pattern.matcher(sentence); + if (!parser.matches()) { + //throw new ParseException(null, 0); + return null; + } + + // Create new position + Position position = new Position(); + + Integer index = 1; + + // Time + Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + time.clear(); + time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); + time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); + + // Validity + position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); + + // Latitude + Double latitude = Double.valueOf(parser.group(index++)); + latitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; + position.setLatitude(latitude); + + // Longitude + Double lonlitude = Double.valueOf(parser.group(index++)); + lonlitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; + position.setLongitude(lonlitude); + + // Altitude + position.setAltitude(0.0); + + // Speed + position.setSpeed(Double.valueOf(parser.group(index++))); + + // Course + String course = parser.group(index++); + if (course != null) { + position.setCourse(Double.valueOf(course)); + } else { + position.setCourse(0.0); + } + + // Date + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); + time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); + position.setTime(time.getTime()); + + // Get device by IMEI + String imei = parser.group(index++); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + + // Power + position.setPower(Double.valueOf(parser.group(index++))); + + return position; + } + +} diff --git a/src/org/traccar/protocol/XexunFrameDecoder.java b/src/org/traccar/protocol/XexunFrameDecoder.java new file mode 100644 index 000000000..86f409b3e --- /dev/null +++ b/src/org/traccar/protocol/XexunFrameDecoder.java @@ -0,0 +1,92 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import org.jboss.netty.handler.codec.frame.FrameDecoder; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.jboss.netty.buffer.ChannelBuffer; + +public class XexunFrameDecoder extends FrameDecoder { + + /** + * Find string in network buffer + */ + private static Integer find( + ChannelBuffer buf, + Integer start, + Integer length, + String subString) { + + int index = start; + boolean match; + + for (; index < length; index++) { + match = true; + + for (int i = 0; i < subString.length(); i++) { + char c = (char) buf.getByte(index + i); + if (c != subString.charAt(i)) { + match = false; + break; + } + } + + if (match) { + return index; + } + } + + return null; + } + + protected Object decode( + ChannelHandlerContext ctx, + Channel channel, + ChannelBuffer buf) throws Exception { + + // Check minimum length + int length = buf.readableBytes(); + if (length < 100) { + return null; + } + + // Find start + Integer beginIndex = find(buf, 0, length, "GPRMC"); + if (beginIndex == null) { + return null; + } + + // Find identifier + Integer idIndex = find(buf, beginIndex, length, "imei:"); + if (idIndex == null) { + return null; + } + + // Find end + Integer endIndex = find(buf, idIndex, length, ","); + if (endIndex == null) { + return null; + } + + // Read buffer + buf.skipBytes(beginIndex); + ChannelBuffer frame = buf.readBytes(endIndex - beginIndex + 1); + + return frame; + } + +} diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java new file mode 100644 index 000000000..398b9a257 --- /dev/null +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -0,0 +1,128 @@ +/* + * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.GregorianCalendar; +import java.util.regex.Pattern; +import java.util.regex.Matcher; +import java.text.ParseException; +import java.util.TimeZone; +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.Position; +import org.traccar.DataManager; +import org.traccar.GenericProtocolDecoder; + +/** + * Xexun tracker protocol decoder + */ +public class XexunProtocolDecoder extends GenericProtocolDecoder { + + /** + * Initialize + */ + public XexunProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + /** + * Regular expressions pattern + */ + static private Pattern pattern = Pattern.compile( + "GPRMC," + + "([\\d]{2})([\\d]{2})([\\d]{2}).([\\d]{3})," + // Time (HHMMSS.SSS) + "([AV])," + // Validity + "([\\d]{2})([\\d]{2}.[\\d]{4})," + // Latitude (DDMM.MMMM) + "([NS])," + + "([\\d]{3})([\\d]{2}.[\\d]{4})," + // Longitude (DDDMM.MMMM) + "([EW])," + + "([\\d]+.[\\d]+)," + // Speed + "([\\d]+.[\\d]+)?," + // Course + "([\\d]{2})([\\d]{2})([\\d]{2})," + // Date (DDMMYY) + ".*imei:" + + "([\\d]+),"); // IMEI + + /** + * Decode message + */ + protected Object decode( + ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + + // Parse message + String sentence = (String) msg; + Matcher parser = pattern.matcher(sentence); + if (!parser.matches()) { + throw new ParseException(null, 0); + } + + // Create new position + Position position = new Position(); + + Integer index = 1; + + // Time + Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + time.clear(); + time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); + time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); + + // Validity + position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); + + // Latitude + Double latitude = Double.valueOf(parser.group(index++)); + latitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; + position.setLatitude(latitude); + + // Longitude + Double lonlitude = Double.valueOf(parser.group(index++)); + lonlitude += Double.valueOf(parser.group(index++)) / 60; + if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; + position.setLongitude(lonlitude); + + // Altitude + position.setAltitude(0.0); + + // Speed + position.setSpeed(Double.valueOf(parser.group(index++))); + + // Course + String course = parser.group(index++); + if (course != null) { + position.setCourse(Double.valueOf(course)); + } else { + position.setCourse(0.0); + } + + // Date + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); + time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); + position.setTime(time.getTime()); + + // Get device by IMEI + String imei = parser.group(index++); + position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); + + return position; + } + +} diff --git a/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java b/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java deleted file mode 100644 index 4fb33f5ba..000000000 --- a/src/org/traccar/protocol/avl08/Avl08ProtocolDecoder.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol.avl08; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.TimeZone; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.Position; -import org.traccar.DataManager; -import org.traccar.Device; // DELME -import org.traccar.GenericProtocolDecoder; - -/** - * AVL-08 tracker protocol decoder - */ -public class Avl08ProtocolDecoder extends GenericProtocolDecoder { - - /** - * Initialize - */ - public Avl08ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - super(dataManager, resetDelay); - } - - /** - * Regular expressions pattern - */ - static private Pattern pattern = Pattern.compile( - "\\$\\$.{2}" + // Length - "(\\d{15})\\|" + // IMEI - "(.{2})" + // Alarm Type - "\\$GPRMC," + - "(\\d{2})(\\d{2})(\\d{2}).(\\d{3})," + // Time (HHMMSS.SSS) - "([AV])," + // Validity - "(\\d{2})(\\d{2}.\\d{4})," + // Latitude (DDMM.MMMM) - "([NS])," + - "(\\d{3})(\\d{2}.\\d{4})," + // Longitude (DDDMM.MMMM) - "([EW])," + - "(\\d+.\\d{2})?," + // Speed - "(\\d+.\\d{2})?," + // Course - "(\\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 - */ - protected Object decode( - ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - - // Parse message - String sentence = (String) msg; - Matcher parser = pattern.matcher(sentence); - if (!parser.matches()) { - return null; - } - - // Create new position - Position position = new Position(); - String extendedInfo = "avl08"; - - Integer index = 1; - - // Get device by IMEI - String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); - - // Alarm type - extendedInfo += "" + parser.group(index++) + ""; - - // Time - Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); - - // Validity - position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); - - // Latitude - Double latitude = Double.valueOf(parser.group(index++)); - latitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; - position.setLatitude(latitude); - - // Longitude - Double lonlitude = Double.valueOf(parser.group(index++)); - lonlitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; - position.setLongitude(lonlitude); - - // Altitude - position.setAltitude(0.0); - - // Speed - position.setSpeed(Double.valueOf(parser.group(index++))); - - // Course - String course = parser.group(index++); - if (course != null) { - position.setCourse(Double.valueOf(course)); - } else { - position.setCourse(0.0); - } - - // Date - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); - position.setTime(time.getTime()); - - // Dilution of precision - extendedInfo += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; - extendedInfo += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; - extendedInfo += "" + parser.group(index++).replaceFirst ("^0*(?![\\.$])", "") + ""; - - // Status - extendedInfo += "" + parser.group(index++) + ""; - - // Real time clock - extendedInfo += "" + parser.group(index++) + ""; - - // Voltage - String voltage = parser.group(index++); - position.setPower(Double.valueOf(voltage.substring(1, 4)) / 100); - extendedInfo += "" + voltage + ""; - - // ADC - extendedInfo += "" + parser.group(index++) + ""; - - // Cell - extendedInfo += "" + parser.group(index++) + ""; - - // Temperature - extendedInfo += "" + parser.group(index++) + ""; - - // Mileage - extendedInfo += "" + parser.group(index++) + ""; - - // Serial - extendedInfo += "" + parser.group(index++).replaceFirst ("^0*", "") + ""; - - // RFID - String rfid = parser.group(index++); - if (rfid != null) { - extendedInfo += "" + rfid + ""; - } - - // Extended info - position.setExtendedInfo(extendedInfo); - - return position; - } - -} diff --git a/src/org/traccar/protocol/gl100/Gl100ProtocolDecoder.java b/src/org/traccar/protocol/gl100/Gl100ProtocolDecoder.java deleted file mode 100644 index e4c0de38a..000000000 --- a/src/org/traccar/protocol/gl100/Gl100ProtocolDecoder.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol.gl100; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.TimeZone; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.Position; -import org.traccar.DataManager; -import org.traccar.GenericProtocolDecoder; - -/** - * GL200 tracker protocol decoder - */ -public class Gl100ProtocolDecoder extends GenericProtocolDecoder { - - /** - * Initialize - */ - public Gl100ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - super(dataManager, resetDelay); - } - - /** - * Regular expressions pattern - */ - static private Pattern pattern = Pattern.compile( - "\\+RESP:GT...," + - "(\\d{15})," + // IMEI - "(?:(?:\\d+," + // Number - "\\d," + // Reserved / Geofence id - "\\d)|" + // Reserved / Geofence alert - "(?:[^,]*))," + // Calling number - "([01])," + // GPS fix - "(\\d+.\\d)," + // Speed - "(\\d+)," + // Course - "(-?\\d+.\\d)," + // Altitude - "\\d*," + // GPS accuracy - "(-?\\d+.\\d+)," + // Longitude - "(-?\\d+.\\d+)," + // Latitude - "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD) - "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) - ".*"); - - /** - * Decode message - */ - protected Object decode( - ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - - String sentence = (String) msg; - - // Send response - if (sentence.contains("AT+GTHBD=")) { - String response = "+RESP:GTHBD,GPRS ACTIVE,"; - response += sentence.substring(9, sentence.lastIndexOf(',')); - response += '\0'; - channel.write(response); - } - - // Parse message - Matcher parser = pattern.matcher(sentence); - if (!parser.matches()) { - return null; - } - - // Create new position - Position position = new Position(); - - Integer index = 1; - - // Get device by IMEI - String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); - - // Validity - position.setValid(Integer.valueOf(parser.group(index++)) == 0 ? false : true); - - // Position info - position.setSpeed(Double.valueOf(parser.group(index++))); - position.setCourse(Double.valueOf(parser.group(index++))); - position.setAltitude(Double.valueOf(parser.group(index++))); - position.setLongitude(Double.valueOf(parser.group(index++))); - position.setLatitude(Double.valueOf(parser.group(index++))); - - // Date - Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.YEAR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - - // Time - time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); - position.setTime(time.getTime()); - - return position; - } - -} diff --git a/src/org/traccar/protocol/gl200/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/gl200/Gl200ProtocolDecoder.java deleted file mode 100644 index 4c1149347..000000000 --- a/src/org/traccar/protocol/gl200/Gl200ProtocolDecoder.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol.gl200; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.TimeZone; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.Position; -import org.traccar.DataManager; -import org.traccar.GenericProtocolDecoder; - -/** - * GL200 tracker protocol decoder - */ -public class Gl200ProtocolDecoder extends GenericProtocolDecoder { - - /** - * Initialize - */ - public Gl200ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - super(dataManager, resetDelay); - } - - /** - * Regular expressions pattern - */ - static private Pattern pattern = Pattern.compile( - "\\+RESP:GT...," + - "\\d{6}," + // Protocol version - "(\\d{15})," + // IMEI - "[^,]*," + // Device name - "(?:(?:\\d," + // Report ID / Geo mode - "\\d*," + // Report type / Geo radius - "\\d*)|" + // Number / Geo check interval - "(?:[^,]*))," + // Call number - "(\\d*)," + // GPS accuracy - "(\\d+.\\d)," + // Speed - "(\\d+)," + // Course - "(-?\\d+.\\d)," + // Altitude - "(-?\\d+.\\d+)," + // Longitude - "(-?\\d+.\\d+)," + // Latitude - "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD) - "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) - ".*"); - - /** - * Decode message - */ - protected Object decode( - ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - - String sentence = (String) msg; - - // Parse message - Matcher parser = pattern.matcher(sentence); - if (!parser.matches()) { - return null; - } - - // Create new position - Position position = new Position(); - - Integer index = 1; - - // Get device by IMEI - String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); - - // Validity - position.setValid(Integer.valueOf(parser.group(index++)) == 0 ? false : true); - - // Position info - position.setSpeed(Double.valueOf(parser.group(index++))); - position.setCourse(Double.valueOf(parser.group(index++))); - position.setAltitude(Double.valueOf(parser.group(index++))); - position.setLongitude(Double.valueOf(parser.group(index++))); - position.setLatitude(Double.valueOf(parser.group(index++))); - - // Date - Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.YEAR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - - // Time - time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); - position.setTime(time.getTime()); - - return position; - } - -} diff --git a/src/org/traccar/protocol/gps103/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/gps103/Gps103ProtocolDecoder.java deleted file mode 100644 index f50dfad2a..000000000 --- a/src/org/traccar/protocol/gps103/Gps103ProtocolDecoder.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol.gps103; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.TimeZone; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.Position; -import org.traccar.DataManager; -import org.traccar.GenericProtocolDecoder; - -/** - * Gps 103 tracker protocol decoder - */ -public class Gps103ProtocolDecoder extends GenericProtocolDecoder { - - /** - * Initialize - */ - public Gps103ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - super(dataManager, resetDelay); - } - - /** - * Regular expressions pattern - */ - static private Pattern pattern = Pattern.compile( - "imei:" + - "([\\d]+)," + // IMEI - "[^,]+," + - "(\\d{2})(\\d{2})(\\d{2})[\\d]+," + // Date - "[+]?[\\d]*," + - "[FL]," + // F - full / L - low - "([\\d]{2})([\\d]{2})([\\d]{2}).([\\d]{3})," + // Time (HHMMSS.SSS) - "([AV])," + // Validity - "([\\d]{2})([\\d]{2}.[\\d]{4})," + // Latitude (DDMM.MMMM) - "([NS])," + - "([\\d]{3})([\\d]{2}.[\\d]{4})," + // Longitude (DDDMM.MMMM) - "([EW])," + - "([\\d]+.[\\d]{2})," + // Speed - ".*"); - - /** - * Decode message - */ - protected Object decode( - ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - - String sentence = (String) msg; - - // Send response #1 - if (sentence.contains("##")) { - channel.write("LOAD"); - } - - // Send response #2 - if (sentence.length() == 15 && Character.isDigit(sentence.charAt(0))) { - channel.write("ON"); - } - - // Parse message - Matcher parser = pattern.matcher(sentence); - if (!parser.matches()) { - return null; - } - - // Create new position - Position position = new Position(); - - Integer index = 1; - - // Get device by IMEI - String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); - - // Date - Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - - // Time - time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); - position.setTime(time.getTime()); - - // Validity - position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); - - // Latitude - Double latitude = Double.valueOf(parser.group(index++)); - latitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; - position.setLatitude(latitude); - - // Longitude - Double lonlitude = Double.valueOf(parser.group(index++)); - lonlitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; - position.setLongitude(lonlitude); - - // Altitude - position.setAltitude(0.0); - - // Speed - position.setSpeed(Double.valueOf(parser.group(index++))); - position.setCourse(0.0); - - return position; - } - -} diff --git a/src/org/traccar/protocol/t55/T55ProtocolDecoder.java b/src/org/traccar/protocol/t55/T55ProtocolDecoder.java deleted file mode 100644 index 5b1558c00..000000000 --- a/src/org/traccar/protocol/t55/T55ProtocolDecoder.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol.t55; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.TimeZone; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.Position; -import org.traccar.DataManager; -import org.traccar.GenericProtocolDecoder; - -/** - * T55 tracker protocol decoder - */ -public class T55ProtocolDecoder extends GenericProtocolDecoder { - - /** - * Device ID - */ - private Long deviceId; - - /** - * Initialize - */ - public T55ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - super(dataManager, resetDelay); - } - - /** - * Regular expressions pattern - */ - static private Pattern pattern = Pattern.compile( - "\\$GPRMC," + - "(\\d{2})(\\d{2})(\\d{2}).(\\d{3})," + // Time (HHMMSS.SSS) - "([AV])," + // Validity - "(\\d{2})(\\d{2}.\\d{4})," + // Latitude (DDMM.MMMM) - "([NS])," + - "(\\d{3})(\\d{2}.\\d{4})," + // Longitude (DDDMM.MMMM) - "([EW])," + - "(\\d+.\\d{2})?," + // Speed - "(\\d+.\\d{2})?," + // Course - "(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY) - ".+"); // Other (Checksumm) - - /** - * Decode message - */ - protected Object decode( - ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - - String sentence = (String) msg; - - //System.out.println(sentence); - - // Detect device ID - if (sentence.contains("$PGID")) { - String imei = sentence.substring(6, 6 + 15); - deviceId = getDataManager().getDeviceByImei(imei).getId(); - } - - // Parse message - else if (sentence.contains("$GPRMC") && deviceId != null) { - - // Send response - if (channel != null) { - channel.write("OK1\r\n"); - } - - // Parse message - Matcher parser = pattern.matcher(sentence); - if (!parser.matches()) { - return null; - } - - // Create new position - Position position = new Position(); - position.setDeviceId(deviceId); - - Integer index = 1; - - // Time - Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); - index += 1; // Skip milliseconds - - // Validity - position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); - - // Latitude - Double latitude = Double.valueOf(parser.group(index++)); - latitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; - position.setLatitude(latitude); - - // Longitude - Double lonlitude = Double.valueOf(parser.group(index++)); - lonlitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; - position.setLongitude(lonlitude); - - // Speed - String speed = parser.group(index++); - if (speed != null) { - position.setSpeed(Double.valueOf(speed)); - } else { - position.setSpeed(0.0); - } - - // Course - String course = parser.group(index++); - if (course != null) { - position.setCourse(Double.valueOf(course)); - } else { - position.setCourse(0.0); - } - - // Date - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); - position.setTime(time.getTime()); - - // Altitude - position.setAltitude(0.0); - - return position; - } - - return null; - } - -} diff --git a/src/org/traccar/protocol/tk103/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/tk103/Tk103ProtocolDecoder.java deleted file mode 100644 index db3280d91..000000000 --- a/src/org/traccar/protocol/tk103/Tk103ProtocolDecoder.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol.tk103; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.TimeZone; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.Position; -import org.traccar.DataManager; -import org.traccar.GenericProtocolDecoder; - -/** - * Gps 103 tracker protocol decoder - */ -public class Tk103ProtocolDecoder extends GenericProtocolDecoder { - - /** - * Initialize - */ - public Tk103ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - super(dataManager, resetDelay); - } - - /** - * Regular expressions pattern - */ - static private Pattern pattern = Pattern.compile( - "\\(" + - "(\\d+)" + // Device ID - "(.{4})" + // Command - "(\\d{15})" + // IMEI (?) - "(\\d{2})(\\d{2})(\\d{2})" + // Date (YYMMDD) - "([AV])" + // Validity - "(\\d{2})(\\d{2}.\\d{4})" + // Latitude (DDMM.MMMM) - "([NS])" + - "(\\d{3})(\\d{2}.\\d{4})" + // Longitude (DDDMM.MMMM) - "([EW])" + - "(\\d+.\\d)" + // Speed - "(\\d{2})(\\d{2})(\\d{2})" + // Time (HHMMSS) - "(\\d+.\\d{2})" + // Course - "(\\d+)" + // State - ".+"); // Mileage (?) - - /** - * Decode message - */ - protected Object decode( - ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - - String sentence = (String) msg; - - // TODO: Send response (?) - - // Parse message - Matcher parser = pattern.matcher(sentence); - if (!parser.matches()) { - return null; - } - - // Create new position - Position position = new Position(); - - Integer index = 1; - index += 2; // Skip Device ID and command - - // Get device by IMEI - String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); - - // Date - Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - - // Validity - position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); - - // Latitude - Double latitude = Double.valueOf(parser.group(index++)); - latitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; - position.setLatitude(latitude); - - // Longitude - Double lonlitude = Double.valueOf(parser.group(index++)); - lonlitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; - position.setLongitude(lonlitude); - - // Altitude - position.setAltitude(0.0); - - // Speed - position.setSpeed(Double.valueOf(parser.group(index++))); - - // Time - time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); - position.setTime(time.getTime()); - - // Course - position.setCourse(Double.valueOf(parser.group(index++))); - - return position; - } - -} diff --git a/src/org/traccar/protocol/xexun/XexunFrameDecoder.java b/src/org/traccar/protocol/xexun/XexunFrameDecoder.java deleted file mode 100644 index 6fd32a4c5..000000000 --- a/src/org/traccar/protocol/xexun/XexunFrameDecoder.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol.xexun; - -import org.jboss.netty.handler.codec.frame.FrameDecoder; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.buffer.ChannelBuffer; - -public class XexunFrameDecoder extends FrameDecoder { - - /** - * Find string in network buffer - */ - private static Integer find( - ChannelBuffer buf, - Integer start, - Integer length, - String subString) { - - int index = start; - boolean match; - - for (; index < length; index++) { - match = true; - - for (int i = 0; i < subString.length(); i++) { - char c = (char) buf.getByte(index + i); - if (c != subString.charAt(i)) { - match = false; - break; - } - } - - if (match) { - return index; - } - } - - return null; - } - - protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { - - // Check minimum length - int length = buf.readableBytes(); - if (length < 100) { - return null; - } - - // Find start - Integer beginIndex = find(buf, 0, length, "GPRMC"); - if (beginIndex == null) { - return null; - } - - // Find identifier - Integer idIndex = find(buf, beginIndex, length, "imei:"); - if (idIndex == null) { - return null; - } - - // Find end - Integer endIndex = find(buf, idIndex, length, ","); - if (endIndex == null) { - return null; - } - - // Read buffer - buf.skipBytes(beginIndex); - ChannelBuffer frame = buf.readBytes(endIndex - beginIndex + 1); - - return frame; - } - -} diff --git a/src/org/traccar/protocol/xexun/XexunProtocolDecoder.java b/src/org/traccar/protocol/xexun/XexunProtocolDecoder.java deleted file mode 100644 index 46b88f8a3..000000000 --- a/src/org/traccar/protocol/xexun/XexunProtocolDecoder.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol.xexun; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import java.text.ParseException; -import java.util.TimeZone; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.Position; -import org.traccar.DataManager; -import org.traccar.GenericProtocolDecoder; - -/** - * Xexun tracker protocol decoder - */ -public class XexunProtocolDecoder extends GenericProtocolDecoder { - - /** - * Initialize - */ - public XexunProtocolDecoder(DataManager dataManager, Integer resetDelay) { - super(dataManager, resetDelay); - } - - /** - * Regular expressions pattern - */ - static private Pattern pattern = Pattern.compile( - "GPRMC," + - "([\\d]{2})([\\d]{2})([\\d]{2}).([\\d]{3})," + // Time (HHMMSS.SSS) - "([AV])," + // Validity - "([\\d]{2})([\\d]{2}.[\\d]{4})," + // Latitude (DDMM.MMMM) - "([NS])," + - "([\\d]{3})([\\d]{2}.[\\d]{4})," + // Longitude (DDDMM.MMMM) - "([EW])," + - "([\\d]+.[\\d]+)," + // Speed - "([\\d]+.[\\d]+)?," + // Course - "([\\d]{2})([\\d]{2})([\\d]{2})," + // Date (DDMMYY) - ".*imei:" + - "([\\d]+),"); // IMEI - - /** - * Decode message - */ - protected Object decode( - ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - - // Parse message - String sentence = (String) msg; - Matcher parser = pattern.matcher(sentence); - if (!parser.matches()) { - throw new ParseException(null, 0); - } - - // Create new position - Position position = new Position(); - - Integer index = 1; - - // Time - Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); - - // Validity - position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); - - // Latitude - Double latitude = Double.valueOf(parser.group(index++)); - latitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; - position.setLatitude(latitude); - - // Longitude - Double lonlitude = Double.valueOf(parser.group(index++)); - lonlitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; - position.setLongitude(lonlitude); - - // Altitude - position.setAltitude(0.0); - - // Speed - position.setSpeed(Double.valueOf(parser.group(index++))); - - // Course - String course = parser.group(index++); - if (course != null) { - position.setCourse(Double.valueOf(course)); - } else { - position.setCourse(0.0); - } - - // Date - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); - position.setTime(time.getTime()); - - // Get device by IMEI - String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); - - return position; - } - -} diff --git a/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java b/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java deleted file mode 100644 index 62ec432ee..000000000 --- a/src/org/traccar/protocol/xexun2/Xexun2ProtocolDecoder.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright 2012 Anton Tananaev (anton.tananaev@gmail.com) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.traccar.protocol.xexun2; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.regex.Pattern; -import java.util.regex.Matcher; -import java.util.TimeZone; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.traccar.Position; -import org.traccar.DataManager; -import org.traccar.GenericProtocolDecoder; - -/** - * Xexun tracker protocol decoder - */ -public class Xexun2ProtocolDecoder extends GenericProtocolDecoder { - - /** - * Initialize - */ - public Xexun2ProtocolDecoder(DataManager dataManager, Integer resetDelay) { - super(dataManager, resetDelay); - } - - /** - * Regular expressions pattern - */ - static private Pattern pattern = Pattern.compile( - "[\r\n]*" + - "\\d+," + - "\\+\\d+," + - "GPRMC," + - "(\\d{2})(\\d{2})(\\d{2}).(\\d{3})," + // Time (HHMMSS.SSS) - "([AV])," + // Validity - "(\\d{2})(\\d{2}.\\d{4})," + // Latitude (DDMM.MMMM) - "([NS])," + - "(\\d{3})(\\d{2}.\\d{4})," + // Longitude (DDDMM.MMMM) - "([EW])," + - "(\\d+.\\d+)," + // Speed - "(\\d+.\\d+)?," + // Course - "(\\d{2})(\\d{2})(\\d{2})," + // Date (DDMMYY) - ".*imei:" + - "(\\d+)," + // IMEI - "\\d+," + - "\\d+.\\d+," + - "F:(\\d+.\\d+)V," + // Power - ".*" + - "[\r\n]*"); - - /** - * Decode message - */ - protected Object decode( - ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { - - // Parse message - String sentence = (String) msg; - Matcher parser = pattern.matcher(sentence); - if (!parser.matches()) { - //throw new ParseException(null, 0); - return null; - } - - // Create new position - Position position = new Position(); - - Integer index = 1; - - // Time - Calendar time = new GregorianCalendar(TimeZone.getTimeZone("UTC")); - time.clear(); - time.set(Calendar.HOUR, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MILLISECOND, Integer.valueOf(parser.group(index++))); - - // Validity - position.setValid(parser.group(index++).compareTo("A") == 0 ? true : false); - - // Latitude - Double latitude = Double.valueOf(parser.group(index++)); - latitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; - position.setLatitude(latitude); - - // Longitude - Double lonlitude = Double.valueOf(parser.group(index++)); - lonlitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("W") == 0) lonlitude = -lonlitude; - position.setLongitude(lonlitude); - - // Altitude - position.setAltitude(0.0); - - // Speed - position.setSpeed(Double.valueOf(parser.group(index++))); - - // Course - String course = parser.group(index++); - if (course != null) { - position.setCourse(Double.valueOf(course)); - } else { - position.setCourse(0.0); - } - - // Date - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); - position.setTime(time.getTime()); - - // Get device by IMEI - String imei = parser.group(index++); - position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); - - // Power - position.setPower(Double.valueOf(parser.group(index++))); - - return position; - } - -} -- cgit v1.2.3