use of org.traccar.model.CellTower in project traccar by tananaev.
the class Jt600ProtocolDecoder method decodeU01.
private Position decodeU01(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN_U01, sentence);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
String type = parser.next();
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setValid(parser.next().equals("T"));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
position.set(Position.KEY_STATUS, parser.nextBinInt(0));
CellTower cellTower = CellTower.fromCidLac(parser.nextInt(0), parser.nextInt(0));
cellTower.setSignalStrength(parser.nextInt(0));
position.setNetwork(new Network(cellTower));
position.set(Position.KEY_ODOMETER, parser.nextLong(0) * 1000);
position.set(Position.KEY_INDEX, parser.nextInt(0));
if (channel != null) {
if (type.equals("U01") || type.equals("U02") || type.equals("U03")) {
channel.writeAndFlush(new NetworkMessage("(S39)", remoteAddress));
} else if (type.equals("U06")) {
channel.writeAndFlush(new NetworkMessage("(S20)", remoteAddress));
}
}
return position;
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class Jt600ProtocolDecoder method decodeBinary.
private List<Position> decodeBinary(ByteBuf buf, Channel channel, SocketAddress remoteAddress) {
List<Position> positions = new LinkedList<>();
// header
buf.readByte();
boolean longFormat = isLongFormat(buf, buf.readerIndex());
String id = String.valueOf(Long.parseLong(ByteBufUtil.hexDump(buf.readSlice(5))));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
int protocolVersion = 0;
if (longFormat) {
protocolVersion = buf.readUnsignedByte();
}
int version = BitUtil.from(buf.readUnsignedByte(), 4);
// length
buf.readUnsignedShort();
boolean responseRequired = false;
while (buf.readableBytes() > 1) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
decodeBinaryLocation(buf, position);
if (longFormat) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
// vehicle id combined
buf.readUnsignedInt();
int status = buf.readUnsignedShort();
position.set(Position.KEY_ALARM, BitUtil.check(status, 1) ? Position.ALARM_GEOFENCE_ENTER : null);
position.set(Position.KEY_ALARM, BitUtil.check(status, 2) ? Position.ALARM_GEOFENCE_EXIT : null);
position.set(Position.KEY_ALARM, BitUtil.check(status, 3) ? Position.ALARM_POWER_CUT : null);
position.set(Position.KEY_ALARM, BitUtil.check(status, 4) ? Position.ALARM_VIBRATION : null);
if (BitUtil.check(status, 5)) {
responseRequired = true;
}
position.set(Position.KEY_BLOCKED, BitUtil.check(status, 7));
position.set(Position.KEY_ALARM, BitUtil.check(status, 8 + 3) ? Position.ALARM_LOW_BATTERY : null);
position.set(Position.KEY_ALARM, BitUtil.check(status, 8 + 6) ? Position.ALARM_FAULT : null);
position.set(Position.KEY_STATUS, status);
int battery = buf.readUnsignedByte();
if (battery == 0xff) {
position.set(Position.KEY_CHARGE, true);
} else {
position.set(Position.KEY_BATTERY_LEVEL, battery);
}
CellTower cellTower = CellTower.fromCidLac(buf.readUnsignedShort(), buf.readUnsignedShort());
cellTower.setSignalStrength((int) buf.readUnsignedByte());
position.setNetwork(new Network(cellTower));
if (protocolVersion == 0x17 || protocolVersion == 0x19) {
// geofence id
buf.readUnsignedByte();
// reserved
buf.skipBytes(3);
buf.skipBytes(buf.readableBytes() - 1);
}
} else if (version == 1) {
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.set(Position.KEY_POWER, buf.readUnsignedByte());
// other flags and sensors
buf.readByte();
position.setAltitude(buf.readUnsignedShort());
int cid = buf.readUnsignedShort();
int lac = buf.readUnsignedShort();
int rssi = buf.readUnsignedByte();
if (cid != 0 && lac != 0) {
CellTower cellTower = CellTower.fromCidLac(cid, lac);
cellTower.setSignalStrength(rssi);
position.setNetwork(new Network(cellTower));
} else {
position.set(Position.KEY_RSSI, rssi);
}
} else if (version == 2) {
int fuel = buf.readUnsignedByte() << 8;
decodeStatus(position, buf);
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
fuel += buf.readUnsignedByte();
position.set(Position.KEY_FUEL_LEVEL, fuel);
} else if (version == 3) {
BitBuffer bitBuffer = new BitBuffer(buf);
position.set("fuel1", bitBuffer.readUnsigned(12));
position.set("fuel2", bitBuffer.readUnsigned(12));
position.set("fuel3", bitBuffer.readUnsigned(12));
position.set(Position.KEY_ODOMETER, bitBuffer.readUnsigned(20) * 1000);
int status = bitBuffer.readUnsigned(24);
position.set(Position.KEY_IGNITION, BitUtil.check(status, 0));
position.set(Position.KEY_STATUS, status);
}
positions.add(position);
}
int index = buf.readUnsignedByte();
if (channel != null && responseRequired) {
if (protocolVersion < 0x19) {
channel.writeAndFlush(new NetworkMessage("(P35)", remoteAddress));
} else {
channel.writeAndFlush(new NetworkMessage("(P69,0," + index + ")", remoteAddress));
}
}
return positions;
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class MegastekProtocolDecoder method decodeNew.
private Position decodeNew(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_NEW, 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());
if (parser.next().equals("S")) {
position.set(Position.KEY_ARCHIVE, true);
}
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1000);
}
if (parser.hasNext(5)) {
int mcc = parser.nextInt();
int mnc = parser.nextInt();
Integer lac = parser.nextHexInt();
Integer cid = parser.nextHexInt();
Integer rssi = parser.nextInt();
if (lac != null && cid != null) {
CellTower tower = CellTower.from(mcc, mnc, lac, cid);
if (rssi != null) {
tower.setSignalStrength(rssi);
}
position.setNetwork(new Network(tower));
}
}
if (parser.hasNext(5)) {
position.set(Position.KEY_INPUT, parser.nextBinInt(0));
position.set(Position.KEY_OUTPUT, parser.nextBinInt(0));
for (int i = 1; i <= 3; i++) {
position.set(Position.PREFIX_ADC + i, parser.nextInt(0));
}
}
if (parser.hasNext(5)) {
position.set(Position.KEY_HEART_RATE, parser.nextInt());
position.set(Position.KEY_STEPS, parser.nextInt());
position.set("activityTime", parser.nextInt());
position.set("lightSleepTime", parser.nextInt());
position.set("deepSleepTime", parser.nextInt());
}
for (int i = 1; i <= 2; i++) {
String adc = parser.next();
if (adc != null) {
position.set(Position.PREFIX_TEMP + i, Double.parseDouble(adc));
}
}
position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
if (parser.hasNext()) {
position.set(Position.KEY_CHARGE, parser.nextInt() > 0);
}
if (parser.hasNext()) {
position.set("belt", parser.nextInt());
}
String battery = parser.next();
if (battery != null) {
position.set(Position.KEY_BATTERY, Integer.parseInt(battery));
}
position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
return position;
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class FlexApiProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String message = (String) msg;
JsonObject root = Json.createReader(new StringReader(message.substring(1, message.length() - 2))).readObject();
String topic = root.getString("topic");
String clientId = topic.substring(3, topic.indexOf('/', 3));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, clientId);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
JsonObject payload = root.getJsonObject("payload");
if (topic.contains("/gnss/")) {
position.setValid(true);
if (payload.containsKey("time")) {
position.setTime(new Date(payload.getInt("time") * 1000L));
position.setLatitude(payload.getJsonNumber("lat").doubleValue());
position.setLongitude(payload.getJsonNumber("log").doubleValue());
} else {
position.setTime(new Date(payload.getInt("gnss.ts") * 1000L));
position.setLatitude(payload.getJsonNumber("gnss.latitude").doubleValue());
position.setLongitude(payload.getJsonNumber("gnss.longitude").doubleValue());
}
position.setValid(payload.getInt("gnss.fix") > 0);
position.setAltitude(payload.getJsonNumber("gnss.altitude").doubleValue());
position.setSpeed(payload.getJsonNumber("gnss.speed").doubleValue());
position.setCourse(payload.getJsonNumber("gnss.heading").doubleValue());
position.set(Position.KEY_SATELLITES, payload.getInt("gnss.num_sv"));
position.set(Position.KEY_HDOP, payload.getJsonNumber("gnss.hdop").doubleValue());
} else if (topic.contains("/cellular1/")) {
getLastLocation(position, new Date(payload.getInt("modem1.ts") * 1000L));
position.set("imei", payload.getString("modem1.imei"));
position.set("imsi", payload.getString("modem1.imsi"));
position.set(Position.KEY_ICCID, payload.getString("modem1.iccid"));
String operator = payload.getString("modem1.operator");
if (!operator.isEmpty()) {
CellTower cellTower = CellTower.from(Integer.parseInt(operator.substring(0, 3)), Integer.parseInt(operator.substring(3)), Integer.parseInt(payload.getString("modem1.lac"), 16), Integer.parseInt(payload.getString("modem1.cell_id"), 16), payload.getInt("modem1.rssi"));
switch(payload.getInt("modem1.network")) {
case 1:
cellTower.setRadioType("gsm");
break;
case 2:
cellTower.setRadioType("wcdma");
break;
case 3:
cellTower.setRadioType("lte");
break;
default:
break;
}
position.setNetwork(new Network(cellTower));
}
} else if (topic.contains("/obd/")) {
getLastLocation(position, new Date(payload.getInt("obd.ts") * 1000L));
if (payload.containsKey("obd.speed")) {
position.set(Position.KEY_OBD_SPEED, payload.getJsonNumber("obd.speed").doubleValue());
}
if (payload.containsKey("obd.odo")) {
position.set(Position.KEY_OBD_ODOMETER, payload.getInt("obd.odo"));
}
if (payload.containsKey("obd.rpm")) {
position.set(Position.KEY_RPM, payload.getInt("obd.rpm"));
}
if (payload.containsKey("obd.vin")) {
position.set(Position.KEY_VIN, payload.getString("obd.vin"));
}
} else if (topic.contains("/motion/")) {
getLastLocation(position, new Date(payload.getInt("motion.ts") * 1000L));
position.set("ax", payload.getJsonNumber("motion.ax").doubleValue());
position.set("ay", payload.getJsonNumber("motion.ay").doubleValue());
position.set("az", payload.getJsonNumber("motion.az").doubleValue());
position.set("gx", payload.getJsonNumber("motion.gx").doubleValue());
position.set("gy", payload.getJsonNumber("motion.gy").doubleValue());
position.set("gz", payload.getJsonNumber("motion.gz").doubleValue());
} else if (topic.contains("/io/")) {
getLastLocation(position, new Date(payload.getInt("io.ts") * 1000L));
if (payload.containsKey("io.IGT")) {
position.set(Position.KEY_IGNITION, payload.getInt("io.IGT") > 0);
}
for (String key : payload.keySet()) {
if (key.startsWith("io.AI")) {
position.set(Position.PREFIX_ADC + key.substring(5), payload.getJsonNumber(key).doubleValue());
} else if (key.startsWith("io.DI") && !key.endsWith("_pullup")) {
position.set(Position.PREFIX_IN + key.substring(5), payload.getInt(key) > 0);
} else if (key.startsWith("io.DO")) {
position.set(Position.PREFIX_OUT + key.substring(5), payload.getInt(key) > 0);
}
}
} else if (topic.contains("/sysinfo/")) {
getLastLocation(position, new Date(payload.getInt("sysinfo.ts") * 1000L));
position.set("serial", payload.getString("sysinfo.serial_number"));
position.set(Position.KEY_VERSION_FW, payload.getString("sysinfo.firmware_version"));
} else {
return null;
}
return position;
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class AtrackProtocolDecoder method readTextCustomData.
private void readTextCustomData(Position position, String data, String form) {
CellTower cellTower = new CellTower();
String[] keys = form.substring(1).split("%");
String[] values = data.split(",|\r\n");
for (int i = 0; i < Math.min(keys.length, values.length); i++) {
switch(keys[i]) {
case "SA":
position.set(Position.KEY_SATELLITES, Integer.parseInt(values[i]));
break;
case "MV":
position.set(Position.KEY_POWER, Integer.parseInt(values[i]) * 0.1);
break;
case "BV":
position.set(Position.KEY_BATTERY, Integer.parseInt(values[i]) * 0.1);
break;
case "GQ":
cellTower.setSignalStrength(Integer.parseInt(values[i]));
break;
case "CE":
cellTower.setCellId(Long.parseLong(values[i]));
break;
case "LC":
cellTower.setLocationAreaCode(Integer.parseInt(values[i]));
break;
case "CN":
if (values[i].length() > 3) {
cellTower.setMobileCountryCode(Integer.parseInt(values[i].substring(0, 3)));
cellTower.setMobileNetworkCode(Integer.parseInt(values[i].substring(3)));
}
break;
case "PC":
position.set(Position.PREFIX_COUNT + 1, Integer.parseInt(values[i]));
break;
case "AT":
position.setAltitude(Integer.parseInt(values[i]));
break;
case "RP":
position.set(Position.KEY_RPM, Integer.parseInt(values[i]));
break;
case "GS":
position.set(Position.KEY_RSSI, Integer.parseInt(values[i]));
break;
case "DT":
position.set(Position.KEY_ARCHIVE, Integer.parseInt(values[i]) == 1);
break;
case "VN":
position.set(Position.KEY_VIN, values[i]);
break;
case "TR":
position.set(Position.KEY_THROTTLE, Integer.parseInt(values[i]));
break;
case "ET":
position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[i]));
break;
case "FL":
position.set(Position.KEY_FUEL_LEVEL, Integer.parseInt(values[i]));
break;
case "FC":
position.set(Position.KEY_FUEL_CONSUMPTION, Integer.parseInt(values[i]));
break;
case "AV1":
position.set(Position.PREFIX_ADC + 1, Integer.parseInt(values[i]));
break;
case "CD":
position.set(Position.KEY_ICCID, values[i]);
break;
case "EH":
position.set(Position.KEY_HOURS, UnitsConverter.msFromHours(Integer.parseInt(values[i]) * 0.1));
break;
case "IA":
position.set("intakeTemp", Integer.parseInt(values[i]));
break;
case "EL":
position.set(Position.KEY_ENGINE_LOAD, Integer.parseInt(values[i]));
break;
case "HA":
if (Integer.parseInt(values[i]) > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
}
break;
case "HB":
if (Integer.parseInt(values[i]) > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
}
break;
case "HC":
if (Integer.parseInt(values[i]) > 0) {
position.set(Position.KEY_ALARM, Position.ALARM_CORNERING);
}
break;
case "MT":
position.set(Position.KEY_MOTION, Integer.parseInt(values[i]) > 0);
break;
case "BC":
String[] beaconValues = values[i].split(":");
decodeBeaconData(position, Integer.parseInt(beaconValues[0]), Integer.parseInt(beaconValues[1]), Unpooled.wrappedBuffer(DataConverter.parseHex(beaconValues[2])));
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