From b38d2c6194c8eb2049cfe175797064195f26341c Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 1 May 2020 15:19:59 +1000 Subject: [PATCH] AP_Arming: regularise CAN pre-arm failure messages AP_Arming tacks on the sub-system bit. Remove PiccoloCAN's silly nullptr check Require the library to supply the failure message (no default message) Remove default cases so authors know to think about places they should add things. --- libraries/AP_Arming/AP_Arming.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/libraries/AP_Arming/AP_Arming.cpp b/libraries/AP_Arming/AP_Arming.cpp index e74ac77e6c..dd73cf09c8 100644 --- a/libraries/AP_Arming/AP_Arming.cpp +++ b/libraries/AP_Arming/AP_Arming.cpp @@ -823,9 +823,8 @@ bool AP_Arming::can_checks(bool report) // To be replaced with macro saying if KDECAN library is included #if APM_BUILD_TYPE(APM_BUILD_ArduCopter) || APM_BUILD_TYPE(APM_BUILD_ArduPlane) || APM_BUILD_TYPE(APM_BUILD_ArduSub) AP_KDECAN *ap_kdecan = AP_KDECAN::get_kdecan(i); - snprintf(fail_msg, ARRAY_SIZE(fail_msg), "KDECAN failed"); if (ap_kdecan != nullptr && !ap_kdecan->pre_arm_check(fail_msg, ARRAY_SIZE(fail_msg))) { - check_failed(ARMING_CHECK_SYSTEM, report, "%s", fail_msg); + check_failed(ARMING_CHECK_SYSTEM, report, "KDECAN: %s", fail_msg); return false; } #endif @@ -836,12 +835,7 @@ bool AP_Arming::can_checks(bool report) AP_PiccoloCAN *ap_pcan = AP_PiccoloCAN::get_pcan(i); if (ap_pcan != nullptr && !ap_pcan->pre_arm_check(fail_msg, ARRAY_SIZE(fail_msg))) { - if (fail_msg == nullptr) { - check_failed(ARMING_CHECK_SYSTEM, report, "PiccoloCAN failed"); - } else { - check_failed(ARMING_CHECK_SYSTEM, report, "%s", fail_msg); - } - + check_failed(ARMING_CHECK_SYSTEM, report, "PiccoloCAN: %s", fail_msg); return false; } @@ -853,15 +847,20 @@ bool AP_Arming::can_checks(bool report) } case AP_BoardConfig_CAN::Protocol_Type_UAVCAN: { - snprintf(fail_msg, ARRAY_SIZE(fail_msg), "UAVCAN failed"); if (!AP::uavcan_dna_server().prearm_check(fail_msg, ARRAY_SIZE(fail_msg))) { - check_failed(ARMING_CHECK_SYSTEM, report, "%s", fail_msg); + check_failed(ARMING_CHECK_SYSTEM, report, "UAVCAN: %s", fail_msg); return false; } break; } + case AP_BoardConfig_CAN::Protocol_Type_ToshibaCAN: + { + // toshibacan doesn't currently have any prearm + // checks. Theres scope for adding a "not + // initialised" prearm check. + break; + } case AP_BoardConfig_CAN::Protocol_Type_None: - default: break; } }