32 float dummy_acc[3] = {0, 0, -9.80665};
33 float dummy_gyro[3] = {0, 0, 0};
45 EXPECT_EQ(rf.state_manager_.state().armed,
false);
46 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
47 EXPECT_EQ(rf.state_manager_.state().error_codes, 0x00);
48 EXPECT_EQ(rf.state_manager_.state().error,
false);
57 rf.state_manager_.set_error(
error);
58 EXPECT_EQ(rf.state_manager_.state().armed,
false);
59 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
60 EXPECT_EQ(rf.state_manager_.state().error_codes,
error);
61 EXPECT_EQ(rf.state_manager_.state().error,
true);
64 rf.state_manager_.clear_error(
error);
65 EXPECT_EQ(rf.state_manager_.state().armed,
false);
66 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
68 EXPECT_EQ(rf.state_manager_.state().error,
false);
76 rf.state_manager_.set_error(error);
77 EXPECT_EQ(rf.state_manager_.state().armed,
false);
78 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
79 EXPECT_EQ(rf.state_manager_.state().error_codes, 0x32);
80 EXPECT_EQ(rf.state_manager_.state().error,
true);
87 rf.state_manager_.set_error(error);
89 EXPECT_EQ(rf.state_manager_.state().armed,
false);
90 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
91 EXPECT_EQ(rf.state_manager_.state().error_codes, 0x33);
92 EXPECT_EQ(rf.state_manager_.state().error,
true);
99 rf.state_manager_.set_error(error);
101 EXPECT_EQ(rf.state_manager_.state().armed,
false);
102 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
103 EXPECT_EQ(rf.state_manager_.state().error_codes,
105 EXPECT_EQ(rf.state_manager_.state().error,
true);
112 rf.state_manager_.set_error(error);
114 EXPECT_EQ(rf.state_manager_.state().armed,
false);
115 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
117 EXPECT_EQ(rf.state_manager_.state().error,
true);
124 rf.state_manager_.set_error(error);
125 rf.state_manager_.clear_error(error);
126 EXPECT_EQ(rf.state_manager_.state().armed,
false);
127 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
128 EXPECT_EQ(rf.state_manager_.state().error_codes, 0x00);
129 EXPECT_EQ(rf.state_manager_.state().error,
false);
137 EXPECT_EQ(rf.state_manager_.state().armed,
false);
138 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
140 EXPECT_EQ(rf.state_manager_.state().error,
true);
146 EXPECT_EQ(rf.state_manager_.state().armed,
true);
147 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
149 EXPECT_EQ(rf.state_manager_.state().error,
false);
155 EXPECT_EQ(rf.state_manager_.state().armed,
true);
158 EXPECT_EQ(rf.state_manager_.state().armed,
false);
159 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
161 EXPECT_EQ(rf.state_manager_.state().error,
false);
170 EXPECT_EQ(rf.state_manager_.state().armed,
false);
171 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
173 EXPECT_EQ(rf.state_manager_.state().error,
false);
177 EXPECT_EQ(rf.state_manager_.state().armed,
true);
178 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
179 EXPECT_EQ(rf.state_manager_.state().error_codes, 0x00);
180 EXPECT_EQ(rf.state_manager_.state().error,
false);
189 EXPECT_EQ(rf.state_manager_.state().armed,
false);
190 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
192 EXPECT_EQ(rf.state_manager_.state().error,
false);
201 EXPECT_EQ(rf.state_manager_.state().armed,
false);
202 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
204 EXPECT_EQ(rf.state_manager_.state().error,
true);
213 EXPECT_EQ(rf.state_manager_.state().armed,
false);
214 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
216 EXPECT_EQ(rf.state_manager_.state().error,
true);
224 EXPECT_EQ(rf.state_manager_.state().armed,
false);
227 EXPECT_EQ(rf.state_manager_.state().armed,
false);
236 EXPECT_EQ(rf.state_manager_.state().armed,
false);
239 EXPECT_EQ(rf.state_manager_.state().armed,
false);
246 EXPECT_EQ(rf.state_manager_.state().armed,
true);
249 EXPECT_EQ(rf.state_manager_.state().armed,
true);
250 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
252 EXPECT_EQ(rf.state_manager_.state().error,
true);
261 EXPECT_EQ(rf.state_manager_.state().armed,
false);
262 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
264 EXPECT_EQ(rf.state_manager_.state().error,
true);
274 EXPECT_EQ(rf.state_manager_.state().armed,
false);
276 EXPECT_EQ(rf.state_manager_.state().error,
true);
281 uint16_t rc_values[8];
282 for (
int i = 0;
i < 8;
i++)
284 rc_values[
i] = (
i > 3) ? 1000 : 1500;
287 board.set_rc(rc_values);
290 EXPECT_EQ(
true, rf.state_manager_.state().armed);
296 uint16_t rc_values[8];
297 for (
int i = 0;
i < 8;
i++)
299 rc_values[
i] = (
i > 3) ? 1000 : 1500;
302 board.set_rc(rc_values);
307 EXPECT_EQ(rf.state_manager_.state().armed,
false);
313 uint16_t rc_values[8];
314 for (
int i = 0;
i < 8;
i++)
316 rc_values[
i] = (
i > 3) ? 1000 : 1500;
319 board.set_rc(rc_values);
324 EXPECT_EQ(rf.state_manager_.state().armed,
false);
330 EXPECT_EQ(rf.state_manager_.state().armed,
false);
331 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
333 EXPECT_EQ(rf.state_manager_.state().error,
true);
340 EXPECT_EQ(rf.state_manager_.state().armed,
false);
347 EXPECT_EQ(rf.state_manager_.state().armed,
false);
350 EXPECT_EQ(rf.state_manager_.state().armed,
true);
357 EXPECT_EQ(rf.state_manager_.state().armed,
true);
358 EXPECT_EQ(rf.state_manager_.state().error,
true);
360 EXPECT_EQ(rf.state_manager_.state().failsafe,
true);
368 EXPECT_EQ(rf.state_manager_.state().armed,
false);
369 EXPECT_EQ(rf.state_manager_.state().error,
true);
371 EXPECT_EQ(rf.state_manager_.state().failsafe,
true);
379 EXPECT_EQ(rf.state_manager_.state().armed,
true);
380 EXPECT_EQ(rf.state_manager_.state().error,
false);
382 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
384 constexpr uint32_t StateManager::BackupData::ARM_MAGIC;
387 board.backup_memory_clear();
388 rf.state_manager_.check_backup_memory();
389 EXPECT_EQ(rf.state_manager_.state().armed,
false);
390 EXPECT_EQ(rf.state_manager_.state().error,
false);
392 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
396 board.backup_memory_clear();
397 StateManager::BackupData data;
400 data.reset_count = 1;
402 board.backup_memory_write(&data,
sizeof(data));
403 rf.state_manager_.check_backup_memory();
404 EXPECT_EQ(rf.state_manager_.state().armed,
false);
405 EXPECT_EQ(rf.state_manager_.state().error,
false);
407 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
411 board.backup_memory_clear();
412 StateManager::BackupData data;
413 data.arm_flag = StateManager::BackupData::ARM_MAGIC;
415 data.reset_count = 1;
417 board.backup_memory_write(&data,
sizeof(data));
418 rf.state_manager_.check_backup_memory();
419 EXPECT_EQ(rf.state_manager_.state().armed,
true);
420 EXPECT_EQ(rf.state_manager_.state().error,
false);
422 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
426 board.backup_memory_clear();
427 StateManager::BackupData data;
428 data.arm_flag = StateManager::BackupData::ARM_MAGIC;
430 data.reset_count = 1;
433 board.backup_memory_write(&data,
sizeof(data));
434 rf.state_manager_.check_backup_memory();
435 EXPECT_EQ(rf.state_manager_.state().armed,
false);
436 EXPECT_EQ(rf.state_manager_.state().error,
false);
438 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
442 board.backup_memory_clear();
443 StateManager::BackupData data;
444 data.arm_flag = StateManager::BackupData::ARM_MAGIC - 101;
446 data.reset_count = 1;
448 board.backup_memory_write(&data,
sizeof(data));
449 rf.state_manager_.check_backup_memory();
450 EXPECT_EQ(rf.state_manager_.state().armed,
false);
451 EXPECT_EQ(rf.state_manager_.state().error,
false);
453 EXPECT_EQ(rf.state_manager_.state().failsafe,
false);
457 board.backup_memory_clear();
458 const StateManager::BackupData::DebugInfo debug_info{1, 2, 3, 4, 5, 6, 7, 8};
459 rf.state_manager_.write_backup_data(debug_info);
460 StateManager::BackupData data;
461 board.backup_memory_read(&data,
sizeof(data));
462 EXPECT_EQ(data.reset_count, 1);
463 EXPECT_EQ(data.arm_flag, 0);
464 EXPECT_TRUE(data.valid_checksum());
465 EXPECT_EQ(data.debug.r0, debug_info.r0);
466 EXPECT_EQ(data.debug.r1, debug_info.r1);
467 EXPECT_EQ(data.debug.r2, debug_info.r2);
468 EXPECT_EQ(data.debug.r3, debug_info.r3);
469 EXPECT_EQ(data.debug.r12, debug_info.r12);
470 EXPECT_EQ(data.debug.lr, debug_info.lr);
471 EXPECT_EQ(data.debug.pc, debug_info.pc);
472 EXPECT_EQ(data.debug.psr, debug_info.psr);
477 board.backup_memory_clear();
479 StateManager::BackupData::DebugInfo debug_info{1, 2, 3, 4, 5, 6, 7, 8};
480 rf.state_manager_.write_backup_data(debug_info);
481 StateManager::BackupData data;
482 board.backup_memory_read(&data,
sizeof(data));
483 EXPECT_EQ(data.reset_count, 1);
484 EXPECT_EQ(data.arm_flag, StateManager::BackupData::ARM_MAGIC);
485 EXPECT_TRUE(data.valid_checksum());
486 EXPECT_EQ(data.debug.r0, debug_info.r0);
487 EXPECT_EQ(data.debug.r1, debug_info.r1);
488 EXPECT_EQ(data.debug.r2, debug_info.r2);
489 EXPECT_EQ(data.debug.r3, debug_info.r3);
490 EXPECT_EQ(data.debug.r12, debug_info.r12);
491 EXPECT_EQ(data.debug.lr, debug_info.lr);
492 EXPECT_EQ(data.debug.pc, debug_info.pc);
493 EXPECT_EQ(data.debug.psr, debug_info.psr);
static uint8_t Init(uint32_t AudioFreq, uint32_t Volume, uint32_t options)
Init Initialize and configures all required resources for audio play function.
static volatile bool error
void set_imu(float *acc, float *gyro, uint64_t time_us)
uint64_t clock_micros() override
TEST_F(StateMachineTest, Init)
void run()
Main loop for the ROSflight autopilot flight stack.
void stepFirmware(uint32_t us)
const State & state() const
void clear_error(uint16_t error)
void backup_memory_clear(size_t len) override
void step_firmware(rosflight_firmware::ROSflight &rf, rosflight_firmware::testBoard &board, uint32_t us)
StateManager state_manager_
void init()
Main initialization routine for the ROSflight autopilot flight stack.
bool set_param_int(uint16_t id, int32_t value)
Sets the value of a parameter by ID and calls the parameter change callback.