use of org.traccar.helper.Parser in project traccar by tananaev.
the class RaveonProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
Parser parser = new Parser(PATTERN, sentence);
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());
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS));
position.setValid(parser.nextInt(0) != 0);
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.setAltitude(parser.nextInt(0));
position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
position.set(Position.KEY_POWER, parser.nextDouble(0));
position.set(Position.KEY_INPUT, parser.nextInt(0));
position.set(Position.KEY_RSSI, parser.nextInt(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
position.setCourse(parser.nextInt(0));
position.set(Position.KEY_ALARM, parser.next());
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class RitiProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// header
buf.skipBytes(2);
Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedShort()));
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.set("mode", buf.readUnsignedByte());
position.set(Position.KEY_COMMAND, buf.readUnsignedByte());
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
// status
buf.skipBytes(5);
// idleCount
buf.readUnsignedShort();
// idleTime in seconds
buf.readUnsignedShort();
position.set(Position.KEY_DISTANCE, buf.readUnsignedInt());
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
// Parse GPRMC
int end = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*');
String gprmc = buf.toString(buf.readerIndex(), end - buf.readerIndex(), StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN, gprmc);
if (!parser.matches()) {
return null;
}
DateBuilder dateBuilder = new DateBuilder().setTime(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));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class SanavProtocolDecoder 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());
DateBuilder dateBuilder = new DateBuilder().setTime(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));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class SiwiProtocolDecoder 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());
position.set(Position.KEY_EVENT, parser.next());
position.set(Position.KEY_IGNITION, parser.next().equals("1"));
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.setCourse(parser.nextInt(0));
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY, "IST"));
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class AuroProtocolDecoder 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_INDEX, parser.nextInt(0));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(true);
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN_MIN));
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setCourse(parser.nextDouble(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.set(Position.KEY_BATTERY, parser.nextInt(0));
position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1);
return position;
}
Aggregations