Fix GPS modem selection and add a GPS-only time source
This commit is contained in:
1 parent
eaf08abcd4
commit
a50c01b416
18 files changed
+682
-16
No files matched your search
@@ -163,8 +163,26 @@ std::vector<std::string> splitCsv(const std::string& s) {
|
||||
return out;
|
||||
}
|
||||
|
||||
// "mmcli -m any" is ambiguous on dual-SIM QMI targets such as the 2720 Flip:
|
||||
// ModemManager can resolve the wrong modem or reject the query outright. The
|
||||
// helper picks the modem that advertises the gps-nmea capability and falls
|
||||
// back to "any" when no modem is enumerated yet.
|
||||
std::string gpsModemArg() {
|
||||
static std::string cached;
|
||||
if (cached.empty()) {
|
||||
std::string path = trimStr(runCaptureCmd(
|
||||
"/usr/bin/bananarchy-gps-modem.sh path 2>/dev/null"));
|
||||
if (path.rfind("/org/freedesktop/ModemManager1/Modem/", 0) == 0)
|
||||
cached = "-m " + shellQuote(path);
|
||||
else
|
||||
cached = "-m any";
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
|
||||
void pollModemGpsStatus(GpsStatus& st) {
|
||||
std::string raw = runCaptureCmd("mmcli -m any -K --location-get 2>/dev/null");
|
||||
std::string raw = runCaptureCmd(
|
||||
"mmcli " + gpsModemArg() + " -K --location-get 2>/dev/null");
|
||||
if (raw.empty()) return;
|
||||
|
||||
st.rawNmea.clear();
|
||||
@@ -559,7 +577,8 @@ int gps_run_main(int argc, char** argv) {
|
||||
else if (std::strcmp(argv[i], "--test") == 0) {
|
||||
// CLI GPS test mode
|
||||
GpsStatus st;
|
||||
runAsyncCmd("mmcli -m any --location-enable-gps-nmea --location-enable-gps-raw >/dev/null 2>&1");
|
||||
runAsyncCmd(std::string("/usr/bin/bananarchy-gps-modem.sh enable >/dev/null 2>&1; ") +
|
||||
"mmcli " + gpsModemArg() + " --location-enable-3gpp >/dev/null 2>&1");
|
||||
::usleep(300000);
|
||||
pollModemGpsStatus(st);
|
||||
std::printf("Fix: %s (%dD) Sats: %d/%d HDOP: %.1f UTC: %s\n",
|
||||
@@ -632,8 +651,11 @@ int gps_run_main(int argc, char** argv) {
|
||||
if (!gps.gpsEnabled) {
|
||||
gps.gpsEnabled = true;
|
||||
runAsyncCmd(
|
||||
"mmcli -m any --location-enable-gps-nmea --location-enable-gps-raw >/dev/null 2>&1; "
|
||||
"mmcli -m any --location-set-gps-refresh-rate=2 >/dev/null 2>&1");
|
||||
"mmcli " + gpsModemArg() +
|
||||
" --location-enable-gps-nmea --location-enable-gps-raw "
|
||||
"--location-enable-3gpp >/dev/null 2>&1; "
|
||||
"mmcli " + gpsModemArg() +
|
||||
" --location-set-gps-refresh-rate=2 >/dev/null 2>&1");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -641,7 +663,8 @@ int gps_run_main(int argc, char** argv) {
|
||||
if (gps.gpsEnabled && !keepGpsInBg) {
|
||||
gps.gpsEnabled = false;
|
||||
runAsyncCmd(
|
||||
"mmcli -m any --location-disable-gps-nmea --location-disable-gps-raw >/dev/null 2>&1");
|
||||
"mmcli " + gpsModemArg() +
|
||||
" --location-disable-gps-nmea --location-disable-gps-raw >/dev/null 2>&1");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1213,6 +1213,10 @@ clear_all_notifications_now(void)
|
||||
"sxmo_hook_statusbar.sh notifications >/dev/null 2>&1");
|
||||
}
|
||||
|
||||
/* Defined with the Config-menu helpers below; used by the time source toggle. */
|
||||
static void time_source_path(char *path, size_t len);
|
||||
static const char *read_time_source(void);
|
||||
|
||||
static void
|
||||
handle_builtin_toggle(const char *toggle_name)
|
||||
{
|
||||
@@ -1322,6 +1326,25 @@ handle_builtin_toggle(const char *toggle_name)
|
||||
} else if (strcmp(toggle_name, "ext_logging") == 0) {
|
||||
int rc = system("doas -n /usr/bin/bananarchy-engmenu-ctl logging toggle >/dev/null 2>&1 || /usr/bin/bananarchy-engmenu-ctl logging toggle >/dev/null 2>&1");
|
||||
(void)rc;
|
||||
} else if (strcmp(toggle_name, "time_source") == 0) {
|
||||
/* Config -> Time source: switch between NTP and GPS-only datetime sync. */
|
||||
char path[256], dir[256], value[16];
|
||||
const char *home = getenv("HOME");
|
||||
const char *next = strcmp(read_time_source(), "gps") == 0 ? "network" : "gps";
|
||||
if (!home || !home[0])
|
||||
home = "/home/user";
|
||||
snprintf(dir, sizeof(dir), "%s/.config/sxmo", home);
|
||||
mkdir(dir, 0755);
|
||||
time_source_path(path, sizeof(path));
|
||||
snprintf(value, sizeof(value), "%s\n", next);
|
||||
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
if (fd >= 0) {
|
||||
(void)!write(fd, value, strlen(value));
|
||||
close(fd);
|
||||
spawn_detached_sh(
|
||||
"doas -n /usr/bin/bananarchy-gps-time-sync.sh apply >/dev/null 2>&1 || "
|
||||
"/usr/bin/bananarchy-gps-time-sync.sh apply >/dev/null 2>&1 || true");
|
||||
}
|
||||
} else if (strcmp(toggle_name, "notif_clear_all") == 0) {
|
||||
clear_all_notifications_now();
|
||||
}
|
||||
@@ -2516,6 +2539,26 @@ idle_blank_label(int secs)
|
||||
return out;
|
||||
}
|
||||
|
||||
/* Config-menu time source (NTP network vs GNSS only) helpers. */
|
||||
static void
|
||||
time_source_path(char *path, size_t len)
|
||||
{
|
||||
const char *home = getenv("HOME");
|
||||
if (!home || !home[0])
|
||||
home = "/home/user";
|
||||
snprintf(path, len, "%s/.config/sxmo/time_source", home);
|
||||
}
|
||||
|
||||
static const char *
|
||||
read_time_source(void)
|
||||
{
|
||||
char path[256], buf[32] = "";
|
||||
time_source_path(path, sizeof(path));
|
||||
if (read_first_line(path, buf, sizeof(buf)) && strcmp(buf, "gps") == 0)
|
||||
return "gps";
|
||||
return "network";
|
||||
}
|
||||
|
||||
static void
|
||||
populate_timezone_menu(void)
|
||||
{
|
||||
@@ -2982,6 +3025,13 @@ open_builtin_menu(const char *menu_name, int keep_idx)
|
||||
snprintf(label, sizeof(label), "%s Sync net time", ICON_CLK);
|
||||
add_menu_item(label, "/usr/bin/bananarchy-sync-net-time.sh", 0);
|
||||
|
||||
/* Time source: NTP or GNSS only; Sync GPS time works in either mode. */
|
||||
snprintf(label, sizeof(label), "%s Time source: %s", ICON_CLK,
|
||||
strcmp(read_time_source(), "gps") == 0 ? "GPS only" : "Network (NTP)");
|
||||
add_menu_item(label, "@toggle:time_source", 1);
|
||||
snprintf(label, sizeof(label), "%s Sync GPS time", ICON_CLK);
|
||||
add_menu_item(label, "/usr/bin/bananarchy-sync-gps-time.sh", 0);
|
||||
|
||||
snprintf(label, sizeof(label), "%s Screen blank: %s", ICON_CLK,
|
||||
idle_blank_label(read_idle_blank_secs()));
|
||||
add_menu_item(label, "@menu:idle_blank", 1);
|
||||
|
||||
Reference in new issue
Block a user