From a946618d649cde478d8750bb6b84cb521b68c87c Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Wed, 15 Aug 2012 08:58:26 -0400 Subject: Corrections of wrong "git fetch upstream" --- src/org/traccar/Server.java | 916 ++++++++++++++----------- src/org/traccar/TrackerEventHandler.java | 3 +- src/org/traccar/http/WebServer.java | 13 +- src/org/traccar/model/DatabaseDataManager.java | 2 + src/org/traccar/model/Position.java | 19 + 5 files changed, 546 insertions(+), 407 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 2f1c7fce5..32a2888cc 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,407 +49,521 @@ import org.traccar.protocol.*; */ public class Server { - /** - * Server list - */ - private List serverList; - - private boolean loggerEnabled; - - public Server() { - serverList = new LinkedList(); - loggerEnabled = false; - } - - public boolean isLoggerEnabled() { - return loggerEnabled; - } - - private DataManager dataManager; - - private WebServer webServer; - - private ReverseGeocoder geocoder; - - /** - * 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); - - // 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(); - } + /** + * Server list + */ + private List serverList; + + private boolean loggerEnabled; + + public Server() { + serverList = new LinkedList(); + 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()); + + } } - /** - * 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("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)); + + } + } } diff --git a/src/org/traccar/TrackerEventHandler.java b/src/org/traccar/TrackerEventHandler.java index 9e46372ca..2a66a084f 100644 --- a/src/org/traccar/TrackerEventHandler.java +++ b/src/org/traccar/TrackerEventHandler.java @@ -56,7 +56,8 @@ public class TrackerEventHandler extends SimpleChannelHandler { ", altitude: " + position.getAltitude() + ", speed: " + position.getSpeed() + ", course: " + position.getCourse() + - ", power: " + position.getPower()); + ", power: " + position.getPower() + + ", mode: " + position.getMode()); } // Write position to database diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java index 6c79e6421..e379a0a9a 100644 --- a/src/org/traccar/http/WebServer.java +++ b/src/org/traccar/http/WebServer.java @@ -146,14 +146,15 @@ public class WebServer { Iterator 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}", 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()); if (i.hasNext()) out.print(","); } } diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java index 384d87828..2207d272b 100644 --- a/src/org/traccar/model/DatabaseDataManager.java +++ b/src/org/traccar/model/DatabaseDataManager.java @@ -210,6 +210,7 @@ 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")); positionList.add(position); } @@ -229,6 +230,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 -- cgit v1.2.3 From 704decd15f70a0251675041826c472b7326ae40c Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Wed, 15 Aug 2012 09:08:57 -0400 Subject: Correction of CELL regex pattern --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index f503fead6..61dcf8782 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -33,7 +33,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{3}\\d{2});","Location Code ID (3 digits hex) + Serving Cell BSIC(2 digits decimal)"), LAT("(-\\d{2}.\\d+);", "Latitude (+/-xx.xxxxxx)"), LON("(-\\d{3}.\\d+);", "Longitude (+/-xxx.xxxxxx)"), SPD("(\\d{3}.\\d{3});","Speed in km/h - This value returns to 0 when it is over than 200,000Km"), -- cgit v1.2.3 From 3a78e641bacccaca181bbd292f0f2f0d579b5caf Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Wed, 15 Aug 2012 11:04:16 -0400 Subject: Changes to save de address field from geocoding and show it on markers at the map and on position's grid --- setup/windows/windowsPG.cfg | 8 +++- src/org/traccar/Server.java | 2 +- src/org/traccar/TrackerEventHandler.java | 3 +- src/org/traccar/http/WebServer.java | 5 ++- src/org/traccar/model/DatabaseDataManager.java | 1 + src/web/index.html | 52 ++++++++++++++------------ test.sh | 0 7 files changed, 42 insertions(+), 29 deletions(-) mode change 100644 => 100755 test.sh (limited to 'src/org') diff --git a/setup/windows/windowsPG.cfg b/setup/windows/windowsPG.cfg index 28e29dbad..aaefc4b21 100644 --- a/setup/windows/windowsPG.cfg +++ b/setup/windows/windowsPG.cfg @@ -14,6 +14,7 @@ 300 + id - Long @@ -80,13 +82,15 @@ extended_info - String (XML) <--> - INSERT INTO positions (id, device_id, time, valid, latitude, longitude, speed, course, power, mode) - VALUES (nextval('positionsSQ'),:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power, :mode) + INSERT INTO positions (id, device_id, time, valid, latitude, longitude, speed, course, power, mode, address) + VALUES (nextval('positionsSQ'),:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power, :mode, :address) true 8082 + + true true diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 32a2888cc..15514bffc 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -193,7 +193,7 @@ public class Server { } private void initGeocoder(Properties properties) throws IOException { - if (Boolean.parseBoolean("geocoder.enable")) { + if (Boolean.parseBoolean(properties.getProperty("geocoder.enable"))) { geocoder = new GoogleReverseGeocoder(); } } diff --git a/src/org/traccar/TrackerEventHandler.java b/src/org/traccar/TrackerEventHandler.java index 2a66a084f..07ecf71de 100644 --- a/src/org/traccar/TrackerEventHandler.java +++ b/src/org/traccar/TrackerEventHandler.java @@ -57,7 +57,8 @@ public class TrackerEventHandler extends SimpleChannelHandler { ", speed: " + position.getSpeed() + ", course: " + position.getCourse() + ", power: " + position.getPower() + - ", mode: " + position.getMode()); + ", mode: " + position.getMode() + + ", address: " + position.getAddress()); } // Write position to database diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java index e379a0a9a..5fac8ff65 100644 --- a/src/org/traccar/http/WebServer.java +++ b/src/org/traccar/http/WebServer.java @@ -146,7 +146,7 @@ public class WebServer { Iterator i = dataManager.getPositions(Long.valueOf(deviceId)).iterator(); while (i.hasNext()) { Position position = i.next(); - out.format("{'device_id':%d,'time':'%s','valid':%b,'latitude':%s,'longitude':%s,'speed':%s,'course':%s,'mode':%d}", + out.format("{'device_id':%d,'time':'%s','valid':%b,'latitude':%s,'longitude':%s,'speed':%s,'course':%s,'mode':%d,'address':'%s'}", position.getDeviceId(), position.getTimeFormated(), position.getValid(), @@ -154,7 +154,8 @@ public class WebServer { position.getLongitude().toString(), position.getSpeed().toString(), position.getCourse().toString(), - position.getMode()); + 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 2207d272b..3092744c0 100644 --- a/src/org/traccar/model/DatabaseDataManager.java +++ b/src/org/traccar/model/DatabaseDataManager.java @@ -211,6 +211,7 @@ public class DatabaseDataManager implements DataManager { position.setCourse(result.getDouble("course")); position.setPower(result.getDouble("power")); position.setMode(result.getInt("mode")); + position.setAddress(result.getString("address")); positionList.add(position); } diff --git a/src/web/index.html b/src/web/index.html index dcc4771db..6be205300 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -166,11 +166,12 @@ setCenter: { }, // or just specify lat/long +*/ setCenter: { - lat: 42.345573, - lng: -71.098326 -} - * + lat: '-15.618767', + lng: '-56.083214' +}, + /* * listeners */ /** * @cfg {Number} zoomLevel @@ -178,7 +179,7 @@ setCenter: { * Also used as the zoom level for panoramas, zero specifies no zoom at all. * Defaults to 3. */ - zoomLevel: 3, + zoomLevel: 10, /** * @cfg {Number} yaw * The Yaw, or rotational direction of the users perspective in degrees. Only applies to panoramas. @@ -291,7 +292,7 @@ markers: [{ Ext.defer(function(){ if (this.gmapType === 'map'){ - this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.ROADMAP}); + this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.HYBRID}); this.mapDefined = true; this.mapDefinedGMap = true; } @@ -302,7 +303,7 @@ markers: [{ } if (!this.mapDefined && this.gmapType){ - this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.ROADMAP}); + this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.HYBRID}); this.gmap.setMapTypeId(this.gmapType); this.mapDefined = true; this.mapDefinedGMap = true; @@ -317,7 +318,7 @@ markers: [{ this.geoCodeLookup(this.setCenter.geoCodeAddr, this.setCenter.marker, false, true, this.setCenter.listeners); }else{ if (this.gmapType === 'map'){ - var point = new google.maps.LatLng(this.setCenter.lat,this.setCenter.lng); + var point = new google.maps.LatLng(-15.618767,-56.083214); this.getMap().setCenter(point, this.zoomLevel); this.lastCenter = point; } @@ -473,9 +474,7 @@ markers: [{ this.lastCenter = point; } - var mark = new google.maps.Marker(Ext.apply(marker, { - position: point - })); + var mark = new google.maps.Marker(Ext.apply(marker, {position: point})); if (marker.infoWindow){ this.createInfoWindow(marker.infoWindow, point, mark); @@ -772,7 +771,8 @@ Ext.onReady(function() { {name: 'speed', type: 'float'}, {name: 'course', type: 'float'}, {name: 'power', type: 'float'}, - {name: 'mode', type: 'int'} + {name: 'mode', type: 'int'}, + {name: 'address', type: 'string'} ] }); @@ -811,7 +811,8 @@ Ext.onReady(function() { 'speed', 'course', 'power', - 'mode' + 'mode', + 'address' ], proxy: { type: 'ajax', @@ -932,25 +933,30 @@ Ext.onReady(function() { ], columns: [ {header: 'Id Dispositivo', dataIndex: 'device_id'}, - {header: 'Data/Hora',dataIndex: 'time', + {header: 'Data/Hora', + dataIndex: 'time', flex: 1, - renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s') + sortable: true, + renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s'), + width: 100 }, - {header: 'Válido', dataIndex: 'valid'}, - {header: 'Latitude', dataIndex: 'latitude'}, - {header: 'Longitude', dataIndex: 'longitude'}, - {header: 'Velocidade', dataIndex: 'speed'}, - {header: 'Curso', dataIndex: 'course'}, - {header: 'Voltagem', dataIndex: 'power'}, - {header: 'Modo', dataIndex: 'mode'} + {header: 'Endereço', dataIndex: 'address', width: 480}, + {header: 'Latitude', dataIndex: 'latitude', width: 70}, + {header: 'Longitude', dataIndex: 'longitude', width: 70}, + {header: 'Velocidade', dataIndex: 'speed', width: 70}, + {header: 'Curso', dataIndex: 'course', width: 70}, + {header: 'Voltagem', dataIndex: 'power', width: 70}, + {header: 'Modo', dataIndex: 'mode', width: 70}, + {header: 'Válido', dataIndex: 'valid', width: 70} ], listeners: { selectionchange: function(sender, selected, eOpts) { if (selected.length != 0) { var lat = positionsPanel.getSelectionModel().getLastSelected().get('latitude'); var lng = positionsPanel.getSelectionModel().getLastSelected().get('longitude'); + var title = positionsPanel.getSelectionModel().getLastSelected().get('address'); var point = new google.maps.LatLng(lat, lng); - map.addMarker(point, {lat: lat, lng: lng}, true, true); + map.addMarker(point, {lat: lat, lng: lng, title: title}, true, true); } else { map.clearMarkers(); // private? } diff --git a/test.sh b/test.sh old mode 100644 new mode 100755 -- cgit v1.2.3 From ba78f64d458bf03a3ffbac87369def5f79cbc8ae Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Wed, 15 Aug 2012 12:07:46 -0400 Subject: Corrections of reamaing problems of CELL field. --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 2 +- test/org/traccar/protocol/ST210ProtocolDecoderTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 61dcf8782..983e9c6f4 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -33,7 +33,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("(\\w{3}\\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"), diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java index 9fc6f9e28..bc2e6e21e 100644 --- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java @@ -27,7 +27,7 @@ public class ST210ProtocolDecoderTest { assertNotNull(decoder .decode(null, null, - "SA200STT;315198;042;20120808;20:37:34;42948;-15.618731;-056.083216;000.007;000.00;12;1;48;0.00;000000;1;0127")); + "SA200STT;315198;042;20120808;20:37:34;3fac25;-15.618731;-056.083216;000.007;000.00;12;1;48;0.00;000000;1;0127")); assertNotNull(decoder .decode(null, null, -- cgit v1.2.3 From 33cc8f56d87556a2233c174a39247048bb2e33fd Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Wed, 15 Aug 2012 22:15:59 -0400 Subject: Improvements on decoder to decode status, emergency and keep alive messages from avl. --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 15 +++++++++++---- test.sh | 3 +++ test/org/traccar/protocol/ST210ProtocolDecoderTest.java | 5 +++++ 3 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 983e9c6f4..2f9bcd863 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"), @@ -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); } @@ -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(); diff --git a/test.sh b/test.sh index 03c1af4fe..66d4535eb 100755 --- a/test.sh +++ b/test.sh @@ -43,3 +43,6 @@ echo "10. st210" echo "11. st210emg" (echo -n -e "SA200EMG;317652;042;20120718;15:35:41;16d41;-15.618740;-056.083252;000.034;000.00;8;1;41548;12.17;110000;1\r";) | nc -v localhost 8801 + +echo "12. st210alv" +(echo -n -e "SA200ALV;317652\r";) | nc -v localhost 8801 diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java index bc2e6e21e..403b5621a 100644 --- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java @@ -1,6 +1,7 @@ package org.traccar.protocol; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import org.junit.Test; @@ -36,6 +37,10 @@ public class ST210ProtocolDecoderTest { .decode(null, null, "SA200EMG;317652;042;20120718;15:35:41;16d41;-15.618740;-056.083252;000.034;000.00;8;1;41548;12.17;110000;1")); + assertNull(decoder + .decode(null, + null, + "SA200ALV;317652")); } } -- cgit v1.2.3 From 996ae7a3f9d128d6ae85e602f9456af2144ebbae Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 16 Aug 2012 09:23:21 -0400 Subject: Defined UTF-8 encoding. --- src/org/traccar/geocode/GoogleReverseGeocoder.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/org') 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; -- cgit v1.2.3 From df91992080ee4db293e6f81882e95e72600d9bd8 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Fri, 17 Aug 2012 08:40:42 -0400 Subject: Log error --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 2f9bcd863..d41a78da5 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -614,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; -- cgit v1.2.3