Skip to content

Commit

Permalink
AP_Stats: Make cumulative flight time updates optional
Browse files Browse the repository at this point in the history
  • Loading branch information
muramura committed Nov 25, 2023
1 parent ea23772 commit d754421
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
31 changes: 27 additions & 4 deletions libraries/AP_Stats/AP_Stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,22 @@ const AP_Param::GroupInfo AP_Stats::var_info[] = {
// @Units: s
// @ReadOnly: True
// @User: Standard
AP_GROUPINFO("_RESET", 3, AP_Stats, params.reset, 1),
AP_GROUPINFO("_RESET", 3, AP_Stats, params.reset, 1),

// @Param: _INTTIM
// @DisplayName: Statistics Flush Interval Time
// @Description: Interval between flushing statistics to EEPROM
// @Range: 1000 30000
// @Units: ms
// @User: Standard
AP_GROUPINFO("_INTTIM", 4, AP_Stats, params.intervaltime, 30000),

// @Param: _NFT
// @DisplayName: National Flight Time
// @Description: Total FlightTime
// @Values: 0:Default,1:Japan
// @User: Standard
AP_GROUPINFO("_NFT", 5, AP_Stats, params.nationalflighttime, 0),

AP_GROUPEND
};
Expand Down Expand Up @@ -97,7 +112,7 @@ void AP_Stats::update()
{
WITH_SEMAPHORE(sem);
const uint32_t now_ms = AP_HAL::millis();
if (now_ms - last_flush_ms > flush_interval_ms) {
if (now_ms - last_flush_ms > uint32_t(params.intervaltime)) {
update_flighttime();
update_runtime();
flush();
Expand Down Expand Up @@ -131,8 +146,16 @@ void AP_Stats::set_flying(const bool is_flying)
_flying_ms = AP_HAL::millis();
}
} else {
update_flighttime();
_flying_ms = 0;
switch (params.nationalflighttime) {
case 0: // Default
update_flighttime();
_flying_ms = 0;
break;
case 1: // Japan
break;
default:
break;
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions libraries/AP_Stats/AP_Stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ class AP_Stats
AP_Int32 flttime;
AP_Int32 runtime;
AP_Int32 reset;
AP_Int16 intervaltime;
AP_Int8 nationalflighttime;
} params;

void copy_variables_from_parameters();

uint64_t last_flush_ms; // in terms of system uptime
const uint16_t flush_interval_ms = 30000;
uint32_t last_flush_ms; // in terms of system uptime

uint64_t _flying_ms;
uint64_t _last_runtime_ms;
Expand Down

0 comments on commit d754421

Please sign in to comment.