use of org.traccar.model.Network 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.model.Network in project traccar by tananaev.
the class Jt600ProtocolDecoder method decodeU01.
private Position decodeU01(String sentence, Channel channel, SocketAddress remoteAddress) {
Parser parser = new Parser(PATTERN_U01, sentence);
if (!parser.matches()) {
return null;
}
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
String type = parser.next();
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
position.setValid(parser.next().equals("T"));
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setSpeed(UnitsConverter.knotsFromMph(parser.nextDouble(0)));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_SATELLITES, parser.nextInt(0));
position.set(Position.KEY_BATTERY_LEVEL, parser.nextInt(0));
position.set(Position.KEY_STATUS, parser.nextBinInt(0));
CellTower cellTower = CellTower.fromCidLac(parser.nextInt(0), parser.nextInt(0));
cellTower.setSignalStrength(parser.nextInt(0));
position.setNetwork(new Network(cellTower));
position.set(Position.KEY_ODOMETER, parser.nextLong(0) * 1000);
position.set(Position.KEY_INDEX, parser.nextInt(0));
if (channel != null) {
if (type.equals("U01") || type.equals("U02") || type.equals("U03")) {
channel.write("(S39)");
} else if (type.equals("U06")) {
channel.write("(S20)");
}
}
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class JpKorjarProtocolDecoder 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.setTime(parser.nextDateTime());
position.setLatitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setLongitude(parser.nextCoordinate(Parser.CoordinateFormat.DEG_HEM));
position.setSpeed(parser.nextDouble(0));
position.setCourse(parser.nextDouble(0));
position.set(Position.KEY_BATTERY, parser.nextDouble(0));
position.setValid(parser.nextInt(0) == 1);
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class SmokeyProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// header
buf.skipBytes(2);
// protocol version
buf.readUnsignedByte();
int type = buf.readUnsignedByte();
ChannelBuffer id = buf.readBytes(8);
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, ChannelBuffers.hexDump(id));
if (deviceSession == null) {
return null;
}
if (type == MSG_DATE_RECORD) {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_VERSION_FW, buf.readUnsignedShort());
int status = buf.readUnsignedShort();
position.set(Position.KEY_STATUS, status);
DateBuilder dateBuilder = new DateBuilder().setDate(2000, 1, 1).addSeconds(buf.readUnsignedInt());
getLastLocation(position, dateBuilder.getDate());
int index = buf.readUnsignedByte();
position.set(Position.KEY_INDEX, index);
int report = buf.readUnsignedShort();
// length
buf.readUnsignedShort();
position.set(Position.KEY_BATTERY, buf.readUnsignedShort());
Network network = new Network();
if (report != 0x0203) {
int count = 1;
if (report != 0x0200) {
count = buf.readUnsignedByte();
}
for (int i = 0; i < count; i++) {
int mcc = buf.readUnsignedShort();
int mnc = buf.readUnsignedShort();
int lac = buf.readUnsignedShort();
int cid = buf.readUnsignedShort();
if (i == 0) {
// timing advance
buf.readByte();
}
int rssi = buf.readByte();
network.addCellTower(CellTower.from(mcc, mnc, lac, cid, rssi));
}
}
if (report == 0x0202 || report == 0x0203) {
int count = buf.readUnsignedByte();
for (int i = 0; i < count; i++) {
// ssid
buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0) + 1);
String mac = String.format("%02x:%02x:%02x:%02x:%02x:%02x", buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
network.addWifiAccessPoint(WifiAccessPoint.from(mac, buf.readByte()));
}
}
position.setNetwork(network);
sendResponse(channel, remoteAddress, id, index, report);
return position;
}
return null;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Tk103ProtocolDecoder method decodeLbsWifi.
private Position decodeLbsWifi(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN_LBSWIFI, 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());
decodeType(position, parser.next(), "0");
getLastLocation(position, null);
Network network = new Network();
network.addCellTower(CellTower.from(parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt()));
int wifiCount = parser.nextInt();
if (parser.hasNext()) {
String[] wifimacs = parser.next().split(",");
if (wifimacs.length == wifiCount) {
for (int i = 0; i < wifiCount; i++) {
String[] wifiinfo = wifimacs[i].split("\\*");
network.addWifiAccessPoint(WifiAccessPoint.from(wifiinfo[0], Integer.parseInt(wifiinfo[1]), Integer.parseInt(wifiinfo[2])));
}
}
}
if (network.getCellTowers() != null || network.getWifiAccessPoints() != null) {
position.setNetwork(network);
}
position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
return position;
}
Aggregations