From d9c99fafa2e4d581f473029144aec495cb94bb62 Mon Sep 17 00:00:00 2001 From: williamchitto Date: Wed, 25 Jul 2012 12:40:09 -0300 Subject: added protocol ST210ProtocolDecoder --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 637 +++++++++++++++++++++ 1 file changed, 637 insertions(+) create mode 100644 src/org/traccar/protocol/ST210ProtocolDecoder.java (limited to 'src/org') diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java new file mode 100644 index 000000000..eeedccf69 --- /dev/null +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -0,0 +1,637 @@ +package org.traccar.protocol; + +import java.util.Calendar; +import java.util.LinkedList; +import java.util.List; +import java.util.TimeZone; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jboss.netty.channel.Channel; +import org.jboss.netty.channel.ChannelHandlerContext; +import org.traccar.GenericProtocolDecoder; +import org.traccar.helper.Log; +import org.traccar.model.DataManager; +import org.traccar.model.Position; + +public class ST210ProtocolDecoder extends GenericProtocolDecoder { + + /** + * Initialize + */ + public ST210ProtocolDecoder(DataManager dataManager, Integer resetDelay) { + super(dataManager, resetDelay); + } + + private enum ST210FIELDS { + HDR_STATUS("SA200STT;", "Status Report"), HDR_EMERGENCY("SA200EMG;", + "Emergency Report"), HDR_EVENT("SA200EVT;", "Event Report"), HDR_ALERT( + "SA200ALT;", "Alert Report"), HDR_ALIVE("SA200ALV;", + "Alive Report"), DEV_ID("(\\d+);", "Device ID"), 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)"), 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"), CRS( + "(\\d{3}.\\d{2});", "Course over ground in degree"), SATT( + "(\\d+);", "Number of satellites"), FIX("(\\d);", + "GPS is fixed(1)\n" + "GPS is not fixed(0)"), DIST("(\\d+);", + "Traveled ddistance in meter"), PWR_VOLT("(\\d{2}.\\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"), EVT_ID("(\\d);", "Event type"), ALERT_ID( + "(\\d);", "Alert type"); + + private String pattern; + + private String desc; + + private ST210FIELDS(String pattern, String desc) { + this.pattern = pattern; + this.desc = desc; + } + + public String getPattern() { + return pattern; + } + + public String getDesc() { + return desc; + } + + public void populatePosition(Position position, String groupValue, + DataManager dataManager) throws Exception { + + switch (this) { + + case DEV_ID: + position.setDeviceId(dataManager.getDeviceByImei(groupValue) + .getId()); + break; + + case LAT: + position.setLatitude(Double.valueOf(groupValue)); + break; + + case LON: + position.setLongitude(Double.valueOf(groupValue)); + break; + + case CRS: + position.setCourse(Double.valueOf(groupValue)); + break; + + case PWR_VOLT: + position.setPower(Double.valueOf(groupValue)); + break; + + case SPD: + position.setSpeed(Double.valueOf(groupValue)); + break; + + case DATE: { + // Date + Calendar time = Calendar.getInstance(TimeZone + .getTimeZone("UTC")); + time.clear(); + time.set(Calendar.YEAR, Integer.valueOf(Integer + .valueOf(groupValue.substring(0, 4)))); + time.set(Calendar.MONTH, Integer.valueOf(Integer + .valueOf(groupValue.substring(4, 6)))); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer + .valueOf(groupValue.substring(6, 8)))); + position.setTime(time.getTime()); + break; + } + + case TIME: { + + Calendar time = Calendar.getInstance(TimeZone + .getTimeZone("UTC")); + time.clear(); + time.setTime(position.getTime()); + + time.set(Calendar.HOUR, Integer.valueOf(Integer + .valueOf(groupValue.substring(0, 2)))); + time.set(Calendar.MINUTE, Integer.valueOf(Integer + .valueOf(groupValue.substring(3, 5)))); + time.set(Calendar.SECOND, Integer.valueOf(Integer + .valueOf(groupValue.substring(6, 8)))); + + position.setTime(time.getTime()); + break; + } + + default: + break; + } + + } + } + + private enum FIELD_FIX_VALUE { + FIXED(1, "GPS is fixed"), NOT_FIXED(0, "GPS is not fixed"); + + private int value; + + private String desc; + + private FIELD_FIX_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_FIX_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_FIX_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return FIXED; + case 0: + return NOT_FIXED; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum FIELD_MODE_VALUE { + PARKING(1, "Idle mode (Parking)"), DRIVING(2, "Active Mode (Driving)"); + + private int value; + + private String desc; + + private FIELD_MODE_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_MODE_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_MODE_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return PARKING; + case 2: + return DRIVING; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum FIELD_EMG_ID_VALUE { + PANIC(1, "Emergency by panic button"), PARKING(2, + "Emergency by parking lock"), MAIN_POWER(3, + "Emergency by removing main power"), ANTI_THEFT(5, + "Emergency by anti-theft"); + + private int value; + + private String desc; + + private FIELD_EMG_ID_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_EMG_ID_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_EMG_ID_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return PANIC; + case 2: + return PARKING; + case 3: + return MAIN_POWER; + case 5: + return ANTI_THEFT; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum FIELD_EVT_ID_VALUE { + INPUT1_GROUND(1, "Input1 goes to ground state"), INPUT1_OPEN(2, + "Input1 goes to open state"), INPUT2_GROUND(3, + "Input2 goes to ground state"), INPUT2_OPEN(4, + "Input2 goes to open state"), INPUT3_GROUND(5, + "Input3 goes to ground state"), INPUT3_OPEN(6, + "Input3 goes to open state"); + + private int value; + + private String desc; + + private FIELD_EVT_ID_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_EVT_ID_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_EVT_ID_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return INPUT1_GROUND; + case 2: + return INPUT1_OPEN; + case 3: + return INPUT2_GROUND; + case 4: + return INPUT2_OPEN; + case 5: + return INPUT3_GROUND; + case 6: + return INPUT3_OPEN; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum FIELD_ALERT_ID_VALUE { + DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), OVER_SPPED( + 2, "Ended over speed condition"), DISCON_GPS(3, + "Disconnected GPS antenna"), RECON_GPS(4, + "Reconnected GPS antenna after disconnected"), OUT_GEO_FENCE(5, + "The vehicle went out from the geo-fence that has following ID"), INTO_GEO_FENCE( + 6, + "The vehicle entered into the geo-fence that has following ID"), SHORTED_GPS( + 8, "Shorted GPS antenna"), DEEP_SLEEP_ON(9, + "Enter to deep sleep mode"), DEEP_SLEEP_OFF(10, + "Exite from deep sleep mode"), BKP_BATTERY(13, + "Backup battery error"), BATTERY_DOWN(14, + "Vehicle battery goes down to so low level"), SHOCKED(15, + "Shocked"), COLLISION(16, "Occurred some collision"), DEVIATE_ROUT( + 18, "Deviate from predefined rout"), ENTER_ROUT(19, + "Enter into predefined rout"); + + private int value; + + private String desc; + + private FIELD_ALERT_ID_VALUE(int value, String desc) { + this.value = value; + this.desc = desc; + } + + public int getValue() { + return value; + } + + public String getDesc() { + return desc; + } + + public FIELD_ALERT_ID_VALUE getValueOf(String indiceStr) { + int indice = Integer.valueOf(indiceStr); + return getValueOf(indice); + } + + public FIELD_ALERT_ID_VALUE getValueOf(int indice) { + switch (indice) { + case 1: + return DRIVING_FASTER; + case 2: + return OVER_SPPED; + case 3: + return DISCON_GPS; + case 4: + return RECON_GPS; + case 5: + return OUT_GEO_FENCE; + case 6: + return INTO_GEO_FENCE; + case 8: + return SHORTED_GPS; + case 9: + return DEEP_SLEEP_ON; + case 10: + return DEEP_SLEEP_OFF; + case 13: + return BKP_BATTERY; + case 14: + return BATTERY_DOWN; + case 15: + return SHOCKED; + case 16: + return COLLISION; + case 18: + return DEVIATE_ROUT; + case 19: + return ENTER_ROUT; + default: + throw new IllegalArgumentException("Índice não definido"); + } + } + } + + private enum ST210REPORTS { + + STATUS("SA200STT"), EMERGENCY("SA200EMG"), EVENT("SA200EVT"), ALERT( + "SA200ALT"), ALIVE("SA200ALV"); + + private String header; + + private ST210REPORTS(String header) { + this.header = header; + } + + public String getHeader() { + return this.header; + } + + public List getProtocol() { + + if (this.equals(STATUS)) { + return StatusProtocol; + } + + if (this.equals(EMERGENCY)) { + return EmergencyProtocol; + } + + if (this.equals(EVENT)) { + return EventProtocol; + } + + if (this.equals(ALERT)) { + return AlertProtocol; + } + + if (this.equals(ALIVE)) { + return AliveProtocol; + } + + return null; + } + + public Pattern getProtocolPattern() { + + if (this.equals(STATUS)) { + return getPattern(StatusProtocol); + } + + if (this.equals(EMERGENCY)) { + return getPattern(EmergencyProtocol); + } + + if (this.equals(EVENT)) { + return getPattern(EventProtocol); + } + + if (this.equals(ALERT)) { + return getPattern(AlertProtocol); + } + + if (this.equals(ALIVE)) { + return getPattern(AliveProtocol); + } + + return null; + } + + } + + private static ST210REPORTS getReportType(String msg) { + + if (msg.startsWith(ST210REPORTS.STATUS.getHeader())) { + return ST210REPORTS.STATUS; + } + + if (msg.startsWith(ST210REPORTS.EMERGENCY.getHeader())) { + return ST210REPORTS.EMERGENCY; + } + + if (msg.startsWith(ST210REPORTS.EVENT.getHeader())) { + return ST210REPORTS.EVENT; + } + + if (msg.startsWith(ST210REPORTS.ALERT.getHeader())) { + return ST210REPORTS.ALERT; + } + + if (msg.startsWith(ST210REPORTS.ALIVE.getHeader())) { + return ST210REPORTS.ALIVE; + } + + return null; + } + + public static Pattern getPattern(List protocol) { + + String patternStr = ""; + + for (ST210FIELDS field : protocol) { + patternStr += field.getPattern(); + } + + return Pattern.compile(patternStr); + + } + + @SuppressWarnings("serial") + static private List StatusProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_STATUS); + add(ST210FIELDS.DEV_ID); + add(ST210FIELDS.SW_VER); + add(ST210FIELDS.DATE); + add(ST210FIELDS.TIME); + add(ST210FIELDS.CELL); + add(ST210FIELDS.LAT); + add(ST210FIELDS.LON); + add(ST210FIELDS.SPD); + add(ST210FIELDS.CRS); + add(ST210FIELDS.SATT); + add(ST210FIELDS.FIX); + add(ST210FIELDS.DIST); + add(ST210FIELDS.PWR_VOLT); + add(ST210FIELDS.IO); + add(ST210FIELDS.MODE); + add(ST210FIELDS.MSG_NUM); + } + + }; + + @SuppressWarnings("serial") + static private List EmergencyProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_EMERGENCY); + add(ST210FIELDS.DEV_ID); + add(ST210FIELDS.SW_VER); + add(ST210FIELDS.DATE); + add(ST210FIELDS.TIME); + add(ST210FIELDS.CELL); + add(ST210FIELDS.LAT); + add(ST210FIELDS.LON); + add(ST210FIELDS.SPD); + add(ST210FIELDS.CRS); + add(ST210FIELDS.SATT); + add(ST210FIELDS.FIX); + add(ST210FIELDS.DIST); + add(ST210FIELDS.PWR_VOLT); + add(ST210FIELDS.IO); + add(ST210FIELDS.EMG_ID); + } + + }; + + @SuppressWarnings("serial") + static private List EventProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_EVENT); + add(ST210FIELDS.DEV_ID); + add(ST210FIELDS.SW_VER); + add(ST210FIELDS.DATE); + add(ST210FIELDS.TIME); + add(ST210FIELDS.CELL); + add(ST210FIELDS.LAT); + add(ST210FIELDS.LON); + add(ST210FIELDS.SPD); + add(ST210FIELDS.CRS); + add(ST210FIELDS.SATT); + add(ST210FIELDS.FIX); + add(ST210FIELDS.DIST); + add(ST210FIELDS.PWR_VOLT); + add(ST210FIELDS.IO); + add(ST210FIELDS.EVT_ID); + } + + }; + + @SuppressWarnings("serial") + static private List AlertProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_ALERT); + add(ST210FIELDS.DEV_ID); + add(ST210FIELDS.SW_VER); + add(ST210FIELDS.DATE); + add(ST210FIELDS.TIME); + add(ST210FIELDS.CELL); + add(ST210FIELDS.LAT); + add(ST210FIELDS.LON); + add(ST210FIELDS.SPD); + add(ST210FIELDS.CRS); + add(ST210FIELDS.SATT); + add(ST210FIELDS.FIX); + add(ST210FIELDS.DIST); + add(ST210FIELDS.PWR_VOLT); + add(ST210FIELDS.IO); + add(ST210FIELDS.ALERT_ID); + } + + }; + + @SuppressWarnings("serial") + static private List AliveProtocol = new LinkedList() { + + { + add(ST210FIELDS.HDR_ALIVE); + add(ST210FIELDS.DEV_ID); + } + + }; + + @Override + public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) + throws Exception { + String sentence = (String) msg; + return decodeMsg(sentence); + } + + public Position decodeMsg(String msg) throws Exception { + + ST210REPORTS report = getReportType(msg); + + List protocol = report.getProtocol(); + + Pattern protocolPattern = report.getProtocolPattern(); + + Log.info("Protocol Pattern: " + protocolPattern.toString()); + Log.info("Msg: " + msg); + + // Parse message + Matcher parser = protocolPattern.matcher(msg); + if (!parser.matches()) { + return null; + } + + // Create new position + Position position = new Position(); + + position.setAltitude(0D); + position.setExtendedInfo(""); + position.setValid(true); + + Integer index = 0; + for (ST210FIELDS field : protocol) { + + String groupValue = parser.group(index++); + + field.populatePosition(position, groupValue, getDataManager()); + } + + return position; + } +} -- cgit v1.2.3 From f5e305c4ea89210a2e4daffa4e947acdc440fbe7 Mon Sep 17 00:00:00 2001 From: williamchitto Date: Tue, 31 Jul 2012 08:08:53 -0300 Subject: adicionando classes de testes --- setup/windows/windows.cfg | 12 +- src/Main.java | 10 +- src/org/traccar/GenericPipelineFactory.java | 2 + src/org/traccar/Server.java | 914 ++++++++++++--------- src/org/traccar/TrackerServer.java | 125 +-- src/org/traccar/model/DatabaseDataManager.java | 2 + src/org/traccar/model/Position.java | 12 + src/org/traccar/protocol/ST210ProtocolDecoder.java | 3 + .../traccar/protocol/ST210ProtocolDecoderTest.java | 47 +- 9 files changed, 667 insertions(+), 460 deletions(-) (limited to 'src/org') diff --git a/setup/windows/windows.cfg b/setup/windows/windows.cfg index 273b0700b..3487189f6 100644 --- a/setup/windows/windows.cfg +++ b/setup/windows/windows.cfg @@ -16,7 +16,7 @@ CREATE TABLE IF NOT EXISTS devices (id INT IDENTITY, imei VARCHAR(16)); - CREATE TABLE IF NOT EXISTS positions (device_id INT, time TIMESTAMP, valid BOOLEAN, latitude DOUBLE, longitude DOUBLE, speed DOUBLE, course DOUBLE, power DOUBLE); + CREATE TABLE IF NOT EXISTS positions (device_id INT, time TIMESTAMP, valid BOOLEAN, latitude DOUBLE, longitude DOUBLE, speed DOUBLE, course DOUBLE, power DOUBLE, mode INT); @@ -72,11 +72,12 @@ speed - Double course - Double power - Double (NULL for some protocols) + mode - Integer extended_info - String (XML) <--> INSERT INTO positions (device_id, time, valid, latitude, longitude, speed, course, power) - VALUES (:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power) + VALUES (:device_id, :time, :valid, :latitude, :longitude, :speed, :course, :power, :mode) @@ -84,7 +85,7 @@ 8082 - false + true [LOG] @@ -136,5 +137,10 @@ true 5009 0 + + + true + 5010 + 0 diff --git a/src/Main.java b/src/Main.java index 8b6f2002e..783ebe0f6 100644 --- a/src/Main.java +++ b/src/Main.java @@ -6,10 +6,18 @@ public class Main { public static void main(String[] args) throws Exception { final Server service = new Server(); - service.init(args); + String[] argss = new String[1]; + argss[0] = "setup\\windows\\windows.cfg"; + service.init(argss); Log.info("starting server..."); + + service.start(); + + + + // Shutdown server properly Runtime.getRuntime().addShutdownHook(new Thread() { diff --git a/src/org/traccar/GenericPipelineFactory.java b/src/org/traccar/GenericPipelineFactory.java index c5e2cc812..db3c378ba 100644 --- a/src/org/traccar/GenericPipelineFactory.java +++ b/src/org/traccar/GenericPipelineFactory.java @@ -59,6 +59,7 @@ public abstract class GenericPipelineFactory implements ChannelPipelineFactory { @Override public void log(ChannelEvent e) { + server.mandaMSG(); if (e instanceof MessageEvent) { MessageEvent event = (MessageEvent) e; String msg = "[" + ((InetSocketAddress) e.getChannel().getLocalAddress()).getPort() + " - "; @@ -110,6 +111,7 @@ public abstract class GenericPipelineFactory implements ChannelPipelineFactory { pipeline.addLast("geocoder", new ReverseGeocoderHandler(geocoder)); } pipeline.addLast("handler", new TrackerEventHandler(dataManager)); + return pipeline; } } \ No newline at end of file diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 5a6b298c7..e6eabdb71 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,519 @@ 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(5010)){ + + 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("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); + } + } + + /** + * 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 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); + + } + } } diff --git a/src/org/traccar/TrackerServer.java b/src/org/traccar/TrackerServer.java index da889d0a3..f4830d778 100644 --- a/src/org/traccar/TrackerServer.java +++ b/src/org/traccar/TrackerServer.java @@ -16,6 +16,7 @@ package org.traccar; import java.net.InetSocketAddress; +import java.util.Iterator; import java.util.concurrent.Executors; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.Channel; @@ -29,60 +30,74 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; */ public class TrackerServer extends ServerBootstrap { - /** - * Initialization - */ - private void init(Integer port, Integer threadPoolSize) { - - setPort(port); - - // Create channel factory - setFactory(new NioServerSocketChannelFactory( - Executors.newCachedThreadPool(), - Executors.newCachedThreadPool())); - } - - public TrackerServer(Integer port) { - init(port, 1); - } - - /** - * Server port - */ - private Integer port; - - public Integer getPort() { - return port; - } - - private void setPort(Integer newPort) { - port = newPort; - } - - /** - * Opened channels - */ - private ChannelGroup allChannels = new DefaultChannelGroup(); - - public ChannelGroup getChannelGroup() { - return allChannels; - } - - /** - * Start server - */ - public void start() { - Channel channel = bind(new InetSocketAddress(getPort())); - getChannelGroup().add(channel); - } - - /** - * Stop server - */ - public void stop() { - ChannelGroupFuture future = getChannelGroup().close(); - future.awaitUninterruptibly(); - getFactory().releaseExternalResources(); - } + /** + * Initialization + */ + private void init(Integer port, Integer threadPoolSize) { + + setPort(port); + + // Create channel factory + setFactory(new NioServerSocketChannelFactory( + Executors.newCachedThreadPool(), + Executors.newCachedThreadPool())); + } + + public TrackerServer(Integer port) { + init(port, 1); + } + + /** + * Server port + */ + private Integer port; + + public Integer getPort() { + return port; + } + + private void setPort(Integer newPort) { + port = newPort; + } + + /** + * Opened channels + */ + private ChannelGroup allChannels = new DefaultChannelGroup(); + + public ChannelGroup getChannelGroup() { + return allChannels; + } + + public void mandaMSG() { + + /* for (Iterator it = this.getChannelGroup().iterator(); it.hasNext();) { + Channel chanel = (Channel) it.next(); + System.out.println(chanel.getRemoteAddress()); + if(chanel.getRemoteAddress() !=null) + this.getChannelGroup().write("OI AMIGO", chanel.getRemoteAddress()); + + } +*/ + // System.out.println(type.getPort()); + + } + + /** + * Start server + */ + public void start() { + Channel channel = bind(new InetSocketAddress(getPort())); + getChannelGroup().add(channel); + } + + /** + * Stop server + */ + public void stop() { + ChannelGroupFuture future = getChannelGroup().close(); + future.awaitUninterruptibly(); + getFactory().releaseExternalResources(); + } } 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..0d04f4d49 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -151,6 +151,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 eeedccf69..8fbea8da5 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -596,6 +596,9 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { @Override public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { + if (channel != null) { + channel.write("OI AMIGO do decoder"); + } String sentence = (String) msg; return decodeMsg(sentence); } diff --git a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java index ba36cb360..a2ffe5bac 100644 --- a/test/org/traccar/protocol/ST210ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/ST210ProtocolDecoderTest.java @@ -2,11 +2,56 @@ package org.traccar.protocol; import static org.junit.Assert.*; +import java.io.IOException; +import java.sql.SQLException; + +import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; +import org.traccar.Server; +import org.traccar.helper.Log; +import org.traccar.server.SocketCliente; public class ST210ProtocolDecoderTest { + @BeforeClass + public static void UpServer() { + final Server service = new Server(); + String[] args = new String[1]; + args[0] = "setup\\windows\\windows.cfg"; + try { + service.init(args); + + Log.info("starting server..."); + service.start(); + + // Shutdown server properly + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + Log.info("shutting down server..."); + service.stop(); + } + }); + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + @Test + public void testClienteMsg() throws Exception { + + SocketCliente cliente = new SocketCliente(); + cliente.SendMSG( + "localhost", + 5010, + "SA200STT;317652;042;20120718;15:37:12;16d41;-15.618755;-056.083241;000.024;000.00;8;1;41548;12.17;100000;2;1979"); + + } + +/* @Test public void testDecode() throws Exception { ST210ProtocolDecoder decoder = new ST210ProtocolDecoder( @@ -24,5 +69,5 @@ public class ST210ProtocolDecoderTest { .decode(null, null, "SA200STT;317652;042;20120722;00:24:23;16d41;-15.618767;-056.083214;000.011;000.00;11;1;41557;12.21;000000;1;3205")); - } + }*/ } -- cgit v1.2.3 From 1dcac709aecfeaf19d616316bd2f23b96ef86390 Mon Sep 17 00:00:00 2001 From: leandro Date: Fri, 3 Aug 2012 13:11:52 -0400 Subject: Atualização de parametros e dependencia do postgre MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 +++++ src/Main.java | 26 ++++++++++++++------------ src/org/traccar/Server.java | 11 +++++++++++ 3 files changed, 30 insertions(+), 12 deletions(-) (limited to 'src/org') diff --git a/pom.xml b/pom.xml index 9e11580f3..a880e58ee 100644 --- a/pom.xml +++ b/pom.xml @@ -26,6 +26,11 @@ junit 4.10 + + postgresql + postgresql + 8.1-407.jdbc3 + diff --git a/src/Main.java b/src/Main.java index 783ebe0f6..69c029c61 100644 --- a/src/Main.java +++ b/src/Main.java @@ -4,21 +4,23 @@ import org.traccar.helper.Log; public class Main { public static void main(String[] args) throws Exception { - - final Server service = new Server(); - String[] argss = new String[1]; - argss[0] = "setup\\windows\\windows.cfg"; - service.init(argss); - - Log.info("starting server..."); - + + final Server service = new Server(); + + if(args.length > 0){ + Log.info("Using parameterized config: " + args[0]); + service.init(args); + } + else{ + String[] argsDefault = new String[]{"setup\\windows\\windows.cfg"}; + Log.info("Using default config: " + argsDefault[0]); + service.init(argsDefault); + } + Log.info("starting server..."); + service.start(); - - - - // Shutdown server properly Runtime.getRuntime().addShutdownHook(new Thread() { @Override diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index e6eabdb71..f01b5af2a 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -251,6 +251,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -284,6 +285,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -316,6 +318,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -348,6 +351,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -380,6 +384,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -412,6 +417,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -444,6 +450,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -475,6 +482,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -503,6 +511,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -531,6 +540,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -560,6 +570,7 @@ public class Server { }); serverList.add(server); + Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } -- cgit v1.2.3 From 1205bd5f9b708ff2633551e6e38f4e90b1efd35b Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 4 Aug 2012 17:13:21 -0400 Subject: Correção de identações MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/traccar/Server.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index f01b5af2a..df035fc21 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -120,8 +120,7 @@ public class Server { // Initialize web server if (Boolean.valueOf(properties.getProperty("http.enable"))) { - Integer port = Integer.valueOf(properties.getProperty("http.port", - "8082")); + Integer port = Integer.valueOf(properties.getProperty("http.port","8082")); webServer = new WebServer(port, dataManager); } } @@ -162,8 +161,7 @@ public class Server { */ private void initLogger(Properties properties) throws IOException { - loggerEnabled = Boolean - .valueOf(properties.getProperty("logger.enable")); + loggerEnabled = Boolean.valueOf(properties.getProperty("logger.enable")); if (loggerEnabled) { -- cgit v1.2.3 From 5a80591e29ee7b05ed50737e3d5d6bb98c1f59a3 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 4 Aug 2012 17:26:40 -0400 Subject: Mais correções de identações para testes com github MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/traccar/Server.java | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index df035fc21..612eeb32a 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -172,15 +172,12 @@ public class Server { // Simple formatter file.setFormatter(new Formatter() { - private final String LINE_SEPARATOR = System.getProperty( - "line.separator", "\n"); + private final String LINE_SEPARATOR = System.getProperty("line.separator", "\n"); - private final DateFormat dateFormat = new SimpleDateFormat( - "yyyy-MM-dd hh:mm:ss"); + 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())); + String line = dateFormat.format(new Date(record.getMillis())); line += " " + record.getLevel().getName() + ": "; line += formatMessage(record); line += LINE_SEPARATOR; @@ -233,18 +230,14 @@ public class Server { String protocol = "xexun"; if (isProtocolEnabled(properties, protocol)) { - TrackerServer server = new TrackerServer(getProtocolPort( - properties, protocol)); - final Integer resetDelay = getProtocolResetDelay(properties, - protocol); + TrackerServer server = new TrackerServer(getProtocolPort(properties, protocol)); + final Integer resetDelay = getProtocolResetDelay(properties,protocol); - server.setPipelineFactory(new GenericPipelineFactory(server, - dataManager, isLoggerEnabled(), geocoder) { + 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)); + pipeline.addLast("objectDecoder", new XexunProtocolDecoder(getDataManager(), resetDelay)); } }); -- cgit v1.2.3 From df9f126e59cf70b7b0d9d7e8a9b7808fe51952bf Mon Sep 17 00:00:00 2001 From: Leandro Ferreira Date: Mon, 6 Aug 2012 12:19:56 -0400 Subject: corrections in wrong words --- src/org/traccar/Server.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 612eeb32a..917bf7bbb 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -242,7 +242,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -276,7 +276,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -309,7 +309,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -342,7 +342,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -375,7 +375,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -408,7 +408,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -441,7 +441,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -473,7 +473,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -502,7 +502,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -531,7 +531,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } @@ -561,7 +561,7 @@ public class Server { }); serverList.add(server); - Log.info("Activeting protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); + Log.info("Activating protocol " + protocol + " @ " + getProtocolPort(properties, protocol)); } } -- cgit v1.2.3 From 356ad74b9a5f803ea7c22eb15e32cf21d2c85e2e Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Tue, 7 Aug 2012 12:27:01 -0400 Subject: Corrected time zones bugs. --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 48 +++++++++++++--------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 8745941cb..8348f5a14 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -1,6 +1,7 @@ package org.traccar.protocol; import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.LinkedList; import java.util.List; import java.util.TimeZone; @@ -97,34 +98,41 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case DATE: { // Date - Calendar time = Calendar.getInstance(TimeZone - .getTimeZone("UTC")); + Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); - time.set(Calendar.YEAR, Integer.valueOf(Integer - .valueOf(groupValue.substring(0, 4)))); - time.set(Calendar.MONTH, Integer.valueOf(Integer - .valueOf(groupValue.substring(4, 6)))); - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer - .valueOf(groupValue.substring(6, 8)))); - position.setTime(time.getTime()); + time.set(Calendar.YEAR, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 4)))); + time.set(Calendar.MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(4, 6))-1)); + time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8)))); + + Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + + ret.setTimeInMillis(time.getTimeInMillis() + + TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) - + TimeZone.getDefault().getOffset(time.getTimeInMillis())); + + position.setTime(ret.getTime()); + break; } case TIME: { - Calendar time = Calendar.getInstance(TimeZone - .getTimeZone("UTC")); + Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); time.setTime(position.getTime()); - - time.set(Calendar.HOUR, Integer.valueOf(Integer - .valueOf(groupValue.substring(0, 2)))); - time.set(Calendar.MINUTE, Integer.valueOf(Integer - .valueOf(groupValue.substring(3, 5)))); - time.set(Calendar.SECOND, Integer.valueOf(Integer - .valueOf(groupValue.substring(6, 8)))); - - position.setTime(time.getTime()); + + time.set(Calendar.HOUR_OF_DAY, Integer.valueOf(Integer.valueOf(groupValue.substring(0, 2)))); + time.set(Calendar.MINUTE, Integer.valueOf(Integer.valueOf(groupValue.substring(3, 5)))); + time.set(Calendar.SECOND, Integer.valueOf(Integer.valueOf(groupValue.substring(6, 8)))); + + Calendar ret = new GregorianCalendar(TimeZone.getTimeZone("UTC")); + + ret.setTimeInMillis(time.getTimeInMillis() + + TimeZone.getTimeZone("UTC").getOffset(time.getTimeInMillis()) - + TimeZone.getDefault().getOffset(time.getTimeInMillis())); + + position.setTime(ret.getTime()); + break; } -- cgit v1.2.3 From bb72110f2ff0ed8f64e61eb578d60040c914a99a Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Wed, 8 Aug 2012 12:04:23 -0400 Subject: Removed wrong code that was generating errors on connections. --- src/org/traccar/GenericPipelineFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/GenericPipelineFactory.java b/src/org/traccar/GenericPipelineFactory.java index db3c378ba..521b8bc74 100644 --- a/src/org/traccar/GenericPipelineFactory.java +++ b/src/org/traccar/GenericPipelineFactory.java @@ -59,7 +59,7 @@ public abstract class GenericPipelineFactory implements ChannelPipelineFactory { @Override public void log(ChannelEvent e) { - server.mandaMSG(); + if (e instanceof MessageEvent) { MessageEvent event = (MessageEvent) e; String msg = "[" + ((InetSocketAddress) e.getChannel().getLocalAddress()).getPort() + " - "; -- cgit v1.2.3 From 208547fae3d20c77309c98c44595dd07ab77ee39 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 9 Aug 2012 08:59:52 -0400 Subject: Log. --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 8348f5a14..8d2200f57 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -608,6 +608,8 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { public Position decodeMsg(String msg) throws Exception { + Log.info("Msg: " + msg); + ST210REPORTS report = getReportType(msg); List protocol = report.getProtocol(); @@ -615,7 +617,6 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { Pattern protocolPattern = report.getProtocolPattern(); Log.info("Protocol Pattern: " + protocolPattern.toString()); - Log.info("Msg: " + msg); // Parse message Matcher parser = protocolPattern.matcher(msg); -- cgit v1.2.3 From 14b10b15c268983c1ce3f0a74fdaaf79b5ce7785 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 9 Aug 2012 09:22:46 -0400 Subject: Changed to correct port. --- src/org/traccar/Server.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/Server.java b/src/org/traccar/Server.java index 917bf7bbb..32a2888cc 100644 --- a/src/org/traccar/Server.java +++ b/src/org/traccar/Server.java @@ -76,7 +76,7 @@ public class Server { for (Iterator iterator = serverList.iterator(); iterator.hasNext();) { TrackerServer type = (TrackerServer) iterator.next(); - if(type.getPort().equals(5010)){ + if(type.getPort().equals(8801)){ for (Iterator it = type.getChannelGroup().iterator(); it.hasNext();) { Channel chanel = (Channel) it.next(); -- cgit v1.2.3 From 7c3649250d4905b1c7024d2e85faebf9467f865a Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Thu, 9 Aug 2012 11:04:36 -0400 Subject: Corrected the PWR_VOLT regex pattern and some encoding errors. --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 59 +++++++++++----------- 1 file changed, 29 insertions(+), 30 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 8d2200f57..226f171bf 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -23,31 +23,30 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum ST210FIELDS { - HDR_STATUS("SA200STT;", "Status Report"), HDR_EMERGENCY("SA200EMG;", - "Emergency Report"), HDR_EVENT("SA200EVT;", "Event Report"), HDR_ALERT( - "SA200ALT;", "Alert Report"), HDR_ALIVE("SA200ALV;", - "Alive Report"), DEV_ID("(\\d+);", "Device ID"), 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)"), 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"), CRS( - "(\\d{3}.\\d{2});", "Course over ground in degree"), SATT( - "(\\d+);", "Number of satellites"), FIX("(\\d);", - "GPS is fixed(1)\n" + "GPS is not fixed(0)"), DIST("(\\d+);", - "Traveled ddistance in meter"), PWR_VOLT("(\\d{2}.\\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"), EVT_ID("(\\d);", "Event type"), ALERT_ID( - "(\\d);", "Alert type"); + HDR_STATUS("SA200STT;", + "Status Report"), + HDR_EMERGENCY("SA200EMG;","Emergency Report"), + HDR_EVENT("SA200EVT;", "Event Report"), + HDR_ALERT("SA200ALT;","Alert Report"), + HDR_ALIVE("SA200ALV;","Alive Report"), + DEV_ID("(\\d+);", "Device ID"), + 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)"), + 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"), + CRS("(\\d{3}.\\d{2});", "Course over ground in degree"), + SATT("(\\d+);", "Number of satellites"), + FIX("(\\d);","GPS is fixed(1)\n" + "GPS is not fixed(0)"), + DIST("(\\d+);","Traveled ddistance in meter"), + 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"), EVT_ID("(\\d);", "Event type"), + ALERT_ID("(\\d);", "Alert type"); private String pattern; @@ -175,7 +174,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 0: return NOT_FIXED; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -212,7 +211,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 2: return DRIVING; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -256,7 +255,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 5: return ANTI_THEFT; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -306,7 +305,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 6: return INPUT3_OPEN; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } @@ -383,7 +382,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { case 19: return ENTER_ROUT; default: - throw new IllegalArgumentException("�ndice n�o definido"); + throw new IllegalArgumentException("Index not defined"); } } } -- cgit v1.2.3 From 485d9e45883b4f028f76a6d05c5a72de08736e4c Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 11 Aug 2012 18:27:37 -0400 Subject: Added more position fields on log --- src/org/traccar/TrackerEventHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/org') diff --git a/src/org/traccar/TrackerEventHandler.java b/src/org/traccar/TrackerEventHandler.java index e4e45a174..2a66a084f 100644 --- a/src/org/traccar/TrackerEventHandler.java +++ b/src/org/traccar/TrackerEventHandler.java @@ -55,7 +55,9 @@ public class TrackerEventHandler extends SimpleChannelHandler { ", longitude: " + position.getLongitude() + ", altitude: " + position.getAltitude() + ", speed: " + position.getSpeed() + - ", course: " + position.getCourse()); + ", course: " + position.getCourse() + + ", power: " + position.getPower() + + ", mode: " + position.getMode()); } // Write position to database -- cgit v1.2.3 From 65433706d8c321c1e29844de41576e1b38af8638 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 11 Aug 2012 20:03:05 -0400 Subject: Translate the user interface to portuguese Corrected the date column Added Mode column --- src/org/traccar/http/WebServer.java | 13 ++++---- src/org/traccar/model/Position.java | 7 +++++ src/web/index.html | 60 ++++++++++++++++++++----------------- 3 files changed, 46 insertions(+), 34 deletions(-) (limited to 'src/org') 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/Position.java b/src/org/traccar/model/Position.java index 0d04f4d49..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; diff --git a/src/web/index.html b/src/web/index.html index cde73f47b..dcc4771db 100644 --- a/src/web/index.html +++ b/src/web/index.html @@ -1,7 +1,9 @@ - - + + -Traccar Manager +Jornada Beta + + @@ -758,6 +760,7 @@ Ext.onReady(function() { ] }); + Ext.define('Position', { extend: 'Ext.data.Model', fields: [ @@ -768,7 +771,8 @@ Ext.onReady(function() { {name: 'longitude', type: 'float'}, {name: 'speed', type: 'float'}, {name: 'course', type: 'float'}, - {name: 'power', type: 'float'} + {name: 'power', type: 'float'}, + {name: 'mode', type: 'int'} ] }); @@ -806,7 +810,8 @@ Ext.onReady(function() { 'longitude', 'speed', 'course', - 'power' + 'power', + 'mode' ], proxy: { type: 'ajax', @@ -824,7 +829,7 @@ Ext.onReady(function() { }); var devicesPanel = Ext.create('Ext.grid.Panel', { - title: 'Devices', + title: 'Dispositivos', region: 'west', split: true, width: 300, @@ -837,16 +842,16 @@ Ext.onReady(function() { tbar: [ { id: 'device_update', - text: 'Update', + text: 'Atualizar', handler : function() { devices.load(); } }, { id: 'device_add', - text: 'Add', + text: 'Incluir', handler : function() { - Ext.Msg.prompt('Add', 'Device IMEI:', function(btn, text) { + Ext.Msg.prompt('Incluir', 'IMEI do Dispositivo:', function(btn, text) { if (btn == 'ok') { devices.add({imei: text}); } @@ -855,10 +860,10 @@ Ext.onReady(function() { }, { id: 'device_remove', - text: 'Remove', + text: 'Remover', disabled: true, handler : function() { - Ext.Msg.confirm('Remove', 'Are you sure to remove item?', function(btn) { + Ext.Msg.confirm('Remover', 'Confirma remoção do item?', function(btn) { if (btn == 'yes') { devices.remove(devicesPanel.getSelectionModel().getLastSelected()); } @@ -867,10 +872,10 @@ Ext.onReady(function() { }, { id: 'device_edit', - text: 'Edit', + text: 'Alterar', disabled: true, handler : function() { - Ext.Msg.prompt('Edit', 'Device IMEI:', function(btn, text) { + Ext.Msg.prompt('Alterar', 'IMEI do Dispositivo:', function(btn, text) { if (btn == 'ok') { devicesPanel.getSelectionModel().getLastSelected().set('imei', text); } @@ -888,11 +893,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(); @@ -905,7 +910,7 @@ Ext.onReady(function() { }); var positionsPanel = Ext.create('Ext.grid.Panel', { - title: 'Positions', + title: 'Posicionamentos', region: 'south', split: true, height: 300, @@ -918,7 +923,7 @@ Ext.onReady(function() { tbar: [ { id: 'position_update', - text: 'Update', + text: 'Atualizar', disabled: true, handler : function() { positions.load(); @@ -926,19 +931,18 @@ Ext.onReady(function() { } ], columns: [ - {header: 'Device Id', dataIndex: 'device_id'}, - { - header: 'Time', - dataIndex: 'time', + {header: 'Id Dispositivo', dataIndex: 'device_id'}, + {header: 'Data/Hora',dataIndex: 'time', flex: 1, - renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s') + renderer: Ext.util.Format.dateRenderer('d/m/Y H:i:s') }, - {header: 'Valid', dataIndex: 'valid'}, + {header: 'Válido', dataIndex: 'valid'}, {header: 'Latitude', dataIndex: 'latitude'}, {header: 'Longitude', dataIndex: 'longitude'}, - {header: 'Speed', dataIndex: 'speed'}, - {header: 'Course', dataIndex: 'course'}, - {header: 'Power', dataIndex: 'power'} + {header: 'Velocidade', dataIndex: 'speed'}, + {header: 'Curso', dataIndex: 'course'}, + {header: 'Voltagem', dataIndex: 'power'}, + {header: 'Modo', dataIndex: 'mode'} ], listeners: { selectionchange: function(sender, selected, eOpts) { @@ -955,7 +959,7 @@ Ext.onReady(function() { }); var mapPanel = Ext.create('Ext.panel.Panel', { - title: 'Map', + title: 'Mapa', region: 'center', margins: {top: 5, bottom: 0, right: 5, left: 0}, -- cgit v1.2.3 From 4aaf5dd3cf3d1b089bb168ffdb2ed8f75e2899c6 Mon Sep 17 00:00:00 2001 From: Leandro Silva Ferreira Date: Sat, 11 Aug 2012 20:04:19 -0400 Subject: Corrected error on regex pattern of EMG_ID field --- src/org/traccar/protocol/ST210ProtocolDecoder.java | 78 ++++++++++++---------- 1 file changed, 43 insertions(+), 35 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/ST210ProtocolDecoder.java b/src/org/traccar/protocol/ST210ProtocolDecoder.java index 226f171bf..f503fead6 100644 --- a/src/org/traccar/protocol/ST210ProtocolDecoder.java +++ b/src/org/traccar/protocol/ST210ProtocolDecoder.java @@ -45,7 +45,8 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { 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"), EVT_ID("(\\d);", "Event type"), + EMG_ID("(\\d)", "Emergency type"), + EVT_ID("(\\d);", "Event type"), ALERT_ID("(\\d);", "Alert type"); private String pattern; @@ -217,10 +218,10 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum FIELD_EMG_ID_VALUE { - PANIC(1, "Emergency by panic button"), PARKING(2, - "Emergency by parking lock"), MAIN_POWER(3, - "Emergency by removing main power"), ANTI_THEFT(5, - "Emergency by anti-theft"); + PANIC(1, "Emergency by panic button"), + PARKING(2,"Emergency by parking lock"), + MAIN_POWER(3,"Emergency by removing main power"), + ANTI_THEFT(5,"Emergency by anti-theft"); private int value; @@ -261,12 +262,12 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum FIELD_EVT_ID_VALUE { - INPUT1_GROUND(1, "Input1 goes to ground state"), INPUT1_OPEN(2, - "Input1 goes to open state"), INPUT2_GROUND(3, - "Input2 goes to ground state"), INPUT2_OPEN(4, - "Input2 goes to open state"), INPUT3_GROUND(5, - "Input3 goes to ground state"), INPUT3_OPEN(6, - "Input3 goes to open state"); + INPUT1_GROUND(1, "Input1 goes to ground state"), + INPUT1_OPEN(2,"Input1 goes to open state"), + INPUT2_GROUND(3,"Input2 goes to ground state"), + INPUT2_OPEN(4,"Input2 goes to open state"), + INPUT3_GROUND(5,"Input3 goes to ground state"), + INPUT3_OPEN(6,"Input3 goes to open state"); private int value; @@ -288,7 +289,7 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { public FIELD_EVT_ID_VALUE getValueOf(String indiceStr) { int indice = Integer.valueOf(indiceStr); return getValueOf(indice); - } + } public FIELD_EVT_ID_VALUE getValueOf(int indice) { switch (indice) { @@ -311,21 +312,21 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { } private enum FIELD_ALERT_ID_VALUE { - DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), OVER_SPPED( - 2, "Ended over speed condition"), DISCON_GPS(3, - "Disconnected GPS antenna"), RECON_GPS(4, - "Reconnected GPS antenna after disconnected"), OUT_GEO_FENCE(5, - "The vehicle went out from the geo-fence that has following ID"), INTO_GEO_FENCE( - 6, - "The vehicle entered into the geo-fence that has following ID"), SHORTED_GPS( - 8, "Shorted GPS antenna"), DEEP_SLEEP_ON(9, - "Enter to deep sleep mode"), DEEP_SLEEP_OFF(10, - "Exite from deep sleep mode"), BKP_BATTERY(13, - "Backup battery error"), BATTERY_DOWN(14, - "Vehicle battery goes down to so low level"), SHOCKED(15, - "Shocked"), COLLISION(16, "Occurred some collision"), DEVIATE_ROUT( - 18, "Deviate from predefined rout"), ENTER_ROUT(19, - "Enter into predefined rout"); + DRIVING_FASTER(1, "Start driving faster than SPEED_LIMIT"), + OVER_SPPED(2, "Ended over speed condition"), + DISCON_GPS(3,"Disconnected GPS antenna"), + RECON_GPS(4,"Reconnected GPS antenna after disconnected"), + OUT_GEO_FENCE(5,"The vehicle went out from the geo-fence that has following ID"), + INTO_GEO_FENCE(6,"The vehicle entered into the geo-fence that has following ID"), + SHORTED_GPS(8, "Shorted GPS antenna"), + DEEP_SLEEP_ON(9,"Enter to deep sleep mode"), + DEEP_SLEEP_OFF(10,"Exite from deep sleep mode"), + BKP_BATTERY(13,"Backup battery error"), + BATTERY_DOWN(14,"Vehicle battery goes down to so low level"), + SHOCKED(15,"Shocked"), + COLLISION(16, "Occurred some collision"), + DEVIATE_ROUT(18, "Deviate from predefined rout"), + ENTER_ROUT(19,"Enter into predefined rout"); private int value; @@ -599,28 +600,35 @@ public class ST210ProtocolDecoder extends GenericProtocolDecoder { }; @Override - public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) - throws Exception { + public Object decode(ChannelHandlerContext ctx, Channel channel, Object msg) { String sentence = (String) msg; - return decodeMsg(sentence); + Log.info("Msg: " + msg); + + Position position = null; + + try{ + position = decodeMsg(sentence); + Log.info("MESSAGE DECODED WITH SUCCESS!"); + } + catch(Exception e){ + Log.info("ERROR WHILE DECODING MESSAGE: " + e.getMessage()); + } + + return position; } public Position decodeMsg(String msg) throws Exception { - Log.info("Msg: " + msg); - ST210REPORTS report = getReportType(msg); List protocol = report.getProtocol(); Pattern protocolPattern = report.getProtocolPattern(); - Log.info("Protocol Pattern: " + protocolPattern.toString()); - // Parse message Matcher parser = protocolPattern.matcher(msg); if (!parser.matches()) { - return null; + throw new Exception("Pattern no match: " + protocolPattern.toString()); } // Create new position -- cgit v1.2.3