Skip to content

Commit a52c375

Browse files
committed
AP_ESC_Telem: ensure that EDTv2 only gets logged when telemetry is available
1 parent 6e26353 commit a52c375

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

libraries/AP_ESC_Telem/AP_ESC_Telem.cpp

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -758,52 +758,52 @@ void AP_ESC_Telem::update()
758758
telemdata.power_percentage);
759759
}
760760
#endif //AP_EXTENDED_ESC_TELEM_ENABLED
761-
}
762761

763762
#if AP_EXTENDED_DSHOT_TELEM_V2_ENABLED
764-
// Write an EDTv2 message, if there is any update
765-
uint16_t edt2_status = telemdata.edt2_status;
766-
uint16_t edt2_stress = telemdata.edt2_stress;
767-
if (EDT2_HAS_NEW_DATA(edt2_status | edt2_stress)) {
768-
// Could probably be faster/smaller with bitmasking, but not sure
769-
uint8_t status = 0;
770-
if (EDT2_HAS_NEW_DATA(edt2_stress)) {
771-
status |= uint8_t(log_Edt2_Status::HAS_STRESS_DATA);
772-
}
773-
if (EDT2_HAS_NEW_DATA(edt2_status)) {
774-
status |= uint8_t(log_Edt2_Status::HAS_STATUS_DATA);
775-
}
776-
if (EDT2_ALERT_BIT_FROM_STATUS(edt2_status)) {
777-
status |= uint8_t(log_Edt2_Status::ALERT_BIT);
778-
}
779-
if (EDT2_WARNING_BIT_FROM_STATUS(edt2_status)) {
780-
status |= uint8_t(log_Edt2_Status::WARNING_BIT);
781-
}
782-
if (EDT2_ERROR_BIT_FROM_STATUS(edt2_status)) {
783-
status |= uint8_t(log_Edt2_Status::ERROR_BIT);
784-
}
785-
// An EDT2 status message is:
786-
// id: starts from 0
787-
// stress: the current stress which comes from edt2_stress
788-
// max_stress: the maximum stress which comes from edt2_status
789-
// status: the status bits which come from both
790-
const struct log_Edt2 pkt_edt2{
791-
LOG_PACKET_HEADER_INIT(uint8_t(LOG_EDT2_MSG)),
792-
time_us : now_us64,
793-
instance : i,
794-
stress : EDT2_STRESS_FROM_STRESS(edt2_stress),
795-
max_stress : EDT2_STRESS_FROM_STATUS(edt2_status),
796-
status : status,
797-
};
798-
if (AP::logger().WriteBlock_first_succeed(&pkt_edt2, sizeof(pkt_edt2))) {
799-
// Only clean the telem_updated bits if the write succeeded.
800-
// This is important because, if rate limiting is enabled,
801-
// the log-on-change behavior may lose a lot of entries
802-
telemdata.edt2_status &= ~EDT2_TELEM_UPDATED;
803-
telemdata.edt2_stress &= ~EDT2_TELEM_UPDATED;
763+
// Write an EDTv2 message, if there is any update
764+
uint16_t edt2_status = telemdata.edt2_status;
765+
uint16_t edt2_stress = telemdata.edt2_stress;
766+
if (EDT2_HAS_NEW_DATA(edt2_status | edt2_stress)) {
767+
// Could probably be faster/smaller with bitmasking, but not sure
768+
uint8_t status = 0;
769+
if (EDT2_HAS_NEW_DATA(edt2_stress)) {
770+
status |= uint8_t(log_Edt2_Status::HAS_STRESS_DATA);
771+
}
772+
if (EDT2_HAS_NEW_DATA(edt2_status)) {
773+
status |= uint8_t(log_Edt2_Status::HAS_STATUS_DATA);
774+
}
775+
if (EDT2_ALERT_BIT_FROM_STATUS(edt2_status)) {
776+
status |= uint8_t(log_Edt2_Status::ALERT_BIT);
777+
}
778+
if (EDT2_WARNING_BIT_FROM_STATUS(edt2_status)) {
779+
status |= uint8_t(log_Edt2_Status::WARNING_BIT);
780+
}
781+
if (EDT2_ERROR_BIT_FROM_STATUS(edt2_status)) {
782+
status |= uint8_t(log_Edt2_Status::ERROR_BIT);
783+
}
784+
// An EDT2 status message is:
785+
// id: starts from 0
786+
// stress: the current stress which comes from edt2_stress
787+
// max_stress: the maximum stress which comes from edt2_status
788+
// status: the status bits which come from both
789+
const struct log_Edt2 pkt_edt2{
790+
LOG_PACKET_HEADER_INIT(uint8_t(LOG_EDT2_MSG)),
791+
time_us : now_us64,
792+
instance : i,
793+
stress : EDT2_STRESS_FROM_STRESS(edt2_stress),
794+
max_stress : EDT2_STRESS_FROM_STATUS(edt2_status),
795+
status : status,
796+
};
797+
if (AP::logger().WriteBlock_first_succeed(&pkt_edt2, sizeof(pkt_edt2))) {
798+
// Only clean the telem_updated bits if the write succeeded.
799+
// This is important because, if rate limiting is enabled,
800+
// the log-on-change behavior may lose a lot of entries
801+
telemdata.edt2_status &= ~EDT2_TELEM_UPDATED;
802+
telemdata.edt2_stress &= ~EDT2_TELEM_UPDATED;
803+
}
804804
}
805-
}
806805
#endif // AP_EXTENDED_DSHOT_TELEM_V2_ENABLED
806+
}
807807
}
808808
}
809809
#endif // HAL_LOGGING_ENABLED

0 commit comments

Comments
 (0)