Browse Source

AP_InternalError: change panic to return error code as string in SITL

gps-1.3.1
Josh Henderson 4 years ago committed by Andrew Tridgell
parent
commit
0ae1536e4a
  1. 80
      libraries/AP_InternalError/AP_InternalError.cpp
  2. 3
      libraries/AP_InternalError/AP_InternalError.h

80
libraries/AP_InternalError/AP_InternalError.cpp

@ -17,7 +17,9 @@ void AP_InternalError::error(const AP_InternalError::error_t e, uint16_t line) {
// don't panic on these to facilitate watchdog testing // don't panic on these to facilitate watchdog testing
break; break;
default: default:
AP_HAL::panic("internal error %u", unsigned(e)); char buffer[50];
AP::internalerror().error_to_string(buffer, ARRAY_SIZE(buffer), e);
AP_HAL::panic("AP_InternalError::error_t::%s", buffer);
} }
#endif #endif
internal_errors |= uint32_t(e); internal_errors |= uint32_t(e);
@ -29,43 +31,49 @@ void AP_InternalError::error(const AP_InternalError::error_t e, uint16_t line) {
hal.util->persistent_data.internal_error_last_line = line; hal.util->persistent_data.internal_error_last_line = line;
} }
void AP_InternalError::errors_as_string(uint8_t *buffer, const uint16_t len) const static const char * const error_bit_descriptions[] {
{ "mapfailure", // logger_mapfailure
static const char * const error_bit_descriptions[] { "miss_struct", // logger_missing_logstructure
"mapfailure", // logger_mapfailure "write_mssfmt", // logger_logwrite_missingfmt
"miss_struct", // logger_missing_logstructure "many_deletes", // logger_too_many_deletions
"write_mssfmt", // logger_logwrite_missingfmt "bad_getfile", // logger_bad_getfilename
"many_deletes", // logger_too_many_deletions "panic",
"bad_getfile", // logger_bad_getfilename "flush_no_sem", // logger_flushing_without_sem
"panic", "bad_curr_blk", // logger_bad_current_block
"flush_no_sem", // logger_flushing_without_sem "blkcnt_bad", // logger_blockcount_mismatch
"bad_curr_blk", // logger_bad_current_block "dq_failure", // logger_dequeue_failure
"blkcnt_bad", // logger_blockcount_mismatch "cnstring_nan", // constraining_nan
"dq_failure", // logger_dequeue_failure "watchdog_rst", // watchdog_reset
"cnstring_nan", // constraining_nan "iomcu_reset",
"watchdog_rst", // watchdog_reset "iomcu_fail",
"iomcu_reset", "spi_fail",
"iomcu_fail", "main_loop_stk", // main_loop_stuck
"spi_fail", "gcs_bad_link", // gcs_bad_missionprotocol_link
"main_loop_stk", // main_loop_stuck "bitmask_range",
"gcs_bad_link", // gcs_bad_missionprotocol_link "gcs_offset",
"bitmask_range", "i2c_isr",
"gcs_offset", "flow_of_ctrl", // flow_of_control
"i2c_isr", "sfs_recursion", // switch_full_sector_recursion
"flow_of_ctrl", // flow_of_control "bad_rotation",
"sfs_recursion", // switch_full_sector_recursion "stack_ovrflw", // stack_overflow
"bad_rotation", "imu_reset", // imu_reset
"stack_ovrflw", // stack_overflow "gpio_isr",
"imu_reset", // imu_reset "mem_guard",
"gpio_isr", "dma_fail",
"mem_guard", "params_restored",
"dma_fail", "invalid arguments",
"params_restored", };
"invalid arguments",
}; static_assert((1U<<(ARRAY_SIZE(error_bit_descriptions))) == uint32_t(AP_InternalError::error_t::__LAST__), "too few descriptions for bits");
static_assert((1U<<(ARRAY_SIZE(error_bit_descriptions))) == uint32_t(AP_InternalError::error_t::__LAST__), "too few descriptions for bits"); void AP_InternalError::error_to_string(char *buffer, const uint16_t len, error_t error_code) const
{
uint32_t temp = log2f(int(error_code));
strncpy(buffer, error_bit_descriptions[temp], len - 1);
}
void AP_InternalError::errors_as_string(uint8_t *buffer, const uint16_t len) const
{
buffer[0] = 0; buffer[0] = 0;
uint32_t buffer_used = 0; uint32_t buffer_used = 0;
for (uint8_t i=0; i<ARRAY_SIZE(error_bit_descriptions); i++) { for (uint8_t i=0; i<ARRAY_SIZE(error_bit_descriptions); i++) {

3
libraries/AP_InternalError/AP_InternalError.h

@ -83,6 +83,9 @@ public:
// internal errors. buffer will always be null-terminated. // internal errors. buffer will always be null-terminated.
void errors_as_string(uint8_t *buffer, uint16_t len) const; void errors_as_string(uint8_t *buffer, uint16_t len) const;
// convert an error code to a string
void error_to_string(char *buffer, uint16_t len, error_t error_code) const;
uint32_t count() const { return total_error_count; } uint32_t count() const { return total_error_count; }
// internal_errors - return mask of internal errors seen // internal_errors - return mask of internal errors seen

Loading…
Cancel
Save