STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
test_mode_core.c
Go to the documentation of this file.
1
/* mode_core: what is powered in each state, where commands go. */
2
#include <stdio.h>
3
#include <stdlib.h>
4
5
#include "
mode_core.h
"
6
7
#define CHECK(c) \
8
do { \
9
if (!(c)) { \
10
fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, #c); \
11
exit(1); \
12
} \
13
} while (0)
14
15
static
void
test_idle_keeps_only_the_radio
(
void
) {
16
mode_outputs_t
o
=
mode_outputs
(
FLIGHT_IDLE
);
17
CHECK
(!
o
.sensors && !
o
.gps && !
o
.ethernet);
18
CHECK
(
o
.idle_loop);
19
CHECK
(
o
.radio_sniff);
/* Idle saves power: the radio duty-cycles */
20
}
21
22
static
void
test_armed_onwards_runs_everything
(
void
) {
23
const
flight_state_t
on[] = {
FLIGHT_ARMED
,
FLIGHT_LAUNCHED
,
24
FLIGHT_RECOVERY
};
25
for
(
unsigned
i = 0; i < 3; ++i) {
26
mode_outputs_t
o
=
mode_outputs
(on[i]);
27
CHECK
(
o
.sensors &&
o
.gps &&
o
.ethernet && !
o
.idle_loop);
28
CHECK
(!
o
.radio_sniff);
/* armed: listen all the time */
29
}
30
mode_outputs_t
s =
mode_outputs
(
FLIGHT_SELF_TEST
);
31
CHECK
(!s.
sensors
&& !s.
idle_loop
&& !s.
radio_sniff
);
32
mode_outputs_t
bad =
mode_outputs
(
FLIGHT_STATE_COUNT
);
33
CHECK
(!bad.
sensors
&& !bad.
gps
&& !bad.
idle_loop
);
34
}
35
36
static
void
test_commands
(
void
) {
37
flight_state_t
next =
FLIGHT_STATE_COUNT
;
38
/* In Idle the Idle loop (PR #162) owns Arm. */
39
CHECK
(
mode_route_command
(
FLIGHT_IDLE
,
MODE_CMD_ARM
, &next) ==
40
MODE_TO_IDLE_LOOP
);
41
/* Armed: Un-arm goes back to Idle; a second Arm is ignored. */
42
CHECK
(
mode_route_command
(
FLIGHT_ARMED
,
MODE_CMD_DISARM
, &next) ==
43
MODE_TRANSITION
);
44
CHECK
(next ==
FLIGHT_IDLE
);
45
CHECK
(
mode_route_command
(
FLIGHT_ARMED
,
MODE_CMD_ARM
, &next) ==
MODE_IGNORE
);
46
/* After launch an Un-arm is ignored (flight_state table). */
47
CHECK
(
mode_route_command
(
FLIGHT_LAUNCHED
,
MODE_CMD_DISARM
, &next) ==
48
MODE_IGNORE
);
49
}
50
51
int
main
(
void
) {
52
test_idle_keeps_only_the_radio
();
53
test_armed_onwards_runs_everything
();
54
test_commands
();
55
puts(
"mode_core: all tests passed"
);
56
return
0;
57
}
flight_state_t
flight_state_t
Definition
flight_state.h:25
FLIGHT_RECOVERY
@ FLIGHT_RECOVERY
Definition
flight_state.h:30
FLIGHT_SELF_TEST
@ FLIGHT_SELF_TEST
Definition
flight_state.h:26
FLIGHT_ARMED
@ FLIGHT_ARMED
Definition
flight_state.h:28
FLIGHT_IDLE
@ FLIGHT_IDLE
Definition
flight_state.h:27
FLIGHT_LAUNCHED
@ FLIGHT_LAUNCHED
Definition
flight_state.h:29
FLIGHT_STATE_COUNT
@ FLIGHT_STATE_COUNT
Definition
flight_state.h:31
o
return o
Definition
json.hpp:13897
mode_route_command
mode_route_t mode_route_command(flight_state_t state, mode_command_t command, flight_state_t *next)
Definition
mode_core.c:23
mode_outputs
mode_outputs_t mode_outputs(flight_state_t state)
Definition
mode_core.c:3
mode_core.h
MODE_TRANSITION
@ MODE_TRANSITION
Definition
mode_core.h:47
MODE_TO_IDLE_LOOP
@ MODE_TO_IDLE_LOOP
Definition
mode_core.h:46
MODE_IGNORE
@ MODE_IGNORE
Definition
mode_core.h:48
MODE_CMD_DISARM
@ MODE_CMD_DISARM
Definition
mode_core.h:43
MODE_CMD_ARM
@ MODE_CMD_ARM
Definition
mode_core.h:43
mode_outputs_t
Definition
mode_core.h:26
mode_outputs_t::idle_loop
bool idle_loop
Definition
mode_core.h:30
mode_outputs_t::gps
bool gps
Definition
mode_core.h:28
mode_outputs_t::sensors
bool sensors
Definition
mode_core.h:27
mode_outputs_t::radio_sniff
bool radio_sniff
Definition
mode_core.h:31
main
int main()
Definition
test_abort_ordering.cpp:67
CHECK
#define CHECK(c)
Definition
test_mode_core.c:7
test_idle_keeps_only_the_radio
static void test_idle_keeps_only_the_radio(void)
Definition
test_mode_core.c:15
test_armed_onwards_runs_everything
static void test_armed_onwards_runs_everything(void)
Definition
test_mode_core.c:22
test_commands
static void test_commands(void)
Definition
test_mode_core.c:36
firmware
Flight_Computer
tests
app
test_mode_core.c
Generated by
1.15.0