MCPcopy Create free account
hub / github.com/cesanta/mongoose / cli

Function cli

tutorials/esp32/uart-bridge/main/cli.c:50–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48static struct mg_iobuf in;
49
50void cli(uint8_t input_byte) {
51 if (input_byte == 0 || input_byte == 0xff) return;
52 if (in.len >= 128) in.len = 0;
53 mg_iobuf_add(&in, in.len, &input_byte, sizeof(input_byte));
54
55 if (input_byte == '\n') {
56 const char *arrow = "---";
57 char buf0[10], buf1[50], buf2[250];
58
59 in.buf[in.len] = '\0';
60 buf0[0] = buf1[0] = buf2[0] = '\0';
61 sscanf((char *) in.buf, "%9s %49s %249[^\r\n]", buf0, buf1, buf2);
62
63 printf("%s CLI command: '%s'\n", arrow, buf0);
64 if (strcmp(buf0, "reboot") == 0) {
65 esp_restart();
66 } else if (strcmp(buf0, "ls") == 0) {
67 cli_ls();
68 } else if (strcmp(buf0, "cat") == 0) {
69 cli_cat(buf1);
70 } else if (strcmp(buf0, "rm") == 0) {
71 cli_rm(buf1);
72 } else if (strcmp(buf0, "reboot") == 0) {
73 esp_restart();
74 } else if (strcmp(buf0, "ll") == 0) {
75 mg_log_set(atoi(buf1));
76 } else if (strcmp(buf0, "wifi") == 0) {
77 cli_wifi(buf1, buf2);
78 } else {
79 printf("%s %s\n", arrow, "Unknown command. Usage:");
80 printf("%s %s\n", arrow, " set NAME VALUE");
81 printf("%s %s\n", arrow, " rm FILENAME");
82 printf("%s %s\n", arrow, " cat FILENAME");
83 printf("%s %s\n", arrow, " ls");
84 printf("%s %s\n", arrow, " reboot");
85 printf("%s %s\n", arrow, " wifi WIFI_NET WIFI_PASS");
86 }
87 printf("%s %s\n", arrow, "CLI output end");
88 in.len = 0;
89 }
90}
91
92void cli_init(void) {
93 mg_iobuf_init(&in, 0, 32);

Callers 1

app_mainFunction · 0.85

Calls 5

cli_lsFunction · 0.85
cli_catFunction · 0.85
cli_rmFunction · 0.85
cli_wifiFunction · 0.85
mg_iobuf_addFunction · 0.50

Tested by

no test coverage detected