use of org.traccar.helper.Parser in project traccar by tananaev.
the class BoxProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.startsWith("H,")) {
int index = sentence.indexOf(',', 2) + 1;
String id = sentence.substring(index, sentence.indexOf(',', index));
getDeviceSession(channel, remoteAddress, id);
} else if (sentence.startsWith("E,")) {
if (channel != null) {
channel.write("A," + sentence.substring(2) + "\r");
}
} else if (sentence.startsWith("L,")) {
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());
position.setTime(parser.nextDateTime());
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_ODOMETER_TRIP, parser.nextDouble(0) * 1000);
position.set(Position.KEY_EVENT, parser.next());
int status = parser.nextInt(0);
position.setValid((status & 0x04) == 0);
position.set(Position.KEY_STATUS, status);
return position;
}
return null;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class CautelaProtocolDecoder 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;
}
String type = parser.next();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder();
dateBuilder.setDateReverse(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setValid(true);
position.setLatitude(parser.nextDouble());
position.setLongitude(parser.nextDouble());
dateBuilder.setHour(parser.nextInt()).setMinute(parser.nextInt());
position.setTime(dateBuilder.getDate());
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class CguardProtocolDecoder method decodePosition.
private Position decodePosition(DeviceSession deviceSession, String sentence) {
Parser parser = new Parser(PATTERN_NV, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime());
position.setValid(true);
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setAccuracy(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class CityeasyProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// header
buf.skipBytes(2);
// length
buf.readUnsignedShort();
String imei = ChannelBuffers.hexDump(buf.readBytes(7));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei, imei + Checksum.luhn(Long.parseLong(imei)));
if (deviceSession == null) {
return null;
}
int type = buf.readUnsignedShort();
if (type == MSG_LOCATION_REPORT || type == MSG_LOCATION_REQUEST) {
String sentence = buf.toString(buf.readerIndex(), buf.readableBytes() - 8, StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (parser.hasNext(15)) {
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setSpeed(parser.nextDouble(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
} else {
getLastLocation(position, null);
}
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0))));
return position;
}
return null;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class AutoGradeProtocolDecoder 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;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
position.setCourse(parser.nextDouble(0));
int status = parser.next().charAt(0);
position.set(Position.KEY_STATUS, status);
position.set(Position.KEY_IGNITION, BitUtil.check(status, 0));
for (int i = 1; i <= 5; i++) {
position.set(Position.PREFIX_ADC + i, parser.next());
}
for (int i = 1; i <= 5; i++) {
position.set("can" + i, parser.next());
}
return position;
}
Aggregations