forked from bristlemouth/bm_protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_spotter.cpp
More file actions
146 lines (131 loc) · 4.49 KB
/
debug_spotter.cpp
File metadata and controls
146 lines (131 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* FreeRTOS+CLI includes. */
#include "FreeRTOS_CLI.h"
#include "bsp.h"
#include "debug.h"
#include "lwip/inet.h"
#include "pubsub.h"
#include "spotter.h"
#include "util.h"
#include <inttypes.h>
#include <string.h>
#ifdef BSP_BRIDGE_V1_0
#define LED_BLUE LED_G
#define ALARM_OUT TP10
#elif BSP_MOTE_V1_0
#define LED_BLUE GPIO1
#define ALARM_OUT GPIO2
#endif
static BaseType_t cmd_spotter_fn(char *writeBuffer, size_t writeBufferLen,
const char *commandString);
static const CLI_Command_Definition_t cmdSpotter = {
// Command string
"spotter",
// Help string
"spotter:\n"
" * spotter printf <string>\n"
" * spotter fprintf <file_name> <string>\n"
" * spotter txdata <i/c> <data>\n",
// Command function
cmd_spotter_fn,
// Number of parameters (variable)
-1};
void debugSpotterInit(void) { FreeRTOS_CLIRegisterCommand(&cmdSpotter); }
static BaseType_t cmd_spotter_fn(char *writeBuffer, size_t writeBufferLen,
const char *commandString) {
// Remove unused argument warnings
(void)commandString;
(void)writeBuffer;
(void)writeBufferLen;
do {
BaseType_t command_str_len;
const char *command = FreeRTOS_CLIGetParameter(commandString,
1, // Get the first parameter (command)
&command_str_len);
if (command == NULL) {
printf("ERR Invalid command\n");
break;
} else if (strncmp("printf", command, command_str_len) == 0) {
const char *dataStr = FreeRTOS_CLIGetParameter(commandString, 2, &command_str_len);
if (command_str_len == 0) {
printf("ERR data required\n");
break;
}
size_t dataLen = strnlen(dataStr, 128);
BmErr res;
res = spotter_log_console(0, "%.*s", dataLen, dataStr);
if (res != BmOK) {
printf("spotter_log_console err: %d\n", res);
}
} else if (strncmp("fprintf", command, command_str_len) == 0) {
const char *filename = FreeRTOS_CLIGetParameter(commandString, 2, &command_str_len);
if (command_str_len == 0) {
printf("ERR file name required\n");
break;
}
char *just_filename = static_cast<char *>(pvPortMalloc(command_str_len + 1));
configASSERT(just_filename);
memset(just_filename, 0, command_str_len + 1);
strncpy(just_filename, filename, command_str_len);
const char *dataStr = FreeRTOS_CLIGetParameter(commandString, 3, &command_str_len);
if (command_str_len == 0) {
printf("ERR data required\n");
vPortFree(just_filename);
just_filename = NULL;
break;
}
size_t dataLen = strnlen(dataStr, 128);
BmErr res;
res = spotter_log(0, just_filename, USE_TIMESTAMP, "%.*s\n", dataLen + 1,
dataStr); // add one for the \n
if (res != BmOK) {
printf("spotter_log err: %d\n", res);
}
vPortFree(just_filename);
just_filename = NULL;
} else if (strncmp("txdata", command, command_str_len) == 0) {
BaseType_t typeStrLen;
const char *typestr = FreeRTOS_CLIGetParameter(commandString, 2, &typeStrLen);
if (typeStrLen == 0) {
printf("Network type required\n");
break;
}
const char *dataStr = FreeRTOS_CLIGetParameter(commandString, 3, &command_str_len);
if (command_str_len == 0) {
printf("ERR data required\n");
break;
}
size_t dataLen = strnlen(dataStr, 129);
if (dataLen > 128) {
printf("ERR max data len for CLI test is 128 bytes\n");
break;
}
printf("transmit-data byte len: %u\n", (uint8_t)dataLen);
BmSerialNetworkType type;
if (strncmp(typestr, "i", typeStrLen) == 0) {
type = BmNetworkTypeCellularIriFallback;
} else if (strncmp(typestr, "c", typeStrLen) == 0) {
type = BmNetworkTypeCellularOnly;
} else {
printf("Invalid network type\n");
break;
}
uint8_t *data = static_cast<uint8_t *>(pvPortMalloc(dataLen + 1));
configASSERT(data);
memcpy(data, dataStr, dataLen);
data[dataLen] = 0;
if (spotter_tx_data(data, dataLen, type)) {
printf("Sucessfully sent data transmit request\n");
} else {
printf("Failed to send data transmit request\n");
}
vPortFree(data);
} else {
printf("ERR Invalid arguments\n");
break;
}
} while (0);
return pdFALSE;
}