use of org.traccar.model.CellTower in project traccar by tananaev.
the class AtrackProtocolDecoder method readBinaryCustomData.
private void readBinaryCustomData(Position position, ByteBuf 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() * 0.1);
break;
case "BV":
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.1);
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;
case "PD":
// pending code status
buf.readUnsignedByte();
break;
case "CD":
position.set(Position.KEY_ICCID, readString(buf));
break;
case "CM":
// imsi
buf.readLong();
break;
case "GN":
// g sensor data
buf.skipBytes(60);
break;
case "GV":
// maximum g force
buf.skipBytes(6);
break;
case "ME":
// imei
buf.readLong();
break;
case "IA":
// intake air temperature
buf.readUnsignedByte();
break;
case "MP":
// manifold absolute pressure
buf.readUnsignedByte();
break;
default:
break;
}
}
if (cellTower.getMobileCountryCode() != null && cellTower.getMobileNetworkCode() != null && cellTower.getCellId() != null && cellTower.getCellId() != 0 && cellTower.getLocationAreaCode() != null) {
position.setNetwork(new Network(cellTower));
} else if (cellTower.getSignalStrength() != null) {
position.set(Position.KEY_RSSI, cellTower.getSignalStrength());
}
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class Pt60ProtocolDecoder 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;
}
String format = parser.next();
int type = parser.nextInt();
String imei = parser.next();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
sendResponse(channel, remoteAddress, format, type, imei);
if (format.equals("G")) {
if (type != MSG_G_TRACK && type != MSG_G_STEP_COUNT && type != MSG_G_HEART_RATE) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setDeviceTime(parser.nextDateTime());
String[] values = parser.next().split(",");
if (type == MSG_G_TRACK) {
position.setValid(true);
position.setFixTime(position.getDeviceTime());
String[] coordinates = values[0].split(";");
position.setLatitude(Double.parseDouble(coordinates[0]));
position.setLongitude(Double.parseDouble(coordinates[1]));
} else {
getLastLocation(position, position.getDeviceTime());
switch(type) {
case MSG_G_STEP_COUNT:
position.set(Position.KEY_STEPS, Integer.parseInt(values[0]));
break;
case MSG_G_HEART_RATE:
position.set(Position.KEY_HEART_RATE, Integer.parseInt(values[0]));
position.set(Position.KEY_BATTERY, Integer.parseInt(values[1]));
break;
default:
break;
}
}
return position;
} else {
if (type != MSG_B_POSITION) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setDeviceTime(parser.nextDateTime());
String[] values = parser.next().split("\\|");
if (Integer.parseInt(values[values.length - 1]) == 2) {
getLastLocation(position, position.getDeviceTime());
Network network = new Network();
for (int i = 0; i < values.length - 1; i++) {
String[] cellValues = values[i].split(",");
CellTower tower = new CellTower();
tower.setCellId(Long.parseLong(cellValues[0]));
tower.setLocationAreaCode(Integer.parseInt(cellValues[1]));
tower.setMobileNetworkCode(Integer.parseInt(cellValues[2]));
tower.setMobileCountryCode(Integer.parseInt(cellValues[3]));
tower.setSignalStrength(Integer.parseInt(cellValues[4]));
network.addCellTower(tower);
}
position.setNetwork(network);
} else {
position.setValid(true);
position.setFixTime(position.getDeviceTime());
position.setLatitude(Double.parseDouble(values[0]));
position.setLongitude(Double.parseDouble(values[1]));
}
return position;
}
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class Gt06ProtocolDecoder method decodeExtendedModular.
private Object decodeExtendedModular(Channel channel, ByteBuf buf, DeviceSession deviceSession) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
while (buf.readableBytes() > 6) {
int moduleType = buf.readUnsignedShort();
int moduleLength = buf.readUnsignedShort();
switch(moduleType) {
case 0x03:
position.set(Position.KEY_ICCID, ByteBufUtil.hexDump(buf.readSlice(10)));
break;
case 0x09:
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
break;
case 0x0a:
position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
break;
case 0x11:
CellTower cellTower = CellTower.from(buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedMedium(), buf.readUnsignedByte());
if (cellTower.getCellId() > 0) {
position.setNetwork(new Network(cellTower));
}
break;
case 0x18:
position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.01);
break;
case 0x28:
position.set(Position.KEY_HDOP, buf.readUnsignedByte() * 0.1);
break;
case 0x29:
position.set(Position.KEY_INDEX, buf.readUnsignedInt());
break;
case 0x2a:
int input = buf.readUnsignedByte();
position.set(Position.KEY_DOOR, BitUtil.to(input, 4) > 0);
position.set("tamper", BitUtil.from(input, 4) > 0);
break;
case 0x2b:
int event = buf.readUnsignedByte();
switch(event) {
case 0x11:
position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
break;
case 0x12:
position.set(Position.KEY_ALARM, Position.ALARM_LOW_POWER);
break;
case 0x13:
position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
break;
case 0x14:
position.set(Position.KEY_ALARM, Position.ALARM_REMOVING);
break;
default:
break;
}
position.set(Position.KEY_EVENT, event);
break;
case 0x2e:
position.set(Position.KEY_ODOMETER, buf.readUnsignedIntLE());
break;
case 0x33:
position.setTime(new Date(buf.readUnsignedInt() * 1000));
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
position.setAltitude(buf.readShort());
double latitude = buf.readUnsignedInt() / 60.0 / 30000.0;
double longitude = buf.readUnsignedInt() / 60.0 / 30000.0;
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
int flags = buf.readUnsignedShort();
position.setCourse(BitUtil.to(flags, 10));
position.setValid(BitUtil.check(flags, 12));
if (!BitUtil.check(flags, 10)) {
latitude = -latitude;
}
if (BitUtil.check(flags, 11)) {
longitude = -longitude;
}
position.setLatitude(latitude);
position.setLongitude(longitude);
break;
case 0x34:
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
// time
buf.readUnsignedIntLE();
// content
buf.skipBytes(buf.readUnsignedByte());
break;
default:
buf.skipBytes(moduleLength);
break;
}
}
if (position.getFixTime() == null) {
getLastLocation(position, null);
}
sendResponse(channel, false, MSG_GPS_MODULAR, buf.readUnsignedShort(), null);
return position;
}
use of org.traccar.model.CellTower in project traccar by tananaev.
the class ProtocolTest method verifyDecodedPosition.
private void verifyDecodedPosition(Object decodedObject, boolean checkLocation, boolean checkAttributes, Position expected) {
assertNotNull("position is null", decodedObject);
assertTrue("not a position", decodedObject instanceof Position);
Position position = (Position) decodedObject;
if (checkLocation) {
if (expected != null) {
if (expected.getFixTime() != null) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
assertEquals("time", dateFormat.format(expected.getFixTime()), dateFormat.format(position.getFixTime()));
}
assertEquals("valid", expected.getValid(), position.getValid());
assertEquals("latitude", expected.getLatitude(), position.getLatitude(), 0.00001);
assertEquals("longitude", expected.getLongitude(), position.getLongitude(), 0.00001);
} else {
assertNotNull(position.getServerTime());
assertNotNull(position.getFixTime());
assertTrue("year > 1999", position.getFixTime().after(new Date(915148800000L)));
assertTrue("time < +25 hours", position.getFixTime().getTime() < System.currentTimeMillis() + 25 * 3600000);
assertTrue("latitude >= -90", position.getLatitude() >= -90);
assertTrue("latitude <= 90", position.getLatitude() <= 90);
assertTrue("longitude >= -180", position.getLongitude() >= -180);
assertTrue("longitude <= 180", position.getLongitude() <= 180);
}
assertTrue("altitude >= -12262", position.getAltitude() >= -12262);
assertTrue("altitude <= 18000", position.getAltitude() <= 18000);
assertTrue("speed >= 0", position.getSpeed() >= 0);
assertTrue("speed <= 869", position.getSpeed() <= 869);
assertTrue("course >= 0", position.getCourse() >= 0);
assertTrue("course <= 360", position.getCourse() <= 360);
assertNotNull("protocol is null", position.getProtocol());
assertTrue("deviceId > 0", position.getDeviceId() > 0);
}
Map<String, Object> attributes = position.getAttributes();
if (checkAttributes) {
assertFalse("no attributes", attributes.isEmpty());
}
if (attributes.containsKey(Position.KEY_INDEX)) {
assertTrue(attributes.get(Position.KEY_INDEX) instanceof Number);
}
if (attributes.containsKey(Position.KEY_HDOP)) {
assertTrue(attributes.get(Position.KEY_HDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_VDOP)) {
assertTrue(attributes.get(Position.KEY_VDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_PDOP)) {
assertTrue(attributes.get(Position.KEY_PDOP) instanceof Number);
}
if (attributes.containsKey(Position.KEY_SATELLITES)) {
assertTrue(attributes.get(Position.KEY_SATELLITES) instanceof Number);
}
if (attributes.containsKey(Position.KEY_SATELLITES_VISIBLE)) {
assertTrue(attributes.get(Position.KEY_SATELLITES_VISIBLE) instanceof Number);
}
if (attributes.containsKey(Position.KEY_RSSI)) {
assertTrue(attributes.get(Position.KEY_RSSI) instanceof Number);
}
if (attributes.containsKey(Position.KEY_ODOMETER)) {
assertTrue(attributes.get(Position.KEY_ODOMETER) instanceof Number);
}
if (attributes.containsKey(Position.KEY_RPM)) {
assertTrue(attributes.get(Position.KEY_RPM) instanceof Number);
}
if (attributes.containsKey(Position.KEY_FUEL_LEVEL)) {
assertTrue(attributes.get(Position.KEY_FUEL_LEVEL) instanceof Number);
}
if (attributes.containsKey(Position.KEY_POWER)) {
assertTrue(attributes.get(Position.KEY_POWER) instanceof Number);
}
if (attributes.containsKey(Position.KEY_BATTERY)) {
assertTrue(attributes.get(Position.KEY_BATTERY) instanceof Number);
}
if (attributes.containsKey(Position.KEY_BATTERY_LEVEL)) {
int batteryLevel = ((Number) attributes.get(Position.KEY_BATTERY_LEVEL)).intValue();
assertTrue(batteryLevel <= 100 && batteryLevel >= 0);
}
if (attributes.containsKey(Position.KEY_CHARGE)) {
assertTrue(attributes.get(Position.KEY_CHARGE) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_IGNITION)) {
assertTrue(attributes.get(Position.KEY_IGNITION) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_MOTION)) {
assertTrue(attributes.get(Position.KEY_MOTION) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_ARCHIVE)) {
assertTrue(attributes.get(Position.KEY_ARCHIVE) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_DRIVER_UNIQUE_ID)) {
assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String);
}
if (attributes.containsKey(Position.KEY_STEPS)) {
assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number);
}
if (attributes.containsKey(Position.KEY_ROAMING)) {
assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean);
}
if (attributes.containsKey(Position.KEY_HOURS)) {
assertTrue(attributes.get(Position.KEY_HOURS) instanceof Number);
}
if (attributes.containsKey(Position.KEY_RESULT)) {
assertTrue(attributes.get(Position.KEY_RESULT) instanceof String);
}
if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) {
for (CellTower cellTower : position.getNetwork().getCellTowers()) {
checkInteger(cellTower.getMobileCountryCode(), 0, 999);
checkInteger(cellTower.getMobileNetworkCode(), 0, 999);
checkInteger(cellTower.getLocationAreaCode(), 1, 65535);
checkInteger(cellTower.getCellId(), 0, 268435455);
}
}
}
Aggregations