use of org.traccar.model.Network in project traccar by tananaev.
the class L100ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// start marker
buf.readUnsignedByte();
// type
buf.readUnsignedByte();
String sentence = buf.readBytes(buf.readableBytes() - 2).toString(StandardCharsets.US_ASCII);
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), 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(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
position.set(Position.KEY_STATUS, parser.next());
position.set(Position.PREFIX_ADC + 1, parser.next());
position.set(Position.KEY_ODOMETER, parser.nextDouble(0));
position.set(Position.PREFIX_TEMP + 1, parser.nextDouble(0));
position.set(Position.KEY_BATTERY, parser.nextDouble(0));
int rssi = parser.nextInt(0);
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), rssi)));
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class LaipacProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.startsWith("$ECHK") && channel != null) {
// heartbeat
channel.write(sentence + "\r\n");
return null;
}
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());
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
String status = parser.next();
position.setValid(status.toUpperCase().equals("A"));
position.set(Position.KEY_STATUS, status);
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
String event = parser.next();
position.set(Position.KEY_ALARM, decodeAlarm(event));
position.set(Position.KEY_EVENT, event);
position.set(Position.KEY_BATTERY, Double.parseDouble(parser.next().replaceAll("\\.", "")) * 0.001);
position.set(Position.KEY_ODOMETER, parser.nextDouble());
position.set(Position.KEY_GPS, parser.nextInt());
position.set(Position.PREFIX_ADC + 1, parser.nextDouble() * 0.001);
position.set(Position.PREFIX_ADC + 2, parser.nextDouble() * 0.001);
Integer lac = parser.nextHexInt();
Integer cid = parser.nextHexInt();
Integer mcc = parser.nextInt();
Integer mnc = parser.nextInt();
if (lac != null && cid != null && mcc != null && mnc != null) {
position.setNetwork(new Network(CellTower.from(mcc, mnc, lac, cid)));
}
String checksum = parser.next();
if (channel != null) {
if (event.equals("3")) {
channel.write("$AVCFG,00000000,d*31\r\n");
} else if (event.equals("X") || event.equals("4")) {
channel.write("$AVCFG,00000000,x*2D\r\n");
} else if (event.equals("Z")) {
channel.write("$AVCFG,00000000,z*2F\r\n");
} else if (Character.isLowerCase(status.charAt(0))) {
String response = "$EAVACK," + event + "," + checksum;
response += Checksum.nmea(response) + "\r\n";
channel.write(response);
}
}
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class MegastekProtocolDecoder method decodeOld.
private Position decodeOld(Channel channel, SocketAddress remoteAddress, String sentence) {
// Detect type
boolean simple = sentence.charAt(3) == ',' || sentence.charAt(6) == ',';
// Split message
String id;
String location;
String status;
if (simple) {
int beginIndex = sentence.indexOf(',') + 1;
int endIndex = sentence.indexOf(',', beginIndex);
id = sentence.substring(beginIndex, endIndex);
beginIndex = endIndex + 1;
endIndex = sentence.indexOf('*', beginIndex);
if (endIndex != -1) {
endIndex += 3;
} else {
endIndex = sentence.length();
}
location = sentence.substring(beginIndex, endIndex);
beginIndex = endIndex + 1;
if (beginIndex > sentence.length()) {
beginIndex = endIndex;
}
status = sentence.substring(beginIndex);
} else {
int beginIndex = 3;
int endIndex = beginIndex + 16;
id = sentence.substring(beginIndex, endIndex).trim();
beginIndex = endIndex + 2;
endIndex = sentence.indexOf('*', beginIndex) + 3;
location = sentence.substring(beginIndex, endIndex);
beginIndex = endIndex + 1;
status = sentence.substring(beginIndex);
}
Position position = new Position(getProtocolName());
if (!parseLocation(location, position)) {
return null;
}
if (simple) {
Parser parser = new Parser(PATTERN_SIMPLE, status);
if (parser.matches()) {
position.set(Position.KEY_ALARM, decodeAlarm(parser.next()));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next(), id);
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
String sat = parser.next();
if (sat.contains("/")) {
position.set(Position.KEY_SATELLITES, Integer.parseInt(sat.split("/")[0]));
position.set(Position.KEY_SATELLITES_VISIBLE, Integer.parseInt(sat.split("/")[1]));
} else {
position.set(Position.KEY_SATELLITES, Integer.parseInt(sat));
}
position.setAltitude(parser.nextDouble(0));
position.set(Position.KEY_BATTERY_LEVEL, parser.nextDouble(0));
String charger = parser.next();
if (charger != null) {
position.set(Position.KEY_CHARGE, Integer.parseInt(charger) == 1);
}
if (parser.hasNext(4)) {
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
}
} else {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
}
} else {
Parser parser = new Parser(PATTERN_ALTERNATIVE, status);
if (parser.matches()) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, id);
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), parser.nextInt(0))));
position.set(Position.KEY_BATTERY_LEVEL, parser.nextDouble());
position.set(Position.KEY_FLAGS, parser.next());
position.set(Position.KEY_INPUT, parser.next());
position.set(Position.KEY_OUTPUT, parser.next());
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.KEY_ALARM, decodeAlarm(parser.next()));
}
}
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class WatchProtocolDecoder method decodePosition.
private Position decodePosition(DeviceSession deviceSession, String data) {
Parser parser = new Parser(PATTERN_POSITION, data);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_RSSI, parser.nextInt(0));
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
position.set(Position.KEY_STEPS, parser.nextInt(0));
int status = parser.nextHexInt(0);
position.set(Position.KEY_ALARM, decodeAlarm(status));
if (BitUtil.check(status, 4)) {
position.set(Position.KEY_MOTION, true);
}
String[] values = parser.next().split(",");
int index = 0;
Network network = new Network();
int cellCount = Integer.parseInt(values[index++]);
// timing advance
index += 1;
int mcc = Integer.parseInt(values[index++]);
int mnc = Integer.parseInt(values[index++]);
for (int i = 0; i < cellCount; i++) {
network.addCellTower(CellTower.from(mcc, mnc, Integer.parseInt(values[index++]), Integer.parseInt(values[index++]), Integer.parseInt(values[index++])));
}
if (index < values.length && !values[index].isEmpty()) {
int wifiCount = Integer.parseInt(values[index++]);
for (int i = 0; i < wifiCount; i++) {
// wifi name
index += 1;
network.addWifiAccessPoint(WifiAccessPoint.from(values[index++], Integer.parseInt(values[index++])));
}
}
if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
position.setNetwork(network);
}
return position;
}
use of org.traccar.model.Network 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);
}
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0), parser.nextInt(0))));
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));
}
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());
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;
}
Aggregations