From 1359371f83393e4a6a5dcbc0df03ab1b33bebde5 Mon Sep 17 00:00:00 2001 From: anton2920 Date: Sun, 24 Jul 2022 17:32:01 +0100 Subject: Added high-level payload parsing --- .../traccar/protocol/PiligrimProtocolDecoder.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index 244df6806..dca8b1329 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -30,6 +30,7 @@ import org.traccar.model.Position; import java.net.SocketAddress; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; @@ -150,6 +151,33 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { } return positions; + } else if (uri.startsWith("/push.do")) { + /* Getting payload */ + ByteBuf content_stream = request.content(); + byte[] payload_bytes = new byte[Integer.parseInt(request.headers().get("Content-Length"))]; + content_stream.readBytes(payload_bytes); + String payload = new String(payload_bytes); + + /* Payload structure: + * &phone&message + */ + String[] payload_parts = payload.split("&"); + System.out.println("Payload parts: " + Arrays.toString(payload_parts)); + String phone_number = payload_parts[1].substring(12); + String message = payload_parts[2].substring(8); + System.out.println("Phone number: " + phone_number); + System.out.println("Message: " + message); + + /* Supported message structure: + * GPS NMEA Command; GSM info; Unknown; Battery voltage? + */ + if (message.startsWith("$GPRMC")) { + System.out.println("Supported message"); + } else { + System.out.println("Unsupported message"); + } + + System.out.println("Finish"); } return null; -- cgit v1.2.3 From 16197c4bec4da40372da7505c6b2093da6b743f5 Mon Sep 17 00:00:00 2001 From: anton2920 Date: Sun, 24 Jul 2022 17:47:13 +0100 Subject: Added high-level parsing of message field --- .../traccar/protocol/PiligrimProtocolDecoder.java | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index dca8b1329..29b6d9ef0 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -168,11 +168,28 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { System.out.println("Phone number: " + phone_number); System.out.println("Message: " + message); - /* Supported message structure: - * GPS NMEA Command; GSM info; Unknown; Battery voltage? - */ if (message.startsWith("$GPRMC")) { + /* Supported message structure: + * GPS NMEA Command; GSM info; Unknown; Battery voltage? + * Example: $GPRMC,180752.000,A,5314.0857,N,03421.8173,E,0.00,104.74,220722,,,A,V* 29,05; GSM: 250-01 0b54-0519,1c30,3e96,3ebe,412e 25; S; Batt: 405,M + */ System.out.println("Supported message"); + + String[] message_parts = message.split(";"); + System.out.println("Message parts: " + Arrays.toString(message_parts)); + + /* Parsing GPS */ + String unprocessed_gps_command = message_parts[0]; + + /* Getting rid of checksum */ + String gps_command = unprocessed_gps_command.replaceFirst("A,V[*].*", ""); + System.out.println("GPS command: " + gps_command); + + /* Parsing other fields */ + /* String gsm_info = message_parts[1]; */ + /* String unknown = message_parts[2]; */ + String battery_info = message_parts[3].substring(7).substring(0, 3); + System.out.println("Battery: " + battery_info); } else { System.out.println("Unsupported message"); } -- cgit v1.2.3 From 3ead0772172daeb3d6fedab5f04a32c33b9d5ebb Mon Sep 17 00:00:00 2001 From: anton2920 Date: Sun, 24 Jul 2022 17:53:21 +0100 Subject: Added NMEA parser (that doesn't s**ck) --- src/main/java/org/traccar/helper/NMEA.java | 126 +++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 src/main/java/org/traccar/helper/NMEA.java diff --git a/src/main/java/org/traccar/helper/NMEA.java b/src/main/java/org/traccar/helper/NMEA.java new file mode 100644 index 000000000..cae47a8f6 --- /dev/null +++ b/src/main/java/org/traccar/helper/NMEA.java @@ -0,0 +1,126 @@ +package org.traccar.helper; + +import java.util.HashMap; +import java.util.Map; + + +public class NMEA { + + // fucking java interfaces + interface SentenceParser { + public boolean parse(String[] tokens, GPSPosition position); + } + + // utils + static float Latitude2Decimal(String lat, String NS) { + float med = Float.parseFloat(lat.substring(2)) / 60.0f; + med += Float.parseFloat(lat.substring(0, 2)); + if (NS.startsWith("S")) { + med = -med; + } + return med; + } + + static float Longitude2Decimal(String lon, String WE) { + float med = Float.parseFloat(lon.substring(3)) / 60.0f; + med += Float.parseFloat(lon.substring(0, 3)); + if (WE.startsWith("W")) { + med = -med; + } + return med; + } + + // parsers + class GPGGA implements SentenceParser { + public boolean parse(String[] tokens, GPSPosition position) { + position.time = Float.parseFloat(tokens[1]); + position.lat = Latitude2Decimal(tokens[2], tokens[3]); + position.lon = Longitude2Decimal(tokens[4], tokens[5]); + position.quality = Integer.parseInt(tokens[6]); + position.altitude = Float.parseFloat(tokens[9]); + return true; + } + } + + class GPGGL implements SentenceParser { + public boolean parse(String[] tokens, GPSPosition position) { + position.lat = Latitude2Decimal(tokens[1], tokens[2]); + position.lon = Longitude2Decimal(tokens[3], tokens[4]); + position.time = Float.parseFloat(tokens[5]); + return true; + } + } + + class GPRMC implements SentenceParser { + public boolean parse(String[] tokens, GPSPosition position) { + position.time = Float.parseFloat(tokens[1]); + position.lat = Latitude2Decimal(tokens[3], tokens[4]); + position.lon = Longitude2Decimal(tokens[5], tokens[6]); + position.velocity = Float.parseFloat(tokens[7]); + position.dir = Float.parseFloat(tokens[8]); + return true; + } + } + + class GPVTG implements SentenceParser { + public boolean parse(String[] tokens, GPSPosition position) { + position.dir = Float.parseFloat(tokens[3]); + return true; + } + } + + class GPRMZ implements SentenceParser { + public boolean parse(String[] tokens, GPSPosition position) { + position.altitude = Float.parseFloat(tokens[1]); + return true; + } + } + + public class GPSPosition { + public float time = 0.0f; + public float lat = 0.0f; + public float lon = 0.0f; + public boolean fixed = false; + public int quality = 0; + public float dir = 0.0f; + public float altitude = 0.0f; + public float velocity = 0.0f; + + public void updatefix() { + fixed = quality > 0; + } + + public String toString() { + return String.format("POSITION: lat: %f, lon: %f, time: %f, Q: %d, dir: %f, alt: %f, vel: %f", lat, lon, time, quality, dir, altitude, velocity); + } + } + + GPSPosition position = new GPSPosition(); + + private static final Map sentenceParsers = new HashMap(); + + public NMEA() { + sentenceParsers.put("GPGGA", new GPGGA()); + sentenceParsers.put("GPGGL", new GPGGL()); + sentenceParsers.put("GPRMC", new GPRMC()); + sentenceParsers.put("GPRMZ", new GPRMZ()); + //only really good GPS devices have this sentence but ... + sentenceParsers.put("GPVTG", new GPVTG()); + } + + public GPSPosition parse(String line) { + + if (line.startsWith("$")) { + String nmea = line.substring(1); + String[] tokens = nmea.split(","); + String type = tokens[0]; + //TODO check crc + if (sentenceParsers.containsKey(type)) { + sentenceParsers.get(type).parse(tokens, position); + } + position.updatefix(); + } + + return position; + } +} -- cgit v1.2.3 From 2274b42c6b1c7b1ef90e3ec4e5e956afe66eaa6d Mon Sep 17 00:00:00 2001 From: anton2920 Date: Sun, 24 Jul 2022 18:01:41 +0100 Subject: Added parsing of GPS NMEA message --- .../java/org/traccar/protocol/PiligrimProtocolDecoder.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index 29b6d9ef0..7f9d20822 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -26,6 +26,7 @@ import org.traccar.session.DeviceSession; import org.traccar.Protocol; import org.traccar.helper.BitUtil; import org.traccar.helper.DateBuilder; +import org.traccar.helper.NMEA; import org.traccar.model.Position; import java.net.SocketAddress; @@ -163,7 +164,7 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { */ String[] payload_parts = payload.split("&"); System.out.println("Payload parts: " + Arrays.toString(payload_parts)); - String phone_number = payload_parts[1].substring(12); + String phone_number = payload_parts[1].substring(15); String message = payload_parts[2].substring(8); System.out.println("Phone number: " + phone_number); System.out.println("Message: " + message); @@ -185,6 +186,14 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { String gps_command = unprocessed_gps_command.replaceFirst("A,V[*].*", ""); System.out.println("GPS command: " + gps_command); + NMEA gps_parser = new NMEA(); + + NMEA.GPSPosition gps_position = gps_parser.parse(gps_command); + + System.out.println("Time: " + gps_position.time); + System.out.println("Coordinates: " + gps_position.lat + " " + gps_position.lon); + System.out.println("Speed over ground: " + gps_position.velocity + " knots"); + /* Parsing other fields */ /* String gsm_info = message_parts[1]; */ /* String unknown = message_parts[2]; */ -- cgit v1.2.3 From 62b38f2ccf0db60e7e953485898a1d3bf5c452e0 Mon Sep 17 00:00:00 2001 From: anton2920 Date: Sun, 24 Jul 2022 18:36:33 +0100 Subject: WIP: Added position return --- .../traccar/protocol/PiligrimProtocolDecoder.java | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index 7f9d20822..967adb82b 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -21,6 +21,7 @@ import io.netty.channel.Channel; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.QueryStringDecoder; +import net.fortuna.ical4j.model.DateTime; import org.traccar.BaseHttpProtocolDecoder; import org.traccar.session.DeviceSession; import org.traccar.Protocol; @@ -32,6 +33,7 @@ import org.traccar.model.Position; import java.net.SocketAddress; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -153,6 +155,13 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { return positions; } else if (uri.startsWith("/push.do")) { + sendResponse(channel, "PUSH.DO: OK"); + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, "123456"); + if (deviceSession == null) { + return null; + } + /* Getting payload */ ByteBuf content_stream = request.content(); byte[] payload_bytes = new byte[Integer.parseInt(request.headers().get("Content-Length"))]; @@ -199,11 +208,26 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { /* String unknown = message_parts[2]; */ String battery_info = message_parts[3].substring(7).substring(0, 3); System.out.println("Battery: " + battery_info); + + /* Constructing response */ + Position position = new Position(getProtocolName()); + + position.setDeviceId(deviceSession.getDeviceId()); + position.setValid(true); + position.setLatitude(gps_position.lat); + position.setLongitude(gps_position.lon); + position.setTime(new Date(System.currentTimeMillis())); + position.setSpeed(gps_position.velocity); + position.setCourse(gps_position.dir); + position.setAccuracy(gps_position.quality); + position.set(Position.KEY_BATTERY, Integer.parseInt(battery_info) / 100); + + System.out.println("Supported message finish"); + + return position; } else { System.out.println("Unsupported message"); } - - System.out.println("Finish"); } return null; -- cgit v1.2.3 From b66d4c3b3250edac4762176277f4f07bc2e74d8e Mon Sep 17 00:00:00 2001 From: anton2920 Date: Sun, 24 Jul 2022 18:43:30 +0100 Subject: Commented out 'System.out.println()'s --- .../org/traccar/protocol/PiligrimProtocolDecoder.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index 967adb82b..775032b64 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -172,11 +172,11 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { * &phone&message */ String[] payload_parts = payload.split("&"); - System.out.println("Payload parts: " + Arrays.toString(payload_parts)); + /* System.out.println("Payload parts: " + Arrays.toString(payload_parts)); */ String phone_number = payload_parts[1].substring(15); String message = payload_parts[2].substring(8); - System.out.println("Phone number: " + phone_number); - System.out.println("Message: " + message); + /* System.out.println("Phone number: " + phone_number); */ + /* System.out.println("Message: " + message); */ if (message.startsWith("$GPRMC")) { /* Supported message structure: @@ -186,28 +186,28 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { System.out.println("Supported message"); String[] message_parts = message.split(";"); - System.out.println("Message parts: " + Arrays.toString(message_parts)); + /* System.out.println("Message parts: " + Arrays.toString(message_parts)); */ /* Parsing GPS */ String unprocessed_gps_command = message_parts[0]; /* Getting rid of checksum */ String gps_command = unprocessed_gps_command.replaceFirst("A,V[*].*", ""); - System.out.println("GPS command: " + gps_command); + /* System.out.println("GPS command: " + gps_command); */ NMEA gps_parser = new NMEA(); NMEA.GPSPosition gps_position = gps_parser.parse(gps_command); - System.out.println("Time: " + gps_position.time); - System.out.println("Coordinates: " + gps_position.lat + " " + gps_position.lon); - System.out.println("Speed over ground: " + gps_position.velocity + " knots"); + /* System.out.println("Time: " + gps_position.time); */ + /* System.out.println("Coordinates: " + gps_position.lat + " " + gps_position.lon); */ + /* System.out.println("Speed over ground: " + gps_position.velocity + " knots"); */ /* Parsing other fields */ /* String gsm_info = message_parts[1]; */ /* String unknown = message_parts[2]; */ String battery_info = message_parts[3].substring(7).substring(0, 3); - System.out.println("Battery: " + battery_info); + /* System.out.println("Battery: " + battery_info); */ /* Constructing response */ Position position = new Position(getProtocolName()); -- cgit v1.2.3 From 26e3d616ef17db2c30da0e9c8c0a7a1e9182cc6c Mon Sep 17 00:00:00 2001 From: anton2920 Date: Sun, 24 Jul 2022 19:18:49 +0100 Subject: Added workaround for 'ALARM KEY;' --- src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index 775032b64..d1f667f6f 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -173,8 +173,8 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { */ String[] payload_parts = payload.split("&"); /* System.out.println("Payload parts: " + Arrays.toString(payload_parts)); */ - String phone_number = payload_parts[1].substring(15); - String message = payload_parts[2].substring(8); + /* String phone_number = payload_parts[1].substring(15); */ + String message = payload_parts[2].substring(8).replaceFirst("ALARM KEY; ", ""); /* System.out.println("Phone number: " + phone_number); */ /* System.out.println("Message: " + message); */ @@ -220,6 +220,7 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { position.setSpeed(gps_position.velocity); position.setCourse(gps_position.dir); position.setAccuracy(gps_position.quality); + position.setAltitude(gps_position.altitude); position.set(Position.KEY_BATTERY, Integer.parseInt(battery_info) / 100); System.out.println("Supported message finish"); -- cgit v1.2.3 From b3caf3c1cee6cb665e8ac05be35d9258c353771e Mon Sep 17 00:00:00 2001 From: anton2920 Date: Tue, 6 Sep 2022 10:53:38 +0100 Subject: Replaced hard-coded ID with phone number --- .../org/traccar/protocol/PiligrimProtocolDecoder.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index d1f667f6f..da8991bd3 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -157,11 +157,6 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { } else if (uri.startsWith("/push.do")) { sendResponse(channel, "PUSH.DO: OK"); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, "123456"); - if (deviceSession == null) { - return null; - } - /* Getting payload */ ByteBuf content_stream = request.content(); byte[] payload_bytes = new byte[Integer.parseInt(request.headers().get("Content-Length"))]; @@ -173,7 +168,15 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { */ String[] payload_parts = payload.split("&"); /* System.out.println("Payload parts: " + Arrays.toString(payload_parts)); */ - /* String phone_number = payload_parts[1].substring(15); */ + String phone_number = payload_parts[1].substring(15); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, phone_number); + if (deviceSession == null) { + return null; + } + + /* TODO: generalize this process; + * TODO: use keys for flags in 'positions'. + */ String message = payload_parts[2].substring(8).replaceFirst("ALARM KEY; ", ""); /* System.out.println("Phone number: " + phone_number); */ /* System.out.println("Message: " + message); */ -- cgit v1.2.3 From bd49d52fc47dcb902b9fb2b3e8cf82d9550a025c Mon Sep 17 00:00:00 2001 From: anton2920 Date: Tue, 6 Sep 2022 10:58:20 +0100 Subject: Refactored naming convention to 'camelCase' and changed 'System.out.println' to 'LOGGER.info' --- .../traccar/protocol/PiligrimProtocolDecoder.java | 77 +++++++++++----------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index da8991bd3..0a22e30c5 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -21,8 +21,10 @@ import io.netty.channel.Channel; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.QueryStringDecoder; -import net.fortuna.ical4j.model.DateTime; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.BaseHttpProtocolDecoder; +import org.traccar.WebDataHandler; import org.traccar.session.DeviceSession; import org.traccar.Protocol; import org.traccar.helper.BitUtil; @@ -32,13 +34,14 @@ import org.traccar.model.Position; import java.net.SocketAddress; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.Date; import java.util.LinkedList; import java.util.List; public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { + private static final Logger LOGGER = LoggerFactory.getLogger(WebDataHandler.class); + public PiligrimProtocolDecoder(Protocol protocol) { super(protocol); } @@ -158,18 +161,18 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { sendResponse(channel, "PUSH.DO: OK"); /* Getting payload */ - ByteBuf content_stream = request.content(); - byte[] payload_bytes = new byte[Integer.parseInt(request.headers().get("Content-Length"))]; - content_stream.readBytes(payload_bytes); - String payload = new String(payload_bytes); + ByteBuf contentStream = request.content(); + byte[] payloadBytes = new byte[Integer.parseInt(request.headers().get("Content-Length"))]; + contentStream.readBytes(payloadBytes); + String payload = new String(payloadBytes); /* Payload structure: * &phone&message */ - String[] payload_parts = payload.split("&"); - /* System.out.println("Payload parts: " + Arrays.toString(payload_parts)); */ - String phone_number = payload_parts[1].substring(15); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, phone_number); + String[] payloadParts = payload.split("&"); + /* LOGGER.info("Payload parts: " + Arrays.toString(payloadParts)); */ + String phoneNumber = payloadParts[1].substring(15); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, phoneNumber); if (deviceSession == null) { return null; } @@ -177,60 +180,60 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { /* TODO: generalize this process; * TODO: use keys for flags in 'positions'. */ - String message = payload_parts[2].substring(8).replaceFirst("ALARM KEY; ", ""); - /* System.out.println("Phone number: " + phone_number); */ - /* System.out.println("Message: " + message); */ + String message = payloadParts[2].substring(8).replaceFirst("ALARM KEY; ", ""); + /* LOGGER.info("Phone number: " + phoneNumber); */ + /* LOGGER.info("Message: " + message); */ if (message.startsWith("$GPRMC")) { /* Supported message structure: * GPS NMEA Command; GSM info; Unknown; Battery voltage? * Example: $GPRMC,180752.000,A,5314.0857,N,03421.8173,E,0.00,104.74,220722,,,A,V* 29,05; GSM: 250-01 0b54-0519,1c30,3e96,3ebe,412e 25; S; Batt: 405,M */ - System.out.println("Supported message"); + LOGGER.info("Supported message"); - String[] message_parts = message.split(";"); - /* System.out.println("Message parts: " + Arrays.toString(message_parts)); */ + String[] messageParts = message.split(";"); + /* LOGGER.info("Message parts: " + Arrays.toString(messageParts)); */ /* Parsing GPS */ - String unprocessed_gps_command = message_parts[0]; + String unprocessedGpsCommand = messageParts[0]; /* Getting rid of checksum */ - String gps_command = unprocessed_gps_command.replaceFirst("A,V[*].*", ""); - /* System.out.println("GPS command: " + gps_command); */ + String gpsCommand = unprocessedGpsCommand.replaceFirst("A,V[*].*", ""); + /* LOGGER.info("GPS command: " + gpsCommand); */ - NMEA gps_parser = new NMEA(); + NMEA gpsParser = new NMEA(); - NMEA.GPSPosition gps_position = gps_parser.parse(gps_command); + NMEA.GPSPosition gpsPosition = gpsParser.parse(gpsCommand); - /* System.out.println("Time: " + gps_position.time); */ - /* System.out.println("Coordinates: " + gps_position.lat + " " + gps_position.lon); */ - /* System.out.println("Speed over ground: " + gps_position.velocity + " knots"); */ + /* LOGGER.info("Time: " + gpsPosition.time); */ + /* LOGGER.info("Coordinates: " + gpsPosition.lat + " " + gpsPosition.lon); */ + /* LOGGER.info("Speed over ground: " + gpsPosition.velocity + " knots"); */ /* Parsing other fields */ - /* String gsm_info = message_parts[1]; */ - /* String unknown = message_parts[2]; */ - String battery_info = message_parts[3].substring(7).substring(0, 3); - /* System.out.println("Battery: " + battery_info); */ + /* String gsmInfo = messageParts[1]; */ + /* String unknown = messageParts[2]; */ + String batteryInfo = messageParts[3].substring(7).substring(0, 3); + /* LOGGER.info("Battery: " + batteryInfo); */ /* Constructing response */ Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); position.setValid(true); - position.setLatitude(gps_position.lat); - position.setLongitude(gps_position.lon); + position.setLatitude(gpsPosition.lat); + position.setLongitude(gpsPosition.lon); position.setTime(new Date(System.currentTimeMillis())); - position.setSpeed(gps_position.velocity); - position.setCourse(gps_position.dir); - position.setAccuracy(gps_position.quality); - position.setAltitude(gps_position.altitude); - position.set(Position.KEY_BATTERY, Integer.parseInt(battery_info) / 100); + position.setSpeed(gpsPosition.velocity); + position.setCourse(gpsPosition.dir); + position.setAccuracy(gpsPosition.quality); + position.setAltitude(gpsPosition.altitude); + position.set(Position.KEY_BATTERY, Integer.parseInt(batteryInfo) / 100); - System.out.println("Supported message finish"); + LOGGER.info("Supported message finish"); return position; } else { - System.out.println("Unsupported message"); + LOGGER.info("Unsupported message"); } } -- cgit v1.2.3 From 55ac4060c38b2ea6e583cbef570f4b9ec35d8b15 Mon Sep 17 00:00:00 2001 From: anton2920 Date: Tue, 6 Sep 2022 11:18:57 +0100 Subject: Changed regex for replacing event keys --- src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index 0a22e30c5..ca6b667cd 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -172,15 +172,13 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { String[] payloadParts = payload.split("&"); /* LOGGER.info("Payload parts: " + Arrays.toString(payloadParts)); */ String phoneNumber = payloadParts[1].substring(15); - DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, phoneNumber); + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, phoneNumber.substring(1)); if (deviceSession == null) { return null; } - /* TODO: generalize this process; - * TODO: use keys for flags in 'positions'. - */ - String message = payloadParts[2].substring(8).replaceFirst("ALARM KEY; ", ""); + /* TODO: use keys for flags in 'positions'. */ + String message = payloadParts[2].substring(8).replaceFirst("[A-Z]* KEY; ", ""); /* LOGGER.info("Phone number: " + phoneNumber); */ /* LOGGER.info("Message: " + message); */ -- cgit v1.2.3 From 278f8c934ec440a6472d467688bfa1c42078bbac Mon Sep 17 00:00:00 2001 From: anton2920 Date: Wed, 7 Sep 2022 09:46:48 +0100 Subject: Fixed regex for replacing event keys --- src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index ca6b667cd..6b3b35eee 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -178,7 +178,7 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { } /* TODO: use keys for flags in 'positions'. */ - String message = payloadParts[2].substring(8).replaceFirst("[A-Z]* KEY; ", ""); + String message = payloadParts[2].substring(8).replaceFirst("[a-zA-Z! ]*; ", ""); /* LOGGER.info("Phone number: " + phoneNumber); */ /* LOGGER.info("Message: " + message); */ @@ -210,7 +210,7 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { /* Parsing other fields */ /* String gsmInfo = messageParts[1]; */ /* String unknown = messageParts[2]; */ - String batteryInfo = messageParts[3].substring(7).substring(0, 3); + String batteryInfo = messageParts[messageParts.length - 1].substring(7).substring(0, 3); /* LOGGER.info("Battery: " + batteryInfo); */ /* Constructing response */ @@ -231,7 +231,7 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { return position; } else { - LOGGER.info("Unsupported message"); + LOGGER.error("Unsupported message"); } } -- cgit v1.2.3 From e5c73ce4fcfc67f13a9151a130783b31cef76293 Mon Sep 17 00:00:00 2001 From: anton2920 Date: Wed, 7 Sep 2022 09:47:47 +0100 Subject: Moved logger messages to debug logs --- .../traccar/protocol/PiligrimProtocolDecoder.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java index 6b3b35eee..6ca9b0795 100644 --- a/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/PiligrimProtocolDecoder.java @@ -170,7 +170,7 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { * &phone&message */ String[] payloadParts = payload.split("&"); - /* LOGGER.info("Payload parts: " + Arrays.toString(payloadParts)); */ + /* LOGGER.debug("Payload parts: " + Arrays.toString(payloadParts)); */ String phoneNumber = payloadParts[1].substring(15); DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, phoneNumber.substring(1)); if (deviceSession == null) { @@ -179,39 +179,39 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { /* TODO: use keys for flags in 'positions'. */ String message = payloadParts[2].substring(8).replaceFirst("[a-zA-Z! ]*; ", ""); - /* LOGGER.info("Phone number: " + phoneNumber); */ - /* LOGGER.info("Message: " + message); */ + /* LOGGER.debug("Phone number: " + phoneNumber); */ + /* LOGGER.debug("Message: " + message); */ if (message.startsWith("$GPRMC")) { /* Supported message structure: * GPS NMEA Command; GSM info; Unknown; Battery voltage? * Example: $GPRMC,180752.000,A,5314.0857,N,03421.8173,E,0.00,104.74,220722,,,A,V* 29,05; GSM: 250-01 0b54-0519,1c30,3e96,3ebe,412e 25; S; Batt: 405,M */ - LOGGER.info("Supported message"); + LOGGER.debug("Supported message"); String[] messageParts = message.split(";"); - /* LOGGER.info("Message parts: " + Arrays.toString(messageParts)); */ + /* LOGGER.debug("Message parts: " + Arrays.toString(messageParts)); */ /* Parsing GPS */ String unprocessedGpsCommand = messageParts[0]; /* Getting rid of checksum */ String gpsCommand = unprocessedGpsCommand.replaceFirst("A,V[*].*", ""); - /* LOGGER.info("GPS command: " + gpsCommand); */ + /* LOGGER.debug("GPS command: " + gpsCommand); */ NMEA gpsParser = new NMEA(); NMEA.GPSPosition gpsPosition = gpsParser.parse(gpsCommand); - /* LOGGER.info("Time: " + gpsPosition.time); */ - /* LOGGER.info("Coordinates: " + gpsPosition.lat + " " + gpsPosition.lon); */ - /* LOGGER.info("Speed over ground: " + gpsPosition.velocity + " knots"); */ + /* LOGGER.debug("Time: " + gpsPosition.time); */ + /* LOGGER.debug("Coordinates: " + gpsPosition.lat + " " + gpsPosition.lon); */ + /* LOGGER.debug("Speed over ground: " + gpsPosition.velocity + " knots"); */ /* Parsing other fields */ /* String gsmInfo = messageParts[1]; */ /* String unknown = messageParts[2]; */ String batteryInfo = messageParts[messageParts.length - 1].substring(7).substring(0, 3); - /* LOGGER.info("Battery: " + batteryInfo); */ + /* LOGGER.debug("Battery: " + batteryInfo); */ /* Constructing response */ Position position = new Position(getProtocolName()); @@ -227,7 +227,7 @@ public class PiligrimProtocolDecoder extends BaseHttpProtocolDecoder { position.setAltitude(gpsPosition.altitude); position.set(Position.KEY_BATTERY, Integer.parseInt(batteryInfo) / 100); - LOGGER.info("Supported message finish"); + LOGGER.debug("Supported message finish"); return position; } else { -- cgit v1.2.3