./
Coverage:
low: ≥ 0%
medium: ≥ 50.0%
high: ≥ 80.0%
Lines:
12 / 27
44.4%
Branches:
2 / 8
25.0%
Functions:
2 / 3
66.7%

kfsw-modules/radio-uhf/src/radio_uhf.c
Line Branch Exec Source
1 #include <errno.h>
2
3 #if CONFIG_KFSW_RADIO_UHF_SHELL
4 #include <zephyr/shell/shell.h>
5 #endif
6 #include <zephyr/sys/util.h>
7
8 #include <kfsw/modules/radio_uhf.h>
9
10 #include "radio_uhf_internal.h"
11
12 #if CONFIG_KFSW_RADIO_UHF_HOLYBRO
13 #define KFSW_RADIO_UHF_SELECTED_IMPLEMENTATION kfsw_radio_uhf_holybro
14 #else
15 #error "No K-FSW UHF radio implementation selected"
16 #endif
17
18 12 int kfsw_radio_uhf_get_info(struct kfsw_radio_uhf_info *info)
19 {
20 12 const struct kfsw_radio_uhf_implementation *implementation =
21 &KFSW_RADIO_UHF_SELECTED_IMPLEMENTATION;
22
23
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
12 if (info == NULL) {
24 4 return -EINVAL;
25 }
26
27 8 *info = (struct kfsw_radio_uhf_info){
28 8 .implementation = implementation->name,
29 8 .expected_hardware = implementation->expected_hardware,
30 8 .expected_serial_baud = implementation->expected_serial_baud,
31 8 .expected_hardware_flow_control = implementation->expected_hardware_flow_control,
32 .hardware_status_available = false,
33 .link_state = KFSW_RADIO_UHF_LINK_UNKNOWN,
34 };
35 8 return 0;
36 }
37
38 4 const char *kfsw_radio_uhf_link_state_name(enum kfsw_radio_uhf_link_state state)
39 {
40 switch (state) {
41 case KFSW_RADIO_UHF_LINK_UNKNOWN:
42 default:
43 4 return "unknown";
44 }
45 }
46
47 #if CONFIG_KFSW_RADIO_UHF_SHELL
48 ✗ static int cmd_uhf_status(const struct shell *sh, size_t argc, char **argv)
49 {
50 struct kfsw_radio_uhf_info info;
51 int result;
52
53 ARG_UNUSED(argc);
54 ARG_UNUSED(argv);
55
56 ✗ result = kfsw_radio_uhf_get_info(&info);
57
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ if (result != 0) {
58 ✗ shell_error(sh, "UHF status unavailable (%d)", result);
59 ✗ return result;
60 }
61
62 ✗ shell_print(sh, "UHF radio");
63 ✗ shell_print(sh, "enabled: yes");
64 ✗ shell_print(sh, "implementation: %s", info.implementation);
65 ✗ shell_print(sh, "expected hardware: %s", info.expected_hardware);
66 ✗ shell_print(sh, "configuration source: build-time expectation, not hardware readback");
67 ✗ shell_print(sh, "expected serial: %u 8N1", info.expected_serial_baud);
68
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ shell_print(sh, "expected flow control: %s",
69 info.expected_hardware_flow_control ? "hardware" : "none");
70
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ shell_print(sh, "hardware status: %s",
71 info.hardware_status_available ? "available" : "unavailable");
72 ✗ shell_print(sh, "RF link: %s", kfsw_radio_uhf_link_state_name(info.link_state));
73
74 #if CONFIG_KFSW_RADIO_UHF_CRYPTO
75 struct kfsw_radio_crypto_info crypto;
76 kfsw_radio_uhf_crypto_get(&crypto);
77 shell_print(sh, "protection: %s, TX %s, RX %s", crypto.enabled ? "enabled" : "disabled",
78 crypto.encrypt_tx ? "encrypted" : "plain",
79 crypto.encrypt_rx ? "required" : "plain");
80 shell_print(sh, "key: %s, sessions TX/RX: %u/%u, last error: %d",
81 crypto.key_set ? "set" : "missing", crypto.tx_ready, crypto.rx_ready,
82 crypto.last_error);
83 shell_print(sh, "authenticated: %u, rejected: %u, replays: %u", crypto.authenticated,
84 crypto.rejected, crypto.replays);
85 #endif
86
87 ✗ return 0;
88 }
89
90 #if CONFIG_KFSW_RADIO_UHF_CRYPTO
91 static int cmd_uhf_connect(const struct shell *sh, size_t argc, char **argv)
92 {
93 ARG_UNUSED(argc);
94 ARG_UNUSED(argv);
95 int result = kfsw_radio_uhf_crypto_connect();
96 shell_print(sh, "Radio session request: %d", result);
97 return result;
98 }
99 #endif
100
101 SHELL_STATIC_SUBCMD_SET_CREATE(uhf_commands,
102 #if CONFIG_KFSW_RADIO_UHF_CRYPTO
103 SHELL_CMD_ARG(connect, NULL, "Establish radio sessions with the configured peer.", cmd_uhf_connect, 1, 0),
104 #endif
105 SHELL_CMD_ARG(status, NULL, "Show configured UHF radio identity and status.",
106 cmd_uhf_status, 1, 0),
107 SHELL_SUBCMD_SET_END);
108
109 /* Under the composition's comms group, next to the other links. */
110 SHELL_SUBCMD_ADD((comms), uhf, &uhf_commands, "UHF radio diagnostics.", NULL, 1, 0);
111 #endif
112