use of org.traccar.helper.Parser in project traccar by tananaev.
the class CarscopProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
DeviceSession deviceSession;
int index = sentence.indexOf("UB05");
if (index != -1) {
String imei = sentence.substring(index + 4, index + 4 + 15);
deviceSession = getDeviceSession(channel, remoteAddress, imei);
} else {
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());
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));
dateBuilder.setDate(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
position.setCourse(parser.nextDouble(0));
if (parser.hasNext(2)) {
position.set(Position.KEY_STATUS, parser.next());
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
}
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class CradlepointProtocolDecoder 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());
int time = parser.nextInt();
DateBuilder dateBuilder = new DateBuilder(new Date());
dateBuilder.setHour(time / 100 / 100);
dateBuilder.setMinute(time / 100 % 100);
dateBuilder.setSecond(time % 100);
position.setTime(dateBuilder.getDate());
position.setValid(true);
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.set("carrid", parser.next());
position.set("serdis", parser.next());
position.set("rsrp", parser.next());
position.set("dbm", parser.next());
position.set("rsrq", parser.next());
position.set("ecio", parser.next());
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class DwayProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.equals("AA55,HB")) {
if (channel != null) {
channel.write("55AA,HB,OK\r\n");
}
return null;
}
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.setValid(true);
position.setTime(parser.nextDateTime());
position.setLatitude(parser.nextDouble());
position.setLongitude(parser.nextDouble());
position.setAltitude(parser.nextDouble(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_INPUT, parser.nextBinInt());
position.set(Position.KEY_OUTPUT, parser.nextBinInt());
position.set(Position.KEY_BATTERY, parser.nextInt() * 0.001);
position.set(Position.PREFIX_ADC + 1, parser.nextInt() * 0.001);
position.set(Position.PREFIX_ADC + 2, parser.nextInt() * 0.001);
position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
return position;
}
use of org.traccar.helper.Parser in project traccar by tananaev.
the class EnforaProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// Find IMEI number
int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new ChannelBufferIndexFinder() {
@Override
public boolean find(ChannelBuffer buffer, int guessedIndex) {
if (buffer.writerIndex() - guessedIndex >= IMEI_LENGTH) {
for (int i = 0; i < IMEI_LENGTH; i++) {
if (!Character.isDigit((char) buffer.getByte(guessedIndex + i))) {
return false;
}
}
return true;
}
return false;
}
});
if (index == -1) {
return null;
}
String imei = buf.toString(index, IMEI_LENGTH, StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
// Find NMEA sentence
int start = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("GPRMC"));
if (start == -1) {
return null;
}
String sentence = buf.toString(start, buf.readableBytes() - start, StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
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 EskyProtocolDecoder 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_SATELLITES, parser.nextInt());
position.setValid(true);
position.setTime(parser.nextDateTime());
position.setLatitude(parser.nextDouble());
position.setLongitude(parser.nextDouble());
position.setSpeed(UnitsConverter.knotsFromMps(parser.nextDouble()));
position.setCourse(parser.nextDouble());
position.set(Position.KEY_INPUT, parser.nextHexInt());
position.set(Position.KEY_EVENT, parser.nextInt());
position.set(Position.KEY_ODOMETER, parser.nextInt());
position.set(Position.KEY_POWER, parser.nextInt());
return position;
}
Aggregations