diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/traccar/Server.java | 852 | ||||
-rw-r--r-- | src/org/traccar/TrackerEventHandler.java | 4 | ||||
-rw-r--r-- | src/org/traccar/geocode/GoogleReverseGeocoder.java | 8 | ||||
-rw-r--r-- | src/org/traccar/http/WebServer.java | 14 | ||||
-rw-r--r-- | src/org/traccar/model/DatabaseDataManager.java | 3 | ||||
-rw-r--r-- | src/org/traccar/model/Position.java | 19 | ||||
-rw-r--r-- | src/org/traccar/protocol/ST210ProtocolDecoder.java | 19 |
7 files changed, 571 insertions, 348 deletions
diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 36d7720b6..a36da81e4 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -21,6 +21,7 @@ import java.sql.SQLException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Properties; @@ -29,6 +30,7 @@ import java.util.logging.Formatter; import java.util.logging.Level; import java.util.logging.LogRecord; import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; @@ -47,6 +49,7 @@ import org.traccar.protocol.*; */ public class Server { +<<<<<<< HEAD /** * Server list */ @@ -120,341 +123,524 @@ public class Server { for (Object server: serverList) { ((TrackerServer) server).start(); } +======= + /** + * Server list + */ + private List<TrackerServer> serverList; + + private boolean loggerEnabled; + + public Server() { + serverList = new LinkedList<TrackerServer>(); + loggerEnabled = false; + } + + public boolean isLoggerEnabled() { + return loggerEnabled; + } + + private DataManager dataManager; + + private WebServer webServer; + + private ReverseGeocoder geocoder; + + public void mandaMSG() + { + + for (Iterator iterator = serverList.iterator(); iterator.hasNext();) { + TrackerServer type = (TrackerServer) iterator.next(); + if(type.getPort().equals(8801)){ + + for (Iterator it = type.getChannelGroup().iterator(); it.hasNext();) { + Channel chanel = (Channel) it.next(); + System.out.println(chanel.getRemoteAddress()); + + } + } + // System.out.println(type.getPort()); + + } +>>>>>>> df91992080ee4db293e6f81882e95e72600d9bd8 } - /** - * Stop - */ - public void stop() { - for (Object server: serverList) { - ((TrackerServer) server).stop(); - } - if (webServer != null) { - webServer.stop(); - } - } - - /** - * Destroy - */ - public void destroy() { - serverList.clear(); - } - - /** - * Initialize logger - */ - private void initLogger(Properties properties) throws IOException { - - loggerEnabled = Boolean.valueOf(properties.getProperty("logger.enable")); - - if (loggerEnabled) { - - String fileName = properties.getProperty("logger.file"); - if (fileName != null) { - - FileHandler file = new FileHandler(fileName, true); - - // Simple formatter - file.setFormatter(new Formatter() { - private final String LINE_SEPARATOR = - System.getProperty("line.separator", "\n"); - - private final DateFormat dateFormat = - new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); - - public String format(LogRecord record) { - String line = dateFormat.format(new Date(record.getMillis())); - line += " " + record.getLevel().getName() + ": "; - line += formatMessage(record); - line += LINE_SEPARATOR; - return line; - } - }); - - // NOTE: Console logger level will remain INFO - Log.getLogger().setLevel(Level.ALL); - Log.getLogger().addHandler(file); - } - } - } - - private void initGeocoder(Properties properties) throws IOException { - if (Boolean.parseBoolean(properties.getProperty("geocoder.enable"))) { - geocoder = new GoogleReverseGeocoder(); - } - } - - private boolean isProtocolEnabled(Properties properties, String protocol) { - String enabled = properties.getProperty(protocol + ".enable"); - if (enabled != null) { - return Boolean.valueOf(enabled); - } - return false; - } - - private Integer getProtocolPort(Properties properties, String protocol) { - String port = properties.getProperty(protocol + ".port"); - if (port != null) { - return Integer.valueOf(port); - } - return 5000; // Magic number - } - - private Integer getProtocolResetDelay(Properties properties, String protocol) { - String resetDelay = properties.getProperty(protocol + ".resetDelay"); - if (resetDelay != null) { - return Integer.valueOf(resetDelay); - } - return 0; - } - - /** - * Init Xexun server - */ - private void initXexunServer(Properties properties) throws SQLException { - - String protocol = "xexun"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new XexunFrameDecoder()); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new XexunProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } - - /** - * Init Gps103 server - */ - private void initGps103Server(Properties properties) throws SQLException { - - String protocol = "gps103"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - byte delimiter[] = { (byte) ';' }; - pipeline.addLast("frameDecoder", - new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Gps103ProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } - - /** - * Init Tk103 server - */ - private void initTk103Server(Properties properties) throws SQLException { - - String protocol = "tk103"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - byte delimiter[] = { (byte) ')' }; - pipeline.addLast("frameDecoder", - new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } - - /** - * Init Gl100 server - */ - private void initGl100Server(Properties properties) throws SQLException { - - String protocol = "gl100"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - byte delimiter[] = { (byte) 0x0 }; - pipeline.addLast("frameDecoder", - new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } - - /** - * Init Gl200 server - */ - private void initGl200Server(Properties properties) throws SQLException { - - String protocol = "gl200"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - byte delimiter[] = { (byte) '$' }; - pipeline.addLast("frameDecoder", - new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } - - /** - * Init T55 server - */ - private void initT55Server(Properties properties) throws SQLException { - - String protocol = "t55"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - byte delimiter[] = { (byte) '\r', (byte) '\n' }; - pipeline.addLast("frameDecoder", - new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("stringEncoder", new StringEncoder()); - pipeline.addLast("objectDecoder", new T55ProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } - - /** - * Init Xexun 2 server - */ - private void initXexun2Server(Properties properties) throws SQLException { - - String protocol = "xexun2"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - byte delimiter[] = { (byte) '\n' }; // tracker bug \n\r - pipeline.addLast("frameDecoder", - new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new Xexun2ProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } - - /** - * Init AVL-08 server - */ - private void initAvl08Server(Properties properties) throws SQLException { - - String protocol = "avl08"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - byte delimiter[] = { (byte) '\r', (byte) '\n' }; - pipeline.addLast("frameDecoder", - new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); - pipeline.addLast("stringDecoder", new StringDecoder()); - pipeline.addLast("objectDecoder", new Avl08ProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } - - /** - * Init Enfora server - */ - private void initEnforaServer(Properties properties) throws SQLException { - - String protocol = "enfora"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 0, 2, -2, 2)); - pipeline.addLast("objectDecoder", new EnforaProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } - - /** - * Init Meiligao server - */ - private void initMeiligaoServer(Properties properties) throws SQLException { - - String protocol = "meiligao"; - if (isProtocolEnabled(properties, protocol)) { - - TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, protocol); - - server.setPipelineFactory(new GenericPipelineFactory(server, dataManager, isLoggerEnabled(), geocoder) { - protected void addSpecificHandlers(ChannelPipeline pipeline) { - pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 4)); - pipeline.addLast("objectDecoder", new MeiligaoProtocolDecoder(getDataManager(), resetDelay)); - } - }); - - serverList.add(server); - } - } + /** + * Initialize + */ + public void init(String[] arguments) throws IOException, + ClassNotFoundException, SQLException { + + // Load properties + Properties properties = new Properties(); + if (arguments.length > 0) { + properties.loadFromXML(new FileInputStream(arguments[0])); + } + + dataManager = new DatabaseDataManager(properties); + + initLogger(properties); + initGeocoder(properties); + + initXexunServer(properties); + initGps103Server(properties); + initTk103Server(properties); + initGl100Server(properties); + initGl200Server(properties); + initT55Server(properties); + initXexun2Server(properties); + initAvl08Server(properties); + initEnforaServer(properties); + initMeiligaoServer(properties); + initST210Server(properties); + + // Initialize web server + if (Boolean.valueOf(properties.getProperty("http.enable"))) { + Integer port = Integer.valueOf(properties.getProperty("http.port","8082")); + webServer = new WebServer(port, dataManager); + } + } + + /** + * Start + */ + public void start() { + if (webServer != null) { + webServer.start(); + } + for (Object server : serverList) { + ((TrackerServer) server).start(); + } + } + + /** + * Stop + */ + public void stop() { + for (Object server : serverList) { + ((TrackerServer) server).stop(); + } + if (webServer != null) { + webServer.stop(); + } + } + + /** + * Destroy + */ + public void destroy() { + serverList.clear(); + } + + /** + * Initialize logger + */ + private void initLogger(Properties properties) throws IOException { + + loggerEnabled = Boolean.valueOf(properties.getProperty("logger.enable")); + + if (loggerEnabled) { + + String fileName = properties.getProperty("logger.file"); + if (fileName != null) { + + FileHandler file = new FileHandler(fileName, true); + + // Simple formatter + file.setFormatter(new Formatter() { + private final String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); + + private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); + + public String format(LogRecord record) { + String line = dateFormat.format(new Date(record.getMillis())); + line += " " + record.getLevel().getName() + ": "; + line += formatMessage(record); + line += LINE_SEPARATOR; + return line; + } + }); + + // NOTE: Console logger level will remain INFO + Log.getLogger().setLevel(Level.ALL); + Log.getLogger().addHandler(file); + } + } + } + + private void initGeocoder(Properties properties) throws IOException { + if (Boolean.parseBoolean(properties.getProperty("geocoder.enable"))) { + geocoder = new GoogleReverseGeocoder(); + } + } + + private boolean isProtocolEnabled(Properties properties, String protocol) { + String enabled = properties.getProperty(protocol + ".enable"); + if (enabled != null) { + return Boolean.valueOf(enabled); + } + return false; + } + + private Integer getProtocolPort(Properties properties, String protocol) { + String port = properties.getProperty(protocol + ".port"); + if (port != null) { + return Integer.valueOf(port); + } + return 5000; // Magic number + } + + private Integer getProtocolResetDelay(Properties properties, String protocol) { + String resetDelay = properties.getProperty(protocol + ".resetDelay"); + if (resetDelay != null) { + return Integer.valueOf(resetDelay); + } + return 0; + } + + /** + * Init Xexun server + */ + private void initXexunServer(Properties properties) throws SQLException { + + String protocol = "xexun"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties,protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server,dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", new XexunFrameDecoder()); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new XexunProtocolDecoder(getDataManager(), resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + /** + * Init Gps103 server + */ + private void initGps103Server(Properties properties) throws SQLException { + + String protocol = "gps103"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + byte delimiter[] = { (byte) ';' }; + pipeline.addLast( + "frameDecoder", + new DelimiterBasedFrameDecoder(1024, ChannelBuffers + .wrappedBuffer(delimiter))); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", + new Gps103ProtocolDecoder(getDataManager(), + resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + /** + * Init Tk103 server + */ + private void initTk103Server(Properties properties) throws SQLException { + + String protocol = "tk103"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + byte delimiter[] = { (byte) ')' }; + pipeline.addLast( + "frameDecoder", + new DelimiterBasedFrameDecoder(1024, ChannelBuffers + .wrappedBuffer(delimiter))); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new Tk103ProtocolDecoder( + getDataManager(), resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + /** + * Init Gl100 server + */ + private void initGl100Server(Properties properties) throws SQLException { + + String protocol = "gl100"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + byte delimiter[] = { (byte) 0x0 }; + pipeline.addLast( + "frameDecoder", + new DelimiterBasedFrameDecoder(1024, ChannelBuffers + .wrappedBuffer(delimiter))); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new Gl100ProtocolDecoder( + getDataManager(), resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + /** + * Init Gl200 server + */ + private void initGl200Server(Properties properties) throws SQLException { + + String protocol = "gl200"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + byte delimiter[] = { (byte) '$' }; + pipeline.addLast( + "frameDecoder", + new DelimiterBasedFrameDecoder(1024, ChannelBuffers + .wrappedBuffer(delimiter))); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new Gl200ProtocolDecoder( + getDataManager(), resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + /** + * Init T55 server + */ + private void initT55Server(Properties properties) throws SQLException { + + String protocol = "t55"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + byte delimiter[] = { (byte) '\r', (byte) '\n' }; + pipeline.addLast( + "frameDecoder", + new DelimiterBasedFrameDecoder(1024, ChannelBuffers + .wrappedBuffer(delimiter))); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("stringEncoder", new StringEncoder()); + pipeline.addLast("objectDecoder", new T55ProtocolDecoder( + getDataManager(), resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + /** + * Init Xexun 2 server + */ + private void initXexun2Server(Properties properties) throws SQLException { + + String protocol = "xexun2"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + byte delimiter[] = { (byte) '\n' }; // tracker bug \n\r + pipeline.addLast( + "frameDecoder", + new DelimiterBasedFrameDecoder(1024, ChannelBuffers + .wrappedBuffer(delimiter))); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", + new Xexun2ProtocolDecoder(getDataManager(), + resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + /** + * Init AVL-08 server + */ + private void initAvl08Server(Properties properties) throws SQLException { + + String protocol = "avl08"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + byte delimiter[] = { (byte) '\r', (byte) '\n' }; + pipeline.addLast( + "frameDecoder", + new DelimiterBasedFrameDecoder(1024, ChannelBuffers + .wrappedBuffer(delimiter))); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new Avl08ProtocolDecoder( + getDataManager(), resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + /** + * Init Enfora server + */ + private void initEnforaServer(Properties properties) throws SQLException { + + String protocol = "enfora"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", + new LengthFieldBasedFrameDecoder(1024, 0, 2, -2, 2)); + pipeline.addLast("objectDecoder", + new EnforaProtocolDecoder(getDataManager(), + resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + /** + * Init Meiligao server + */ + private void initMeiligaoServer(Properties properties) throws SQLException { + + String protocol = "meiligao"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + pipeline.addLast("frameDecoder", + new LengthFieldBasedFrameDecoder(1024, 2, 2, -4, 4)); + pipeline.addLast("objectDecoder", + new MeiligaoProtocolDecoder(getDataManager(), + resetDelay)); + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + } + } + + private void initST210Server(Properties properties) throws SQLException { + + String protocol = "st210"; + if (isProtocolEnabled(properties, protocol)) { + + TrackerServer server = new TrackerServer(getProtocolPort( + properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties, + protocol); + + server.setPipelineFactory(new GenericPipelineFactory(server, + dataManager, isLoggerEnabled(), geocoder) { + protected void addSpecificHandlers(ChannelPipeline pipeline) { + byte delimiter[] = { (byte) '\r' }; + pipeline.addLast( + "frameDecoder", + new DelimiterBasedFrameDecoder(1024, ChannelBuffers + .wrappedBuffer(delimiter))); + pipeline.addLast("stringDecoder", new StringDecoder()); + pipeline.addLast("objectDecoder", new ST210ProtocolDecoder( + getDataManager(), resetDelay)); + + } + }); + + serverList.add(server); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + + } + } private void initMaxonServer(Properties properties) throws SQLException { String protocol = "maxon"; diff --git a/src/org/traccar/TrackerEventHandler.java b/src/org/traccar/TrackerEventHandler.java index 9e46372ca..07ecf71de 100644 --- a/src/org/traccar/TrackerEventHandler.java +++ b/src/org/traccar/TrackerEventHandler.java @@ -56,7 +56,9 @@ public class TrackerEventHandler extends SimpleChannelHandler { ", altitude: " + position.getAltitude() + ", speed: " + position.getSpeed() + ", course: " + position.getCourse() + - ", power: " + position.getPower()); + ", power: " + position.getPower() + + ", mode: " + position.getMode() + + ", address: " + position.getAddress()); } // Write position to database diff --git a/src/org/traccar/geocode/GoogleReverseGeocoder.java b/src/org/traccar/geocode/GoogleReverseGeocoder.java index 724c60e50..a25f60d66 100644 --- a/src/org/traccar/geocode/GoogleReverseGeocoder.java +++ b/src/org/traccar/geocode/GoogleReverseGeocoder.java @@ -19,6 +19,8 @@ import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.Charset; + import org.traccar.helper.Log; /** @@ -36,8 +38,10 @@ public class GoogleReverseGeocoder implements ReverseGeocoder { try { URL url = new URL("http://maps.googleapis.com/maps/api/geocode/json?latlng=" + latitude + "," + longitude + "&sensor=false"); URLConnection connection = url.openConnection(); - BufferedReader reader = new BufferedReader( - new InputStreamReader(connection.getInputStream())); + + connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); + + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),Charset.forName("UTF-8"))); // Find address line String line; diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java index 5dfeabed2..853bff3de 100644 --- a/src/org/traccar/http/WebServer.java +++ b/src/org/traccar/http/WebServer.java @@ -147,14 +147,16 @@ public class WebServer { Iterator<Position> i = dataManager.getPositions(Long.valueOf(deviceId)).iterator(); while (i.hasNext()) { Position position = i.next(); - out.format("{'device_id':%d,'time':'%tF %tT','valid':%b,'latitude':%f,'longitude':%f,'speed':%f,'course':%f}", + out.format("{'device_id':%d,'time':'%s','valid':%b,'latitude':%s,'longitude':%s,'speed':%s,'course':%s,'mode':%d,'address':'%s'}", position.getDeviceId(), - position.getTime(), position.getTime(), + position.getTimeFormated(), position.getValid(), - position.getLatitude(), - position.getLongitude(), - position.getSpeed(), - position.getCourse()); + position.getLatitude().toString(), + position.getLongitude().toString(), + position.getSpeed().toString(), + position.getCourse().toString(), + position.getMode(), + position.getAddress()); if (i.hasNext()) out.print(","); } } diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java index 384d87828..3092744c0 100644 --- a/src/org/traccar/model/DatabaseDataManager.java +++ b/src/org/traccar/model/DatabaseDataManager.java @@ -210,6 +210,8 @@ public class DatabaseDataManager implements DataManager { position.setSpeed(result.getDouble("speed")); position.setCourse(result.getDouble("course")); position.setPower(result.getDouble("power")); + position.setMode(result.getInt("mode")); + position.setAddress(result.getString("address")); positionList.add(position); } @@ -229,6 +231,7 @@ public class DatabaseDataManager implements DataManager { queryAddPosition.setDouble("speed", position.getSpeed()); queryAddPosition.setDouble("course", position.getCourse()); queryAddPosition.setDouble("power", position.getPower()); + queryAddPosition.setInt("mode", position.getMode()); queryAddPosition.setString("address", position.getAddress()); queryAddPosition.setString("extended_info", position.getExtendedInfo()); diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index b408dbbf2..e6ac46de1 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -15,6 +15,7 @@ */ package org.traccar.model; +import java.text.SimpleDateFormat; import java.util.Date; /** @@ -56,6 +57,12 @@ public class Position { public Date getTime() { return time; } + + public String getTimeFormated(){ + SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); + df.setLenient(false); + return df.format(time); + } public void setTime(Date time) { this.time = time; @@ -151,6 +158,18 @@ public class Position { public void setPower(Double power) { this.power = power; } + /** + * Mode / 1 - Parking | 2 - Driving + */ + private int mode; + + public int getMode() { + return mode; + } + + public void setMode(int mode) { + this.mode = mode; + } /** * Address diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index f503fead6..d41a78da5 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -23,8 +23,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum ST210FIELDS { - HDR_STATUS("SA200STT;", - "Status Report"), + HDR_STATUS("SA200STT;","Status Report"), HDR_EMERGENCY("SA200EMG;","Emergency Report"), HDR_EVENT("SA200EVT;", "Event Report"), HDR_ALERT("SA200ALT;","Alert Report"), @@ -33,7 +32,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { 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)"), + CELL("(\\w+);","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"), @@ -44,8 +43,8 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { 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"), + 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"); @@ -488,6 +487,10 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { patternStr += field.getPattern(); } + if(patternStr.endsWith(";")){ + patternStr = patternStr.substring(0, patternStr.length()-1); + } + return Pattern.compile(patternStr); } @@ -611,7 +614,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { Log.info("MESSAGE DECODED WITH SUCCESS!"); } catch(Exception e){ - Log.info("ERROR WHILE DECODING MESSAGE: " + e.getMessage()); + Log.severe("ERROR WHILE DECODING MESSAGE: " + e.getMessage()); } return position; @@ -631,6 +634,10 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { throw new Exception("Pattern no match: " + protocolPattern.toString()); } + if(report.equals(ST210REPORTS.ALIVE)){ + return null; + } + // Create new position Position position = new Position(); |