0

我一直在使用 TK06A GPS 跟踪器,并且正在开发自己的服务器 java 文件,并且根据 TK06A 手册收到了初始登录消息包,现在我需要将 ack 发送回设备以获取 GPS 消息包。

我没有收到保存坐标的 GPS 消息包。我在下面添加代码。我确信在获得 LOC 中的 IMEI 号码是正确的之前,我在输出流/发送 Ak 时遇到问题。我完全被这里打动了。我不知道我哪里错了。

请帮忙!

public void run() {
DataInputStream inputS = null;
DataOutputStream dos = null;
try {
    inputS = new DataInputStream(socket.getInputStream());
    if (inputS.available() > 0) {
        byte[] bb = getBytesFromInputStream(inputS);
        ChannelBuffer buf = toByteBuffer(bb);
        String imei = readImei(buf);
        System.out.println("IMEI::::: " + imei);
        buf.skipBytes(5); // End

        OutputStream os = socket.getOutputStream();
        dos = new DataOutputStream(os);
        byte[] response = parseHex();

        dos.write(response);
        Thread.sleep(1000);
        dos.flush();

    }

} catch (Exception e) {
    e.printStackTrace();
}

finally {
    try {
        inputS.close();
        if (dos != null)
            dos.close();
        socket.close();
    } catch (IOException e) {

    }
}

}

public byte[] parseHex() {
    String  hexACKlogin = "787805010001D9DC0D0A"; // String in HEX format
    int len = hexACKlogin.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(hexACKlogin.charAt(i), 16) << 4)
                             + Character.digit(hexACKlogin.charAt(i+1), 16));
    }  
     return data;
}
4

1 回答 1

0

我正在为 GPS 跟踪设备 (TK06A) 实现逻辑。客户端是我用来读取从跟踪器发送的数据的 GPS 跟踪器和服务器。

我收到一个 18 字节的数据,我发现它是一个不包含坐标/纬度和经度的登录消息数据包。

据说我需要向客户端发送一个ACK响应[我卡在这里]。

在我的情况下,我需要将字节作为响应发送给客户端 Gps 跟踪器字节 [] 响应 = {0x78 0x78 0x05 0x01 0x00 0x01 0xD9 0xDC 0x0D 0x0A};

我已经使用 portpeeker 发送了 ack,它返回了一些 36 字节的响应。

PS:我正在使用 TCP 进行数据传输

try {
        inputS = new DataInputStream(socket.getInputStream());
        oos = new ObjectOutputStream(socket.getOutputStream());
        if (inputS.available() > 0) {
            System.out.println("Bytes Cap::: "+inputS.available());
            byte[] bb = getBytesFromInputStream(inputS);
            ChannelBuffer buf = toByteBuffer(bb);
            buf.skipBytes(4);
            String imei = readImei(buf);
            System.out.println("IMEI::::: " + imei);
            buf.skipBytes(5); // End

            byte[] response = sendOutputMessage();
            oos.write(response);
            oos.flush();
        }

    } catch (Exception e) {
        e.printStackTrace();
    }finally{
        try {
            inputS.close();
            oos.close();
            socket.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

 public byte[] sendOutputMessage() {
    byte buf[] = new byte[10];
    // Start of the body of setOutput
    // Message type  0x78 0x78 0x05 0x01 0x00 0x01 0xD9 0xDC 0x0D 0x0A
    buf[0] = (byte) 0x78;
    buf[1] = (byte) 0x78;
    buf[2] = (byte) 0x05;
    buf[3] = (byte) 0x01;
    buf[4] = (byte) 0x00;
    buf[5] = (byte) 0x01;
    buf[6] = (byte) 0xD9;
    buf[7] = (byte) 0xDC;
    buf[8] = (byte) 0x0D; // end f1
    buf[9] = (byte) 0x0A;
    return buf;
}
于 2014-12-28T14:33:45.823 回答