6#include "dawn/system/gnss.hxx"
12#include <nuttx/uorb.h>
14#include "dawn/debug.hxx"
15#include "dawn/porting/lte.hxx"
16#include "dawn/porting/sensors.hxx"
23#define GNSS_MONITOR_POLL_US (1000000)
29#define GNSS_SETTLE_S CONFIG_DAWN_SYSTEM_GNSS_SETTLE
30#define GNSS_ACQUIRE_S CONFIG_DAWN_SYSTEM_GNSS_ACQUIRE
31#define GNSS_RETRY_S CONFIG_DAWN_SYSTEM_GNSS_RETRY
32#define GNSS_MAXATTEMPTS CONFIG_DAWN_SYSTEM_GNSS_MAXATTEMPTS
33#define GNSS_REARM_S CONFIG_DAWN_SYSTEM_GNSS_REARM
39#ifdef CONFIG_DAWN_SYSTEM_GNSS_ENABLED
40# define GNSS_ENABLED_DEFAULT (true)
42# define GNSS_ENABLED_DEFAULT (false)
49 , settle(GNSS_SETTLE_S)
50 , acquire(GNSS_ACQUIRE_S)
52 , maxAttempts(GNSS_MAXATTEMPTS)
58void CSystemGnss::loadParams()
68 mode = CONFIG_DAWN_SYSTEM_GNSS_MODE;
69 enabled = GNSS_ENABLED_DEFAULT;
70 settle = GNSS_SETTLE_S;
71 acquire = GNSS_ACQUIRE_S;
73 maxAttempts = GNSS_MAXATTEMPTS;
78 for (i = 0; i < count; i++)
94 mode =
static_cast<uint8_t
>(item->
data[0] & 0xff);
98 settle = item->
data[0];
102 acquire = item->
data[0];
106 retry = item->
data[0];
110 maxAttempts = item->
data[0];
114 rearm = item->
data[0];
118 enabled = (item->
data[0] != 0);
133void CSystemGnss::monitor()
135 struct sensor_gnss gnss;
141 sensor_set_interval(fd, GNSS_MONITOR_POLL_US);
147 auto waitLte = [
this](uint32_t timeout)
150 for (uint32_t t = 0; t < timeout && !shouldQuit(); t++)
165 auto idle = [
this](uint32_t secs)
167 for (uint32_t t = 0; t < secs && !shouldQuit(); t++)
191 while (!shouldQuit() && !fixed)
193 uint32_t attempt = 0;
195 while (!shouldQuit() && (maxAttempts == 0 || attempt < maxAttempts))
202 sensor_gnss_set_priority(fd,
true);
203 DAWNINFO(
"GNSS manager: acquiring (bounded %lus, attempt %lu)\n",
204 (
unsigned long)acquire,
205 (
unsigned long)attempt);
207 for (uint32_t t = 0; t < acquire && !shouldQuit(); t++)
209 n = sensor_read(fd, &gnss,
sizeof(gnss));
222 sensor_gnss_set_priority(fd,
false);
228 DAWNINFO(
"GNSS manager: fix acquired (lat=%f); LTE restored\n",
229 static_cast<double>(gnss.latitude));
236 if (maxAttempts == 0 || attempt < maxAttempts)
238 DAWNINFO(
"GNSS manager: no fix in %lus; LTE reachable, "
240 (
unsigned long)acquire,
241 (
unsigned long)retry);
246 if (fixed || shouldQuit())
253 DAWNINFO(
"GNSS manager: gave up after %lu attempts; LTE only, "
255 (
unsigned long)attempt,
256 (
unsigned long)rearm);
262 sensor_gnss_set_priority(fd,
false);
266int CSystemGnss::startMonitor()
275 std::snprintf(path,
sizeof(path),
"/dev/uorb/sensor_gnss0");
277 fd = sensor_open(path);
280 DAWNERR(
"GNSS manager: open %s failed %d\n", path, fd);
284 DAWNINFO(
"GNSS manager: enabled, starting acquisition\n");
288void CSystemGnss::stopMonitor()
313 DAWNINFO(
"GNSS manager: off (mode)\n");
319 DAWNINFO(
"GNSS manager: idle (disabled); enable over LwM2M to start\n");
323 return startMonitor();
345 enabled = (data[0] != 0);
349 return startMonitor();
352 DAWNINFO(
"GNSS manager: disabled over LwM2M; LTE only\n");
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemNext(size_t &offset) const
Get config item at current offset and advance past it.
CDescObject & getDesc()
Get descriptor object for this object.
Base class for OBJTYPE_ANY configuration objects.
@ SYSTEM_CLASS_GNSS
GNSS coexistence manager (policy)
int doStart()
Start implementation hook.
@ GNSS_CFG_MODE
DAWN_GNSS_MODE_* (DTYPE_UINT8)
@ GNSS_CFG_ENABLED
Runtime on/off switch (DTYPE_BOOL)
@ GNSS_CFG_ACQUIRE
Bounded fix window, seconds (DTYPE_UINT32)
@ GNSS_CFG_REARM
Re-arm delay after give-up, s (DTYPE_UINT32)
@ GNSS_CFG_MAXATTEMPTS
No-fix windows before give-up (DTYPE_UINT32)
@ GNSS_CFG_SETTLE
LTE-first grace, seconds (DTYPE_UINT32)
@ GNSS_CFG_RETRY
Cooldown between attempts, s (DTYPE_UINT32)
int configure()
Configure object from descriptor data.
int onSetObjConfig(SObjectCfg::ObjectCfgId objcfg, uint32_t *data, size_t len)
React to runtime config writes (e.g.
int doStop()
Stop implementation hook.
bool isRunning() const
Check if the worker thread is running.
int stopWorkerThread()
Stop the worker thread.
int startWorkerThread(Func &&func)
Start the worker thread with a given function.
uint32_t ObjectCfgId
ConfigID type - single 32-bit value.
static uint16_t objectCfgGetCls(const ObjectCfgId objcfg)
Extract object class from ConfigID.
static uint8_t objectCfgGetId(const ObjectCfgId objcfg)
Extract configuration identifier from ConfigID.
Out-of-tree user-extension hooks for Dawn.
@ DAWN_GNSS_MODE_OFF
Manager idle; do not touch the radio knobs.
@ DAWN_LTE_PSAVE_NONE
PSM and eDRX disabled (always reachable)
@ DAWN_LTE_PSAVE_PSM
Power Saving Mode.
@ DAWN_LTE_STATUS_CONNECTED
Connected (PDN active, IP assigned)
Single configuration item within object.
ObjectCfgData_t data[]
Configuration data array (flexible, size from cfgid.s.size).
UObjectCfgId cfgid
Configuration ID header (type, class, id, size, rw, dtype).
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.