以下是我们从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;
}
要计算xor char在“ $”和“ *”之间的总和。我的程序是:
基本上,我们检查每个字符是否为“ $”,然后检查xor元素,直到收到*。 但是我有一个小问题...我需要检查每行数据-NEO-7每隔一定时间[280]个字符的传输包,其中包括11“ $:和11 *。有两种方法检查我能想到的一切: