/** Error message. * Halts the program while continually sending a fixed error message in SBP * message format to the FTDI USART, in a way that should get the message * through to the Python console even if it's interrupting another transmission. * * \param msg A pointer to an array of chars containing the error message. */ void _screaming_death(const char *pos, const char *msg) { __asm__("CPSID if;"); /* Disable all interrupts and faults */ #define SPEAKING_MSG_N 222 /* Maximum length of error message */ static char err_msg[SPEAKING_MSG_N] = "ERROR: "; strncat(err_msg, pos, SPEAKING_MSG_N - 8); strncat(err_msg, " : ", SPEAKING_MSG_N - strlen(err_msg) - 1); strncat(err_msg, msg, SPEAKING_MSG_N - strlen(err_msg) - 1); strncat(err_msg, "\n", SPEAKING_MSG_N - strlen(err_msg) - 1); u8 len = strlen(err_msg); static sbp_state_t sbp_state; sbp_state_init(&sbp_state); /* Continuously send error message */ #define APPROX_ONE_SEC 200000000 while (1) { led_toggle(LED_RED); for (u32 d = 0; d < APPROX_ONE_SEC; d++) { __asm__("nop"); } /* TODO: Send to other UARTs? */ sbp_send_message(&sbp_state, SBP_MSG_PRINT_DEP, 0, len, (u8*)err_msg, &fallback_write_ftdi); } }
END_TEST START_TEST(test_sbp_send_message) { /* TODO: Tests with different write function behaviour. */ sbp_state_t s; sbp_state_init(&s); u8 smsg[] = { 0x22, 0x33 }; fail_unless(sbp_send_message(&s, 0x2233, 0x4455, 0, smsg, 0) == SBP_NULL_ERROR, "sbp_send_message should return an error if write is NULL"); dummy_reset(); fail_unless(sbp_send_message(&s, 0x2233, 0x4455, 1, 0, &dummy_write) == SBP_NULL_ERROR, "sbp_send_message should return an error if payload is NULL and len != 0"); dummy_reset(); fail_unless(sbp_send_message(&s, 0x2233, 0x4455, 0, 0, &dummy_write) == SBP_OK, "sbp_send_message should return OK if payload is NULL and len == 0"); u8 zero_len_message[] = {0x55, 0x33, 0x22, 0x55, 0x44, 0x00, 0x2C, 0x4C}; fail_unless(memcmp(dummy_buff, zero_len_message, sizeof(zero_len_message)) == 0, "sbp_send_message encode error for len = 0"); dummy_reset(); sbp_send_message(&s, 0x2233, 0x6677, sizeof(smsg), smsg, &dummy_write); u8 awesome_message[] = {0x55, 0x33, 0x22, 0x77, 0x66, 0x02, 0x22, 0x33, 0x8A, 0x33}; fail_unless(memcmp(dummy_buff, awesome_message, sizeof(awesome_message)) == 0, "sbp_send_message encode error for test message"); }