./
Coverage:
low: ≥ 0%
medium: ≥ 50.0%
high: ≥ 80.0%
Lines:
3 / 28
10.7%
Branches:
0 / 4
0.0%
Functions:
1 / 6
16.7%

k-fsw/app/src/parameters/telemetry_table.c
Line Branch Exec Source
1 #include <stdint.h>
2
3 #include <zephyr/sys/util.h>
4
5 #include <kfsw/platform/time.h>
6 #include <kfsw/services/parameter.h>
7
8 #include "tables.h"
9
10 #if CONFIG_KFSW_CSP
11 #include <kfsw/comms/csp.h>
12 #endif
13 #if CONFIG_KFSW_STORAGE
14 #include <kfsw/platform/storage.h>
15 #endif
16
17 #define KFSW_MS_PER_S 1000U
18 #define KFSW_BYTES_PER_KB 1024U
19
20 /* Every value is sampled when it is read. */
21 static uint32_t telemetry_uptime_s;
22 static uint16_t telemetry_csp_buf_free;
23 static uint32_t telemetry_fs_free_kb;
24 static uint32_t telemetry_fs_total_kb;
25 static uint8_t telemetry_fs_mounted;
26
27 6 static void sample_uptime_s(void *value)
28 {
29 6 *(uint32_t *)value = (uint32_t)(kfsw_time_monotonic_ms() / KFSW_MS_PER_S);
30 6 }
31
32 ✗ static void sample_csp_buf_free(void *value)
33 {
34 #if CONFIG_KFSW_CSP
35 struct kfsw_csp_info info;
36
37 /* Current number of free CSP packet buffers. */
38 ✗ kfsw_csp_get_info(&info);
39 ✗ *(uint16_t *)value = (uint16_t)info.free_buffers;
40 #else
41 *(uint16_t *)value = 0U;
42 #endif
43 ✗ }
44
45 #if CONFIG_KFSW_STORAGE
46 ✗ static void sample_storage(void)
47 {
48 struct kfsw_storage_info info;
49
50
0/2
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ if (kfsw_storage_get_info(&info) != 0) {
51 ✗ telemetry_fs_mounted = 0U;
52 ✗ telemetry_fs_free_kb = 0U;
53 ✗ telemetry_fs_total_kb = 0U;
54 ✗ return;
55 }
56
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ telemetry_fs_mounted = info.ready ? 1U : 0U;
57 ✗ telemetry_fs_free_kb = (uint32_t)(info.free_bytes / KFSW_BYTES_PER_KB);
58 ✗ telemetry_fs_total_kb = (uint32_t)(info.total_bytes / KFSW_BYTES_PER_KB);
59 }
60 #endif
61
62 ✗ static void sample_fs_free_kb(void *value)
63 {
64 #if CONFIG_KFSW_STORAGE
65 ✗ sample_storage();
66 #endif
67 ✗ *(uint32_t *)value = telemetry_fs_free_kb;
68 ✗ }
69
70 ✗ static void sample_fs_total_kb(void *value)
71 {
72 #if CONFIG_KFSW_STORAGE
73 ✗ sample_storage();
74 #endif
75 ✗ *(uint32_t *)value = telemetry_fs_total_kb;
76 ✗ }
77
78 ✗ static void sample_fs_mounted(void *value)
79 {
80 #if CONFIG_KFSW_STORAGE
81 ✗ sample_storage();
82 #endif
83 ✗ *(uint8_t *)value = telemetry_fs_mounted;
84 ✗ }
85
86 static const struct kfsw_param_definition telemetry_param_definitions[] = {
87 {
88 .offset = 0x00U,
89 .type = KFSW_PARAM_U32,
90 .flags = KFSW_PARAM_FLAG_READ_ONLY,
91 .name = "uptime_s",
92 .unit = "s",
93 .description = "Seconds since boot",
94 .value = &telemetry_uptime_s,
95 .default_value = {.u32 = 0U},
96 .sample = sample_uptime_s,
97 },
98 {
99 .offset = 0x04U,
100 .type = KFSW_PARAM_U32,
101 .flags = KFSW_PARAM_FLAG_READ_ONLY,
102 .name = "fs_total_kb",
103 .unit = "kB",
104 .description = "Filesystem capacity, or zero while unmounted",
105 .value = &telemetry_fs_total_kb,
106 .default_value = {.u32 = 0U},
107 .sample = sample_fs_total_kb,
108 },
109 {
110 .offset = 0x08U,
111 .type = KFSW_PARAM_U32,
112 .flags = KFSW_PARAM_FLAG_READ_ONLY,
113 .name = "fs_free_kb",
114 .unit = "kB",
115 .description = "Filesystem space available, or zero while unmounted",
116 .value = &telemetry_fs_free_kb,
117 .default_value = {.u32 = 0U},
118 .sample = sample_fs_free_kb,
119 },
120 {
121 .offset = 0x0cU,
122 .type = KFSW_PARAM_U16,
123 .flags = KFSW_PARAM_FLAG_READ_ONLY,
124 .name = "csp_buf_free",
125 .description = "CSP buffers available to the router",
126 .value = &telemetry_csp_buf_free,
127 .default_value = {.u16 = 0U},
128 .sample = sample_csp_buf_free,
129 },
130 {
131 .offset = 0x0eU,
132 .type = KFSW_PARAM_U8,
133 .flags = KFSW_PARAM_FLAG_READ_ONLY,
134 .name = "fs_mounted",
135 .description = "Whether the filesystem is mounted and usable",
136 .value = &telemetry_fs_mounted,
137 .default_value = {.u8 = 0U},
138 .sample = sample_fs_mounted,
139 },
140 };
141
142 KFSW_PARAM_TABLE_FITS_THE_LINK(telemetry_param_definitions);
143
144 const struct kfsw_param_definition_set kfsw_telemetry_param_definitions = {
145 .table = KFSW_PARAM_TABLE_TELEMETRY,
146 .name = KFSW_PARAM_TABLE_TELEMETRY_NAME,
147 .description = "Uptime, storage and CSP buffers",
148 .definitions = telemetry_param_definitions,
149 .count = ARRAY_SIZE(telemetry_param_definitions),
150 };
151