Moved code for radio state update to a dedicated function
This commit is contained in:
parent
91c9408f32
commit
3f2df608c9
|
|
@ -32,10 +32,10 @@
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint8_t id; // ID of the satellite
|
||||
uint8_t elevation; // Elevation in degrees
|
||||
uint8_t id; // ID of the satellite
|
||||
uint8_t elevation; // Elevation in degrees
|
||||
uint16_t azimuth; // Azimuth in degrees
|
||||
uint8_t snr; // Quality of the signal in range 0-99
|
||||
uint8_t snr; // Quality of the signal in range 0-99
|
||||
}
|
||||
sat_t;
|
||||
|
||||
|
|
@ -44,19 +44,19 @@ sat_t;
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
curTime_t timestamp; // Timestamp of the latest GPS update
|
||||
uint8_t fix_quality; // 0: no fix, 1: GPS, 2: GPS SPS, 3: GPS PPS
|
||||
uint8_t fix_type; // 0: no fix, 1: 2D, 2: 3D
|
||||
uint8_t satellites_tracked; // Number of tracked satellites
|
||||
uint8_t satellites_in_view; // Satellites in view
|
||||
sat_t satellites[12]; // Details about satellites in view
|
||||
uint32_t active_sats; // Bitmap representing which sats are part of the fix
|
||||
float latitude; // Latitude coordinates
|
||||
float longitude; // Longitude coordinates
|
||||
float altitude; // Antenna altitude above mean sea level (geoid) in m
|
||||
float speed; // Ground speed in km/h
|
||||
float tmg_mag; // Course over ground, degrees, magnetic
|
||||
float tmg_true; // Course over ground, degrees, true
|
||||
curTime_t timestamp; // Timestamp of the latest GPS update
|
||||
uint8_t fix_quality; // 0: no fix, 1: GPS, 2: GPS SPS, 3: GPS PPS
|
||||
uint8_t fix_type; // 0: no fix, 1: 2D, 2: 3D
|
||||
uint8_t satellites_tracked; // Number of tracked satellites
|
||||
uint8_t satellites_in_view; // Satellites in view
|
||||
sat_t satellites[12]; // Details about satellites in view
|
||||
uint32_t active_sats; // Bitmap representing which sats are part of the fix
|
||||
float latitude; // Latitude coordinates
|
||||
float longitude; // Longitude coordinates
|
||||
float altitude; // Antenna altitude above mean sea level (geoid) in m
|
||||
float speed; // Ground speed in km/h
|
||||
float tmg_mag; // Course over ground, degrees, magnetic
|
||||
float tmg_true; // Course over ground, degrees, true
|
||||
}
|
||||
gps_t;
|
||||
|
||||
|
|
@ -77,14 +77,13 @@ m17_t;
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
bool radioStateUpdated;
|
||||
curTime_t time;
|
||||
uint16_t v_bat;
|
||||
uint8_t charge;
|
||||
float rssi;
|
||||
curTime_t time;
|
||||
uint16_t v_bat;
|
||||
uint8_t charge;
|
||||
float rssi;
|
||||
|
||||
uint8_t ui_screen;
|
||||
uint8_t tuner_mode;
|
||||
uint8_t ui_screen;
|
||||
uint8_t tuner_mode;
|
||||
|
||||
//time_t rx_status_tv;
|
||||
//bool rx_status;
|
||||
|
|
@ -92,18 +91,18 @@ typedef struct
|
|||
//time_t tx_status_tv;
|
||||
//bool tx_status;
|
||||
|
||||
uint16_t channel_index;
|
||||
channel_t channel;
|
||||
channel_t vfo_channel;
|
||||
bool zone_enabled;
|
||||
zone_t zone;
|
||||
uint8_t rtxStatus;
|
||||
uint16_t channel_index;
|
||||
channel_t channel;
|
||||
channel_t vfo_channel;
|
||||
bool zone_enabled;
|
||||
zone_t zone;
|
||||
uint8_t rtxStatus;
|
||||
|
||||
bool emergency;
|
||||
bool emergency;
|
||||
settings_t settings;
|
||||
gps_t gps_data;
|
||||
bool gps_set_time;
|
||||
m17_t m17_data;
|
||||
gps_t gps_data;
|
||||
bool gps_set_time;
|
||||
m17_t m17_data;
|
||||
}
|
||||
state_t;
|
||||
|
||||
|
|
@ -131,17 +130,21 @@ extern state_t state;
|
|||
void state_init();
|
||||
|
||||
/**
|
||||
* Write default values to OpenRTX settings and VFO Channel configuration
|
||||
* Writes out to flash and calls state_init again to reload it immediately
|
||||
* Write default values to OpenRTX settings and VFO Channel configuration.
|
||||
* Writes out to flash and calls state_init again to reload it immediately.
|
||||
*/
|
||||
void defaultSettingsAndVfo();
|
||||
|
||||
/**
|
||||
* This function terminates the Radio state,
|
||||
* Saving persistent settings to flash.
|
||||
* This function terminates the radio state saving persistent settings to flash.
|
||||
*/
|
||||
void state_terminate();
|
||||
|
||||
/**
|
||||
* Update radio state fetching data from device drivers.
|
||||
*/
|
||||
void state_update();
|
||||
|
||||
/**
|
||||
* The RTC and state.time are set to UTC time
|
||||
* Use this function to get local time from UTC time based on timezone setting
|
||||
|
|
|
|||
|
|
@ -65,10 +65,9 @@ void state_init()
|
|||
/*
|
||||
* Initialise remaining fields
|
||||
*/
|
||||
state.radioStateUpdated = true;
|
||||
#ifdef HAS_RTC
|
||||
#ifdef HAS_RTC
|
||||
state.time = rtc_getTime();
|
||||
#endif
|
||||
#endif
|
||||
state.v_bat = platform_getVbat();
|
||||
state.charge = battery_getCharge(state.v_bat);
|
||||
state.rssi = rtx_getRssi();
|
||||
|
|
@ -95,6 +94,25 @@ void state_terminate()
|
|||
nvm_writeSettingsAndVfo(&state.settings, &state.channel);
|
||||
}
|
||||
|
||||
void state_update()
|
||||
{
|
||||
/*
|
||||
* Low-pass filtering with a time constant of 10s when updated at 1Hz
|
||||
* Original computation: state.v_bat = 0.02*vbat + 0.98*state.v_bat
|
||||
* Peak error is 18mV when input voltage is 49mV.
|
||||
*/
|
||||
uint16_t vbat = platform_getVbat();
|
||||
state.v_bat -= (state.v_bat * 2) / 100;
|
||||
state.v_bat += (vbat * 2) / 100;
|
||||
|
||||
state.charge = battery_getCharge(state.v_bat);
|
||||
state.rssi = rtx_getRssi();
|
||||
|
||||
#ifdef HAS_RTC
|
||||
state.time = rtc_getTime();
|
||||
#endif
|
||||
}
|
||||
|
||||
curTime_t state_getLocalTime(curTime_t utc_time)
|
||||
{
|
||||
curTime_t local_time = utc_time;
|
||||
|
|
|
|||
|
|
@ -225,23 +225,7 @@ void *dev_task(void *arg)
|
|||
{
|
||||
// Lock mutex and update internal state
|
||||
pthread_mutex_lock(&state_mutex);
|
||||
|
||||
#ifdef HAS_RTC
|
||||
state.time = rtc_getTime();
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Low-pass filtering with a time constant of 10s when updated at 1Hz
|
||||
* Original computation: state.v_bat = 0.02*vbat + 0.98*state.v_bat
|
||||
* Peak error is 18mV when input voltage is 49mV.
|
||||
*/
|
||||
uint16_t vbat = platform_getVbat();
|
||||
state.v_bat -= (state.v_bat * 2) / 100;
|
||||
state.v_bat += (vbat * 2) / 100;
|
||||
|
||||
state.charge = battery_getCharge(state.v_bat);
|
||||
state.rssi = rtx_getRssi();
|
||||
|
||||
state_update();
|
||||
pthread_mutex_unlock(&state_mutex);
|
||||
|
||||
// Signal state update to UI thread
|
||||
|
|
|
|||
Loading…
Reference in New Issue