use of org.traccar.model.Network in project traccar by tananaev.
the class Gt06ProtocolDecoder method decodeWifi.
private Object decodeWifi(ChannelBuffer buf, DeviceSession deviceSession) throws Exception {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setYear(BcdUtil.readInteger(buf, 2)).setMonth(BcdUtil.readInteger(buf, 2)).setDay(BcdUtil.readInteger(buf, 2)).setHour(BcdUtil.readInteger(buf, 2)).setMinute(BcdUtil.readInteger(buf, 2)).setSecond(BcdUtil.readInteger(buf, 2));
getLastLocation(position, dateBuilder.getDate());
Network network = new Network();
int wifiCount = buf.getByte(2);
for (int i = 0; i < wifiCount; i++) {
String mac = String.format("%02x:%02x:%02x:%02x:%02x:%02x", buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
network.addWifiAccessPoint(WifiAccessPoint.from(mac, buf.readUnsignedByte()));
}
int cellCount = buf.readUnsignedByte();
int mcc = buf.readUnsignedShort();
int mnc = buf.readUnsignedByte();
for (int i = 0; i < cellCount; i++) {
network.addCellTower(CellTower.from(mcc, mnc, buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedByte()));
}
position.setNetwork(network);
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Gt06ProtocolDecoder method decodeBasicOther.
private Object decodeBasicOther(Channel channel, ChannelBuffer buf, DeviceSession deviceSession, int type, int dataLength) throws Exception {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (type == MSG_LBS_MULTIPLE || type == MSG_LBS_EXTEND || type == MSG_LBS_WIFI || type == MSG_LBS_2 || type == MSG_WIFI_3) {
boolean longFormat = type == MSG_LBS_2 || type == MSG_WIFI_3;
DateBuilder dateBuilder = new DateBuilder(deviceSession.getTimeZone()).setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
getLastLocation(position, dateBuilder.getDate());
int mcc = buf.readUnsignedShort();
int mnc = BitUtil.check(mcc, 15) ? buf.readUnsignedShort() : buf.readUnsignedByte();
Network network = new Network();
for (int i = 0; i < 7; i++) {
int lac = longFormat ? buf.readInt() : buf.readUnsignedShort();
int cid = longFormat ? (int) buf.readLong() : buf.readUnsignedMedium();
int rssi = -buf.readUnsignedByte();
if (lac > 0) {
network.addCellTower(CellTower.from(BitUtil.to(mcc, 15), mnc, lac, cid, rssi));
}
}
// time leads
buf.readUnsignedByte();
if (type != MSG_LBS_MULTIPLE && type != MSG_LBS_2) {
int wifiCount = buf.readUnsignedByte();
for (int i = 0; i < wifiCount; i++) {
String mac = ChannelBuffers.hexDump(buf.readBytes(6)).replaceAll("(..)", "$1:");
network.addWifiAccessPoint(WifiAccessPoint.from(mac.substring(0, mac.length() - 1), buf.readUnsignedByte()));
}
}
position.setNetwork(network);
} else if (type == MSG_STRING) {
getLastLocation(position, null);
int commandLength = buf.readUnsignedByte();
if (commandLength > 0) {
// server flag (reserved)
buf.readUnsignedByte();
position.set(Position.KEY_RESULT, buf.readBytes(commandLength - 1).toString(StandardCharsets.US_ASCII));
}
} else if (isSupported(type)) {
if (hasGps(type)) {
decodeGps(position, buf, false, deviceSession.getTimeZone());
} else {
getLastLocation(position, null);
}
if (hasLbs(type)) {
decodeLbs(position, buf, hasStatus(type));
}
if (hasStatus(type)) {
decodeStatus(position, buf);
}
if (type == MSG_GPS_LBS_1 && buf.readableBytes() >= 4 + 6) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
}
if (type == MSG_GPS_LBS_2 && buf.readableBytes() >= 3 + 6) {
position.set(Position.KEY_IGNITION, buf.readUnsignedByte() > 0);
// reason
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() > 0);
}
} else {
buf.skipBytes(dataLength);
if (type != MSG_COMMAND_0 && type != MSG_COMMAND_1 && type != MSG_COMMAND_2) {
sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null);
}
return null;
}
if (hasLanguage(type)) {
buf.readUnsignedShort();
}
if (type == MSG_GPS_LBS_STATUS_3 || type == MSG_FENCE_MULTI) {
position.set(Position.KEY_GEOFENCE, buf.readUnsignedByte());
}
sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null);
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Gt06ProtocolDecoder method decodeLbs.
private boolean decodeLbs(Position position, ChannelBuffer buf, boolean hasLength) {
int length = 0;
if (hasLength) {
length = buf.readUnsignedByte();
if (length == 0) {
return false;
}
}
int mcc = buf.readUnsignedShort();
int mnc = BitUtil.check(mcc, 15) ? buf.readUnsignedShort() : buf.readUnsignedByte();
position.setNetwork(new Network(CellTower.from(BitUtil.to(mcc, 15), mnc, buf.readUnsignedShort(), buf.readUnsignedMedium())));
if (length > 0) {
buf.skipBytes(length - (hasLength ? 9 : 8));
}
return true;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class H02ProtocolDecoder method decodeLbs.
private Position decodeLbs(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN_NBR, 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());
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
Network network = new Network();
int mcc = parser.nextInt(0);
int mnc = parser.nextInt(0);
String[] cells = parser.next().split(",");
for (int i = 0; i < cells.length / 3; i++) {
network.addCellTower(CellTower.from(mcc, mnc, Integer.parseInt(cells[i * 3]), Integer.parseInt(cells[i * 3 + 1]), Integer.parseInt(cells[i * 3 + 2])));
}
position.setNetwork(network);
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
getLastLocation(position, dateBuilder.getDate());
processStatus(position, parser.nextLong(16, 0));
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Jt600ProtocolDecoder method decodeBinary.
private List<Position> decodeBinary(ChannelBuffer buf, Channel channel, SocketAddress remoteAddress) {
List<Position> positions = new LinkedList<>();
// header
buf.readByte();
boolean longFormat = buf.getUnsignedByte(buf.readerIndex()) == 0x75;
String id = String.valueOf(Long.parseLong(ChannelBuffers.hexDump(buf.readBytes(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();
while (buf.readableBytes() > 1) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setDay(BcdUtil.readInteger(buf, 2)).setMonth(BcdUtil.readInteger(buf, 2)).setYear(BcdUtil.readInteger(buf, 2)).setHour(BcdUtil.readInteger(buf, 2)).setMinute(BcdUtil.readInteger(buf, 2)).setSecond(BcdUtil.readInteger(buf, 2));
position.setTime(dateBuilder.getDate());
double latitude = convertCoordinate(BcdUtil.readInteger(buf, 8));
double longitude = convertCoordinate(BcdUtil.readInteger(buf, 9));
byte flags = buf.readByte();
position.setValid((flags & 0x1) == 0x1);
if ((flags & 0x2) == 0) {
latitude = -latitude;
}
position.setLatitude(latitude);
if ((flags & 0x4) == 0) {
longitude = -longitude;
}
position.setLongitude(longitude);
position.setSpeed(BcdUtil.readInteger(buf, 2));
position.setCourse(buf.readUnsignedByte() * 2.0);
if (longFormat) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 1000);
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
// vehicle id combined
buf.readUnsignedInt();
position.set(Position.KEY_STATUS, buf.readUnsignedShort());
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) {
// geofence id
buf.readUnsignedByte();
// reserved
buf.skipBytes(3);
}
} 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;
position.set(Position.KEY_STATUS, buf.readUnsignedInt());
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);
}
// index
buf.readUnsignedByte();
return positions;
}
Aggregations