use of org.traccar.DeviceSession in project traccar by tananaev.
the class ArnaviProtocolDecoder 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());
position.set(Position.KEY_INDEX, parser.nextInt(0));
position.set(Position.KEY_POWER, parser.nextInt(0) * 0.01);
position.set(Position.KEY_BATTERY, parser.nextInt(0) * 0.01);
position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
position.set(Position.KEY_INPUT, parser.nextInt(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(true);
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.DeviceSession in project traccar by tananaev.
the class AtrackProtocolDecoder method decodeString.
private Position decodeString(Channel channel, SocketAddress remoteAddress, String sentence) {
Position position = new Position(getProtocolName());
getLastLocation(position, null);
DeviceSession deviceSession;
if (sentence.startsWith("$INFO")) {
Parser parser = new Parser(PATTERN_INFO, sentence);
if (!parser.matches()) {
return null;
}
deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
position.set("model", parser.next());
position.set(Position.KEY_VERSION_FW, parser.next());
position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
position.set(Position.KEY_BATTERY, parser.nextInt() * 0.1);
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_RSSI, parser.nextInt());
} else {
deviceSession = getDeviceSession(channel, remoteAddress);
position.set(Position.KEY_RESULT, sentence);
}
if (deviceSession == null) {
return null;
} else {
position.setDeviceId(deviceSession.getDeviceId());
return position;
}
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class AdmProtocolDecoder method decodeData.
private Position decodeData(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int type) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
if (BitUtil.to(type, 2) == 0) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_VERSION_FW, buf.readUnsignedByte());
position.set(Position.KEY_INDEX, buf.readUnsignedShort());
int status = buf.readUnsignedShort();
position.set(Position.KEY_STATUS, status);
position.setValid(!BitUtil.check(status, 5));
position.setLatitude(buf.readFloat());
position.setLongitude(buf.readFloat());
position.setCourse(buf.readUnsignedShort() * 0.1);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort() * 0.1));
position.set(Position.KEY_ACCELERATION, buf.readUnsignedByte() * 0.1);
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte() & 0x0f);
position.setTime(new Date(buf.readUnsignedInt() * 1000));
position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.001);
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
if (BitUtil.check(type, 2)) {
// vib
buf.readUnsignedByte();
// vib_count
buf.readUnsignedByte();
int out = buf.readUnsignedByte();
for (int i = 0; i <= 3; i++) {
position.set(Position.PREFIX_OUT + (i + 1), BitUtil.check(out, i) ? 1 : 0);
}
// in_alarm
buf.readUnsignedByte();
}
if (BitUtil.check(type, 3)) {
for (int i = 1; i <= 6; i++) {
position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort() * 0.001);
}
}
if (BitUtil.check(type, 4)) {
for (int i = 1; i <= 2; i++) {
position.set(Position.PREFIX_COUNT + i, buf.readUnsignedInt());
}
}
if (BitUtil.check(type, 5)) {
for (int i = 1; i <= 3; i++) {
// fuel level
buf.readUnsignedShort();
}
for (int i = 1; i <= 3; i++) {
position.set(Position.PREFIX_TEMP + i, buf.readUnsignedByte());
}
}
if (BitUtil.check(type, 6)) {
buf.skipBytes(buf.getUnsignedByte(buf.readerIndex()));
}
if (BitUtil.check(type, 7)) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
}
return position;
}
return null;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class AlematicsProtocolDecoder 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_TYPE, parser.nextInt());
position.set(Position.KEY_INDEX, parser.nextInt());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.setFixTime(parser.nextDateTime());
position.setDeviceTime(parser.nextDateTime());
position.setValid(true);
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
position.setCourse(parser.nextInt(0));
position.setAltitude(parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextDouble());
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_INPUT, parser.nextInt());
position.set(Position.KEY_OUTPUT, parser.nextInt());
position.set(Position.PREFIX_ADC + 1, parser.nextDouble());
position.set(Position.KEY_POWER, parser.nextDouble());
position.set(Position.KEY_ODOMETER, parser.nextInt());
if (parser.hasNext()) {
position.set("text", parser.next());
} else {
decodeExtras(position, parser);
}
return position;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class ApelProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
int type = buf.readUnsignedShort();
boolean alarm = (type & 0x8000) != 0;
type = type & 0x7FFF;
// length
buf.readUnsignedShort();
if (alarm) {
sendSimpleMessage(channel, MSG_ACK_ALARM);
}
if (type == MSG_TRACKER_ID) {
// unsupported authentication type
return null;
}
if (type == MSG_TRACKER_ID_EXT) {
// id
buf.readUnsignedInt();
int length = buf.readUnsignedShort();
buf.skipBytes(length);
length = buf.readUnsignedShort();
getDeviceSession(channel, remoteAddress, buf.readBytes(length).toString(StandardCharsets.US_ASCII));
} else if (type == MSG_LAST_LOG_INDEX) {
long index = buf.readUnsignedInt();
if (index > 0) {
newIndex = index;
requestArchive(channel);
}
} else if (type == MSG_CURRENT_GPS_DATA || type == MSG_STATE_FULL_INFO_T104 || type == MSG_LOG_RECORDS) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
List<Position> positions = new LinkedList<>();
int recordCount = 1;
if (type == MSG_LOG_RECORDS) {
recordCount = buf.readUnsignedShort();
}
for (int j = 0; j < recordCount; j++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int subtype = type;
if (type == MSG_LOG_RECORDS) {
position.set(Position.KEY_ARCHIVE, true);
lastIndex = buf.readUnsignedInt() + 1;
position.set(Position.KEY_INDEX, lastIndex);
subtype = buf.readUnsignedShort();
if (subtype != MSG_CURRENT_GPS_DATA && subtype != MSG_STATE_FULL_INFO_T104) {
buf.skipBytes(buf.readUnsignedShort());
continue;
}
// length
buf.readUnsignedShort();
}
position.setTime(new Date(buf.readUnsignedInt() * 1000));
position.setLatitude(buf.readInt() * 180.0 / 0x7FFFFFFF);
position.setLongitude(buf.readInt() * 180.0 / 0x7FFFFFFF);
if (subtype == MSG_STATE_FULL_INFO_T104) {
int speed = buf.readUnsignedByte();
position.setValid(speed != 255);
position.setSpeed(UnitsConverter.knotsFromKph(speed));
position.set(Position.KEY_HDOP, buf.readByte());
} else {
int speed = buf.readShort();
position.setValid(speed != -1);
position.setSpeed(UnitsConverter.knotsFromKph(speed * 0.01));
}
position.setCourse(buf.readShort() * 0.01);
position.setAltitude(buf.readShort());
if (subtype == MSG_STATE_FULL_INFO_T104) {
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
position.set(Position.KEY_EVENT, buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
position.set(Position.KEY_INPUT, buf.readUnsignedByte());
position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
for (int i = 1; i <= 8; i++) {
position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort());
}
position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt());
position.set(Position.PREFIX_COUNT + 2, buf.readUnsignedInt());
position.set(Position.PREFIX_COUNT + 3, buf.readUnsignedInt());
}
positions.add(position);
}
// crc
buf.readUnsignedInt();
if (type == MSG_LOG_RECORDS) {
requestArchive(channel);
} else {
sendSimpleMessage(channel, MSG_REQUEST_LAST_LOG_INDEX);
}
return positions;
}
return null;
}
Aggregations