-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpsChecksum_dev.cpp
47 lines (37 loc) · 1.14 KB
/
gpsChecksum_dev.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
GPS Checksum function and testing
Author(s): Skye Mceowen
*/
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
using namespace std;
//global variable so you can print its value outside of the checksum fxn
int tmpChecksum;
//Function comparing GPS checksum with your checksum
bool checksum(char* gpsData, int gpsChecksum){
//int length = 82; //double check
tmpChecksum = 0; //double check
int i = 1;
//for(int i=0; i<length; i++){
while(gpsData[i] != '*'){
tmpChecksum ^= gpsData[i];
i++;}
if(tmpChecksum == gpsChecksum){return true;}
else{return false;}
}
/*MAIN
Takes a gps packet and valid gps checksum to compare
NOTE: MUST put "\" in front of gps packet so format is "\$"[bunch of shit]"*"[2 char checksum in DECIMAL]
*/
int main( int argc, char *argv[] ){
argc = 2;
char* packet = argv[1]; //gps checksum
int gpsChecksum = (atoi)(argv[2]);
bool compatible;
compatible = checksum(packet, gpsChecksum);
cout << "Checksum compatibility was " << compatible << endl;
cout << "GPS checksum: " << gpsChecksum << endl;
cout << "Your checksum: " << tmpChecksum << endl;
return 0;
}