diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/Server.java | 852 | ||||
-rw-r--r-- | src/org/traccar/TrackerEventHandler.java | 4 | ||||
-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/web/index.html | 92 |
6 files changed, 381 insertions, 603 deletions
diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index a36da81e4..36d7720b6 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -21,7 +21,6 @@ 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; @@ -30,7 +29,6 @@ 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; @@ -49,7 +47,6 @@ import org.traccar.protocol.*; */ public class Server { -<<<<<<< HEAD /** * Server list */ @@ -123,524 +120,341 @@ 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 } - /** - * 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)); - - } - } + /** + * 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); + } + } 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 07ecf71de..9e46372ca 100644 --- a/src/org/traccar/TrackerEventHandler.java +++ b/src/org/traccar/TrackerEventHandler.java @@ -56,9 +56,7 @@ public class TrackerEventHandler extends SimpleChannelHandler { ", altitude: " + position.getAltitude() + ", speed: " + position.getSpeed() + ", course: " + position.getCourse() + - ", power: " + position.getPower() + - ", mode: " + position.getMode() + - ", address: " + position.getAddress()); + ", power: " + position.getPower()); } // Write position to database diff --git a/src/org/traccar/http/WebServer.java b/src/org/traccar/http/WebServer.java index 853bff3de..5dfeabed2 100644 --- a/src/org/traccar/http/WebServer.java +++ b/src/org/traccar/http/WebServer.java @@ -147,16 +147,14 @@ 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':'%s','valid':%b,'latitude':%s,'longitude':%s,'speed':%s,'course':%s,'mode':%d,'address':'%s'}", + out.format("{'device_id':%d,'time':'%tF %tT','valid':%b,'latitude':%f,'longitude':%f,'speed':%f,'course':%f}", position.getDeviceId(), - position.getTimeFormated(), + position.getTime(), position.getTime(), position.getValid(), - position.getLatitude().toString(), - position.getLongitude().toString(), - position.getSpeed().toString(), - position.getCourse().toString(), - position.getMode(), - position.getAddress()); + position.getLatitude(), + position.getLongitude(), + position.getSpeed(), + position.getCourse()); if (i.hasNext()) out.print(","); } } diff --git a/src/org/traccar/model/DatabaseDataManager.java b/src/org/traccar/model/DatabaseDataManager.java index 3092744c0..384d87828 100644 --- a/src/org/traccar/model/DatabaseDataManager.java +++ b/src/org/traccar/model/DatabaseDataManager.java @@ -210,8 +210,6 @@ 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); } @@ -231,7 +229,6 @@ 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 e6ac46de1..b408dbbf2 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -15,7 +15,6 @@ */ package org.traccar.model; -import java.text.SimpleDateFormat; import java.util.Date; /** @@ -57,12 +56,6 @@ 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; @@ -158,18 +151,6 @@ 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/web/index.html b/src/web/index.html index 6be205300..cde73f47b 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -1,9 +1,7 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -<html xmlns="http://www.w3.org/1999/xhtml"> +<!doctype html> +<html> <head> -<title>Jornada Beta</title> -<meta http-equiv="content-type" content="text/html;charset=utf-8" /> - +<title>Traccar Manager</title> <link rel="stylesheet" type="text/css" href="http://cdn.sencha.io/ext-4.1.0-gpl/resources/css/ext-all.css" /> <script type="text/javascript" src="http://cdn.sencha.io/ext-4.1.0-gpl/ext-all.js"></script> @@ -166,12 +164,11 @@ setCenter: { }, // or just specify lat/long -*/ setCenter: { - lat: '-15.618767', - lng: '-56.083214' -}, - /* * </code></pre>listeners + lat: 42.345573, + lng: -71.098326 +} + * </code></pre> */ /** * @cfg {Number} zoomLevel @@ -179,7 +176,7 @@ setCenter: { * Also used as the zoom level for panoramas, zero specifies no zoom at all. * Defaults to <tt>3</tt>. */ - zoomLevel: 10, + zoomLevel: 3, /** * @cfg {Number} yaw * The Yaw, or rotational direction of the users perspective in degrees. Only applies to panoramas. @@ -292,7 +289,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.HYBRID}); + this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.ROADMAP}); this.mapDefined = true; this.mapDefinedGMap = true; } @@ -303,7 +300,7 @@ markers: [{ } if (!this.mapDefined && this.gmapType){ - this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.HYBRID}); + this.gmap = new google.maps.Map(this.getEl().dom, {zoom:this.zoomLevel,mapTypeId: google.maps.MapTypeId.ROADMAP}); this.gmap.setMapTypeId(this.gmapType); this.mapDefined = true; this.mapDefinedGMap = true; @@ -318,7 +315,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(-15.618767,-56.083214); + var point = new google.maps.LatLng(this.setCenter.lat,this.setCenter.lng); this.getMap().setCenter(point, this.zoomLevel); this.lastCenter = point; } @@ -474,7 +471,9 @@ 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); @@ -759,7 +758,6 @@ Ext.onReady(function() { ] }); - Ext.define('Position', { extend: 'Ext.data.Model', fields: [ @@ -770,9 +768,7 @@ Ext.onReady(function() { {name: 'longitude', type: 'float'}, {name: 'speed', type: 'float'}, {name: 'course', type: 'float'}, - {name: 'power', type: 'float'}, - {name: 'mode', type: 'int'}, - {name: 'address', type: 'string'} + {name: 'power', type: 'float'} ] }); @@ -810,9 +806,7 @@ Ext.onReady(function() { 'longitude', 'speed', 'course', - 'power', - 'mode', - 'address' + 'power' ], proxy: { type: 'ajax', @@ -830,7 +824,7 @@ Ext.onReady(function() { }); var devicesPanel = Ext.create('Ext.grid.Panel', { - title: 'Dispositivos', + title: 'Devices', region: 'west', split: true, width: 300, @@ -843,16 +837,16 @@ Ext.onReady(function() { tbar: [ { id: 'device_update', - text: 'Atualizar', + text: 'Update', handler : function() { devices.load(); } }, { id: 'device_add', - text: 'Incluir', + text: 'Add', handler : function() { - Ext.Msg.prompt('Incluir', 'IMEI do Dispositivo:', function(btn, text) { + Ext.Msg.prompt('Add', 'Device IMEI:', function(btn, text) { if (btn == 'ok') { devices.add({imei: text}); } @@ -861,10 +855,10 @@ Ext.onReady(function() { }, { id: 'device_remove', - text: 'Remover', + text: 'Remove', disabled: true, handler : function() { - Ext.Msg.confirm('Remover', 'Confirma remoção do item?', function(btn) { + Ext.Msg.confirm('Remove', 'Are you sure to remove item?', function(btn) { if (btn == 'yes') { devices.remove(devicesPanel.getSelectionModel().getLastSelected()); } @@ -873,10 +867,10 @@ Ext.onReady(function() { }, { id: 'device_edit', - text: 'Alterar', + text: 'Edit', disabled: true, handler : function() { - Ext.Msg.prompt('Alterar', 'IMEI do Dispositivo:', function(btn, text) { + Ext.Msg.prompt('Edit', 'Device IMEI:', function(btn, text) { if (btn == 'ok') { devicesPanel.getSelectionModel().getLastSelected().set('imei', text); } @@ -894,11 +888,11 @@ Ext.onReady(function() { Ext.getCmp('device_remove').enable(); Ext.getCmp('device_edit').enable(); - positions.getProxy().url = positionsUrl + '?deviceId=' + devicesPanel.getSelectionModel().getLastSelected().get('id'); + positions.getProxy().url = positionsUrl + '?deviceId=' + + devicesPanel.getSelectionModel().getLastSelected().get('id'); positions.load(); Ext.getCmp('position_update').enable(); - } - else { + } else { Ext.getCmp('position_update').disable(); positions.getProxy().url = positionsUrl; positions.load(); @@ -911,7 +905,7 @@ Ext.onReady(function() { }); var positionsPanel = Ext.create('Ext.grid.Panel', { - title: 'Posicionamentos', + title: 'Positions', region: 'south', split: true, height: 300, @@ -924,7 +918,7 @@ Ext.onReady(function() { tbar: [ { id: 'position_update', - text: 'Atualizar', + text: 'Update', disabled: true, handler : function() { positions.load(); @@ -932,31 +926,27 @@ Ext.onReady(function() { } ], columns: [ - {header: 'Id Dispositivo', dataIndex: 'device_id'}, - {header: 'Data/Hora', + {header: 'Device Id', dataIndex: 'device_id'}, + { + header: 'Time', dataIndex: 'time', flex: 1, - sortable: true, - renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s'), - width: 100 + renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s') }, - {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} + {header: 'Valid', dataIndex: 'valid'}, + {header: 'Latitude', dataIndex: 'latitude'}, + {header: 'Longitude', dataIndex: 'longitude'}, + {header: 'Speed', dataIndex: 'speed'}, + {header: 'Course', dataIndex: 'course'}, + {header: 'Power', dataIndex: 'power'} ], 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, title: title}, true, true); + map.addMarker(point, {lat: lat, lng: lng}, true, true); } else { map.clearMarkers(); // private? } @@ -965,7 +955,7 @@ Ext.onReady(function() { }); var mapPanel = Ext.create('Ext.panel.Panel', { - title: 'Mapa', + title: 'Map', region: 'center', margins: {top: 5, bottom: 0, right: 5, left: 0}, |