use of org.traccar.model.CellTower in project traccar by tananaev.
the class TeltonikaProtocolDecoder method decodeLocation.
private void decodeLocation(Position position, ByteBuf buf, int codec) {
int globalMask = 0x0f;
if (codec == CODEC_GH3000) {
long time = buf.readUnsignedInt() & 0x3fffffff;
// 2007-01-01 00:00:00
time += 1167609600;
globalMask = buf.readUnsignedByte();
if (BitUtil.check(globalMask, 0)) {
position.setTime(new Date(time * 1000));
int locationMask = buf.readUnsignedByte();
if (BitUtil.check(locationMask, 0)) {
position.setLatitude(buf.readFloat());
position.setLongitude(buf.readFloat());
}
if (BitUtil.check(locationMask, 1)) {
position.setAltitude(buf.readUnsignedShort());
}
if (BitUtil.check(locationMask, 2)) {
position.setCourse(buf.readUnsignedByte() * 360.0 / 256);
}
if (BitUtil.check(locationMask, 3)) {
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
}
if (BitUtil.check(locationMask, 4)) {
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
}
if (BitUtil.check(locationMask, 5)) {
CellTower cellTower = CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort());
if (BitUtil.check(locationMask, 6)) {
cellTower.setSignalStrength((int) buf.readUnsignedByte());
}
if (BitUtil.check(locationMask, 7)) {
cellTower.setOperator(buf.readUnsignedInt());
}
position.setNetwork(new Network(cellTower));
} else {
if (BitUtil.check(locationMask, 6)) {
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
}
if (BitUtil.check(locationMask, 7)) {
position.set(Position.KEY_OPERATOR, buf.readUnsignedInt());
}
}
} else {
getLastLocation(position, new Date(time * 1000));
}
} else {
position.setTime(new Date(buf.readLong()));
position.set("priority", buf.readUnsignedByte());
position.setLongitude(buf.readInt() / 10000000.0);
position.setLatitude(buf.readInt() / 10000000.0);
position.setAltitude(buf.readShort());
position.setCourse(buf.readUnsignedShort());
int satellites = buf.readUnsignedByte();
position.set(Position.KEY_SATELLITES, satellites);
position.setValid(satellites != 0);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));
position.set(Position.KEY_EVENT, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16));
if (codec == CODEC_16) {
// generation type
buf.readUnsignedByte();
}
// total IO data records
readExtByte(buf, codec, CODEC_8_EXT);
}
// Read 1 byte data
if (BitUtil.check(globalMask, 1)) {
int cnt = readExtByte(buf, codec, CODEC_8_EXT);
for (int j = 0; j < cnt; j++) {
decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 1, codec);
}
}
// Read 2 byte data
if (BitUtil.check(globalMask, 2)) {
int cnt = readExtByte(buf, codec, CODEC_8_EXT);
for (int j = 0; j < cnt; j++) {
decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 2, codec);
}
}
// Read 4 byte data
if (BitUtil.check(globalMask, 3)) {
int cnt = readExtByte(buf, codec, CODEC_8_EXT);
for (int j = 0; j < cnt; j++) {
decodeParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 4, codec);
}
}
// Read 8 byte data
if (codec == CODEC_8 || codec == CODEC_8_EXT || codec == CODEC_16) {
int cnt = readExtByte(buf, codec, CODEC_8_EXT);
for (int j = 0; j < cnt; j++) {
decodeOtherParameter(position, readExtByte(buf, codec, CODEC_8_EXT, CODEC_16), buf, 8);
}
}
// Read 16 byte data
if (extended) {
int cnt = readExtByte(buf, codec, CODEC_8_EXT);
for (int j = 0; j < cnt; j++) {
int id = readExtByte(buf, codec, CODEC_8_EXT, CODEC_16);
position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(16)));
}
}
// Read X byte data
if (codec == CODEC_8_EXT) {
int cnt = buf.readUnsignedShort();
for (int j = 0; j < cnt; j++) {
int id = buf.readUnsignedShort();
int length = buf.readUnsignedShort();
if (id == 256) {
position.set(Position.KEY_VIN, buf.readSlice(length).toString(StandardCharsets.US_ASCII));
} else if (id == 281) {
position.set(Position.KEY_DTCS, buf.readSlice(length).toString(StandardCharsets.US_ASCII).replace(',', ' '));
} else if (id == 385) {
ByteBuf data = buf.readSlice(length);
// data part
data.readUnsignedByte();
int index = 1;
while (data.isReadable()) {
int flags = data.readUnsignedByte();
if (BitUtil.from(flags, 4) > 0) {
position.set("beacon" + index + "Uuid", ByteBufUtil.hexDump(data.readSlice(16)));
position.set("beacon" + index + "Major", data.readUnsignedShort());
position.set("beacon" + index + "Minor", data.readUnsignedShort());
} else {
position.set("beacon" + index + "Namespace", ByteBufUtil.hexDump(data.readSlice(10)));
position.set("beacon" + index + "Instance", ByteBufUtil.hexDump(data.readSlice(6)));
}
position.set("beacon" + index + "Rssi", (int) data.readByte());
if (BitUtil.check(flags, 1)) {
position.set("beacon" + index + "Battery", data.readUnsignedShort() * 0.01);
}
if (BitUtil.check(flags, 2)) {
position.set("beacon" + index + "Temp", data.readUnsignedShort());
}
index += 1;
}
} else {
position.set(Position.PREFIX_IO + id, ByteBufUtil.hexDump(buf.readSlice(length)));
}
}
}
decodeNetwork(position);
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class TotemProtocolDecoder method decode4.
private boolean decode4(Position position, Parser parser) {
long status = parser.nextHexLong();
position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 1) ? Position.ALARM_SOS : null);
position.set(Position.KEY_IGNITION, BitUtil.check(status, 32 - 2));
position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 3) ? Position.ALARM_OVERSPEED : null);
position.set(Position.KEY_CHARGE, BitUtil.check(status, 32 - 4));
position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 5) ? Position.ALARM_GEOFENCE_EXIT : null);
position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 6) ? Position.ALARM_GEOFENCE_ENTER : null);
position.set(Position.KEY_ALARM, BitUtil.check(status, 32 - 7) ? Position.ALARM_GPS_ANTENNA_CUT : null);
position.set(Position.PREFIX_OUT + 1, BitUtil.check(status, 32 - 9));
position.set(Position.PREFIX_OUT + 2, BitUtil.check(status, 32 - 10));
position.set(Position.PREFIX_OUT + 3, BitUtil.check(status, 32 - 11));
// see https://github.com/traccar/traccar/pull/4762
position.set(Position.KEY_STATUS, status);
position.setTime(parser.nextDateTime());
position.set(Position.KEY_BATTERY, parser.nextDouble() * 0.1);
position.set(Position.KEY_POWER, parser.nextDouble());
position.set(Position.PREFIX_ADC + 1, parser.next());
position.set(Position.PREFIX_ADC + 2, parser.next());
position.set(Position.PREFIX_ADC + 3, parser.next());
position.set(Position.PREFIX_ADC + 4, parser.next());
position.set(Position.PREFIX_TEMP + 1, parser.next());
if (parser.hasNext()) {
position.set(Position.PREFIX_TEMP + 2, parser.next());
position.setValid(BitUtil.check(status, 32 - 20));
} else {
position.setValid(BitUtil.check(status, 32 - 18));
}
int lac = parser.nextHexInt();
int cid = parser.nextHexInt();
CellTower cellTower;
if (parser.hasNext(2)) {
int mnc = parser.nextInt();
int mcc = parser.nextInt();
cellTower = CellTower.from(mcc, mnc, lac, cid);
} else {
cellTower = CellTower.fromLacCid(lac, cid);
}
position.set(Position.KEY_SATELLITES, parser.nextInt());
cellTower.setSignalStrength(parser.nextInt());
position.setNetwork(new Network(cellTower));
position.setCourse(parser.nextDouble());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
position.set(Position.KEY_HDOP, parser.nextDouble());
position.set(Position.KEY_ODOMETER, parser.nextInt() * 1000);
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
return true;
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class AutoFonProtocolDecoder method decodePosition.
private Position decodePosition(DeviceSession deviceSession, ByteBuf 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.CellTower in project traccar by tananaev.
the class SuntechProtocolDecoder method decodeUniversal.
private Position decodeUniversal(Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException {
int index = 0;
String type = values[index++];
if (!type.equals("STT") && !type.equals("ALT") && !type.equals("BLE")) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_TYPE, type);
int mask;
if (type.equals("BLE")) {
mask = 0b1100000110110;
} else {
mask = Integer.parseInt(values[index++], 16);
}
if (BitUtil.check(mask, 1)) {
// model
index += 1;
}
if (BitUtil.check(mask, 2)) {
position.set(Position.KEY_VERSION_FW, values[index++]);
}
if (BitUtil.check(mask, 3) && values[index++].equals("0")) {
position.set(Position.KEY_ARCHIVE, true);
}
if (BitUtil.check(mask, 4) && BitUtil.check(mask, 5)) {
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
position.setTime(dateFormat.parse(values[index++] + values[index++]));
}
CellTower cellTower = new CellTower();
if (BitUtil.check(mask, 6)) {
cellTower.setCellId(Long.parseLong(values[index++], 16));
}
if (BitUtil.check(mask, 7)) {
cellTower.setMobileCountryCode(Integer.parseInt(values[index++]));
}
if (BitUtil.check(mask, 8)) {
cellTower.setMobileNetworkCode(Integer.parseInt(values[index++]));
}
if (BitUtil.check(mask, 9)) {
cellTower.setLocationAreaCode(Integer.parseInt(values[index++], 16));
}
if (cellTower.getCellId() != null) {
position.setNetwork(new Network(cellTower));
}
if (BitUtil.check(mask, 10)) {
position.set(Position.KEY_RSSI, Integer.parseInt(values[index++]));
}
if (BitUtil.check(mask, 11)) {
position.setLatitude(Double.parseDouble(values[index++]));
}
if (BitUtil.check(mask, 12)) {
position.setLongitude(Double.parseDouble(values[index++]));
}
if (type.equals("BLE")) {
position.setValid(true);
int count = Integer.parseInt(values[index++]);
for (int i = 1; i <= count; i++) {
position.set("tag" + i + "Rssi", Integer.parseInt(values[index++]));
// rssi min
index += 1;
// rssi max
index += 1;
position.set("tag" + i + "Id", values[index++]);
position.set("tag" + i + "Samples", Integer.parseInt(values[index++]));
position.set("tag" + i + "Major", Integer.parseInt(values[index++]));
position.set("tag" + i + "Minor", Integer.parseInt(values[index++]));
}
} else {
if (BitUtil.check(mask, 13)) {
position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++])));
}
if (BitUtil.check(mask, 14)) {
position.setCourse(Double.parseDouble(values[index++]));
}
if (BitUtil.check(mask, 15)) {
position.set(Position.KEY_SATELLITES, Integer.parseInt(values[index++]));
}
if (BitUtil.check(mask, 16)) {
position.setValid(values[index++].equals("1"));
}
if (BitUtil.check(mask, 17)) {
position.set(Position.KEY_INPUT, Integer.parseInt(values[index++]));
}
if (BitUtil.check(mask, 18)) {
position.set(Position.KEY_OUTPUT, Integer.parseInt(values[index++]));
}
if (type.equals("ALT")) {
if (BitUtil.check(mask, 19)) {
position.set("alertId", values[index++]);
}
if (BitUtil.check(mask, 20)) {
position.set("alertModifier", values[index++]);
}
if (BitUtil.check(mask, 21)) {
position.set("alertData", values[index++]);
}
} else {
if (BitUtil.check(mask, 19)) {
position.set("mode", Integer.parseInt(values[index++]));
}
if (BitUtil.check(mask, 20)) {
position.set("reason", Integer.parseInt(values[index++]));
}
if (BitUtil.check(mask, 21)) {
position.set(Position.KEY_INDEX, Integer.parseInt(values[index++]));
}
}
if (BitUtil.check(mask, 22)) {
// reserved
index += 1;
}
if (BitUtil.check(mask, 23)) {
int assignMask = Integer.parseInt(values[index++], 16);
for (int i = 0; i <= 30; i++) {
if (BitUtil.check(assignMask, i)) {
position.set(Position.PREFIX_IO + (i + 1), values[index++]);
}
}
}
}
return position;
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class AtrackProtocolDecoder method readCustomData.
private void readCustomData(Position position, ChannelBuffer buf, String form) {
CellTower cellTower = new CellTower();
String[] keys = form.substring(1).split("%");
for (String key : keys) {
switch(key) {
case "SA":
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case "MV":
position.set(Position.KEY_POWER, buf.readUnsignedShort());
break;
case "BV":
position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
break;
case "GQ":
cellTower.setSignalStrength((int) buf.readUnsignedByte());
break;
case "CE":
cellTower.setCellId(buf.readUnsignedInt());
break;
case "LC":
cellTower.setLocationAreaCode(buf.readUnsignedShort());
break;
case "CN":
// cccnn
int combinedMobileCodes = (int) (buf.readUnsignedInt() % 100000);
cellTower.setMobileCountryCode(combinedMobileCodes / 100);
cellTower.setMobileNetworkCode(combinedMobileCodes % 100);
break;
case "RL":
// rxlev
buf.readUnsignedByte();
break;
case "PC":
position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt());
break;
case "AT":
position.setAltitude(buf.readUnsignedInt());
break;
case "RP":
position.set(Position.KEY_RPM, buf.readUnsignedShort());
break;
case "GS":
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
break;
case "DT":
position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() == 1);
break;
case "VN":
position.set(Position.KEY_VIN, readString(buf));
break;
case "MF":
// mass air flow rate
buf.readUnsignedShort();
break;
case "EL":
// engine load
buf.readUnsignedByte();
break;
case "TR":
position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
break;
case "ET":
position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort());
break;
case "FL":
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
break;
case "ML":
// mil status
buf.readUnsignedByte();
break;
case "FC":
position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
break;
case "CI":
// format string
readString(buf);
break;
case "AV1":
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
break;
case "NC":
// gsm neighbor cell info
readString(buf);
break;
case "SM":
// max speed between reports
buf.readUnsignedShort();
break;
case "GL":
// google link
readString(buf);
break;
case "MA":
// mac address
readString(buf);
break;
default:
break;
}
}
if (cellTower.getMobileCountryCode() != null && cellTower.getMobileNetworkCode() != null && cellTower.getCellId() != null && cellTower.getLocationAreaCode() != null) {
position.setNetwork(new Network(cellTower));
} else if (cellTower.getSignalStrength() != null) {
position.set(Position.KEY_RSSI, cellTower.getSignalStrength());
}
}
Aggregations