Search in sources :

Example 81 with NetworkMessage

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));
    }
}
Also used : NetworkMessage(org.traccar.NetworkMessage)

Example 82 with NetworkMessage

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));
    }
}
Also used : NetworkMessage(org.traccar.NetworkMessage)

Example 83 with NetworkMessage

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;
}
Also used : DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) NetworkMessage(org.traccar.NetworkMessage) Parser(org.traccar.helper.Parser)

Example 84 with NetworkMessage

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;
}
Also used : Position(org.traccar.model.Position) LinkedList(java.util.LinkedList) List(java.util.List) ByteBuf(io.netty.buffer.ByteBuf) NetworkMessage(org.traccar.NetworkMessage) WifiAccessPoint(org.traccar.model.WifiAccessPoint)

Example 85 with NetworkMessage

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()));
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) NetworkMessage(org.traccar.NetworkMessage)

Aggregations

NetworkMessage (org.traccar.NetworkMessage)146 ByteBuf (io.netty.buffer.ByteBuf)93 DeviceSession (org.traccar.DeviceSession)67 Position (org.traccar.model.Position)67 Parser (org.traccar.helper.Parser)34 Date (java.util.Date)27 DateBuilder (org.traccar.helper.DateBuilder)20 LinkedList (java.util.LinkedList)18 Network (org.traccar.model.Network)16 SimpleDateFormat (java.text.SimpleDateFormat)9 WifiAccessPoint (org.traccar.model.WifiAccessPoint)8 DateFormat (java.text.DateFormat)6 List (java.util.List)5 DatagramChannel (io.netty.channel.socket.DatagramChannel)4 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)4 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)4 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 CellTower (org.traccar.model.CellTower)3 DatagramPacket (io.netty.channel.socket.DatagramPacket)2