Search in sources :

Example 61 with NetworkMessage

use of org.traccar.NetworkMessage in project traccar by tananaev.

the class Pt60ProtocolDecoder method sendResponse.

private void sendResponse(Channel channel, SocketAddress remoteAddress, String format, int type, String imei) {
    if (channel != null) {
        String message;
        String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        if (format.equals("G")) {
            message = String.format("@G#@,V01,38,%s,@R#@", time);
        } else {
            message = String.format("@B#@|01|%03d|%s|0|%s|@E#@", type + 1, imei, time);
        }
        channel.writeAndFlush(new NetworkMessage(message, remoteAddress));
    }
}
Also used : NetworkMessage(org.traccar.NetworkMessage) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 62 with NetworkMessage

use of org.traccar.NetworkMessage in project traccar by tananaev.

the class R12wProtocolDecoder method sendResponse.

private void sendResponse(Channel channel, String type, String id, String data) {
    if (channel != null) {
        String sentence = String.format("$HX,%s,%s,%s,#", type, id, data);
        sentence += String.format(",%02x,\r\n", Checksum.xor(sentence));
        channel.writeAndFlush(new NetworkMessage(sentence, channel.remoteAddress()));
    }
}
Also used : NetworkMessage(org.traccar.NetworkMessage)

Example 63 with NetworkMessage

use of org.traccar.NetworkMessage in project traccar by tananaev.

the class RaceDynamicsProtocolDecoder method sendResponse.

private void sendResponse(Channel channel, SocketAddress remoteAddress, int type) {
    if (channel != null) {
        String response = String.format("$GPRMC,%1$d,%2$td%2$tm%2$ty,%2$tH%2$tM%2$tS,%3$s,\r\n", type, new Date(), imei);
        channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
    }
}
Also used : NetworkMessage(org.traccar.NetworkMessage) Date(java.util.Date)

Example 64 with NetworkMessage

use of org.traccar.NetworkMessage in project traccar by tananaev.

the class SanulProtocolDecoder method sendResponse.

private void sendResponse(Channel channel, int type) {
    if (channel != null) {
        ByteBuf response = Unpooled.buffer();
        // header
        response.writeByte(0xaa);
        // reserved
        response.writeShortLE(0x85da);
        // length
        response.writeShortLE(15);
        // edition
        response.writeByte(1);
        response.writeShortLE(MSG_RESPONSE);
        response.writeShortLE(type);
        // command id
        response.writeIntLE(0);
        // status
        response.writeByte(0);
        // result length
        response.writeByte(0);
        // result data ?
        response.writeIntLE(0x20000);
        channel.writeAndFlush(new NetworkMessage(response, channel.remoteAddress()));
    }
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) NetworkMessage(org.traccar.NetworkMessage)

Example 65 with NetworkMessage

use of org.traccar.NetworkMessage in project traccar by tananaev.

the class Pt215ProtocolDecoder method sendResponse.

private void sendResponse(Channel channel, SocketAddress remoteAddress, int type, ByteBuf content) {
    if (channel != null) {
        ByteBuf response = Unpooled.buffer();
        response.writeByte('X');
        response.writeByte('X');
        response.writeByte(content != null ? 1 + content.readableBytes() : 1);
        response.writeByte(type);
        if (content != null) {
            response.writeBytes(content);
            content.release();
        }
        response.writeByte('\r');
        response.writeByte('\n');
        channel.writeAndFlush(new NetworkMessage(response, 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