use of org.traccar.model.Network in project traccar by tananaev.
the class FlexCommProtocolDecoder 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;
}
Position position = new Position(getProtocolName());
position.set(Position.KEY_STATUS, parser.nextInt());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("1"));
position.setLatitude(parseSignedValue(parser, 6));
position.setLongitude(parseSignedValue(parser, 6));
position.setAltitude(parseSignedValue(parser, 0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt()));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt());
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_RSSI, parser.nextInt());
position.setNetwork(new Network(CellTower.from(parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt())));
for (int i = 1; i <= 3; i++) {
position.set(Position.PREFIX_IN + i, parser.nextInt());
}
for (int i = 1; i <= 2; i++) {
position.set(Position.PREFIX_OUT + i, parser.nextInt());
}
position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
position.set(Position.PREFIX_TEMP + 1, parseSignedValue(parser, 0));
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
if (channel != null) {
channel.write("{01}");
}
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class FlextrackProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.contains("LOGON")) {
Parser parser = new Parser(PATTERN_LOGON, sentence);
if (!parser.matches()) {
return null;
}
sendAcknowledgement(channel, parser.next());
String id = parser.next();
String iccid = parser.next();
getDeviceSession(channel, remoteAddress, iccid, id);
} else if (sentence.contains("UNITSTAT")) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
sendAcknowledgement(channel, parser.next());
position.setTime(parser.nextDateTime());
position.setValid(true);
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
position.setCourse(parser.nextInt(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_BATTERY, parser.nextInt(0));
int rssi = parser.nextInt(0);
position.set(Position.KEY_STATUS, parser.nextHexInt(0));
int mcc = parser.nextInt(0);
int mnc = parser.nextInt(0);
position.setAltitude(parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextInt(0) * 0.1);
position.setNetwork(new Network(CellTower.from(mcc, mnc, parser.nextHexInt(0), parser.nextHexInt(0), rssi)));
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
return position;
}
return null;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decodeWif.
private Object decodeWif(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_WIF, sentence);
Position position = initPosition(parser, channel, remoteAddress);
if (position == null) {
return null;
}
getLastLocation(position, null);
Network network = new Network();
// count
parser.nextInt();
Matcher matcher = Pattern.compile("([0-9a-fA-F]{12}),(-?\\d+),,,,").matcher(parser.next());
while (matcher.find()) {
String mac = matcher.group(1).replaceAll("(..)", "$1:");
network.addWifiAccessPoint(WifiAccessPoint.from(mac.substring(0, mac.length() - 1), Integer.parseInt(matcher.group(2))));
}
position.setNetwork(network);
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decodeBasic.
private Object decodeBasic(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
Parser parser = new Parser(PATTERN_BASIC, sentence);
Position position = initPosition(parser, channel, remoteAddress);
if (position == null) {
return null;
}
int hdop = parser.nextInt();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop);
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
if (parser.hasNext(2)) {
position.setLongitude(parser.nextDouble());
position.setLatitude(parser.nextDouble());
} else {
getLastLocation(position, null);
}
if (parser.hasNext(6)) {
position.setTime(parser.nextDateTime());
}
if (parser.hasNext(4)) {
position.setNetwork(new Network(CellTower.from(parser.nextInt(), parser.nextInt(), parser.nextHexInt(), parser.nextHexInt())));
}
decodeDeviceTime(position, parser);
switch(type) {
case "PNA":
position.set(Position.KEY_ALARM, Position.ALARM_POWER_ON);
break;
case "PFA":
position.set(Position.KEY_ALARM, Position.ALARM_POWER_OFF);
break;
case "EPN":
position.set(Position.KEY_ALARM, Position.ALARM_POWER_RESTORED);
break;
case "EPF":
position.set(Position.KEY_ALARM, Position.ALARM_POWER_CUT);
break;
case "BPL":
position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY);
break;
case "STT":
position.set(Position.KEY_ALARM, Position.ALARM_MOVEMENT);
break;
case "SWG":
position.set(Position.KEY_ALARM, Position.ALARM_GEOFENCE);
break;
case "TMP":
case "TEM":
position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE);
break;
case "JDR":
case "JDS":
position.set(Position.KEY_ALARM, Position.ALARM_JAMMING);
break;
default:
break;
}
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Gt06ProtocolDecoder method decodeBasic.
private Object decodeBasic(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {
int length = buf.readUnsignedByte();
int dataLength = length - 5;
int type = buf.readUnsignedByte();
DeviceSession deviceSession = null;
if (type != MSG_LOGIN) {
deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
if (deviceSession.getTimeZone() == null) {
deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId()));
}
}
if (type == MSG_LOGIN) {
String imei = ChannelBuffers.hexDump(buf.readBytes(8)).substring(1);
// type
buf.readUnsignedShort();
deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession != null && deviceSession.getTimeZone() == null) {
deviceSession.setTimeZone(getTimeZone(deviceSession.getDeviceId()));
}
if (dataLength > 10) {
int extensionBits = buf.readUnsignedShort();
int hours = (extensionBits >> 4) / 100;
int minutes = (extensionBits >> 4) % 100;
int offset = (hours * 60 + minutes) * 60;
if ((extensionBits & 0x8) != 0) {
offset = -offset;
}
if (deviceSession != null) {
TimeZone timeZone = deviceSession.getTimeZone();
if (timeZone.getRawOffset() == 0) {
timeZone.setRawOffset(offset * 1000);
deviceSession.setTimeZone(timeZone);
}
}
}
if (deviceSession != null) {
sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null);
}
} else if (type == MSG_HEARTBEAT) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
int status = buf.readUnsignedByte();
position.set(Position.KEY_ARMED, BitUtil.check(status, 0));
position.set(Position.KEY_IGNITION, BitUtil.check(status, 1));
position.set(Position.KEY_CHARGE, BitUtil.check(status, 2));
sendResponse(channel, false, type, buf.getShort(buf.writerIndex() - 6), null);
return position;
} else if (type == MSG_ADDRESS_REQUEST) {
String response = "NA&&NA&&0##";
ChannelBuffer content = ChannelBuffers.dynamicBuffer();
content.writeByte(response.length());
content.writeInt(0);
content.writeBytes(response.getBytes(StandardCharsets.US_ASCII));
sendResponse(channel, true, MSG_ADDRESS_RESPONSE, 0, content);
} else if (type == MSG_TIME_REQUEST) {
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
ChannelBuffer content = ChannelBuffers.dynamicBuffer();
content.writeByte(calendar.get(Calendar.YEAR) - 2000);
content.writeByte(calendar.get(Calendar.MONTH) + 1);
content.writeByte(calendar.get(Calendar.DAY_OF_MONTH));
content.writeByte(calendar.get(Calendar.HOUR_OF_DAY));
content.writeByte(calendar.get(Calendar.MINUTE));
content.writeByte(calendar.get(Calendar.SECOND));
sendResponse(channel, false, MSG_TIME_REQUEST, 0, content);
} else if (type == MSG_X1_GPS) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
// data and alarm
buf.readUnsignedInt();
decodeGps(position, buf, false, deviceSession.getTimeZone());
// terminal info
buf.readUnsignedShort();
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
position.setNetwork(new Network(CellTower.from(buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedShort(), buf.readUnsignedInt())));
return position;
} else if (type == MSG_X1_PHOTO_INFO) {
// time
buf.skipBytes(6);
// fix status
buf.readUnsignedByte();
// latitude
buf.readUnsignedInt();
// longitude
buf.readUnsignedInt();
// camera id
buf.readUnsignedByte();
// photo source
buf.readUnsignedByte();
// picture format
buf.readUnsignedByte();
ChannelBuffer photo = ChannelBuffers.buffer(buf.readInt());
int pictureId = buf.readInt();
photos.put(pictureId, photo);
sendPhotoRequest(channel, pictureId);
} else if (type == MSG_WIFI || type == MSG_WIFI_2) {
return decodeWifi(buf, deviceSession);
} else {
return decodeBasicOther(channel, buf, deviceSession, type, dataLength);
}
return null;
}
Aggregations