use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class KenjiProtocolDecoder 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_ALARM, decodeAlarm(parser.nextHexInt(0)));
position.set(Position.KEY_OUTPUT, parser.nextHexInt(0));
position.set(Position.KEY_INPUT, parser.nextHexInt(0));
DateBuilder dateBuilder = new DateBuilder().setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG_MIN));
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_SATELLITES, parser.nextInt(0));
return position;
}
use of org.traccar.helper.DateBuilder 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.helper.DateBuilder 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.helper.DateBuilder 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.helper.DateBuilder in project traccar by tananaev.
the class OrionProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// header
buf.skipBytes(2);
int type = buf.readUnsignedByte() & 0x0f;
if (type == MSG_USERLOG) {
int header = buf.readUnsignedByte();
if ((header & 0x40) != 0) {
sendResponse(channel, buf);
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(buf.readUnsignedInt()));
if (deviceSession == null) {
return null;
}
List<Position> positions = new LinkedList<>();
for (int i = 0; i < (header & 0x0f); i++) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_EVENT, buf.readUnsignedByte());
// length
buf.readUnsignedByte();
position.set(Position.KEY_FLAGS, buf.readUnsignedShort());
position.setLatitude(convertCoordinate(buf.readInt()));
position.setLongitude(convertCoordinate(buf.readInt()));
position.setAltitude(buf.readShort() / 10.0);
position.setCourse(buf.readUnsignedShort());
position.setSpeed(buf.readUnsignedShort() * 0.0539957);
DateBuilder dateBuilder = new DateBuilder().setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
int satellites = buf.readUnsignedByte();
position.setValid(satellites >= 3);
position.set(Position.KEY_SATELLITES, satellites);
positions.add(position);
}
return positions;
}
return null;
}
Aggregations