use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class Pt502ProtocolDecoder 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());
String type = parser.next();
if (type.startsWith("PHO") && channel != null) {
photo = new byte[Integer.parseInt(type.substring(3))];
channel.write("#PHD0," + Math.min(photo.length, MAX_CHUNK_SIZE) + "\r\n");
}
position.set(Position.KEY_ALARM, decodeAlarm(type));
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), 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());
position.set(Position.KEY_INPUT, parser.next());
position.set(Position.KEY_OUTPUT, parser.next());
if (parser.hasNext()) {
String[] values = parser.next().split(",");
for (int i = 0; i < values.length; i++) {
position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(values[i], 16));
}
}
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
if (parser.hasNext()) {
int value = parser.nextHexInt(0);
position.set(Position.KEY_BATTERY, value >> 8);
position.set(Position.KEY_RSSI, (value >> 4) & 0xf);
position.set(Position.KEY_SATELLITES, value & 0xf);
}
return position;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class XexunProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
Pattern pattern = PATTERN_BASIC;
if (full) {
pattern = PATTERN_FULL;
}
Parser parser = new Parser(pattern, (String) msg);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
if (full) {
position.set("serial", parser.next());
position.set("number", parser.next());
}
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(convertSpeed(parser.nextDouble(0), "kn"));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
position.set("signal", parser.next());
decodeStatus(position, parser.next());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
if (full) {
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.setAltitude(parser.nextDouble(0));
position.set(Position.KEY_POWER, parser.nextDouble(0));
}
return position;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class MegastekProtocolDecoder method parseLocation.
private boolean parseLocation(String location, Position position) {
Parser parser = new Parser(PATTERN_GPRMC, location);
if (!parser.matches()) {
return false;
}
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), 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 true;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class MxtProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// start
buf.readUnsignedByte();
// device descriptor
int device = buf.readUnsignedByte();
int type = buf.readUnsignedByte();
long id = buf.readUnsignedInt();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id));
if (deviceSession == null) {
return null;
}
if (type == MSG_POSITION) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
// protocol
buf.readUnsignedByte();
int infoGroups = buf.readUnsignedByte();
position.set(Position.KEY_INDEX, buf.readUnsignedShort());
DateBuilder dateBuilder = new DateBuilder().setDate(2000, 1, 1);
long date = buf.readUnsignedInt();
long days = BitUtil.from(date, 6 + 6 + 5);
long hours = BitUtil.between(date, 6 + 6, 6 + 6 + 5);
long minutes = BitUtil.between(date, 6, 6 + 6);
long seconds = BitUtil.to(date, 6);
dateBuilder.addMillis((((days * 24 + hours) * 60 + minutes) * 60 + seconds) * 1000);
position.setTime(dateBuilder.getDate());
position.setValid(true);
position.setLatitude(buf.readInt() / 1000000.0);
position.setLongitude(buf.readInt() / 1000000.0);
long flags = buf.readUnsignedInt();
position.set(Position.KEY_IGNITION, BitUtil.check(flags, 0));
if (BitUtil.check(flags, 1)) {
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
}
position.set(Position.KEY_INPUT, BitUtil.between(flags, 2, 7));
position.set(Position.KEY_OUTPUT, BitUtil.between(flags, 7, 10));
position.setCourse(BitUtil.between(flags, 10, 13) * 45);
// position.setValid(BitUtil.check(flags, 15));
position.set(Position.KEY_CHARGE, BitUtil.check(flags, 20));
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
// input mask
buf.readUnsignedByte();
if (BitUtil.check(infoGroups, 0)) {
// waypoints
buf.skipBytes(8);
}
if (BitUtil.check(infoGroups, 1)) {
// wireless accessory
buf.skipBytes(8);
}
if (BitUtil.check(infoGroups, 2)) {
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
position.setAccuracy(buf.readUnsignedByte());
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
// time since boot
buf.readUnsignedShort();
position.set(Position.KEY_POWER, buf.readUnsignedByte());
position.set(Position.PREFIX_TEMP + 1, buf.readByte());
}
if (BitUtil.check(infoGroups, 3)) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
}
if (BitUtil.check(infoGroups, 4)) {
position.set(Position.KEY_HOURS, buf.readUnsignedInt());
}
if (BitUtil.check(infoGroups, 5)) {
// reason
buf.readUnsignedInt();
}
if (BitUtil.check(infoGroups, 6)) {
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
}
if (BitUtil.check(infoGroups, 7)) {
position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(buf.readUnsignedInt()));
}
buf.readerIndex(buf.writerIndex() - 3);
sendResponse(channel, device, id, buf.readUnsignedShort());
return position;
}
return null;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class MeiligaoProtocolDecoder method decodeRegular.
private Position decodeRegular(Position position, String sentence) {
Parser parser = new Parser(PATTERN, sentence);
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());
if (parser.hasNext()) {
position.setSpeed(parser.nextDouble(0));
}
if (parser.hasNext()) {
position.setCourse(parser.nextDouble(0));
}
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
position.set(Position.KEY_HDOP, parser.nextDouble());
if (parser.hasNext()) {
position.setAltitude(parser.nextDouble(0));
}
position.set(Position.KEY_STATUS, parser.next());
for (int i = 1; i <= 8; i++) {
position.set(Position.PREFIX_ADC + i, parser.nextHexInt());
}
position.set(Position.KEY_RSSI, parser.nextHexInt());
position.set(Position.KEY_ODOMETER, parser.nextHexLong());
position.set(Position.KEY_SATELLITES, parser.nextHexInt());
position.set("driverLicense", parser.next());
position.set(Position.KEY_ODOMETER, parser.nextLong());
position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
return position;
}
Aggregations