use of org.traccar.model.Network in project traccar by tananaev.
the class Avl301ProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
ChannelBuffer buf = (ChannelBuffer) msg;
// header
buf.skipBytes(1);
int type = buf.readUnsignedByte();
// length
buf.readUnsignedByte();
if (type == MSG_LOGIN) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, readImei(buf));
if (deviceSession == null) {
sendResponse(channel, type);
}
} else if (type == MSG_STATUS) {
sendResponse(channel, type);
} else if (type == MSG_GPS_LBS_STATUS) {
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress);
if (deviceSession == null) {
return null;
}
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder().setDate(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte()).setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
position.setTime(dateBuilder.getDate());
// gps len and sat
int gpsLength = buf.readUnsignedByte();
position.set(Position.KEY_SATELLITES, gpsLength & 0xf);
// satellites
position.set(Position.KEY_SATELLITES_VISIBLE, buf.readUnsignedByte());
double latitude = buf.readUnsignedInt() / 600000.0;
double longitude = buf.readUnsignedInt() / 600000.0;
position.setSpeed(buf.readUnsignedByte());
// course and flags
int union = buf.readUnsignedShort();
position.setCourse(union & 0x03FF);
position.setValid((union & 0x1000) != 0);
if ((union & 0x0400) != 0) {
latitude = -latitude;
}
if ((union & 0x0800) != 0) {
longitude = -longitude;
}
position.setLatitude(latitude);
position.setLongitude(longitude);
if ((union & 0x4000) != 0) {
position.set("acc", (union & 0x8000) != 0);
}
position.setNetwork(new Network(CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedMedium())));
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
int flags = buf.readUnsignedByte();
position.set("acc", (flags & 0x2) != 0);
// parse other flags
position.set(Position.KEY_POWER, buf.readUnsignedByte());
position.set(Position.KEY_RSSI, buf.readUnsignedByte());
return position;
}
return null;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class CastelProtocolDecoder method decodeSc.
private Object decodeSc(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
if (type == MSG_SC_HEARTBEAT) {
sendResponse(channel, remoteAddress, version, id, MSG_SC_HEARTBEAT_RESPONSE, null);
} else if (type == MSG_SC_LOGIN || type == MSG_SC_LOGOUT || type == MSG_SC_GPS || type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION || type == MSG_SC_FUEL) {
if (type == MSG_SC_LOGIN) {
ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 10);
response.writeInt(0xFFFFFFFF);
response.writeShort(0);
response.writeInt((int) (System.currentTimeMillis() / 1000));
sendResponse(channel, remoteAddress, version, id, MSG_SC_LOGIN_RESPONSE, response);
}
if (type == MSG_SC_GPS) {
// historical
buf.readUnsignedByte();
} else if (type == MSG_SC_ALARM) {
// alarm
buf.readUnsignedInt();
} else if (type == MSG_SC_CURRENT_LOCATION) {
buf.readUnsignedShort();
}
// ACC ON time
buf.readUnsignedInt();
// UTC time
buf.readUnsignedInt();
long odometer = buf.readUnsignedInt();
long tripOdometer = buf.readUnsignedInt();
long fuelConsumption = buf.readUnsignedInt();
// current fuel consumption
buf.readUnsignedShort();
long status = buf.readUnsignedInt();
buf.skipBytes(8);
int count = buf.readUnsignedByte();
List<Position> positions = new LinkedList<>();
for (int i = 0; i < count; i++) {
Position position = readPosition(deviceSession, buf);
position.set(Position.KEY_ODOMETER, odometer);
position.set(Position.KEY_ODOMETER_TRIP, tripOdometer);
position.set(Position.KEY_FUEL_CONSUMPTION, fuelConsumption);
position.set(Position.KEY_STATUS, status);
positions.add(position);
}
if (type == MSG_SC_ALARM) {
int alarmCount = buf.readUnsignedByte();
for (int i = 0; i < alarmCount; i++) {
if (buf.readUnsignedByte() != 0) {
int alarm = buf.readUnsignedByte();
for (Position position : positions) {
decodeAlarm(position, alarm);
}
// description
buf.readUnsignedShort();
// threshold
buf.readUnsignedShort();
}
}
} else if (type == MSG_SC_FUEL) {
for (Position position : positions) {
position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
}
}
if (!positions.isEmpty()) {
return positions;
}
} else if (type == MSG_SC_GPS_SLEEP) {
// device time
buf.readUnsignedInt();
return readPosition(deviceSession, buf);
} else if (type == MSG_SC_AGPS_REQUEST) {
return readPosition(deviceSession, buf);
} else if (type == MSG_SC_PID_DATA) {
Position position = createPosition(deviceSession);
decodeStat(position, buf);
// sample rate
buf.readUnsignedShort();
decodeObd(position, buf, true);
return position;
} else if (type == MSG_SC_DTCS_PASSENGER) {
Position position = createPosition(deviceSession);
decodeStat(position, buf);
// flag
buf.readUnsignedByte();
position.add(ObdDecoder.decodeCodes(ChannelBuffers.hexDump(buf.readBytes(buf.readUnsignedByte()))));
return position;
} else if (type == MSG_SC_OBD_DATA) {
Position position = createPosition(deviceSession);
decodeStat(position, buf);
// flag
buf.readUnsignedByte();
decodeObd(position, buf, false);
return position;
} else if (type == MSG_SC_CELL) {
Position position = createPosition(deviceSession);
decodeStat(position, buf);
position.setNetwork(new Network(CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
return position;
}
return null;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class CastelProtocolDecoder method decodeCc.
private Object decodeCc(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf, int version, ChannelBuffer id, int type, DeviceSession deviceSession) {
if (type == MSG_CC_HEARTBEAT) {
sendResponse(channel, remoteAddress, version, id, MSG_CC_HEARTBEAT_RESPONSE, null);
// 0x01 for history
buf.readUnsignedByte();
int count = buf.readUnsignedByte();
List<Position> positions = new LinkedList<>();
for (int i = 0; i < count; i++) {
Position position = readPosition(deviceSession, buf);
position.set(Position.KEY_STATUS, buf.readUnsignedInt());
position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
// geo-fencing id
buf.readUnsignedByte();
// geo-fencing flags
buf.readUnsignedByte();
// additional flags
buf.readUnsignedByte();
position.setNetwork(new Network(CellTower.fromLacCid(buf.readUnsignedShort(), buf.readUnsignedShort())));
positions.add(position);
}
return positions;
} else if (type == MSG_CC_LOGIN) {
sendResponse(channel, remoteAddress, version, id, MSG_CC_LOGIN_RESPONSE, null);
Position position = readPosition(deviceSession, buf);
position.set(Position.KEY_STATUS, buf.readUnsignedInt());
position.set(Position.KEY_BATTERY, buf.readUnsignedByte());
position.set(Position.KEY_ODOMETER, buf.readUnsignedInt());
// geo-fencing id
buf.readUnsignedByte();
// geo-fencing flags
buf.readUnsignedByte();
// additional flags
buf.readUnsignedByte();
return position;
}
return null;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class FifotrackProtocolDecoder 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.set(Position.KEY_ALARM, parser.next());
position.setTime(parser.nextDateTime());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextDouble(0));
position.setLongitude(parser.nextDouble(0));
position.setSpeed(UnitsConverter.knotsFromKph(parser.nextInt(0)));
position.setCourse(parser.nextInt(0));
position.setAltitude(parser.nextInt(0));
position.set(Position.KEY_ODOMETER, parser.nextLong(0));
position.set(Position.KEY_STATUS, parser.nextHexInt(0));
if (parser.hasNext()) {
position.set(Position.KEY_INPUT, parser.nextHexInt(0));
}
if (parser.hasNext()) {
position.set(Position.KEY_OUTPUT, parser.nextHexInt(0));
}
position.setNetwork(new Network(CellTower.from(parser.nextInt(0), parser.nextInt(0), parser.nextHexInt(0), parser.nextHexInt(0))));
String[] adc = parser.next().split("\\|");
for (int i = 0; i < adc.length; i++) {
position.set(Position.PREFIX_ADC + (i + 1), Integer.parseInt(adc[i], 16));
}
position.set(Position.KEY_DRIVER_UNIQUE_ID, parser.next());
if (parser.hasNext()) {
String[] sensors = parser.next().split("\\|");
for (int i = 0; i < sensors.length; i++) {
position.set(Position.PREFIX_IO + (i + 1), sensors[i]);
}
}
return position;
}
use of org.traccar.model.Network in project traccar by tananaev.
the class Gl200BinaryProtocolDecoder method decodeEvent.
private Position decodeEvent(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) {
Position position = new Position(getProtocolName());
int type = buf.readUnsignedByte();
// mask
buf.readUnsignedInt();
// length
buf.readUnsignedShort();
// device type
buf.readUnsignedByte();
// protocol version
buf.readUnsignedShort();
position.set(Position.KEY_VERSION_FW, String.valueOf(buf.readUnsignedShort()));
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.format("%015d", buf.readLong()));
if (deviceSession == null) {
return null;
}
position.setDeviceId(deviceSession.getDeviceId());
position.set(Position.KEY_BATTERY_LEVEL, buf.readUnsignedByte());
position.set(Position.KEY_POWER, buf.readUnsignedShort());
// motion status
buf.readUnsignedByte();
position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
switch(type) {
case MSG_EVT_BPL:
// backup battery voltage
buf.readUnsignedShort();
break;
case MSG_EVT_VGN:
case MSG_EVT_VGF:
// reserved
buf.readUnsignedShort();
// report type
buf.readUnsignedByte();
// ignition duration
buf.readUnsignedInt();
break;
case MSG_EVT_UPD:
// code
buf.readUnsignedShort();
// retry
buf.readUnsignedByte();
break;
case MSG_EVT_IDF:
// idling duration
buf.readUnsignedInt();
break;
case MSG_EVT_GSS:
// gps signal status
buf.readUnsignedByte();
// reserved
buf.readUnsignedInt();
break;
case MSG_EVT_GES:
// trigger geo id
buf.readUnsignedShort();
// trigger geo enable
buf.readUnsignedByte();
// trigger mode
buf.readUnsignedByte();
// radius
buf.readUnsignedInt();
// check interval
buf.readUnsignedInt();
break;
case MSG_EVT_GPJ:
// cw jamming value
buf.readUnsignedByte();
// gps jamming state
buf.readUnsignedByte();
break;
case MSG_EVT_RMD:
// roaming state
buf.readUnsignedByte();
break;
case MSG_EVT_JDS:
// jamming state
buf.readUnsignedByte();
break;
case MSG_EVT_CRA:
// crash counter
buf.readUnsignedByte();
break;
case MSG_EVT_UPC:
// command id
buf.readUnsignedByte();
// result
buf.readUnsignedShort();
break;
default:
break;
}
// count
buf.readUnsignedByte();
int hdop = buf.readUnsignedByte();
position.setValid(hdop > 0);
position.set(Position.KEY_HDOP, hdop);
position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedMedium() * 0.1));
position.setCourse(buf.readUnsignedShort());
position.setAltitude(buf.readShort());
position.setLongitude(buf.readInt() * 0.000001);
position.setLatitude(buf.readInt() * 0.000001);
position.setTime(decodeTime(buf));
position.setNetwork(new Network(CellTower.from(buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort(), buf.readUnsignedShort())));
// reserved
buf.readUnsignedByte();
return position;
}
Aggregations