带有GPS的Ack数据包构造

时间:2017-01-31 04:11:45

标签: c sockets server gps

我在C中运行服务器来收听GPS设备。根据制造商的规范,服务器应以确认数据包的形式响应登录数据包和心跳数据包。服务器确认包长度为10个字节。我正在尝试按如下方式构建数据包:

/* 
packet structure
start bit - 2 bytes ( 0-1)
packet length - 1 byte(2)
Protocol no - 1 byte(3)
info serial no - 2 bytes(4-5)
check sum - 2 bytes(6-7)
stop_bit - 2 bytes(8-9)
TOTAL 10 bytes

*/  
 unsigned char ack[11];
 ack[0] = 0x78;
 ack[1] = 0x78;
 ack[2] = 0x05; //packet length
 ack[3] = buffer[3]; //protocol no
 ack[4] = buffer[size-6]; //info serial 1st byte where 
 //size is incoming packet length
 ack[5] = buffer[size-5]; //info serial 2nd byte
 // crc16 is the value coming from checksum function
 ack[6] = ack[6] =(crc16>>8) & 0xFF; //chksum byte1
 ack[7] = crc16 & 0xFF;//chksum byte 2
 ack[8] = 0x0D; //stop byte1
 ack[9] = 0x0A; //stop byte2

但是,我没有从登录数据包之外的服务器收到任何响应。获得快速回复会很有帮助

0 个答案:

没有答案