use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class ExtremTracProtocolDecoder 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());
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());
return position;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class Gps056ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// header
buf.skipBytes(2);
// length
buf.skipBytes(2);
String type = buf.readBytes(7).toString(StandardCharsets.US_ASCII);
String imei = buf.readBytes(15).toString(StandardCharsets.US_ASCII);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession == null) {
return null;
}
if (type.startsWith("LOGN")) {
sendResponse(channel, "LGSA" + type.substring(4), imei, ChannelBuffers.copiedBuffer("1", StandardCharsets.US_ASCII));
} else if (type.startsWith("GPSL")) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setDateReverse(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setValid(true);
position.setTime(dateBuilder.getDate());
position.setLatitude(decodeCoordinate(buf));
position.setLongitude(decodeCoordinate(buf));
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
position.setCourse(buf.readUnsignedShort());
decodeStatus(buf, position);
sendResponse(channel, "GPSA" + type.substring(4), imei, buf.readBytes(2));
return position;
} else if (type.startsWith("SYNC")) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, null);
decodeStatus(buf, position);
sendResponse(channel, "SYSA" + type.substring(4), imei, null);
return position;
}
return null;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class GoSafeProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
if (channel != null) {
channel.write("1234");
}
String sentence = (String) msg;
Pattern pattern = PATTERN;
if (sentence.startsWith("*GS02")) {
pattern = PATTERN_OLD;
}
Parser parser = new Parser(pattern, (String) msg);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
if (pattern == PATTERN_OLD) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
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));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.HEM_DEG));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_HDOP, parser.next());
dateBuilder.setDateReverse(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
position.setTime(dateBuilder.getDate());
return position;
} else {
Date time = null;
if (parser.hasNext(6)) {
time = parser.nextDateTime(Parser.DateTimeFormat.HMS_DMY);
}
List<Position> positions = new LinkedList<>();
Parser itemParser = new Parser(PATTERN_ITEM, parser.next());
while (itemParser.find()) {
positions.add(decodePosition(deviceSession, itemParser, time));
}
return positions;
}
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class GpsGateProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = (String) msg;
if (sentence.startsWith("$FRLIN,")) {
// Login
int beginIndex = sentence.indexOf(',', 7);
if (beginIndex != -1) {
beginIndex += 1;
int endIndex = sentence.indexOf(',', beginIndex);
if (endIndex != -1) {
String imei = sentence.substring(beginIndex, endIndex);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, imei);
if (deviceSession != null) {
if (channel != null) {
send(channel, "$FRSES," + channel.getId());
}
} else {
send(channel, "$FRERR,AuthError,Unknown device");
}
} else {
send(channel, "$FRERR,AuthError,Parse error");
}
} else {
send(channel, "$FRERR,AuthError,Parse error");
}
} else if (sentence.startsWith("$FRVER,")) {
// Version check
send(channel, "$FRVER,1,0,GpsGate Server 1.0");
} else if (sentence.startsWith("$GPRMC,")) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Parser parser = new Parser(PATTERN_GPRMC, sentence);
if (!parser.matches()) {
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.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());
return position;
} else if (sentence.startsWith("$FRCMD,")) {
Parser parser = new Parser(PATTERN_FRCMD, 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.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
position.setAltitude(parser.nextDouble(0));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setValid(parser.next().equals("1"));
return position;
}
return null;
}
use of org.traccar.helper.DateBuilder in project traccar by tananaev.
the class Gt06ProtocolDecoder method decodeGps.
private boolean decodeGps(Position position, ChannelBuffer buf, boolean hasLength, TimeZone timezone) {
DateBuilder dateBuilder = new DateBuilder(timezone).setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
if (hasLength && buf.readUnsignedByte() == 0) {
return false;
}
position.set(Position.KEY_SATELLITES, BitUtil.to(buf.readUnsignedByte(), 4));
double latitude = buf.readUnsignedInt() / 60.0 / 30000.0;
double longitude = buf.readUnsignedInt() / 60.0 / 30000.0;
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
int flags = buf.readUnsignedShort();
position.setCourse(BitUtil.to(flags, 10));
position.setValid(BitUtil.check(flags, 12));
if (!BitUtil.check(flags, 10)) {
latitude = -latitude;
}
if (BitUtil.check(flags, 11)) {
longitude = -longitude;
}
position.setLatitude(latitude);
position.setLongitude(longitude);
if (BitUtil.check(flags, 14)) {
position.set(Position.KEY_IGNITION, BitUtil.check(flags, 15));
}
return true;
}
Aggregations