发送数据包到UBX协议
send packet to UBX protocol
最近我一直在研究一个支持UBX和NEMA协议的GPS接收器。我在c++上使用串行编程。我正在尝试使用UBX协议,但似乎我只从NEMA收到。我下载了驱动程序,我想我需要先发送一个包裹通过UBX接收。有人知道链接或可以告诉我如何发送这些包,我开发的方法如下所述,我想我需要一个小命令,然后我开始阅读数据。D
void read_port(void)
{
unsigned char c='D';
while (c!='q')
{
if (read(fd, UBX_buffer, sizeof(UBX_buffer))>0)
{
data = read(fd, UBX_buffer, sizeof(UBX_buffer));
// write(fd,&UBX_buffer,1); // if new data is available on the serial port, print it out
cout<<"Data on the port = ";
for (unsigned i =0; i< sizeof(UBX_buffer) ;i++){
cout<<&UBX_buffer[i];
}
cout<<" "<<endl;
for (int i=0; i<fd; i++) // Process bytes received
{
switch(UBX_step) //we start from zero and increment as we go through the cases
{
case 0:
if(data==0xB5) UBX_step++; break; // UBX sync char 1 //check for the first data packet and go to next byte
case 1: if(data==0x62) UBX_step++;// UBX sync char 2 //check for the second data packet and go to the next byte
else UBX_step=0; break; //if first and second packets are not correct then go back and check again
case 2: UBX_class=data; checksum(UBX_class); UBX_step++; break;
case 3: UBX_id=data; checksum(UBX_id); UBX_step++; break;
case 4: UBX_payload_length_hi=data; checksum(UBX_payload_length_hi); UBX_step++; break;
case 5: UBX_payload_length_lo=data; checksum(UBX_payload_length_lo); UBX_step++; break;
case 6: // Payload data read...
if (UBX_payload_counter < UBX_payload_length_hi) // We stay in this state until we reach the payload_length
{
UBX_buffer[UBX_payload_counter] = data;
checksum(data);
UBX_payload_counter++;
}
else
UBX_step++;
break;
case 7: ck_a=data; UBX_step++; break; // First checksum byte
case 8: ck_b=data; // Second checksum byte
// We end the GPS read...
if((ck_a= ck_a)&&(ck_b= ck_a)) // Verify the received checksum with the generated checksum..
parse_ubx_gps(); // Parse new GPS packet...
UBX_step=0;
UBX_payload_counter=0;
ck_a=0;
ck_b=0;
GPS_timer=0; //Restarting timer...
break;
}
}
if (read(STDIN_FILENO,&c,1)>0) write(fd,&c,1); // if new data is available on the console, send it to the serial port
}
close(fd);
} // End Switch
} // End For
您可以在ublox主页下载ublox协议规范。在这里,查看cfg消息。出于测试目的,您还可以通过工具u-Center
启用ubx协议。
相关文章:
- 如何在cpp.中使用协议缓冲区存储大缓冲区/数组(char/int)
- 如何使用url确定网站协议
- MSYS2 MinGW程序包中缺少grpc_cpp_plugin协议
- 用CMake构建C++协议
- 从原始字节解码协议缓冲区(以 C++为单位)
- 如何使用ZeroMQ为协议缓冲区编写自己的RPC实现
- 协议缓冲区字符串字段的文本编码
- 如何使用librdkafka设置明文协议(无SASL)的用户名和密码?
- 构建使用协议缓冲区(不含 APK)的 Android 可执行 gRPC 服务器
- 用于处理多个通信协议处理的设计类
- 无法使用 ReadBinaryProto Tensorflow 加载协议缓冲区
- 协议缓冲区的静态链接会导致与现有符号冲突
- 协议缓冲区ParseFromString不检查消息结尾
- 如何自定义wxApp来实现协议
- 与Qt交叉编译到Raspberry Pi 3B+通讯录(协议缓冲区)-错误符号查找错误
- 编译的谷歌协议缓冲区不工作(C++)
- 使用协议缓冲区创建通用反序列化程序
- 在协议缓冲区 c++ 中反序列化字符串数组
- 使用升压缓冲区使用 UDP 协议进行序列化和发送
- 发送数据包到UBX协议