use of org.traccar.NetworkMessage in project traccar by tananaev.
the class LaipacProtocolDecoder method sendEventResponse.
private void sendEventResponse(String event, String devicePassword, Channel channel, SocketAddress remoteAddress) {
String responseCode = null;
switch(event) {
case "3":
responseCode = "d";
break;
case "S":
case "T":
responseCode = "t";
break;
case "X":
case "4":
responseCode = "x";
break;
case "Y":
responseCode = "y";
break;
case "Z":
responseCode = "z";
break;
default:
break;
}
if (responseCode != null) {
String response = "$AVCFG," + devicePassword + "," + responseCode;
response += Checksum.nmea(response.substring(1)) + "\r\n";
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class LaipacProtocolDecoder method sendAcknowledge.
private void sendAcknowledge(String status, String event, String checksum, Channel channel, SocketAddress remoteAddress) {
if (Character.isLowerCase(status.charAt(0))) {
String response = "$EAVACK," + event + "," + checksum;
response += Checksum.nmea(response.substring(1)) + "\r\n";
channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
}
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decodeAck.
private Object decodeAck(Channel channel, SocketAddress remoteAddress, String sentence, String type) {
Parser parser = new Parser(PATTERN_ACK, sentence);
if (parser.matches()) {
String protocolVersion = parser.next();
DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next());
if (deviceSession == null) {
return null;
}
if (type.equals("HBD")) {
if (channel != null) {
parser.skip(6);
channel.writeAndFlush(new NetworkMessage("+SACK:GTHBD," + protocolVersion + "," + parser.next() + "$", remoteAddress));
}
} else {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
getLastLocation(position, parser.nextDateTime());
position.setValid(false);
position.set(Position.KEY_RESULT, "Command " + type + " accepted");
return position;
}
}
return null;
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class Gl200TextProtocolDecoder method decode.
@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
String sentence = ((ByteBuf) msg).toString(StandardCharsets.US_ASCII);
int typeIndex = sentence.indexOf(":GT");
if (typeIndex < 0) {
return null;
}
Object result;
String type = sentence.substring(typeIndex + 3, typeIndex + 6);
if (sentence.startsWith("+ACK")) {
result = decodeAck(channel, remoteAddress, sentence, type);
} else {
switch(type) {
case "INF":
result = decodeInf(channel, remoteAddress, sentence);
break;
case "OBD":
result = decodeObd(channel, remoteAddress, sentence);
break;
case "CAN":
result = decodeCan(channel, remoteAddress, sentence);
break;
case "CTN":
case "FRI":
case "GEO":
case "RTL":
case "DOG":
case "STR":
result = decodeFri(channel, remoteAddress, sentence);
break;
case "ERI":
result = decodeEri(channel, remoteAddress, sentence);
break;
case "IGN":
case "IGF":
result = decodeIgn(channel, remoteAddress, sentence);
break;
case "LSW":
case "TSW":
result = decodeLsw(channel, remoteAddress, sentence);
break;
case "IDA":
result = decodeIda(channel, remoteAddress, sentence);
break;
case "WIF":
result = decodeWif(channel, remoteAddress, sentence);
break;
case "GSM":
result = decodeGsm(channel, remoteAddress, sentence);
break;
case "VER":
result = decodeVer(channel, remoteAddress, sentence);
break;
case "PNA":
case "PFA":
result = decodePna(channel, remoteAddress, sentence);
break;
default:
result = decodeOther(channel, remoteAddress, sentence, type);
break;
}
if (result == null) {
result = decodeBasic(channel, remoteAddress, sentence, type);
}
if (result != null) {
if (result instanceof Position) {
((Position) result).set(Position.KEY_TYPE, type);
} else {
for (Position p : (List<Position>) result) {
p.set(Position.KEY_TYPE, type);
}
}
}
}
if (channel != null && Context.getConfig().getBoolean(Keys.PROTOCOL_ACK.withPrefix(getProtocolName()))) {
String checksum;
if (sentence.endsWith("$")) {
checksum = sentence.substring(sentence.length() - 1 - 4, sentence.length() - 1);
} else {
checksum = sentence.substring(sentence.length() - 4);
}
channel.writeAndFlush(new NetworkMessage("+SACK:" + checksum + "$", remoteAddress));
}
return result;
}
use of org.traccar.NetworkMessage in project traccar by tananaev.
the class GalileoProtocolDecoder method sendResponse.
private void sendResponse(Channel channel, int header, int checksum) {
if (channel != null) {
ByteBuf reply = Unpooled.buffer(3);
reply.writeByte(header);
reply.writeShortLE((short) checksum);
channel.writeAndFlush(new NetworkMessage(reply, channel.remoteAddress()));
}
}
Aggregations