c - GPS 模块数据 - 解决方案?
问题描述
以下是我们从 GNSS 模块收到的数据:
#include <stdio.h>
#include <stdlib.h>
//$GPGLL,,,,,,V,N*64
//$GaabL,,,,,,V,N*5D
char Received[] = { "Odetnij to jak mozesz$GaabL,,,,,,V,N*5D" };
int main(void)
{
int i = 0;
int b;
int c;
int super_atoi;
int wynik;
int xor = 0;
while (Received[i] != '$')
{
printf("%c", Received[i]);
i++;
}
i++;
printf("%c\n ");
while (Received[i] != '*')
{
printf("%c", Received[i]);
xor ^= Received[i];
i++;
}
printf("\n XOR = %d", xor);
printf("\n XOR w hex = %#02x ", xor);
printf("\n XOR w dec = %d ", xor);
if (Received[i] == '*')
{
i++;
b = Received[i];
printf("\n 1 znak w kodzie za * = %c", b);
i++;
c = Received[i];
printf("\n 2 znak w kodzie za * = %c", c);
}
char a[3] = { b, c };
super_atoi = atoi(a);
super_atoi = strtol(a, NULL, 16);
printf("\n ATOI = %s ", a, super_atoi);
if (xor == super_atoi)
{
printf("%c\n ");
printf("\n WORKING!");
}
else
{
printf("%c\n ");
printf("\n not working");
}
return 0;
}
要计算每个的 sumcheck,我们必须在 "$" 和 "*" 之间对字符进行异或运算。我的计划是:
基本上,我们检查每个字符是否为“$”,然后对元素进行异或,直到我们收到 *。但是我有一个小问题......我需要检查每一行数据 - NEO-7 在每个特定时间段传输 [280]+ 字符包,其中包括 11"$: 和 11 *。有两种方法检查我能想到的一切:
- 检查每一个字节(char),在出现“$”时开始计数,在出现*时结束,将结果与“*”后的2个元素进行比较。
- (更适合我的程序)从 GPS 模块接收数组 [35],创建单独的数组,我将在其中包含上一次 sumcheck 剩下的内容,放入来自 GPS 的下一组数据,重复。你能告诉我什么更好吗?还有如何创建这些解决方案?
解决方案
推荐阅读
- c# - c#中的a is string和a !is string有什么区别
- android - 将 android studio 活动保存在单独的文件中
- mysql - PHP mySQL 查询,加入另一个表,但需要获取所有行
- react-native - Branch.io React Native 单次使用邀请链接
- soap - soapUI 中出现 401 Not Authorized 错误,但 Web 服务在 Postman 中运行良好
- javascript - 在链接单击 JS (anchrome.js) 时在新选项卡上打开链接
- python - 为什么 django 的 reverse() 不能匹配电子邮件参数?
- c++ - 解决这个问题最省时的方法是什么?
- python - 如何连接到新窗口
- java - 删除数据库中的所有表后,如何在数据库中创建表?