Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
164 lines (151 loc) · 4.51 KB
/
Copy pathmain.cpp
File metadata and controls
164 lines (151 loc) · 4.51 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <stdio.h>
#include <cstdint>
#include "TelemetryBlackBox.h"
using namespace std;
int calcXORsum(uint32_t frame){
uint8_t byte1 = (uint8_t)((0x000000FF & frame));
uint8_t byte2 = (uint8_t)((0x0000FF00 & frame) >> 8);
uint8_t byte3 = (uint8_t)((0x00FF0000 & frame) >> 16);
int checkSum = byte1 ^ byte2 ^ byte3;
return checkSum;
}
void regularTest(TelemetryBlackBox box, int i){
box.onRocketStateChange(RocketState::FLIGHT);
box.onParachuteDeployed();
box.onBaroReading(0, 1562);
box.recordCurrentState();
printf("Funkcjonalnosc podstawowa ---\n");
uint32_t output = box.getLastDataframe();
uint32_t correct = (1562 << 8) + 0b00001010;
uint32_t xorSum = calcXORsum(correct);
correct += (xorSum << 24);
if (output == correct){
printf("Test numer %d: PASS\n", i);
}
else{
printf("Test numer %d: FAIL\n", i);
}
}
void zeroAltTestLanded(TelemetryBlackBox box, int i){
box.onRocketStateChange(RocketState::LANDED);
box.onBaroReading(0, 200);
box.recordCurrentState();
printf("Zerowanie altitude przy landed---\n");
uint32_t output = box.getLastDataframe();
uint32_t correct = 0b0100;
uint32_t xorSum = calcXORsum(correct);
correct += (xorSum << 24);
if (output == correct){
printf("Test numer %d: PASS\n", i);
}
else{
printf("Test numer %d: FAIL\n", i);
}
}
void zeroAltTestDisarm(TelemetryBlackBox box, int i){
box.onRocketStateChange(RocketState::DISARM);
box.onBaroReading(0, 200);
box.recordCurrentState();
printf("Zerowanie altitude przy disarm ---\n");
uint32_t output = box.getLastDataframe();
uint32_t correct = 0b0000;
uint32_t xorSum = calcXORsum(correct);
correct += (xorSum << 24);
if (output == correct){
printf("Test numer %d: PASS\n", i);
}
else{
printf("Test numer %d: FAIL\n", i);
}
}
void baroErrorTest(TelemetryBlackBox box, int i){
box.onRocketStateChange(RocketState::FLIGHT);
box.onBaroReading(1, 1000);
box.recordCurrentState();
printf("Blad odczytu ---\n");
uint32_t output = box.getLastDataframe();
uint32_t correct = 0b00010010 + 0x00FFFF00;
uint32_t xorSum = calcXORsum(correct);
correct += (xorSum << 24);
if (output == correct){
printf("Test numer %d: PASS\n", i);
}
else{
printf("Test numer %d: FAIL\n", i);
}
}
void historyTest(TelemetryBlackBox box, int i){
box.onRocketStateChange(RocketState::FLIGHT);
box.onBaroReading(0, 1500);
box.recordCurrentState();
box.getLastDataframe();
box.onBaroReading(0, 1750);
box.recordCurrentState();
printf("\nTest historii ---\n");
uint32_t output = box.getLastDataframe();
uint32_t correct = (1750 << 8) + 0b00000010;
uint32_t xorSum = calcXORsum(correct);
correct += (xorSum << 24);
if (output == correct){
printf("Test numer %d: PASS\n", i);
}
else{
printf("Test numer %d: FAIL\n", i);
}
}
void checkSumTest(TelemetryBlackBox box, int i){
box.onRocketStateChange(RocketState::FLIGHT);
box.onParachuteDeployed();
box.onBaroReading(0, 1562);
box.recordCurrentState();
printf("Funkcjonalnosc checksum ---\n");
uint32_t output = box.recordWithBadXor();
if (output == 0xFFFFFFFF){
printf("Test numer %d: PASS\n", i);
}
else{
printf("Test numer %d: FAIL\n", i);
}
}
void checkCircleBuffer(TelemetryBlackBox box, int i){
for(int j = 0; j < 20; j++){
box.onRocketStateChange(RocketState::FLIGHT);
box.onBaroReading(0, j*100+j);
box.recordCurrentState();
}
box.onRocketStateChange(RocketState::FLIGHT);
box.onBaroReading(0, 3000);
box.recordCurrentState();
printf("Funkcjonalnosc bufora kolowego ---\n");
uint32_t output = box.getLastDataframe();
uint32_t correct = (3000 << 8) + 0b00000010;
uint32_t xorSum = calcXORsum(correct);
correct += (xorSum << 24);
if (output == correct){
printf("Test numer %d: PASS\n", i);
}
else{
printf("Test numer %d: FAIL\n", i);
}
}
int main(){
// lista testow
void (*tests[])(TelemetryBlackBox object, int i) = {
regularTest,
zeroAltTestLanded,
zeroAltTestDisarm,
baroErrorTest,
historyTest,
checkSumTest,
checkCircleBuffer
};
TelemetryBlackBox testBox;
// wykonywanie testow
int counter = 1;
for (auto test : tests){
printf("\n");
test(testBox, counter++);
}
printf("\n");
return 0;
}