use of org.traccar.DeviceSession in project traccar by tananaev.
the class MiniFinderProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.startsWith("!1,")) {
int index = sentence.indexOf(',', 3);
if (index < 0) {
index = sentence.length();
}
getDeviceSession(channel, remoteAddress, sentence.substring(3, index));
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null || !sentence.matches("![A-D],.*")) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
String type = sentence.substring(1, 2);
position.set(Position.KEY_TYPE, type);
if (type.equals("B") || type.equals("D")) {
Parser parser = new Parser(PATTERN_BD, sentence);
if (!parser.matches()) {
return null;
}
decodeFix(position, parser);
decodeState(position, parser);
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_SATELLITES_VISIBLE, parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
return position;
} else if (type.equals("C")) {
Parser parser = new Parser(PATTERN_C, sentence);
if (!parser.matches()) {
return null;
}
decodeFix(position, parser);
decodeState(position, parser);
return position;
} else if (type.equals("A")) {
Parser parser = new Parser(PATTERN_A, sentence);
if (!parser.matches()) {
return null;
}
decodeFix(position, parser);
return position;
}
return null;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class M2cProtocolDecoder method decodePosition.
private Position decodePosition(Channel channel, SocketAddress remoteAddress, String line) {
Parser parser = new Parser(PATTERN, line);
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());
position.set(Position.KEY_INDEX, parser.nextInt());
if (parser.next().equals("H")) {
position.set(Position.KEY_ARCHIVE, true);
}
position.set(Position.KEY_EVENT, parser.nextInt());
position.setValid(true);
position.setTime(parser.nextDateTime());
position.setLatitude(parser.nextDouble());
position.setLongitude(parser.nextDouble());
position.setAltitude(parser.nextInt());
position.setCourse(parser.nextInt());
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_ODOMETER, parser.nextLong());
position.set(Position.KEY_INPUT, parser.nextInt());
position.set(Position.KEY_OUTPUT, parser.nextInt());
position.set(Position.KEY_POWER, parser.nextInt() * 0.001);
position.set(Position.KEY_BATTERY, parser.nextInt() * 0.001);
position.set(Position.PREFIX_ADC + 1, parser.nextInt());
position.set(Position.PREFIX_ADC + 2, parser.nextInt());
position.set(Position.PREFIX_TEMP + 1, parser.nextDouble());
return position;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class M2mProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// Remove offset
for (int i = 0; i < buf.readableBytes(); i++) {
int b = buf.getByte(i);
if (b != 0x0b) {
buf.setByte(i, b - 0x20);
}
}
if (firstPacket) {
firstPacket = false;
StringBuilder imei = new StringBuilder();
for (int i = 0; i < 8; i++) {
int b = buf.readByte();
if (i != 0) {
imei.append(b / 10);
}
imei.append(b % 10);
}
getDeviceSession(channel, remoteAddress, imei.toString());
} else {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setDay(buf.readUnsignedByte() & 0x3f).setMonth(buf.readUnsignedByte() & 0x3f).setYear(buf.readUnsignedByte()).setHour(buf.readUnsignedByte() & 0x3f).setMinute(buf.readUnsignedByte() & 0x7f).setSecond(buf.readUnsignedByte() & 0x7f);
position.setTime(dateBuilder.getDate());
int degrees = buf.readUnsignedByte();
double latitude = buf.readUnsignedByte();
latitude += buf.readUnsignedByte() / 100.0;
latitude += buf.readUnsignedByte() / 10000.0;
latitude /= 60;
latitude += degrees;
int b = buf.readUnsignedByte();
degrees = (b & 0x7f) * 100 + buf.readUnsignedByte();
double longitude = buf.readUnsignedByte();
longitude += buf.readUnsignedByte() / 100.0;
longitude += buf.readUnsignedByte() / 10000.0;
longitude /= 60;
longitude += degrees;
if ((b & 0x80) != 0) {
longitude = -longitude;
}
if ((b & 0x40) != 0) {
latitude = -latitude;
}
position.setValid(true);
position.setLatitude(latitude);
position.setLongitude(longitude);
position.setSpeed(buf.readUnsignedByte());
int satellites = buf.readUnsignedByte();
if (satellites == 0) {
// cell information
return null;
}
position.set(Position.KEY_SATELLITES, satellites);
return position;
}
return null;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class MaestroProtocolDecoder 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;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setValid(parser.nextInt(0) == 1);
position.set(Position.KEY_BATTERY, parser.nextDouble(0));
position.set(Position.KEY_RSSI, parser.nextInt(0));
position.set(Position.KEY_CHARGE, parser.nextInt(0) == 1);
position.set(Position.KEY_IGNITION, parser.nextInt(0) == 1);
position.setTime(parser.nextDateTime());
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setAltitude(parser.nextDouble(0));
position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_HDOP, parser.nextDouble(0));
position.set(Position.KEY_ODOMETER, parser.nextDouble(0) * 1609.34);
if (parser.hasNext()) {
position.set(Position.PREFIX_ADC + 1, parser.nextInt(0));
}
return position;
}
use of org.traccar.DeviceSession in project traccar by tananaev.
the class ManPowerProtocolDecoder 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());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_STATUS, parser.next());
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setSpeed(parser.nextDouble(0));
return position;
}
Aggregations