use of org.traccar.helper.Parser in project traccar by tananaev.
the class StarLinkProtocolDecoder 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;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
int type = parser.nextInt(0);
if (type != MSG_EVENT_REPORT) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
position.set(Position.KEY_INDEX, parser.nextInt(0));
String[] data = parser.next().split(",");
Integer lac = null, cid = null;
int event = 0;
for (int i = 0; i < Math.min(data.length, dataTags.length); i++) {
if (data[i].isEmpty()) {
continue;
}
switch(dataTags[i]) {
case "#EDT#":
position.setDeviceTime(dateFormat.parse(data[i]));
break;
case "#EID#":
event = Integer.parseInt(data[i]);
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
break;
case "#PDT#":
position.setFixTime(dateFormat.parse(data[i]));
break;
case "#LAT#":
position.setLatitude(parseCoordinate(data[i]));
break;
case "#LONG#":
position.setLongitude(parseCoordinate(data[i]));
break;
case "#SPD#":
position.setSpeed(Double.parseDouble(data[i]));
break;
case "#HEAD#":
position.setCourse(Integer.parseInt(data[i]));
break;
case "#ODO#":
position.set(Position.KEY_ODOMETER, Long.parseLong(data[i]) * 1000);
break;
case "#IN1#":
position.set(Position.PREFIX_IN + 1, Integer.parseInt(data[i]));
break;
case "#IN2#":
position.set(Position.PREFIX_IN + 2, Integer.parseInt(data[i]));
break;
case "#IN3#":
position.set(Position.PREFIX_IN + 3, Integer.parseInt(data[i]));
break;
case "#IN4#":
position.set(Position.PREFIX_IN + 4, Integer.parseInt(data[i]));
break;
case "#OUT1#":
position.set(Position.PREFIX_OUT + 1, Integer.parseInt(data[i]));
break;
case "#OUT2#":
position.set(Position.PREFIX_OUT + 2, Integer.parseInt(data[i]));
break;
case "#OUT3#":
position.set(Position.PREFIX_OUT + 3, Integer.parseInt(data[i]));
break;
case "#OUT4#":
position.set(Position.PREFIX_OUT + 4, Integer.parseInt(data[i]));
break;
case "#LAC#":
if (!data[i].isEmpty()) {
lac = Integer.parseInt(data[i]);
}
break;
case "#CID#":
if (!data[i].isEmpty()) {
cid = Integer.parseInt(data[i]);
}
break;
case "#VIN#":
position.set(Position.KEY_POWER, Double.parseDouble(data[i]));
break;
case "#VBAT#":
position.set(Position.KEY_BATTERY, Double.parseDouble(data[i]));
break;
case "#DEST#":
position.set("destination", data[i]);
break;
case "#IGN#":
position.set(Position.KEY_IGNITION, data[i].equals("1"));
break;
case "#ENG#":
position.set("engine", data[i].equals("1"));
break;
default:
break;
}
}
if (position.getFixTime() == null) {
getLastLocation(position, null);
}
if (lac != null && cid != null) {
position.setNetwork(new Network(CellTower.fromLacCid(lac, cid)));
}
if (event == 20) {
String rfid = data[data.length - 1];
if (rfid.matches("0+")) {
rfid = data[data.length - 2];
}
position.set(Position.KEY_DRIVER_UNIQUE_ID, rfid);
}
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class T55ProtocolDecoder method decodeGpgga.
private Position decodeGpgga(DeviceSession deviceSession, String sentence) {
Parser parser = new Parser(PATTERN_GPGGA, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setCurrentDate().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
position.setValid(true);
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class T55ProtocolDecoder method decodeGprma.
private Position decodeGprma(DeviceSession deviceSession, String sentence) {
Parser parser = new Parser(PATTERN_GPRMA, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(new Date());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class T55ProtocolDecoder method decodeTrccr.
private Position decodeTrccr(DeviceSession deviceSession, String sentence) {
Parser parser = new Parser(PATTERN_TRCCR, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.set(Position.KEY_BATTERY, parser.nextDouble(0));
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class TaipProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
int beginIndex = sentence.indexOf('>');
if (beginIndex != -1) {
sentence = sentence.substring(beginIndex + 1);
}
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
Boolean valid = null;
Integer event = null;
if (parser.hasNext(3)) {
event = parser.nextInt();
position.setTime(getTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0)));
} else if (parser.hasNext()) {
position.setTime(getTime(parser.nextInt(0)));
}
if (parser.hasNext()) {
event = parser.nextInt();
}
if (parser.hasNext(6)) {
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
}
if (parser.hasNext(4)) {
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_DEG));
}
if (parser.hasNext(6)) {
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
}
position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
if (parser.hasNext(4)) {
valid = parser.nextInt() > 0;
int input = parser.nextHexInt();
position.set(Position.KEY_IGNITION, BitUtil.check(input, 7));
position.set(Position.KEY_INPUT, input);
event = parser.nextInt();
position.set(Position.KEY_HDOP, parser.nextInt());
}
if (parser.hasNext(4)) {
position.set(Position.KEY_INPUT, parser.nextHexInt(0));
position.set(Position.KEY_SATELLITES, parser.nextHexInt(0));
position.set(Position.KEY_BATTERY, parser.nextInt(0));
position.set(Position.KEY_ODOMETER, parser.nextLong(16, 0));
}
if (parser.hasNext(4)) {
valid = parser.nextInt() > 0;
position.set(Position.KEY_PDOP, parser.nextInt());
position.set(Position.KEY_RSSI, parser.nextInt());
position.set(Position.PREFIX_TEMP + 1, parser.nextInt() * 0.01);
position.set(Position.PREFIX_TEMP + 2, parser.nextInt() * 0.01);
}
position.setValid(valid != null ? valid : true);
if (event != null) {
position.set(Position.KEY_EVENT, event);
switch(event) {
case 22:
position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
break;
case 23:
position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
break;
case 24:
position.set(Position.KEY_ALARM, Position.ALARM_ACCIDENT);
break;
case 26:
case 28:
position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
break;
default:
break;
}
}
String[] attributes = null;
beginIndex = sentence.indexOf(';');
if (beginIndex != -1) {
int endIndex = sentence.indexOf('<', beginIndex);
if (endIndex == -1) {
endIndex = sentence.length();
}
attributes = sentence.substring(beginIndex, endIndex).split(";");
}
return decodeAttributes(channel, remoteAddress, position, attributes);
}
Aggregations