use of org.traccar.DeviceSession in project traccar by tananaev.
the class SuntechProtocolDecoder method decode9.
private Position decode9(Channel channel, SocketAddress remoteAddress, String[] values) throws ParseException {
int index = 1;
String type = values[index++];
if (!type.equals("Location") && !type.equals("Emergency") && !type.equals("Alert")) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (type.equals("Emergency") || type.equals("Alert")) {
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
}
if (!type.equals("Alert") || protocolType == 0) {
position.set(Position.KEY_VERSION_FW, values[index++]);
}
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
position.setTime(dateFormat.parse(values[index++] + values[index++]));
if (protocolType == 1) {
// cell
index += 1;
}
position.setLatitude(Double.parseDouble(values[index++]));
position.setLongitude(Double.parseDouble(values[index++]));
position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++])));
position.setCourse(Double.parseDouble(values[index++]));
position.setValid(values[index++].equals("1"));
if (protocolType == 1) {
position.set(Position.KEY_ODOMETER, Integer.parseInt(values[index++]));
}
return position;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class T800xProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
buf.skipBytes(2);
int type = buf.readUnsignedByte();
// length
buf.readUnsignedShort();
int index = buf.readUnsignedShort();
ChannelBuffer imei = buf.readBytes(8);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(imei).substring(1));
if (deviceSession == null) {
return null;
}
if (type == MSG_LOGIN || type == MSG_ALARM || type == MSG_HEARTBEAT) {
sendResponse(channel, type, imei);
}
if (type == MSG_GPS || type == MSG_ALARM) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_INDEX, index);
// acc on interval
buf.readUnsignedShort();
// acc off interval
buf.readUnsignedShort();
// angle compensation
buf.readUnsignedByte();
// distance compensation
buf.readUnsignedShort();
// speed alarm
buf.readUnsignedShort();
int locationStatus = buf.readUnsignedByte();
// gsensor manager status
buf.readUnsignedByte();
// other flags
buf.readUnsignedByte();
// heartbeat
buf.readUnsignedByte();
// relay status
buf.readUnsignedByte();
// drag alarm setting
buf.readUnsignedShort();
int io = buf.readUnsignedShort();
position.set(Position.KEY_IGNITION, BitUtil.check(io, 14));
position.set("ac", BitUtil.check(io, 13));
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
position.set(Position.PREFIX_ADC + 2, buf.readUnsignedShort());
position.set(Position.KEY_ALARM, decodeAlarm(buf.readUnsignedByte()));
// reserved
buf.readUnsignedByte();
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
int battery = BcdUtil.readInteger(buf, 2);
if (battery == 0) {
battery = 100;
}
position.set(Position.KEY_BATTERY, battery);
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));
if (BitUtil.check(locationStatus, 6)) {
position.setValid(!BitUtil.check(locationStatus, 7));
position.setTime(dateBuilder.getDate());
position.setAltitude(readSwappedFloat(buf));
position.setLongitude(readSwappedFloat(buf));
position.setLatitude(readSwappedFloat(buf));
position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4) * 0.1));
position.setCourse(buf.readUnsignedShort());
} else {
getLastLocation(position, dateBuilder.getDate());
byte[] array = new byte[16];
buf.readBytes(array);
ChannelBuffer swapped = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, array);
position.setNetwork(new Network(CellTower.from(swapped.readUnsignedShort(), swapped.readUnsignedShort(), swapped.readUnsignedShort(), swapped.readUnsignedShort())));
// two more cell towers
}
return position;
}
return null;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class TeltonikaProtocolDecoder method parseIdentification.
private DeviceSession parseIdentification(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
int length = buf.readUnsignedShort();
String imei = buf.toString(buf.readerIndex(), length, StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (channel != null) {
ChannelBuffer response = ChannelBuffers.directBuffer(1);
if (deviceSession != null) {
response.writeByte(1);
} else {
response.writeByte(0);
}
channel.write(response);
}
return deviceSession;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class Tk103ProtocolDecoder method decodeBattery.
private Position decodeBattery(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_BATTERY, 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());
getLastLocation(position, parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
int batterylevel = parser.nextInt(0);
if (batterylevel != 255) {
position.set(Position.KEY_BATTERY_LEVEL, decodeBattery(batterylevel));
}
int battery = parser.nextInt(0);
if (battery != 65535) {
position.set(Position.KEY_BATTERY, battery * 0.01);
}
int power = parser.nextInt(0);
if (power != 65535) {
position.set(Position.KEY_POWER, power * 0.1);
}
return position;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class Tk103ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (channel != null) {
String id = sentence.substring(1, 13);
String type = sentence.substring(13, 17);
if (type.equals("BP00")) {
channel.write("(" + id + "AP01HSO)");
return null;
} else if (type.equals("BP05")) {
channel.write("(" + id + "AP05)");
}
}
if (sentence.contains("ZC20")) {
return decodeBattery(channel, remoteAddress, sentence);
} else if (sentence.contains("BZ00")) {
return decodeNetwork(channel, remoteAddress, sentence);
} else if (sentence.contains("ZC03")) {
return decodeCommandResult(channel, remoteAddress, sentence);
} else if (sentence.contains("DW5")) {
return decodeLbsWifi(channel, remoteAddress, sentence);
}
Parser parser = new Parser(PATTERN, 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());
boolean alternative = parser.next() != null;
decodeType(position, parser.next(), parser.next());
DateBuilder dateBuilder = new DateBuilder();
if (alternative) {
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
} else {
dateBuilder.setDate(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
}
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(convertSpeed(parser.nextDouble(0), "kmh"));
dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
position.setCourse(parser.nextDouble(0));
if (parser.hasNext(6)) {
position.set(Position.KEY_CHARGE, parser.nextInt() == 0);
position.set(Position.KEY_IGNITION, parser.nextInt() == 1);
int mask1 = parser.nextHexInt();
position.set(Position.PREFIX_IN + 2, BitUtil.check(mask1, 0) ? 1 : 0);
position.set("panic", BitUtil.check(mask1, 1) ? 1 : 0);
position.set(Position.PREFIX_OUT + 2, BitUtil.check(mask1, 2) ? 1 : 0);
if (decodeLow || BitUtil.check(mask1, 3)) {
position.set(Position.KEY_BLOCKED, BitUtil.check(mask1, 3) ? 1 : 0);
}
int mask2 = parser.nextHexInt();
for (int i = 0; i < 3; i++) {
if (decodeLow || BitUtil.check(mask2, i)) {
position.set("hs" + (3 - i), BitUtil.check(mask2, i) ? 1 : 0);
}
}
if (decodeLow || BitUtil.check(mask2, 3)) {
position.set(Position.KEY_DOOR, BitUtil.check(mask2, 3) ? 1 : 0);
}
int mask3 = parser.nextHexInt();
for (int i = 1; i <= 3; i++) {
if (decodeLow || BitUtil.check(mask3, i)) {
position.set("ls" + (3 - i + 1), BitUtil.check(mask3, i) ? 1 : 0);
}
}
position.set(Position.KEY_FUEL_LEVEL, parser.nextHexInt());
}
if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER, parser.nextLong(16, 0));
}
if (parser.hasNext()) {
position.set(Position.PREFIX_TEMP + 1, parser.nextDouble(0));
}
if (parser.hasNext()) {
position.setAltitude(parser.nextDouble(0));
}
if (parser.hasNext()) {
position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0));
}
return position;
}
Aggregations