use of org.traccar.model.Network in project traccar by tananaev.
the class AutoFonProtocolDecoder method decodePosition.
private Position decodePosition(DeviceSession deviceSession, ChannelBuffer buf, boolean history) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (!history) {
// interval
buf.readUnsignedByte();
// settings
buf.skipBytes(8);
}
position.set(Position.KEY_STATUS, buf.readUnsignedByte());
if (!history) {
buf.readUnsignedShort();
}
position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
// time
buf.skipBytes(6);
if (!history) {
for (int i = 0; i < 2; i++) {
// time
buf.skipBytes(5);
// interval
buf.readUnsignedShort();
// mode
buf.skipBytes(5);
}
}
position.set(Position.PREFIX_TEMP + 1, buf.readByte());
int rssi = buf.readUnsignedByte();
CellTower cellTower = CellTower.from(buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), rssi);
position.setNetwork(new Network(cellTower));
int valid = buf.readUnsignedByte();
position.setValid((valid & 0xc0) != 0);
position.set(Position.KEY_SATELLITES, valid & 0x3f);
DateBuilder dateBuilder = new DateBuilder().setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
position.setLatitude(convertCoordinate(buf.readInt()));
position.setLongitude(convertCoordinate(buf.readInt()));
position.setAltitude(buf.readShort());
position.setSpeed(buf.readUnsignedByte());
position.setCourse(buf.readUnsignedByte() * 2.0);
position.set(Position.KEY_HDOP, buf.readUnsignedShort());
// reserved
buf.readUnsignedShort();
// checksum
buf.readUnsignedByte();
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class BceProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
String imei = String.format("%015d", buf.readLong());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
List<Position> positions = new LinkedList<>();
while (buf.readableBytes() > 1) {
int dataEnd = buf.readUnsignedShort() + buf.readerIndex();
int type = buf.readUnsignedByte();
int confirmKey = buf.readUnsignedByte() & 0x7F;
while (buf.readerIndex() < dataEnd) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
int structEnd = buf.readUnsignedByte() + buf.readerIndex();
long time = buf.readUnsignedInt();
if ((time & 0x0f) == DATA_TYPE) {
time = time >> 4 << 1;
// 01/01/2008
time += 0x47798280;
position.setTime(new Date(time * 1000));
// Read masks
int mask;
List<Integer> masks = new LinkedList<>();
do {
mask = buf.readUnsignedShort();
masks.add(mask);
} while (BitUtil.check(mask, 15));
mask = masks.get(0);
if (BitUtil.check(mask, 0)) {
position.setValid(true);
position.setLongitude(buf.readFloat());
position.setLatitude(buf.readFloat());
position.setSpeed(buf.readUnsignedByte());
int gps = buf.readUnsignedByte();
position.set(Position.KEY_SATELLITES, gps & 0xf);
position.set(Position.KEY_HDOP, gps >> 4);
position.setCourse(buf.readUnsignedByte());
position.setAltitude(buf.readUnsignedShort());
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
}
if (BitUtil.check(mask, 1)) {
position.set(Position.KEY_INPUT, buf.readUnsignedShort());
}
for (int i = 1; i <= 8; i++) {
if (BitUtil.check(mask, i + 1)) {
position.set(Position.PREFIX_ADC + i, buf.readUnsignedShort());
}
}
if (BitUtil.check(mask, 10)) {
buf.skipBytes(4);
}
if (BitUtil.check(mask, 11)) {
buf.skipBytes(4);
}
if (BitUtil.check(mask, 12)) {
buf.skipBytes(2);
}
if (BitUtil.check(mask, 13)) {
buf.skipBytes(2);
}
if (BitUtil.check(mask, 14)) {
position.setNetwork(new Network(CellTower.from(buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedByte())));
buf.readUnsignedByte();
}
if (BitUtil.check(mask, 0)) {
positions.add(position);
}
}
buf.readerIndex(structEnd);
}
// Send response
if (type == MSG_ASYNC_STACK && channel != null) {
ChannelBuffer response = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 8 + 2 + 2 + 1);
response.writeLong(Long.parseLong(imei));
response.writeShort(2);
response.writeByte(MSG_STACK_COFIRM);
response.writeByte(confirmKey);
int checksum = 0;
for (int i = 0; i < response.writerIndex(); i++) {
checksum += response.getUnsignedByte(i);
}
response.writeByte(checksum);
channel.write(response);
}
}
return positions;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class EelinkProtocolDecoder method decodeNew.
private Position decodeNew(DeviceSession deviceSession, ChannelBuffer buf, int index) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
position.setTime(new Date(buf.readUnsignedInt() * 1000));
int flags = buf.readUnsignedByte();
if (BitUtil.check(flags, 0)) {
position.setLatitude(buf.readInt() / 1800000.0);
position.setLongitude(buf.readInt() / 1800000.0);
position.setAltitude(buf.readShort());
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.setCourse(buf.readUnsignedShort());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
} else {
getLastLocation(position, position.getDeviceTime());
}
if (BitUtil.check(flags, 1)) {
position.setNetwork(new Network(CellTower.from(buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedInt(), buf.readUnsignedByte())));
}
if (BitUtil.check(flags, 2)) {
// bsid1
buf.skipBytes(7);
}
if (BitUtil.check(flags, 3)) {
// bsid2
buf.skipBytes(7);
}
if (BitUtil.check(flags, 4)) {
// bss0
buf.skipBytes(7);
}
if (BitUtil.check(flags, 5)) {
// bss1
buf.skipBytes(7);
}
if (BitUtil.check(flags, 6)) {
// bss2
buf.skipBytes(7);
}
if (buf.readableBytes() >= 2) {
int status = buf.readUnsignedShort();
position.setValid(BitUtil.check(status, 0));
if (BitUtil.check(status, 1)) {
position.set(Position.KEY_IGNITION, BitUtil.check(status, 2));
}
position.set(Position.KEY_STATUS, status);
}
if (buf.readableBytes() >= 2) {
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
}
if (buf.readableBytes() >= 4) {
position.set(Position.PREFIX_ADC + 0, buf.readUnsignedShort());
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
}
if (buf.readableBytes() >= 4) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
}
if (buf.readableBytes() >= 4) {
// gsm counter
buf.readUnsignedShort();
// gps counter
buf.readUnsignedShort();
}
if (buf.readableBytes() >= 4) {
position.set(Position.KEY_STEPS, buf.readUnsignedShort());
// walking time
buf.readUnsignedShort();
}
if (buf.readableBytes() >= 12) {
position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort() / 256.0);
position.set("humidity", buf.readUnsignedShort() * 0.1);
position.set("illuminance", buf.readUnsignedInt() / 256.0);
position.set("co2", buf.readUnsignedInt());
}
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class EelinkProtocolDecoder method decodeOld.
private Position decodeOld(DeviceSession deviceSession, ChannelBuffer buf, int type, int index) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
position.setTime(new Date(buf.readUnsignedInt() * 1000));
position.setLatitude(buf.readInt() / 1800000.0);
position.setLongitude(buf.readInt() / 1800000.0);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
position.setCourse(buf.readUnsignedShort());
position.setNetwork(new Network(CellTower.from(buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedMedium())));
position.setValid((buf.readUnsignedByte() & 0x01) != 0);
if (type == MSG_GPS) {
if (buf.readableBytes() >= 2) {
decodeStatus(position, buf.readUnsignedShort());
}
if (buf.readableBytes() >= 2 * 4) {
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.001);
position.set(Position.KEY_RSSI, buf.readUnsignedShort());
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
}
} else if (type == MSG_ALARM) {
position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
} else if (type == MSG_STATE) {
int statusType = buf.readUnsignedByte();
position.set(Position.KEY_EVENT, statusType);
if (statusType == 0x01 || statusType == 0x02 || statusType == 0x03) {
// device time
buf.readUnsignedInt();
if (buf.readableBytes() >= 2) {
decodeStatus(position, buf.readUnsignedShort());
}
}
}
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Gl200BinaryProtocolDecoder method decodeLocation.
private List<Position> decodeLocation(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
List<Position> positions = new LinkedList<>();
int type = buf.readUnsignedByte();
// mask
buf.readUnsignedInt();
// length
buf.readUnsignedShort();
// device type
buf.readUnsignedByte();
// protocol version
buf.readUnsignedShort();
// firmware version
buf.readUnsignedShort();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.format("%015d", buf.readLong()));
if (deviceSession == null) {
return null;
}
int battery = buf.readUnsignedByte();
int power = buf.readUnsignedShort();
if (type == MSG_RSP_GEO) {
// reserved
buf.readUnsignedByte();
// reserved
buf.readUnsignedByte();
}
// motion status
buf.readUnsignedByte();
int satellites = buf.readUnsignedByte();
if (type != MSG_RSP_COMPRESSED) {
// index
buf.readUnsignedByte();
}
if (type == MSG_RSP_LCB) {
// phone length
buf.readUnsignedByte();
for (int b = buf.readUnsignedByte(); ; b = buf.readUnsignedByte()) {
if ((b & 0xf) == 0xf || (b & 0xf0) == 0xf0) {
break;
}
}
}
if (type == MSG_RSP_COMPRESSED) {
int count = buf.readUnsignedShort();
BitBuffer bits;
int speed = 0;
int heading = 0;
int latitude = 0;
int longitude = 0;
long time = 0;
for (int i = 0; i < count; i++) {
if (time > 0) {
time += 1;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
switch(BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 8 - 2)) {
case 1:
bits = new BitBuffer(buf.readBytes(3));
// point attribute
bits.readUnsigned(2);
// fix type
bits.readUnsigned(1);
speed = bits.readUnsigned(12);
heading = bits.readUnsigned(9);
longitude = buf.readInt();
latitude = buf.readInt();
if (time == 0) {
time = buf.readUnsignedInt();
}
break;
case 2:
bits = new BitBuffer(buf.readBytes(5));
// point attribute
bits.readUnsigned(2);
// fix type
bits.readUnsigned(1);
speed += bits.readSigned(7);
heading += bits.readSigned(7);
longitude += bits.readSigned(12);
latitude += bits.readSigned(11);
break;
default:
// invalid or same
buf.readUnsignedByte();
continue;
}
position.setValid(true);
position.setTime(new Date(time * 1000));
position.setSpeed(UnitsConverter.knotsFromKph(speed * 0.1));
position.setCourse(heading);
position.setLongitude(longitude * 0.000001);
position.setLatitude(latitude * 0.000001);
positions.add(position);
}
} else {
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_BATTERY_LEVEL, battery);
position.set(Position.KEY_POWER, power);
position.set(Position.KEY_SATELLITES, satellites);
int hdop = buf.readUnsignedByte();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedMedium() * 0.1));
position.setCourse(buf.readUnsignedShort());
position.setAltitude(buf.readShort());
position.setLongitude(buf.readInt() * 0.000001);
position.setLatitude(buf.readInt() * 0.000001);
position.setTime(decodeTime(buf));
position.setNetwork(new Network(CellTower.from(buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort())));
// reserved
buf.readUnsignedByte();
positions.add(position);
}
}
return positions;
}
Aggregations