forked from bristlemouth/bm_protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_pluart_cli.cpp
More file actions
80 lines (70 loc) · 2.12 KB
/
debug_pluart_cli.cpp
File metadata and controls
80 lines (70 loc) · 2.12 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
#include "debug_pluart_cli.h"
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "payload_uart.h"
/* FreeRTOS+CLI includes. */
#include "FreeRTOS_CLI.h"
#include "app_util.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mbedtls_base64/base64.h"
static BaseType_t plUartCliCommand( char *writeBuffer,
size_t writeBufferLen,
const char *commandString);
//static bool plUartWrite(const unsigned char * buf, size_t binLen);
static const CLI_Command_Definition_t cmdPlUartCli = {
// Command string
"pluart",
// Help string
"pluart:\n"
" * pluart write <ascii data>\n",
// Command function
plUartCliCommand,
// Number of parameters (variable)
-1
};
void debugPlUartCliInit(void) {
FreeRTOS_CLIRegisterCommand( &cmdPlUartCli );
}
static BaseType_t plUartCliCommand( char *writeBuffer,
size_t writeBufferLen,
const char *commandString) {
// Remove unused argument warnings
( void ) commandString;
( void ) writeBuffer;
( void ) writeBufferLen;
do {
BaseType_t opStrLen;
const char *opStr = FreeRTOS_CLIGetParameter(
commandString,
1,
&opStrLen);
if(opStr == NULL) {
printf("ERR Invalid parameters\n");
break;
}
if (strncmp("write", opStr,opStrLen) == 0) {
BaseType_t argDataLen;
const char *argDataStr = FreeRTOS_CLIGetParameter(
commandString,
2,
&argDataLen);
if(argDataStr == NULL) {
printf("ERR Invalid parameters\n");
break;
}
// TODO - make the termination configurable.
const char* termination = {"\r\n"};
// Use start and end transaction guards, have no effect if transactions not being used.
PLUART::startTransaction();
PLUART::write((uint8_t*)argDataStr, strlen(argDataStr));
PLUART::write((uint8_t*)termination, strlen(termination));
PLUART::endTransaction();
} else {
printf("ERROR - Unsupported op!: %s\n", opStr);
}
} while(0);
return pdFALSE;
}