forked from n7tae/mrefd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-all.cpp
57 lines (46 loc) · 1.27 KB
/
test-all.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
48
49
50
51
52
53
54
55
56
57
#include <cstdio>
#include <cstring>
#include "crc.h"
#include "callsign.h"
int main()
{
if (sizeof(uint64_t) != sizeof(size_t))
{
printf("ERROR! Type size_t is not 64 bits.\n");
return 1;
}
std::string callsign("M17-USA A");
CCallsign cs(callsign);
auto coded = cs.Hash();
if (coded == 0x05f74c74caedu)
{
uint8_t code[6] = { 0 };
auto c = coded;
for (int i=5; c; i--)
{
code[i] = c % 0x100u;
c /= 0x100u;
}
CCallsign cs1(code);
printf("Callsign %s is 0x%lx and decodes back to %s\n", callsign.c_str(), coded, cs1.GetCS().c_str());
}
else
{
printf("ERROR with callsign encoding!\n");
return 1;
}
CCRC crc;
unsigned char string[256];
string[0] = 'A';
auto calc = crc.CalcCRC(string, 1);
printf("\nThe calculated crc of \"A\" is 0x%x. This result is %s!\n\n", calc, (calc==0x206eu) ? "correct" : "INCORRECT");
memcpy(string, "123456789", 9);
calc = crc.CalcCRC(string, 9);
printf("The calculated crc of \"123456789\" is 0x%x. This result is %s!\n\n", calc, (calc==0x772bu) ? "correct" : "INCORRECT");
string[0] = 'A';
for (int i=0; i<0x100; i++)
string[i] = i;
calc = crc.CalcCRC(string, 256);
printf("The calculated crc of {0x0..0xff} is 0x%x. This result is %s!\n\n", calc, (calc==0x1c31u) ? "correct" : "INCORRECT");
return 0;
}