use of org.traccar.DeviceSession in project traccar by tananaev.
the class Gl100ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.contains("AT+GTHBD=") && channel != null) {
String response = "+RESP:GTHBD,GPRS ACTIVE,";
response += sentence.substring(9, sentence.lastIndexOf(','));
response += '\0';
// heartbeat response
channel.write(response);
}
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());
position.setValid(parser.nextInt(0) == 0);
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setLatitude(parser.nextDouble(0));
position.setTime(parser.nextDateTime());
return position;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decodeFri.
private Object decodeFri(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_FRI, sentence);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
LinkedList<Position> positions = new LinkedList<>();
String vin = parser.next();
Integer power = parser.nextInt();
Parser itemParser = new Parser(PATTERN_LOCATION, parser.next());
while (itemParser.find()) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_VIN, vin);
decodeLocation(position, itemParser);
positions.add(position);
}
Position position = positions.getLast();
decodeLocation(position, parser);
if (power != null && power > 10) {
// only on some devices
position.set(Position.KEY_POWER, power * 0.001);
}
if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
}
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
if (parser.hasNext()) {
position.set(Position.KEY_ODOMETER, parser.nextDouble() * 1000);
}
position.set(Position.KEY_HOURS, parser.next());
position.set(Position.PREFIX_ADC + 1, parser.next());
position.set(Position.PREFIX_ADC + 2, parser.next());
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
decodeStatus(position, parser);
position.set(Position.KEY_RPM, parser.nextInt());
position.set(Position.KEY_FUEL_LEVEL, parser.nextInt());
decodeDeviceTime(position, parser);
if (ignoreFixTime) {
positions.clear();
positions.add(position);
}
return positions;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decodeCan.
private Object decodeCan(Channel channel, SocketAddress remoteAddress, String sentence) throws ParseException {
Position position = new Position(getProtocolName());
int index = 0;
String[] values = sentence.split(",");
// header
index += 1;
// protocol version
index += 1;
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, values[index++]);
position.setDeviceId(deviceSession.getDeviceId());
// device name
index += 1;
// report type
index += 1;
// canbus state
index += 1;
long reportMask = Long.parseLong(values[index++], 16);
if (BitUtil.check(reportMask, 0)) {
position.set(Position.KEY_VIN, values[index++]);
}
if (BitUtil.check(reportMask, 1)) {
position.set(Position.KEY_IGNITION, Integer.parseInt(values[index++]) > 0);
}
if (BitUtil.check(reportMask, 2)) {
position.set("totalVehicleDistance", values[index++]);
}
if (BitUtil.check(reportMask, 3)) {
position.set("totalFuelConsumption", Double.parseDouble(values[index++]));
}
if (BitUtil.check(reportMask, 5) && !values[index++].isEmpty()) {
position.set(Position.KEY_RPM, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 4) && !values[index++].isEmpty()) {
position.set(Position.KEY_OBD_SPEED, UnitsConverter.knotsFromKph(Integer.parseInt(values[index - 1])));
}
if (BitUtil.check(reportMask, 6) && !values[index++].isEmpty()) {
position.set(Position.KEY_COOLANT_TEMP, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 7) && !values[index++].isEmpty()) {
position.set(Position.KEY_FUEL_CONSUMPTION, Double.parseDouble(values[index - 1].substring(1)));
}
if (BitUtil.check(reportMask, 8) && !values[index++].isEmpty()) {
position.set(Position.KEY_FUEL_LEVEL, Double.parseDouble(values[index - 1].substring(1)));
}
if (BitUtil.check(reportMask, 9) && !values[index++].isEmpty()) {
position.set("range", Long.parseLong(values[index - 1]) * 100);
}
if (BitUtil.check(reportMask, 10) && !values[index++].isEmpty()) {
position.set(Position.KEY_THROTTLE, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 11)) {
position.set(Position.KEY_HOURS, Double.parseDouble(values[index++]));
}
if (BitUtil.check(reportMask, 12)) {
position.set("drivingHours", Double.parseDouble(values[index++]));
}
if (BitUtil.check(reportMask, 13)) {
position.set("idleHours", Double.parseDouble(values[index++]));
}
if (BitUtil.check(reportMask, 14) && !values[index++].isEmpty()) {
position.set("idleFuelConsumption", Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 15) && !values[index++].isEmpty()) {
position.set(Position.KEY_AXLE_WEIGHT, Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 16) && !values[index++].isEmpty()) {
position.set("tachographInfo", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 17) && !values[index++].isEmpty()) {
position.set("indicators", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 18) && !values[index++].isEmpty()) {
position.set("lights", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 19) && !values[index++].isEmpty()) {
position.set("doors", Integer.parseInt(values[index - 1]));
}
if (BitUtil.check(reportMask, 20) && !values[index++].isEmpty()) {
position.set("vehicleOverspeed", Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 21) && !values[index++].isEmpty()) {
position.set("engineOverspeed", Double.parseDouble(values[index - 1]));
}
if (BitUtil.check(reportMask, 29)) {
// expansion
index += 1;
}
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
if (BitUtil.check(reportMask, 30)) {
position.setValid(Integer.parseInt(values[index++]) > 0);
if (!values[index].isEmpty()) {
position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(values[index++])));
position.setCourse(Integer.parseInt(values[index++]));
position.setAltitude(Double.parseDouble(values[index++]));
position.setLongitude(Double.parseDouble(values[index++]));
position.setLatitude(Double.parseDouble(values[index++]));
position.setTime(dateFormat.parse(values[index++]));
} else {
// no location
index += 6;
getLastLocation(position, null);
}
} else {
getLastLocation(position, null);
}
if (BitUtil.check(reportMask, 31)) {
// cell
index += 4;
}
// reserved
index += 1;
if (ignoreFixTime) {
position.setTime(dateFormat.parse(values[index]));
} else {
position.setDeviceTime(dateFormat.parse(values[index]));
}
return position;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class Gl200TextProtocolDecoder method initPosition.
private Position initPosition(Parser parser, Channel channel, SocketAddress remoteAddress) {
if (parser.matches()) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession != null) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
return position;
}
}
return null;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class GlobalSatProtocolDecoder method decodeAlternative.
private Position decodeAlternative(Channel channel, SocketAddress remoteAddress, String sentence) {
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());
position.setValid(!parser.next().equals("1"));
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setAltitude(parser.nextDouble(0));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextDouble());
return position;
}
Aggregations