use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class H02ProtocolDecoder method decodeV3.
private Position decodeV3(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN_V3, 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));
int mcc = parser.nextInt();
int mnc = parser.nextInt();
int count = parser.nextInt();
Network network = new Network();
String[] values = parser.next().split(",");
for (int i = 0; i < count; i++) {
network.addCellTower(CellTower.from(mcc, mnc, Integer.parseInt(values[i * 4]), Integer.parseInt(values[i * 4 + 1])));
}
position.setNetwork(network);
position.set(Position.KEY_BATTERY, parser.nextHexInt());
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
getLastLocation(position, dateBuilder.getDate());
processStatus(position, parser.nextLong(16, 0));
return position;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class H02ProtocolDecoder method decodeLink.
private Position decodeLink(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN_LINK, 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));
position.set(Position.KEY_RSSI, parser.nextInt());
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt());
position.set(Position.KEY_STEPS, parser.nextInt());
position.set("turnovers", parser.nextInt());
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
getLastLocation(position, dateBuilder.getDate());
processStatus(position, parser.nextLong(16, 0));
return position;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class H02ProtocolDecoder method decodeText.
private Position decodeText(String sentence, Channel channel, SocketAddress remoteAddress) {
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());
if (parser.hasNext()) {
position.set(Position.KEY_RESULT, parser.next());
}
DateBuilder dateBuilder = new DateBuilder();
if (parser.hasNext(3)) {
dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
}
if (parser.hasNext()) {
position.setValid(parser.next().equals("A"));
}
if (parser.hasNext()) {
// coding scheme
parser.nextInt();
position.setValid(true);
}
if (parser.hasNext(2)) {
position.setLatitude(-parser.nextCoordinate());
}
if (parser.hasNext(2)) {
position.setLatitude(parser.nextCoordinate());
}
if (parser.hasNext(2)) {
position.setLongitude(-parser.nextCoordinate());
}
if (parser.hasNext(2)) {
position.setLongitude(parser.nextCoordinate());
}
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
if (parser.hasNext(3)) {
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
} else {
position.setTime(new Date());
}
if (parser.hasNext()) {
processStatus(position, parser.nextLong(16, 0));
}
if (parser.hasNext(6)) {
position.set(Position.KEY_ODOMETER, parser.nextInt(0));
position.set(Position.PREFIX_TEMP + 1, parser.nextInt(0));
position.set(Position.KEY_FUEL_LEVEL, parser.nextDouble(0));
position.setAltitude(parser.nextInt(0));
position.setNetwork(new Network(CellTower.fromLacCid(parser.nextHexInt(0), parser.nextHexInt(0))));
}
if (parser.hasNext(4)) {
String[] values = parser.next().split(",");
for (int i = 0; i < values.length; i++) {
position.set(Position.PREFIX_IO + (i + 1), values[i].trim());
}
}
return position;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class Gt30ProtocolDecoder 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().trim());
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
if (parser.hasNext()) {
position.set(Position.KEY_ALARM, decodeAlarm(parser.next().charAt(0)));
}
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_HDOP, parser.nextDouble());
position.setAltitude(parser.nextDouble(0));
return position;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class KhdProtocolDecoder 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();
// size
buf.readUnsignedShort();
if (type == MSG_ON_DEMAND || type == MSG_POSITION_UPLOAD || type == MSG_POSITION_REUPLOAD || type == MSG_ALARM || type == MSG_REPLY || type == MSG_PERIPHERAL) {
Position position = new Position(getProtocolName());
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readSerialNumber(buf));
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setYear(BcdUtil.readInteger(buf, 2)).setMonth(BcdUtil.readInteger(buf, 2)).setDay(BcdUtil.readInteger(buf, 2)).setHour(BcdUtil.readInteger(buf, 2)).setMinute(BcdUtil.readInteger(buf, 2)).setSecond(BcdUtil.readInteger(buf, 2));
position.setTime(dateBuilder.getDate());
position.setLatitude(BcdUtil.readCoordinate(buf));
position.setLongitude(BcdUtil.readCoordinate(buf));
position.setSpeed(UnitsConverter.knotsFromKph(BcdUtil.readInteger(buf, 4)));
position.setCourse(BcdUtil.readInteger(buf, 4));
position.setValid((buf.readUnsignedByte() & 0x80) != 0);
if (type != MSG_ALARM) {
position.set(Position.KEY_ODOMETER, buf.readUnsignedMedium());
position.set(Position.KEY_STATUS, buf.readUnsignedInt());
position.set(Position.KEY_HDOP, buf.readUnsignedByte());
position.set(Position.KEY_VDOP, buf.readUnsignedByte());
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
// other location data
buf.skipBytes(5);
if (type == MSG_PERIPHERAL) {
// data length
buf.readUnsignedShort();
int dataType = buf.readUnsignedByte();
// content length
buf.readUnsignedByte();
switch(dataType) {
case 0x01:
position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
break;
case 0x02:
position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedByte() * 100 + buf.readUnsignedByte());
break;
default:
break;
}
}
}
return position;
} else if (type == MSG_LOGIN && channel != null) {
// serial number
buf.skipBytes(4);
// reserved
buf.readByte();
ChannelBuffer response = ChannelBuffers.dynamicBuffer();
// header
response.writeByte(0x29);
// header
response.writeByte(0x29);
response.writeByte(MSG_CONFIRMATION);
// size
response.writeShort(5);
response.writeByte(buf.readUnsignedByte());
response.writeByte(type);
// reserved
response.writeByte(0);
response.writeByte(Checksum.xor(response.toByteBuffer()));
// ending
response.writeByte(0x0D);
channel.write(response);
}
return null;
}
Aggregations