src: format using clang-format

This commit is contained in:
Arnaud Ferraris
2024-10-29 14:04:59 +01:00
parent 57142c2c11
commit 9f6178dafd
17 changed files with 2364 additions and 2231 deletions

View File

@@ -4,18 +4,18 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include "config.h"
#include "gnss.h"
#include "manager.h"
#include "at.h"
#include "config.h"
#include "manager.h"
#include <errno.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
#include <errno.h>
#define BUFFER_SIZE 256
#define UPLOAD_DELAY_US 25000
#define UPLOAD_TIMEOUT_S 10
#define BUFFER_SIZE 256
#define UPLOAD_DELAY_US 25000
#define UPLOAD_TIMEOUT_S 10
#define RESCHEDULE_IN_SECS 30
static void gnss_step(struct EG25Manager *manager);
@@ -29,26 +29,25 @@ gboolean gnss_upload_assistance_data(struct EG25Manager *manager)
if (manager->gnss_assistance_step < EG25_GNSS_STEP_LAST) {
g_warning("GNSS assistance data upload already in process (%d/%d)",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
return FALSE;
}
/* data upload isn't necessary to bring the modem onine, so we should wait
* until we've finished the rest of our configuration */
if (!manager->modem_iface ||
manager->modem_state < EG25_STATE_CONFIGURED ||
manager->modem_state > EG25_STATE_CONNECTED) {
g_message ("Rescheduling upload since modem isn't online yet, in %ds",
RESCHEDULE_IN_SECS);
if (!manager->modem_iface || manager->modem_state < EG25_STATE_CONFIGURED ||
manager->modem_state > EG25_STATE_CONNECTED) {
g_message("Rescheduling upload since modem isn't online yet, in %ds", RESCHEDULE_IN_SECS);
manager->gnss_assistance_step = EG25_GNSS_STEP_LAST;
return TRUE;
}
#ifdef HAVE_MMGLIB
/* ModemManager's Location is only available after unlocking */
if(manager->modem_iface == MODEM_IFACE_MODEMMANAGER && !manager->mm_location) {
g_message ("Rescheduling upload since Location interface is not available, in %ds",
RESCHEDULE_IN_SECS);
if (manager->modem_iface == MODEM_IFACE_MODEMMANAGER && !manager->mm_location) {
g_message("Rescheduling upload since Location interface is not available, in %ds",
RESCHEDULE_IN_SECS);
manager->gnss_assistance_step = EG25_GNSS_STEP_LAST;
return TRUE;
}
@@ -62,7 +61,7 @@ gboolean gnss_upload_assistance_data(struct EG25Manager *manager)
void gnss_init(struct EG25Manager *manager, toml_table_t *config[])
{
toml_table_t *gnss_config[EG25_CONFIG_COUNT];
g_autoptr (GError) error = NULL;
g_autoptr(GError) error = NULL;
for (int i = 0; i < EG25_CONFIG_COUNT; i++)
gnss_config[i] = config[i] ? toml_table_in(config[i], "gnss") : NULL;
@@ -92,12 +91,11 @@ void gnss_init(struct EG25Manager *manager, toml_table_t *config[])
/* Create temporary file to store assistance data */
manager->gnss_assistance_fd = g_file_open_tmp(NULL, NULL, &error);
if (error != NULL)
g_error ("Unable to create temporary file: %s", error->message);
g_error("Unable to create temporary file: %s", error->message);
/* Initialize state and schedule upload */
manager->gnss_assistance_step = EG25_GNSS_STEP_LAST;
g_timeout_add_seconds(RESCHEDULE_IN_SECS,
G_SOURCE_FUNC(gnss_upload_assistance_data), manager);
g_timeout_add_seconds(RESCHEDULE_IN_SECS, G_SOURCE_FUNC(gnss_upload_assistance_data), manager);
}
void gnss_destroy(struct EG25Manager *manager)
@@ -113,8 +111,8 @@ void gnss_destroy(struct EG25Manager *manager)
static void disable_mm_gnss(struct EG25Manager *manager)
{
MMModemLocationSource sources;
gboolean signals_location;
g_autoptr (GError) error = NULL;
gboolean signals_location;
g_autoptr(GError) error = NULL;
sources = mm_modem_location_get_enabled(manager->mm_location);
signals_location = mm_modem_location_signals_location(manager->mm_location);
@@ -140,17 +138,14 @@ static void disable_mm_gnss(struct EG25Manager *manager)
sources &= ~MM_MODEM_LOCATION_SOURCE_GPS_RAW;
sources &= ~MM_MODEM_LOCATION_SOURCE_GPS_NMEA;
sources &= ~MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED;
mm_modem_location_setup_sync(manager->mm_location, sources,
signals_location, NULL, &error);
mm_modem_location_setup_sync(manager->mm_location, sources, signals_location, NULL, &error);
if (error != NULL) {
g_warning("Unable to disable GNSS engine through ModemManager: %s",
error->message);
g_warning("Unable to disable GNSS engine through ModemManager: %s", error->message);
}
}
#endif
static void disable_at_gnss_cb(struct EG25Manager *manager,
const char *response)
static void disable_at_gnss_cb(struct EG25Manager *manager, const char *response)
{
/* Clear QGPSEND AT command and process next */
at_next_command(manager);
@@ -199,27 +194,25 @@ static void state_at_gnss(struct EG25Manager *manager)
static void fetch_assistance_data(struct EG25Manager *manager)
{
CURLcode response;
curl_off_t downloaded;
CURL *curl = NULL;
CURLcode response;
curl_off_t downloaded;
CURL *curl = NULL;
g_autofree gchar *url = NULL;
FILE *tmp_file = NULL;
gchar errbuf[CURL_ERROR_SIZE];
FILE *tmp_file = NULL;
gchar errbuf[CURL_ERROR_SIZE];
errbuf[0] = 0;
/* Fetch assistance data with curl */
tmp_file = fdopen(manager->gnss_assistance_fd, "wb+");
if (tmp_file == NULL) {
g_critical("Unable to open file to save assistance data: %s",
g_strerror(errno));
g_critical("Unable to open file to save assistance data: %s", g_strerror(errno));
goto bail;
}
lseek(manager->gnss_assistance_fd, 0, SEEK_SET);
if (ftruncate(manager->gnss_assistance_fd, 0) < 0)
g_warning("Unable to truncate file, assistance data might be invalid!");
url = g_strconcat(manager->gnss_assistance_url, "/",
manager->gnss_assistance_file, NULL);
url = g_strconcat(manager->gnss_assistance_url, "/", manager->gnss_assistance_file, NULL);
curl = curl_easy_init();
if (!curl) {
@@ -237,7 +230,8 @@ static void fetch_assistance_data(struct EG25Manager *manager)
response = curl_easy_perform(curl);
if (response != CURLE_OK) {
g_warning("Unable to fetch GNSS assistance data from %s: %s",
url, strlen(errbuf) ? errbuf : curl_easy_strerror(response));
url,
strlen(errbuf) ? errbuf : curl_easy_strerror(response));
goto bail;
}
@@ -268,8 +262,7 @@ bail:
/******************************************************************************/
static void init_assistance_data_upload_ready(struct EG25Manager *manager,
const char *response)
static void init_assistance_data_upload_ready(struct EG25Manager *manager, const char *response)
{
/* Search for 'CONNECT' in response to start upload */
if (strstr(response, "CONNECT")) {
@@ -285,8 +278,7 @@ static void init_assistance_data_upload_ready(struct EG25Manager *manager,
}
}
static void init_assistance_data_upload_start(struct EG25Manager *manager,
const char *response)
static void init_assistance_data_upload_start(struct EG25Manager *manager, const char *response)
{
gchar value[BUFFER_SIZE];
off_t size;
@@ -305,11 +297,14 @@ static void init_assistance_data_upload_start(struct EG25Manager *manager,
lseek(manager->gnss_assistance_fd, 0, SEEK_SET);
/* Start upload */
g_snprintf(value, BUFFER_SIZE, "\"RAM:%s\",%ld,%d",
manager->gnss_assistance_file, size, UPLOAD_TIMEOUT_S);
g_snprintf(value,
BUFFER_SIZE,
"\"RAM:%s\",%ld,%d",
manager->gnss_assistance_file,
size,
UPLOAD_TIMEOUT_S);
g_message("Initiate GNSS assistance data upload: %s", value);
at_append_command(manager, "QFUPL", NULL, value, NULL,
init_assistance_data_upload_ready);
at_append_command(manager, "QFUPL", NULL, value, NULL, init_assistance_data_upload_ready);
at_send_command(manager);
}
@@ -319,16 +314,15 @@ static void init_assistance_data_upload(struct EG25Manager *manager)
* Delete all previous GNSS assistance data files in RAM
* and start uploading the latest one to RAM.
*/
at_append_command(manager, "QFDEL", NULL, "\"RAM:*\"\r\n",
NULL, init_assistance_data_upload_start);
at_append_command(manager, "QFDEL", NULL, "\"RAM:*\"\r\n", NULL, init_assistance_data_upload_start);
at_send_command(manager);
}
static void upload_assistance_data(struct EG25Manager *manager)
{
gint error;
off_t written_total = 0;
gint ret;
gint error;
off_t written_total = 0;
gint ret;
struct stat sb;
if (fstat(manager->gnss_assistance_fd, &sb) != 0) {
@@ -357,8 +351,7 @@ static void upload_assistance_data(struct EG25Manager *manager)
}
}
static void finish_assistance_data_upload_cb(struct EG25Manager *manager,
const char *response)
static void finish_assistance_data_upload_cb(struct EG25Manager *manager, const char *response)
{
/* Process response */
at_process_result(manager, response);
@@ -371,23 +364,20 @@ static void finish_assistance_data_upload_cb(struct EG25Manager *manager,
static void finish_assistance_data_upload(struct EG25Manager *manager)
{
gchar value[BUFFER_SIZE];
gchar value[BUFFER_SIZE];
GDateTime *datetime;
gchar *timestring;
gchar *timestring;
/* Configure GNSS assistance clock to current system time (UTC) */
datetime = g_date_time_new_now_utc();
timestring = g_date_time_format(datetime, "0,\"%Y/%m/%d,%H:%M:%S\"");
g_message("Setting GNSS assistance UTC clock to: %s", timestring);
at_append_command(manager, "QGPSXTRATIME", NULL, timestring, NULL,
at_process_result);
at_append_command(manager, "QGPSXTRATIME", NULL, timestring, NULL, at_process_result);
/* Configure GNSS engine to use uploaded GNSS assistance data */
g_snprintf(value, BUFFER_SIZE, "\"RAM:%s\"",
manager->gnss_assistance_file);
g_snprintf(value, BUFFER_SIZE, "\"RAM:%s\"", manager->gnss_assistance_file);
g_message("Setting GNSS assistance file to: %s", value);
at_append_command(manager, "QGPSXTRADATA", NULL, value, NULL,
finish_assistance_data_upload_cb);
at_append_command(manager, "QGPSXTRADATA", NULL, value, NULL, finish_assistance_data_upload_cb);
at_send_command(manager);
}
@@ -396,7 +386,7 @@ static void finish_assistance_data_upload(struct EG25Manager *manager)
#ifdef HAVE_MMGLIB
static void enable_mm_gnss(struct EG25Manager *manager)
{
g_autoptr (GError) error = NULL;
g_autoptr(GError) error = NULL;
MMModemLocationSource sources = mm_modem_location_get_enabled(manager->mm_location);
gboolean signal_location = mm_modem_location_signals_location(manager->mm_location);
@@ -407,11 +397,9 @@ static void enable_mm_gnss(struct EG25Manager *manager)
if (manager->gnss_sources & EG25_GNSS_SOURCE_RAW)
sources |= MM_MODEM_LOCATION_SOURCE_GPS_RAW;
mm_modem_location_setup_sync(manager->mm_location, sources,
signal_location, NULL, &error);
mm_modem_location_setup_sync(manager->mm_location, sources, signal_location, NULL, &error);
if (error != NULL)
g_warning("Unable to enable GNSS engine through ModemManager: %s",
error->message);
g_warning("Unable to enable GNSS engine through ModemManager: %s", error->message);
}
#endif
@@ -424,8 +412,7 @@ static void enable_at_gnss_cb(struct EG25Manager *manager, const char *response)
static void enable_at_gnss(struct EG25Manager *manager)
{
if (manager->gnss_sources & EG25_GNSS_SOURCE_QGPS) {
at_append_command(manager, "QGPS", NULL, "1", NULL,
enable_at_gnss_cb);
at_append_command(manager, "QGPS", NULL, "1", NULL, enable_at_gnss_cb);
at_send_command(manager);
return;
}
@@ -437,7 +424,7 @@ static void enable_at_gnss(struct EG25Manager *manager)
void gnss_step(struct EG25Manager *manager)
{
switch(manager->gnss_assistance_step) {
switch (manager->gnss_assistance_step) {
case EG25_GNSS_STEP_FIRST:
manager->gnss_assistance_step++;
g_message("GNSS assistance upload started...");
@@ -446,7 +433,8 @@ void gnss_step(struct EG25Manager *manager)
case EG25_GNSS_STEP_FETCH_ASSISTANCE_DATA:
g_message("GNSS assistance upload step (%d/%d): "
"fetching assistance data",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
fetch_assistance_data(manager);
break;
@@ -455,7 +443,8 @@ void gnss_step(struct EG25Manager *manager)
if (manager->modem_iface == MODEM_IFACE_MODEMMANAGER) {
g_message("GNSS assistance upload step (%d/%d): "
"disabling GNSS engine through ModemManager",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
disable_mm_gnss(manager);
}
manager->gnss_assistance_step++;
@@ -465,26 +454,30 @@ void gnss_step(struct EG25Manager *manager)
case EG25_GNSS_STEP_AT_GNSS_DISABLE:
g_message("GNSS assistance upload step (%d/%d): "
"disabling GNSS engine through AT+QGPS",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
state_at_gnss(manager);
break;
case EG25_GNSS_STEP_INIT_UPLOAD:
g_message("GNSS assistance upload step (%d/%d): initiating upload",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
init_assistance_data_upload(manager);
break;
case EG25_GNSS_STEP_UPLOAD:
g_message("GNSS assistance upload step (%d/%d): "
"uploading assistance data",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
upload_assistance_data(manager);
break;
case EG25_GNSS_STEP_FINISH_UPLOAD:
g_message("GNSS assistance upload step (%d/%d): finishing upload",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
finish_assistance_data_upload(manager);
break;
@@ -493,7 +486,8 @@ void gnss_step(struct EG25Manager *manager)
if (manager->modem_iface == MODEM_IFACE_MODEMMANAGER) {
g_message("GNSS assistance upload step (%d/%d): "
"re-enabling GNSS through ModemManager",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
enable_mm_gnss(manager);
}
manager->gnss_assistance_step++;
@@ -503,13 +497,15 @@ void gnss_step(struct EG25Manager *manager)
case EG25_GNSS_STEP_AT_QGPS_ENABLE:
g_message("GNSS assistance upload step (%d/%d): "
"re-enabling GNSS through AT+QGPS",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
enable_at_gnss(manager);
break;
case EG25_GNSS_STEP_LAST:
g_message("GNSS assistance upload step (%d/%d): finished",
manager->gnss_assistance_step, EG25_GNSS_STEP_LAST);
manager->gnss_assistance_step,
EG25_GNSS_STEP_LAST);
break;
}
}