Loading...
Searching...
No Matches
debug_sx1272.c
1/***********************************************************************************
2 * @file launch.c *
3 * @author Matt Ricci *
4 * @addtogroup Shell *
5 * *
6 * @{ *
7 ***********************************************************************************/
8
9#if defined(EXTRA_sx1272) && defined(EXTRA_lora)
10
11#include "AustralisConfig.h"
12
13#include "FreeRTOS.h"
14#include "event_groups.h"
15#include "groups.h"
16
17#include "stdio.h"
18#include "string.h"
19
20#include "parser.h"
21#include "shell.h"
22
23#include "lorapub.h"
24#include "sx1272.h"
25
26static void SX1272_exec(UART_t *uart, char *flags);
27static void SX1272_help(UART_t *uart);
28
29DEFINE_PROGRAM_HANDLE("sx1272", SX1272_exec, SX1272_help)
30
31static void SX1272_help(UART_t *uart) {
32 uart->println(uart, "NAME:");
33 uart->println(uart, "\tsx1272\n");
34 uart->println(uart, "USAGE:");
35 uart->println(uart, "\tconfigure\n");
36 uart->println(uart, "DESCRIPTION:");
37 uart->println(uart, "\tProvides debug access to a SX1272 device associated with the LoRa publication\n");
38 uart->println(uart, "\tconfigure");
39 uart->println(uart, "\t Configure options for SX1272 transceiver.\n");
40 uart->println(uart, "OPTIONS:");
41 uart->println(uart, "\t-h, --help");
42 uart->println(uart, "\t Print this help and exit");
43}
44
45/* ============================================================================================== */
52static void SX1272_exec(UART_t *uart, char *flags) {
53
54 ArgParser parser = ArgParser_init();
55 int argOperationIdx = parser.addArg(
56 &parser, "configure", 0, ARG_TYPE_STRING, true
57 );
58
59 char *tokens[MAX_ARGS];
60 int numTokens = 0;
61
62 // Tokenize the input string
63 char *token = strtok(flags, " ");
64 while (token != NULL && numTokens < MAX_ARGS) {
65 tokens[numTokens++] = token;
66 token = strtok(NULL, " ");
67 }
68
69 // Parse input tokens
70 parser.parseArgs(&parser, numTokens, tokens);
71
72 // Early exit with error message if parse failed
73 if (parser.error.status == PARSER_STATUS_ERROR) {
74 uart->println(uart, parser.error.msg);
75 return;
76 }
77
78 SX1272_t *transceiver = (SX1272_t *)LoRa_getTransceiver();
79
80 // Early exit with error message if transceiver is not set
81 if (transceiver == NULL) {
82 uart->println(uart, "Error: No transceiver is available on the LoRa topic.");
83 return;
84 }
85
86 if (parser.args[argOperationIdx].provided) {
87 SX1272_Config config = transceiver->config;
88
89 transceiver->updateConfig(transceiver, &config);
90 }
91}
92
93#endif
94
SX1272 LoRa configuration struct.
Definition sx1272.h:159
Struct definition for SX1272. Provides the interface for API consumers to interact with the SX1272 Lo...
Definition sx1272.h:189
Struct definition for UART interface.
Definition uart.h:132