mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-07 08:23:56 -04:00
AP_DroneCAN: add msg period measurement to DroneCAN_sniffer
This commit is contained in:
parent
efe5fb7e69
commit
cbef055f6b
@ -48,6 +48,10 @@ private:
|
|||||||
static struct {
|
static struct {
|
||||||
const char *msg_name;
|
const char *msg_name;
|
||||||
uint32_t count;
|
uint32_t count;
|
||||||
|
uint64_t last_time_us;
|
||||||
|
uint32_t avg_period_us;
|
||||||
|
uint32_t max_period_us;
|
||||||
|
uint32_t min_period_us;
|
||||||
} counters[100];
|
} counters[100];
|
||||||
|
|
||||||
static void count_msg(const char *name)
|
static void count_msg(const char *name)
|
||||||
@ -55,11 +59,26 @@ static void count_msg(const char *name)
|
|||||||
for (uint16_t i=0; i<ARRAY_SIZE(counters); i++) {
|
for (uint16_t i=0; i<ARRAY_SIZE(counters); i++) {
|
||||||
if (counters[i].msg_name == name) {
|
if (counters[i].msg_name == name) {
|
||||||
counters[i].count++;
|
counters[i].count++;
|
||||||
|
uint64_t now = AP_HAL::micros64();
|
||||||
|
uint32_t period_us = now - counters[i].last_time_us;
|
||||||
|
counters[i].last_time_us = now;
|
||||||
|
if (counters[i].avg_period_us == 0) {
|
||||||
|
counters[i].avg_period_us = period_us;
|
||||||
|
} else {
|
||||||
|
counters[i].avg_period_us = (counters[i].avg_period_us * (counters[i].count - 1) + period_us) / counters[i].count;
|
||||||
|
}
|
||||||
|
if (counters[i].max_period_us < period_us) {
|
||||||
|
counters[i].max_period_us = period_us;
|
||||||
|
}
|
||||||
|
if (counters[i].min_period_us == 0 || counters[i].min_period_us > period_us) {
|
||||||
|
counters[i].min_period_us = period_us;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (counters[i].msg_name == nullptr) {
|
if (counters[i].msg_name == nullptr) {
|
||||||
counters[i].msg_name = name;
|
counters[i].msg_name = name;
|
||||||
counters[i].count++;
|
counters[i].count++;
|
||||||
|
counters[i].last_time_us = AP_HAL::micros64();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,8 +206,15 @@ void DroneCAN_sniffer::print_stats(void)
|
|||||||
if (counters[i].msg_name == nullptr) {
|
if (counters[i].msg_name == nullptr) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
hal.console->printf("%s: %u\n", counters[i].msg_name, unsigned(counters[i].count));
|
hal.console->printf("%s: %lu AVG_US: %lu MAX_US: %lu MIN_US: %lu\n", counters[i].msg_name,
|
||||||
|
(long unsigned)counters[i].count,
|
||||||
|
(long unsigned)counters[i].avg_period_us,
|
||||||
|
(long unsigned)counters[i].max_period_us,
|
||||||
|
(long unsigned)counters[i].min_period_us);
|
||||||
counters[i].count = 0;
|
counters[i].count = 0;
|
||||||
|
counters[i].avg_period_us = 0;
|
||||||
|
counters[i].max_period_us = 0;
|
||||||
|
counters[i].min_period_us = 0;
|
||||||
}
|
}
|
||||||
hal.console->printf("\n");
|
hal.console->printf("\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user