use of org.traccar.helper.DateBuilder 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.DateBuilder in project traccar by tananaev.
the class SkypatrolProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
int apiNumber = buf.readUnsignedShort();
int commandType = buf.readUnsignedByte();
int messageType = BitUtil.from(buf.readUnsignedByte(), 4);
long mask = defaultMask;
if (buf.readUnsignedByte() == 4) {
mask = buf.readUnsignedInt();
}
// Binary position report
if (apiNumber == 5 && commandType == 2 && messageType == 1 && BitUtil.check(mask, 0)) {
Position position = new Position(getProtocolName());
if (BitUtil.check(mask, 1)) {
position.set(Position.KEY_STATUS, buf.readUnsignedInt());
}
String id;
if (BitUtil.check(mask, 23)) {
id = buf.toString(buf.readerIndex(), 8, StandardCharsets.US_ASCII).trim();
buf.skipBytes(8);
} else if (BitUtil.check(mask, 2)) {
id = buf.toString(buf.readerIndex(), 22, StandardCharsets.US_ASCII).trim();
buf.skipBytes(22);
} else {
Log.warning("No device id field");
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
if (BitUtil.check(mask, 3)) {
position.set(Position.PREFIX_IO + 1, buf.readUnsignedShort());
}
if (BitUtil.check(mask, 4)) {
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
}
if (BitUtil.check(mask, 5)) {
position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
}
if (BitUtil.check(mask, 7)) {
// function category
buf.readUnsignedByte();
}
DateBuilder dateBuilder = new DateBuilder();
if (BitUtil.check(mask, 8)) {
dateBuilder.setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
}
if (BitUtil.check(mask, 9)) {
// gps status
position.setValid(buf.readUnsignedByte() == 1);
}
if (BitUtil.check(mask, 10)) {
position.setLatitude(convertCoordinate(buf.readUnsignedInt()));
}
if (BitUtil.check(mask, 11)) {
position.setLongitude(convertCoordinate(buf.readUnsignedInt()));
}
if (BitUtil.check(mask, 12)) {
position.setSpeed(buf.readUnsignedShort() / 10.0);
}
if (BitUtil.check(mask, 13)) {
position.setCourse(buf.readUnsignedShort() / 10.0);
}
if (BitUtil.check(mask, 14)) {
dateBuilder.setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
}
position.setTime(dateBuilder.getDate());
if (BitUtil.check(mask, 15)) {
position.setAltitude(buf.readMedium());
}
if (BitUtil.check(mask, 16)) {
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
}
if (BitUtil.check(mask, 17)) {
position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
}
if (BitUtil.check(mask, 20)) {
position.set(Position.KEY_ODOMETER_TRIP, buf.readUnsignedInt());
}
if (BitUtil.check(mask, 21)) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
}
if (BitUtil.check(mask, 22)) {
// time of message generation
buf.skipBytes(6);
}
if (BitUtil.check(mask, 24)) {
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
}
if (BitUtil.check(mask, 25)) {
// gps overspeed
buf.skipBytes(18);
}
if (BitUtil.check(mask, 26)) {
// cell information
buf.skipBytes(54);
}
if (BitUtil.check(mask, 28)) {
position.set(Position.KEY_INDEX, buf.readUnsignedShort());
}
return position;
}
return null;
}
use of org.traccar.helper.DateBuilder 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.DateBuilder 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;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class Avl301ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// header
buf.skipBytes(1);
int type = buf.readUnsignedByte();
// length
buf.readUnsignedByte();
if (type == MSG_LOGIN) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readImei(buf));
if (deviceSession == null) {
sendResponse(channel, type);
}
} else if (type == MSG_STATUS) {
sendResponse(channel, type);
} else if (type == MSG_GPS_LBS_STATUS) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
// gps len and sat
int gpsLength = buf.readUnsignedByte();
position.set(Position.KEY_SATELLITES, gpsLength & 0xf);
// satellites
position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
double latitude = buf.readUnsignedInt() / 600000.0;
double longitude = buf.readUnsignedInt() / 600000.0;
position.setSpeed(buf.readUnsignedByte());
// course and flags
int union = buf.readUnsignedShort();
position.setCourse(union & 0x03FF);
position.setValid((union & 0x1000) != 0);
if ((union & 0x0400) != 0) {
latitude = -latitude;
}
if ((union & 0x0800) != 0) {
longitude = -longitude;
}
position.setLatitude(latitude);
position.setLongitude(longitude);
if ((union & 0x4000) != 0) {
position.set("acc", (union & 0x8000) != 0);
}
position.setNetwork(new Network(CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedMedium())));
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
int flags = buf.readUnsignedByte();
position.set("acc", (flags & 0x2) != 0);
// parse other flags
position.set(Position.KEY_POWER, buf.readUnsignedByte());
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
return position;
}
return null;
}
Aggregations