use of org.traccar.helper.Parser in project traccar by tananaev.
the class TrvProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
String id = sentence.startsWith("TRV") ? sentence.substring(0, 3) : sentence.substring(0, 2);
String type = sentence.substring(id.length(), id.length() + 4);
if (channel != null) {
String responseHeader = id + (char) (type.charAt(0) + 1) + type.substring(1);
if (type.equals("AP00") && id.equals("IW")) {
String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
channel.write(responseHeader + "," + time + ",0#");
} else if (type.equals("AP14")) {
channel.write(responseHeader + ",0.000,0.000#");
} else {
channel.write(responseHeader + "#");
}
}
if (type.equals("AP00")) {
getDeviceSession(channel, remoteAddress, sentence.substring(id.length() + type.length()));
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
if (type.equals("CP01")) {
Parser parser = new Parser(PATTERN_HEATRBEAT, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
decodeCommon(position, parser);
if (parser.hasNext(3)) {
position.set(Position.KEY_BLOCKED, decodeOptionalValue(parser, 2));
position.set(Position.KEY_CHARGE, decodeOptionalValue(parser, 1));
position.set(Position.KEY_MOTION, decodeOptionalValue(parser, 1));
}
return position;
} else if (type.equals("AP01") || type.equals("AP10")) {
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setDate(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
dateBuilder.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setTime(dateBuilder.getDate());
position.setCourse(parser.nextDouble());
decodeCommon(position, parser);
position.setNetwork(new Network(CellTower.from(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt())));
return position;
}
return null;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class Tt8850ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
Parser parser = new Parser(PATTERN, (String) msg);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
position.setAccuracy(parser.nextInt(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setLatitude(parser.nextDouble(0));
position.setTime(parser.nextDateTime());
if (parser.hasNext(4)) {
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
}
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class FlexCommProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
Parser parser = new Parser(PATTERN, (String) msg);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.set(Position.KEY_STATUS, parser.nextInt());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("1"));
position.setLatitude(parseSignedValue(parser, 6));
position.setLongitude(parseSignedValue(parser, 6));
position.setAltitude(parseSignedValue(parser, 0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt());
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_RSSI, parser.nextInt());
position.setNetwork(new Network(CellTower.from(parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt())));
for (int i = 1; i <= 3; i++) {
position.set(Position.PREFIX_IN + i, parser.nextInt());
}
for (int i = 1; i <= 2; i++) {
position.set(Position.PREFIX_OUT + i, parser.nextInt());
}
position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
position.set(Position.PREFIX_TEMP + 1, parseSignedValue(parser, 0));
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
if (channel != null) {
channel.write("{01}");
}
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class FlextrackProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.contains("LOGON")) {
Parser parser = new Parser(PATTERN_LOGON, sentence);
if (!parser.matches()) {
return null;
}
sendAcknowledgement(channel, parser.next());
String id = parser.next();
String iccid = parser.next();
getDeviceSession(channel, remoteAddress, iccid, id);
} else if (sentence.contains("UNITSTAT")) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
sendAcknowledgement(channel, parser.next());
position.setTime(parser.nextDateTime());
position.setValid(true);
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
position.setCourse(parser.nextInt(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_BATTERY, parser.nextInt(0));
int rssi = parser.nextInt(0);
position.set(Position.KEY_STATUS, parser.nextHexInt(0));
int mcc = parser.nextInt(0);
int mnc = parser.nextInt(0);
position.setAltitude(parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextInt(0) * 0.1);
position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextHexInt(0), parser.nextHexInt(0), rssi)));
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
return position;
}
return null;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class FoxProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String xml = (String) msg;
String id = getAttribute(xml, "id");
String data = getAttribute(xml, "data");
if (id != null && data != null) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
Parser parser = new Parser(PATTERN, data);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_STATUS, parser.nextInt(0));
position.setValid(parser.next().equals("A"));
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_INPUT, parser.nextBinInt(0));
position.set(Position.KEY_POWER, parser.nextDouble(0) * 0.1);
position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
position.set(Position.KEY_RPM, parser.nextInt(0));
position.set(Position.KEY_FUEL_LEVEL, parser.nextInt(0));
position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
position.set(Position.PREFIX_ADC + 2, parser.nextInt(0));
position.set(Position.KEY_OUTPUT, parser.nextBinInt(0));
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
position.set("statusData", parser.next());
return position;
}
return null;
}
Aggregations