Dawn Framework 1.0
Universal data acquisition framework for embedded systems
lte_signal.cxx
1// dawn/src/io/lte_signal.cxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#include "dawn/io/lte_signal.hxx"
7
8#include <cerrno>
9#include <cinttypes>
10#include <cstring>
11
12#include "dawn/porting/lte.hxx"
13
14using namespace dawn;
15
17{
18 CDescObject &desc = getDesc();
20 size_t offset = 0;
21
22#ifdef CONFIG_DAWN_IO_NOTIFY
23 interval = 0;
24#endif
25
26 for (size_t i = 0; i < desc.getSize(); i++)
27 {
28 item = desc.objectCfgItemAtOffset(offset);
29
31 {
32 if (item->cfgid.s.id == LTE_SIGNAL_CFG_INTERVAL)
33 {
34 timfd_interval(item->data[0]);
35 }
36 }
37 else if (item->cfgid.s.cls != CIOCommon::IO_CLASS_ANY)
38 {
39 DAWNERR("unsupported lte_signal cfg 0x%08" PRIx32 "\n", item->cfgid.v);
40 return -EINVAL;
41 }
42
43 offset += cfgCmnOffset(item);
44 }
45
46 return OK;
47}
48
50{
51#ifdef CONFIG_DAWN_IO_NOTIFY
52 if (interval == 0)
53 {
54 DAWNERR("lte_signal requires interval > 0\n");
55 return -EINVAL;
56 }
57#endif
58
59 return timfd_init();
60}
61
63{
64 timfd_stop();
65 return OK;
66}
67
69{
70 return timfd_start();
71}
72
74{
75 return timfd_stop();
76}
77
79{
80 int16_t vec[DAWN_LTE_SIGNAL_DIM];
81 struct SLteQuality q;
82 struct SLteCellinfo cell;
83 size_t i;
84 int ret;
85
86 // RSRP/RSRQ/SINR from the quality read - the primary metrics. No camped
87 // cell / RF off: report no data so a 'latest' wrapper keeps the last value.
88
89 ret = lte_port_get_quality(&q);
90 if (ret < 0)
91 {
92 timfd_ack();
93 return ret;
94 }
95
96 if (!q.valid)
97 {
98 timfd_ack();
99 return -ENODATA;
100 }
101
102 vec[DAWN_LTE_SIGNAL_RSRP] = q.rsrp;
103 vec[DAWN_LTE_SIGNAL_RSRQ] = q.rsrq;
104 vec[DAWN_LTE_SIGNAL_SINR] = q.sinr;
105
106 // Band from the cell-info read - best-effort (0 when unavailable).
107
108 ret = lte_port_get_cellinfo(&cell);
109 vec[DAWN_LTE_SIGNAL_BAND] = (ret == OK && cell.valid) ? static_cast<int16_t>(cell.band) : 0;
110
111 for (i = 0; i < len; i++)
112 {
113 std::memcpy(data.getDataPtr(i), vec, sizeof(vec));
114
115 if (isTimestamp())
116 {
117 data.getTs(i) = getTimestamp();
118 }
119 }
120
121 timfd_ack();
122 return OK;
123}
124
126{
127 return DAWN_LTE_SIGNAL_DIM * sizeof(int16_t);
128}
129
131{
132 return DAWN_LTE_SIGNAL_DIM;
133}
134
135#ifdef CONFIG_DAWN_IO_NOTIFY
136int CIOLteSignal::getFd() const
137{
138 return timfd_fd();
139}
140#endif
Descriptor wrapper for individual object configuration.
size_t getSize() const
Get number of configuration items for this object.
SObjectCfg::SObjectCfgItem * objectCfgItemAtOffset(size_t offset) const
Get configuration item at specified offset.
virtual int getFd() const
Get file descriptor for notifications.
Definition common.hxx:444
uint64_t getTimestamp()
Get current timestamp.
Definition common.cxx:194
bool isTimestamp() const
Check if I/O supports timestamp.
Definition common.cxx:189
size_t cfgCmnOffset(const SObjectCfg::SObjectCfgItem *cfg)
Get offset of configuration item in descriptor.
Definition common.cxx:144
@ IO_CLASS_ANY
Any I/O class.
Definition common.hxx:86
@ IO_CLASS_LTE_SIGNAL
LTE signal quality (RSRP/RSRQ/SINR/RSSI)
Definition common.hxx:203
size_t getDataDim() const
Get data vector dimension.
int getDataImpl(IODataCmn &data, size_t len)
Get data implementation (override in derived classes).
size_t getDataSize() const
Get data size in bytes.
@ LTE_SIGNAL_CFG_INTERVAL
Poll interval, microseconds (DTYPE_UINT32)
int configure()
Configure object from descriptor data.
int doStop()
Stop implementation hook.
int doStart()
Start implementation hook.
int deinit()
De-initialize object.
int init()
One-time initialize object after bindings are resolved.
CDescObject & getDesc()
Get descriptor object for this object.
Definition object.cxx:190
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
@ DAWN_LTE_SIGNAL_DIM
Number of metrics in the vector.
@ DAWN_LTE_SIGNAL_RSRP
Reference Signal Received Power (dBm)
@ DAWN_LTE_SIGNAL_SINR
Signal to Interference + Noise Ratio (dB)
@ DAWN_LTE_SIGNAL_RSRQ
Reference Signal Received Quality (dB)
@ DAWN_LTE_SIGNAL_BAND
Serving E-UTRA band number.
Base interface for I/O data buffers (static and dynamic).
Definition idata.hxx:21
virtual void * getDataPtr(size_t batch=0)=0
Get pointer to data only (skips timestamp if present).
virtual uint64_t & getTs(size_t batch=0)=0
Get timestamp reference for batch.
Parameters used to bring up an LTE data connection.
Definition lte.hxx:64
bool valid
Values are meaningful only when true (RF on, camped).
Definition lte.hxx:65
int16_t rsrp
Reference Signal Received Power, dBm (-140..0).
Definition lte.hxx:66
int16_t sinr
Signal to Interference + Noise Ratio, dB (-128..40).
Definition lte.hxx:68
int16_t rsrq
Reference Signal Received Quality, dB (-60..0).
Definition lte.hxx:67
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).
ObjectCfgId v
Raw 32-bit ConfigID value (for storage, comparison).
Definition objectcfg.hxx:82
uint32_t cls
Object class (bits 21-29, max 511).
uint32_t id
Configuration identifier (bits 0-4, max 31).
Definition objectcfg.hxx:94
struct dawn::SObjectCfg::UObjectCfgId::@10 s
Bit-field structure for named member access.