use of org.traccar.model.Position in project traccar by traccar.
the class OigoProtocolDecoder method decodeArMessage.
private Position decodeArMessage(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
// header
buf.skipBytes(1);
// length
buf.readUnsignedShort();
int type = buf.readUnsignedByte();
int tag = buf.readUnsignedByte();
DeviceSession deviceSession;
switch(BitUtil.to(tag, 3)) {
case 0:
String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
deviceSession = getDeviceSession(channel, remoteAddress, imei);
break;
case 1:
buf.skipBytes(1);
String meid = buf.readBytes(14).toString(StandardCharsets.US_ASCII);
deviceSession = getDeviceSession(channel, remoteAddress, meid);
break;
default:
deviceSession = getDeviceSession(channel, remoteAddress);
break;
}
if (deviceSession == null || type != MSG_AR_LOCATION) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
int mask = buf.readInt();
if (BitUtil.check(mask, 0)) {
position.set(Position.KEY_INDEX, buf.readUnsignedShort());
}
if (BitUtil.check(mask, 1)) {
int date = buf.readUnsignedByte();
DateBuilder dateBuilder = new DateBuilder().setDate(BitUtil.between(date, 4, 8) + 2010, BitUtil.to(date, 4), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
}
if (BitUtil.check(mask, 2)) {
// device time
buf.skipBytes(5);
}
if (BitUtil.check(mask, 3)) {
position.setLatitude(buf.readUnsignedInt() * 0.000001 - 90);
position.setLongitude(buf.readUnsignedInt() * 0.000001 - 180.0);
}
if (BitUtil.check(mask, 4)) {
int status = buf.readUnsignedByte();
position.setValid(BitUtil.between(status, 4, 8) != 0);
position.set(Position.KEY_SATELLITES, BitUtil.to(status, 4));
position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
}
if (BitUtil.check(mask, 5)) {
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
}
if (BitUtil.check(mask, 6)) {
position.setCourse(buf.readUnsignedShort());
}
if (BitUtil.check(mask, 7)) {
position.setAltitude(buf.readShort());
}
if (BitUtil.check(mask, 8)) {
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
}
if (BitUtil.check(mask, 9)) {
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
}
if (BitUtil.check(mask, 10)) {
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
}
if (BitUtil.check(mask, 11)) {
// gpio
buf.skipBytes(2);
}
if (BitUtil.check(mask, 12)) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
}
if (BitUtil.check(mask, 13)) {
// software version
buf.skipBytes(6);
}
if (BitUtil.check(mask, 14)) {
// hardware version
buf.skipBytes(5);
}
if (BitUtil.check(mask, 15)) {
// device config
buf.readUnsignedShort();
}
return position;
}
use of org.traccar.model.Position in project traccar by traccar.
the class PathAwayProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
HttpRequest request = (HttpRequest) msg;
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, decoder.getParameters().get("UserName").get(0));
if (deviceSession == null) {
return null;
}
Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0));
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setValid(true);
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
if (channel != null) {
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
return position;
}
use of org.traccar.model.Position in project traccar by traccar.
the class L100ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// start marker
buf.readUnsignedByte();
// type
buf.readUnsignedByte();
String sentence = buf.readBytes(buf.readableBytes() - 2).toString(StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN, sentence);
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), 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_STATUS, parser.next());
position.set(Position.PREFIX_ADC + 1, parser.next());
position.set(Position.KEY_ODOMETER, parser.nextDouble(0));
position.set(Position.PREFIX_TEMP + 1, parser.nextDouble(0));
position.set(Position.KEY_BATTERY, parser.nextDouble(0));
int rssi = parser.nextInt(0);
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), rssi)));
return position;
}
use of org.traccar.model.Position in project traccar by traccar.
the class LaipacProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.startsWith("$ECHK") && channel != null) {
// heartbeat
channel.write(sentence + "\r\n");
return null;
}
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());
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
String status = parser.next();
position.setValid(status.toUpperCase().equals("A"));
position.set(Position.KEY_STATUS, status);
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());
String event = parser.next();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
position.set(Position.KEY_BATTERY, Double.parseDouble(parser.next().replaceAll("\\.", "")) * 0.001);
position.set(Position.KEY_ODOMETER, parser.nextDouble());
position.set(Position.KEY_GPS, parser.nextInt());
position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001);
position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001);
Integer lac = parser.nextHexInt();
Integer cid = parser.nextHexInt();
Integer mcc = parser.nextInt();
Integer mnc = parser.nextInt();
if (lac != null && cid != null && mcc != null && mnc != null) {
position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid)));
}
String checksum = parser.next();
if (channel != null) {
if (event.equals("3")) {
channel.write("$AVCFG,00000000,d*31\r\n");
} else if (event.equals("X") || event.equals("4")) {
channel.write("$AVCFG,00000000,x*2D\r\n");
} else if (event.equals("Z")) {
channel.write("$AVCFG,00000000,z*2F\r\n");
} else if (Character.isLowerCase(status.charAt(0))) {
String response = "$EAVACK," + event + "," + checksum;
response += Checksum.nmea(response) + "\r\n";
channel.write(response);
}
}
return position;
}
use of org.traccar.model.Position in project traccar by traccar.
the class M2cProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
// remove start symbol
sentence = sentence.substring(1);
List<Position> positions = new LinkedList<>();
for (String line : sentence.split("\r\n")) {
if (!line.isEmpty()) {
Position position = decodePosition(channel, remoteAddress, line);
if (position != null) {
positions.add(position);
}
}
}
return positions;
}
Aggregations