Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Stats: Make cumulative flight time updates optional #25630

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading