Teltonika TST100 GPRS 命令未通过 TCP 发送

发布于 2025-01-11 05:08:17 字数 1872 浏览 0 评论 0原文

我有一个 teltonika tcp 服务器,可以解析数据,它工作正常,但我无法发送 gprs 命令,我不知道为什么或我做错了什么。以下是他们的网站文档:

首先,Teltonika设备打开GPRS会话并发送AVL数据 到服务器(请参阅设备协议)。所有记录发送完毕后 设备收到正确发送的数据阵列确认,然后 GPRS 可以将十六进制命令发送到设备。 ACK(确认 来自服务器的 IMEI)是一个一字节常量 0x01。的认可 从设备发送的每个数据数组都是四个字节整数 - 一个数字 收到的记录数。

这是应该有效的 getinfo 十六进制示例 第 1 个示例:通过 GPRS Codec12 发送 getinfo SMS 命令

十六进制流中的服务器请求: 000000000000000F0C010500000007676574696E666F0100004312

这是我的nodejs tcp服务器

const net = require('net');
const Parser = require('teltonika-parser-ex');
const binutils = require('binutils64');
const { parse } = require('path');


let server = net.createServer((c) => {
    console.log("client connected");
    c.on('end', () => {
        console.log("client disconnected");
    });

    c.on('data', (data) => {

   
        let buffer = data;
        console.log(buffer);
      
        let parser = new Parser(buffer);     

        if (parser.isImei) {
            c.write(Buffer.alloc(1, 1)); // send ACK for IMEI
        } else {


            let avl = parser.getAvl();
          
             console.log("parseRec", avl?.records?.map(({ gps, timestamp }) => {
                  return { gps, timestamp }
              }
              )
              )

            let writer = new binutils.BinaryWriter();
            writer.WriteInt32(avl.number_of_data);


            let response = writer.ByteBuffer;

           c.write(response); // send ACK for AVL DATA
            // console.log(test);
            
        c.write("000000000000000F0C010500000007676574696E666F0100004312"); // SEND GETINFO command that is not working
        }
 
    });

});

server.listen(1574, '0.0.0.0', () => {
    console.log("Server started");
});

最后一个c.write("000000000000000F0C010500000007676574696E666F0100004312");应该发送 getinfo 命令,我应该得到答案,但我什么也没得到。

i have a teltonika tcp server that parses data it works ok but i'm not able to send gprs command and i don't know why or what i do wrong. Here is from their website documentation:

First, the Teltonika device opens the GPRS session and sends AVL data
to the server (refer device protocols). Once all records are sent and
correct sent data array acknowledgment is received by device then GPRS
commands in Hex can be sent to the device. The ACK (acknowledge of
IMEI from server) is a one-byte constant 0x01. The acknowledgment of
each data array send from the device is four bytes integer – a number
of received records.

this is the getinfo hex example that should work
1'st example: Sending getinfo SMS command via GPRS Codec12

Server request in hexadecimal stream:
000000000000000F0C010500000007676574696E666F0100004312

here is my nodejs tcp server

const net = require('net');
const Parser = require('teltonika-parser-ex');
const binutils = require('binutils64');
const { parse } = require('path');


let server = net.createServer((c) => {
    console.log("client connected");
    c.on('end', () => {
        console.log("client disconnected");
    });

    c.on('data', (data) => {

   
        let buffer = data;
        console.log(buffer);
      
        let parser = new Parser(buffer);     

        if (parser.isImei) {
            c.write(Buffer.alloc(1, 1)); // send ACK for IMEI
        } else {


            let avl = parser.getAvl();
          
             console.log("parseRec", avl?.records?.map(({ gps, timestamp }) => {
                  return { gps, timestamp }
              }
              )
              )

            let writer = new binutils.BinaryWriter();
            writer.WriteInt32(avl.number_of_data);


            let response = writer.ByteBuffer;

           c.write(response); // send ACK for AVL DATA
            // console.log(test);
            
        c.write("000000000000000F0C010500000007676574696E666F0100004312"); // SEND GETINFO command that is not working
        }
 
    });

});

server.listen(1574, '0.0.0.0', () => {
    console.log("Server started");
});

the last c.write("000000000000000F0C010500000007676574696E666F0100004312"); should send the getinfo command and i should get an answer but i don't get nothing back.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风渺 2025-01-18 05:08:17

最好发送“no_of_avl_data”的十六进制值。检查下面的完整代码。

server.on("connection", (socket) => {

socket.setEncoding("hex");

socket.on("data", (data) => {   
        
    if (data.length == 34) {            
        let imeiAck = Buffer.from('01', 'hex');
        socket.write(imeiAck);  // send IMEI ack to device          
    } else {                    
    
        //parse data            
        let parsed = new ProtocolParser(data)
        const avlData = JSON.stringify(parsed.Content.AVL_Datas);  
        const avlDataParse = JSON.parse(avlData)
        var avlLength = avlDataParse.length;

        let numData = avlLength; // Replace with the actual number of data received
        let hexString = numData.toString(16).padStart(8, '0');
        let packetAck = Buffer.from(hexString, 'hex');

        socket.write(packetAck); // send packet ack to device back  
        
        console.log('play with data');
                            
    }
            
});
socket.on("close", () => {});
socket.on("error", (err) => {
    //console.log(err.message);
});
});

It would be best if you will send the HEX value of "no_of_avl_data". Check the full code below.

server.on("connection", (socket) => {

socket.setEncoding("hex");

socket.on("data", (data) => {   
        
    if (data.length == 34) {            
        let imeiAck = Buffer.from('01', 'hex');
        socket.write(imeiAck);  // send IMEI ack to device          
    } else {                    
    
        //parse data            
        let parsed = new ProtocolParser(data)
        const avlData = JSON.stringify(parsed.Content.AVL_Datas);  
        const avlDataParse = JSON.parse(avlData)
        var avlLength = avlDataParse.length;

        let numData = avlLength; // Replace with the actual number of data received
        let hexString = numData.toString(16).padStart(8, '0');
        let packetAck = Buffer.from(hexString, 'hex');

        socket.write(packetAck); // send packet ack to device back  
        
        console.log('play with data');
                            
    }
            
});
socket.on("close", () => {});
socket.on("error", (err) => {
    //console.log(err.message);
});
});
萌逼全场 2025-01-18 05:08:17

我设法让它工作,我必须将它转换为十六进制缓冲区。看来我正在发送一个字符串。这是我必须修改的内容,以防其他人遇到我的问题:

c.write(Buffer.from('000000000000000F0C010500000007676574696E666F0100004312', 'hex'));

i managed to make it work, i had to convert it to a buffer in hex. It seems i was sending a string. Here is what i had to modify in case someone else has my problem:

c.write(Buffer.from('000000000000000F0C010500000007676574696E666F0100004312', 'hex'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文