-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.c
More file actions
executable file
·780 lines (628 loc) · 20.7 KB
/
Copy pathcli.c
File metadata and controls
executable file
·780 lines (628 loc) · 20.7 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
/**
* @brief Compact & Simple Command Line Interface for microcontrollers
*
* Copyright (c) 2018 Vitaliy Nimych - vitaliy.nimych@gmail.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Modified 14 January 2019 - Vitaliy Nimych
* add cli input log commands
*
* Modified 20 April 2019 - Vitaliy Nimych
* add pars buttons: UP, DOWN, LEFT, RIGHT
*
* Modified 1 September 2019 - Vitaliy Nimych
* add pars buttons: TAB, ESC, Ctrl + C
*
* Modified 27 December 2020 - Vitaliy Nimych
* add pars buttons for clear screen : Ctrl + L, small code refactoring
*
* */
#include "cli.h"
#include "cli_queue.h"
#include "tinystring.h"
#include "cli_time.h"
#include "cli_log.h"
#include "cli_input.h"
#define PRINT_ARROW() {CLI_PRINTF("%s%s",STRING_TERM_ENTER, STRING_TERM_ARROW);} // Output of input line
#define SEPARATOR_ASTERISK ("\r\n***********************************************************")
#define SEPARATOR ("\r\n-----------------------------------------------------------")
// todo: need refactor this variable, maybe put to struct
char output_print_buffer[256];
volatile uint64_t _tick;
// need change address for another MCU, see datasheet for MCU (for stm32f4 0x1FFF7A10, stm32F1 0x1FFFF7E8) or another MCU
static volatile uint32_t *UniqueID = (uint32_t *) 0x1FFF7A10;
/** @brief Command settings */
typedef struct {
uint8_t (*fcn)(); // callback function command
const char *name; // name command
uint8_t argc; // min count argument
uint16_t mode; // mode execute command
const char *description; // description command
} CLI_Cmd_t;
typedef struct{
uint8_t argc;
char** argv;
} CLI_Params_t;
/** @brief CLI State */
struct {
CLI_Cmd_t cmds[CLI_SIZE_MAX_CMD]; // list commands
uint8_t countCommand; // count commands
uint8_t executeState; // state terminal
volatile CLI_Params_t inputArgs; // args current execute command
bool isEntered;
bool first_in;
} CLI_State_s;
// **************** Callback for included in CLI commands *****************
static CLI_Result_t help_cmd(); // print help
static CLI_Result_t reboot_mcu(); // reboot mcu
static CLI_Result_t print_cli_w(void); // print welcome screen
static CLI_Result_t set_loglevel(void); // set loglevel output
// ************************************************************************
// ************************** static function *****************************
static CLI_Cmd_t *_find_cli_command(const char *cmdName);
static void _clear_screen(void);
static void _print_result_exec(uint8_t code);
static void _print_result_add_cmd(uint8_t code);
static void _print_boot_time(CLI_Time_t *time);
static int8_t _index_of_flag(const char *flag);
static void _cli_print_time();
static void _arg_destroy(CLI_Params_t* src);
static uint8_t _strPartCmp(const char* str1, const char* str2);
// ************************************************************************
// ************************* interrupt function ***************************
static bool _interrupt_operation = false; // todo: need implement - abort run current job
/** @brief Checking the status of the start of the operation (return, stator-on) */
inline bool cli_get_int_state(void) {
bool res = _interrupt_operation;
_interrupt_operation = false;
return res;
}
// ************************************************************************
// ************************** CLI function ********************************
static void cli_welcome(void) {
CLI_PRINTF(SEPARATOR_ASTERISK);
CLI_PRINTF("\r\n| %s\t\t\t\t\t |", BUILD_NAME);
CLI_PRINTF("\r\n| SW ver: v%s.%s.%s MCU: %s \t\t\t |", MINOR, MAJOR, PATCH, MCU);
CLI_PRINTF("\r\n| CLI ver: %s UID: %X-%X-%X\t |", _TERM_VER_, UniqueID[0], UniqueID[1], UniqueID[2]);
CLI_PRINTF("\r\n| Build Date: %s %s Where: %s\t |", __DATE__, __TIME__, _WHERE_BUILD);
CLI_PRINTF("\r\n| Branch: %s GIT-HASH: %s\t\t\t |", GIT_BRANCH, GIT_HASH);
CLI_PRINTF(SEPARATOR_ASTERISK);
CLI_PRINTF("\r\n");
}
CLI_Result_t sys_uptime(void)
{
return CLI_OK;
}
/** @brief Terminal initialize */
void cli_init(void)
{
/** Register external data logger */ // todo: need to integrate the logger into CLI
ULOG_INIT();
ULOG_SUBSCRIBE(console_logger, ULOG_DEBUG_LEVEL);
ULOG_INFO("Logger init\n");
/** ***************************** */
cli_input_init();
CLI_State_s.countCommand = 0;
CLI_State_s.executeState = 0;
CLI_State_s.isEntered = false;
cli_add_new_cmd("help", help_cmd, 0, CLI_PrintNone, "help by CLI command");
cli_add_new_cmd("welcome", print_cli_w, 0, CLI_PrintNone, "CLI welcome message");
cli_add_new_cmd("boottime", sys_uptime, 0, CLI_PrintStartTime, "System BootTime");
cli_add_new_cmd("reboot", reboot_mcu, 0, CLI_PrintNone, "reboot MCU");
#if (DEBUG == 1)
cli_add_new_cmd("loglevel", set_loglevel, 1, CLI_PrintNone, "for set LogLevel output");
#endif
CLI_PRINTF("\r\n");
CLI_State_s.inputArgs.argv = (char **) cli_malloc(sizeof(char *) * CLI_ARGS_BUF_SIZE);
for (uint8_t i = 0; i < CLI_ARGS_BUF_SIZE; i++)
CLI_State_s.inputArgs.argv[i] = cli_malloc(sizeof(char) * (CLI_ARG_SIZE + 1));
cli_log_init();
PRINT_ARROW();
}
/**
* @brief Get index coinciding args string or -1
* @param flag - searched string
* */
int8_t _index_of_flag(const char *flag)
{
for (uint8_t i = 0; i < CLI_State_s.inputArgs.argc; i++) {
if ( _strcmp(CLI_State_s.inputArgs.argv[i], flag)) {
return i;
}
}
return -1;
}
uint8_t _strPartCmp(const char* str1, const char* str2)
{
uint8_t co = 0;
while(((str1 + co) != NULL) && (*(str1 + co) != '\0') &&
((str2 + co) != NULL) && (*(str2 + co) != '\0')){
if (str1[co] != str2[co])
return 0;
co++;
}
return 1;
}
uint16_t _getCountSeparator(const char* strSrc, const char* separator)
{
uint8_t i = 0;
uint16_t result = 0;
uint16_t count_separator = _strlen((char*) separator);
for(; strSrc[i] != '\0'; i++)
{
uint16_t j = 0;
for(; j < count_separator; j++)
if (strSrc[i] == separator[j]){
result++;
break;
}
}
return result + 1;
}
void _arg_destroy(CLI_Params_t* src)
{
src->argc = 0;
}
void _split(char* strSrc, const char* separator, CLI_Params_t* dst)
{
uint8_t count_sep = _getCountSeparator(strSrc, separator);
uint16_t lenSep = _strlen((char*)separator);
dst->argc = count_sep;
int start_index = 0;
int size_word = 0;
int co = 0;
int co_arg = 0;
while(1)
{
uint16_t s = 0;
for(; s < lenSep; s++){
if((strSrc[co] == separator[s]) || (strSrc[co] == '\0'))
{
size_word = co - start_index;
dst->argv[co_arg][size_word] = '\0';
_strcpy(strSrc, start_index, dst->argv[co_arg], 0, size_word);
start_index = co + 1;
co_arg++;
break;
}
}
if (strSrc[co] == '\0')
break;
co++;
}
}
#define CLI_GetDecString(str) ((uint32_t)strtol((const char *)str, NULL, 10))
#define CLI_GetHexString(str) ((uint32_t)strtol((const char *)str, NULL, 16))
#define CLI_GetArgString(str) ((uint32_t)_strcmp((const char *)str, NULL, 16))
inline char* cli_get_arg(uint8_t index)
{
return CLI_State_s.inputArgs.argv[index + 1];
}
/** @brief Get argument in Dec */
inline uint32_t cli_get_arg_dec(uint8_t index)
{
return CLI_GetDecString(CLI_State_s.inputArgs.argv[index + 1]);
}
/** @brief Get argument in Hex */
inline uint32_t cli_get_arg_hex(uint8_t index)
{
return CLI_GetHexString(CLI_State_s.inputArgs.argv[index + 1]);
}
/** @brief Get argument in str */
int cli_get_arg_str(uint8_t index, char *str)
{
return _strcmp(CLI_State_s.inputArgs.argv[index + 1], str);
}
bool cli_get_arg_dec_by_flag(const char *flag, uint32_t *outValue)
{
int8_t w = _index_of_flag(flag);
if ((w > 0) && (w + 1 < CLI_State_s.inputArgs.argc)) {
*outValue = cli_get_arg_dec(w);
return true;
}
return false;
}
bool cli_get_arg_hex_by_flag(const char *flag, uint32_t *outValue)
{
int8_t w = _index_of_flag(flag);
if ((w > 0) && (w + 1 < CLI_State_s.inputArgs.argc)) {
*outValue = cli_get_arg_hex(w);
return true;
}
return false;
}
bool cli_is_arg_flag(const char *flag)
{
return _index_of_flag(flag) >= 0;
}
/**
* @brief Execute command
* @param argv argument strings
* @param argc count argument strings
* @return result execute command
* */
CLI_Result_t _execute_cli_cmd(char **argv, uint8_t argc)
{
if ( argc < 1 )
return CLI_ArgErr;
CLI_Cmd_t *cmd = _find_cli_command(argv[0]);
if ( cmd != NULL) {
if (cmd->argc != 0) {
if ( ((argc - 1) < cmd->argc) || ((argc - 1) != cmd->argc) )
return CLI_ArgErr;
}
CLI_State_s.executeState = 1;
if ( cmd->mode & CLI_PrintStartTime )
_cli_print_time();
uint32_t startMs = CLI_GETMS();
CLI_Result_t result = cmd->fcn(argv, argc);
uint32_t stopMs = CLI_GETMS();
if ( cmd->mode & CLI_PrintStopTime )
_cli_print_time();
if ( cmd->mode & CLI_PrintDiffTime ) {
CLI_Time_t t = cli_time_get_time_ms(stopMs - startMs);
_print_boot_time(&t);
}
CLI_State_s.executeState = 0;
return result;
}
return CLI_NotFound;
}
/**
* @brief Execute command
* @param str command const string include arguments
* @return result execute command
* */
CLI_Result_t ExecuteString(const char *str)
{
_split((char *) str, " ", (CLI_Params_t *) &CLI_State_s.inputArgs);
CLI_Result_t result = _execute_cli_cmd(CLI_State_s.inputArgs.argv, CLI_State_s.inputArgs.argc);
_arg_destroy((CLI_Params_t *) &CLI_State_s.inputArgs);
#if (CLI_PRINT_ERROR_EXEC_EN == 1)
_print_result_exec(result);
#endif
PRINT_ARROW();
return result;
}
/** @brief Execute CLI */
bool cli_loop_service(void)
{
if (CLI_State_s.isEntered == true ) {
ExecuteString((const char *) cli_input_get_buffer(TransitBuffer));
CLI_State_s.isEntered = false;
return true;
}
return false;
}
/**
* @brief Add command
* @param name - input name
* @param fcn - callback function
* @param argc - min count arguments
* @param mode - execute mode
* @param descr - description
* @return result append command
* */
CLI_Add_Result_t cli_add_new_cmd(const char *name, CLI_Result_t (*fcn)(), uint8_t argc, CLI_Type_Mode_Cmd_t mode, const char *descr)
{
if (CLI_State_s.countCommand >= CLI_SIZE_MAX_CMD) {
_print_result_add_cmd(ADD_CMD_MaxCmd);
return ADD_CMD_MaxCmd;
}
if ( fcn == NULL) {
_print_result_add_cmd(ADD_CMD_FcnNull);
return ADD_CMD_FcnNull;
}
if ( _strlen((char *) name) == 0 ) {
_print_result_add_cmd(ADD_CMD_EmptyName);
return ADD_CMD_EmptyName;
}
uint8_t i = 0;
for (; i < CLI_State_s.countCommand; i++)
if ( _strcmp((char *) CLI_State_s.cmds[i].name, (char *) name)) {
_print_result_add_cmd(ADD_CMD_RetryName);
return ADD_CMD_RetryName;
}
uint8_t countCmd = CLI_State_s.countCommand;
CLI_State_s.cmds[countCmd].fcn = fcn;
CLI_State_s.cmds[countCmd].name = name;
CLI_State_s.cmds[countCmd].argc = argc;
CLI_State_s.cmds[countCmd].mode = mode;
CLI_State_s.cmds[countCmd].description = descr;
CLI_State_s.countCommand++;
return ADD_CMD_OK;
}
/**
* @brief Print result execute command
* @param code - result code
* @return none
* */
static void _print_result_exec(uint8_t code)
{
switch (code) {
case CLI_NotFound:
CLI_PRINTF ("\n\rCommand not found");
break;
case CLI_ArgErr:
CLI_PRINTF ("\n\rFault argument");
break;
case CLI_ExecErr:
CLI_PRINTF ("\n\rExecute functions");
break;
case CLI_WorkInt:
CLI_PRINTF ("\n\rCommand abort");
break;
default:
break;
}
}
/**
* @brief Print result add command action
* @param code - result code
* @return none
* */
static void _print_result_add_cmd(uint8_t code)
{
#if (CLI_PRINT_ERROR_ADD_CMD_EN == 1)
switch (code) {
case ADD_CMD_MaxCmd:
CLI_PRINTF ("\n\rAdd cmd err: Memory is full");
break;
case ADD_CMD_FcnNull:
CLI_PRINTF ("\n\rAdd cmd err: Function callback is NULL");
break;
case ADD_CMD_EmptyName:
CLI_PRINTF ("\n\rAdd cmd err: Empty name command");
break;
case ADD_CMD_RetryName:
CLI_PRINTF ("\n\rAdd cmd err: Retry name command");
break;
default:
break;
}
#endif
}
/**
* @brief Search command by name
* @return Command pointer or NULL
* */
CLI_Cmd_t *_find_cli_command(const char *cmdName)
{
uint8_t i = 0;
for (; i < CLI_State_s.countCommand; i++) {
char *name1 = (char *) CLI_State_s.cmds[i].name;
char *name2 = (char *) cmdName;
int res = _strcmp(name1, name2);
if ( res )
return &CLI_State_s.cmds[i];
}
return NULL;
}
/**
* @brief Search command by name
* @return Command pointer or NULL
* */
CLI_Cmd_t *_find_part_term_cmd(const char *cmdName)
{
CLI_Cmd_t *result = NULL;
uint8_t i = 0;
for (; i < CLI_State_s.countCommand; i++) {
char *name1 = (char *) CLI_State_s.cmds[i].name;
char *name2 = (char *) cmdName;
int res = _strPartCmp(name1, name2);
if ( res ) {
if ( result != NULL)
return NULL;
result = &CLI_State_s.cmds[i];
}
}
return result;
}
// ************************************************************************
// ************************* sys cmd CLI *****************************
CLI_Result_t help_cmd()
{
CLI_PRINTF("\r\nCount command: %d", (int) CLI_State_s.countCommand ); // -1 HELP
CLI_PRINTF(SEPARATOR);
for (uint16_t i = 0; i < CLI_State_s.countCommand; i++) {
CLI_PRINTF("\r\n%-10s - %s", CLI_State_s.cmds[i].name, CLI_State_s.cmds[i].description);
CLI_PRINTF(SEPARATOR);
}
return CLI_OK;
}
CLI_Result_t reboot_mcu(void)
{
CLI_PRINTF("\r\nreset MCU\r\n")
HAL_Delay(1000);
HAL_NVIC_SystemReset();
return CLI_OK;
}
CLI_Result_t print_cli_w(void)
{
cli_welcome();
return CLI_OK;
}
__attribute__((unused))
CLI_Result_t set_loglevel(void)
{
uint8_t argv_0;
char *arg = cli_get_arg(0);
if (*arg == 0)
argv_0 = 0xFF;
else
argv_0 = cli_get_arg_dec(0);
switch (argv_0) {
case 1:
ULOG_UNSUBSCRIBE(console_logger);
ULOG_SUBSCRIBE(console_logger, ULOG_CRITICAL_LEVEL);
CLI_PRINTF("\nSET loglevel: NO OUTPUT");
break;
case 2:
ULOG_UNSUBSCRIBE(console_logger);
ULOG_SUBSCRIBE(console_logger, ULOG_ERROR_LEVEL);
CLI_PRINTF("\nSET loglevel: ERROR LEVEL");
break;
case 3:
ULOG_UNSUBSCRIBE(console_logger);
ULOG_SUBSCRIBE(console_logger, ULOG_WARNING_LEVEL);
CLI_PRINTF("\nSET loglevel: WARNING LEVEL");
break;
case 4:
ULOG_UNSUBSCRIBE(console_logger);
ULOG_SUBSCRIBE(console_logger, ULOG_INFO_LEVEL);
CLI_PRINTF("\nSET loglevel: INFO LEVEL");
break;
case 5:
ULOG_UNSUBSCRIBE(console_logger);
ULOG_SUBSCRIBE(console_logger, ULOG_DEBUG_LEVEL);
CLI_PRINTF("\nSET loglevel: DEBUG LEVEL");
break;
case 6:
ULOG_UNSUBSCRIBE(console_logger);
ULOG_SUBSCRIBE(console_logger, ULOG_TRACE_LEVEL);
CLI_PRINTF("\nSET loglevel: TRACE LEVEL");
break;
default: {
CLI_PRINTF("\nloglevel <arg>:\n"
"\t1 - NO OUTPUT\n"
"\t2 - ERROR LEVEL\n"
"\t3 - WARNING LEVEL\n"
"\t4 - INFO LEVEL\n"
"\t5 - DEBUG LEVEL\n"
"\t6 - TRACE_LEVEL\n");
return CLI_ArgErr;
}
}
return CLI_OK;
}
// ************************************************************************
void _print_boot_time(CLI_Time_t *time)
{
CLI_PRINTF("\r\n%02dh:%02dm:%02ds.%03dms", (int) time->hour, (int) time->minute, (int) time->second, (int) time->msec);
}
/**
* @brief CLI Print Time
* @return none
* */
void _cli_print_time()
{
#if (CLI_TIMELEFT_EN == 1)
uint32_t ms = CLI_GETMS();
CLI_Time_t tv = cli_time_get_plus_time_ms(ms);
_print_boot_time(&tv);
#endif
}
void cli_set_first_in_cli(bool set)
{
CLI_State_s.first_in = set;
}
void _clear_screen(void)
{
CLI_PRINTF("\033[2J"); /* Clear the entire screen. */
CLI_PRINTF("\033[0;0f"); /* Move cursor to the top left hand corner */
}
/** @brief Append new symbols */
CLI_Append_Result_t cli_append_char(char ch)
{
static bool rstUnlock = false;
if ( rstUnlock )
rstUnlock = false;
CLI_InputValue_t iv = cli_input_put_char(ch);
char c = iv.keyCode;
if ( iv.isValid ) {
switch (c) {
case CLI_KEY_ENTER: {
if (CLI_State_s.first_in == false ) {
cli_welcome();
CLI_State_s.first_in = true;
}
if ( cli_input_is_empty()) {
PRINT_ARROW();
return CLI_APPEND_Ignore;
}
CLI_State_s.isEntered = true;
cli_input_cache();
cli_log_cmd_push(cli_input_get_buffer(MainBuffer));
cli_log_cur_reset();
cli_input_reset();
return CLI_APPEND_Enter;
}
break;
case CLI_KEY_ESCAPE:
case CHAR_INTERRUPT:
_interrupt_operation = true;
CLI_PRINTF("\r\nINTERRUPT\n");
break;
case CLI_KEY_BACKSPACE:
cli_input_backspace();
break;
case CLI_KEY_TAB: {
if ((!cli_input_is_empty()) && (cli_input_get_last_char() != ' ')) {
char *buf = cli_input_get_buffer(MainBuffer);
CLI_Cmd_t *cmd = _find_part_term_cmd(buf);
if ( cmd != NULL) {
uint8_t len = _strlen(cmd->name);
cli_input_set_buffer(MainBuffer, (char *) cmd->name, len + 1);
cli_input_refresh(strcat(buf, " ")); // todo: need implement light strcat func
}
}
}
break;
case CLI_KEY_DOWN: {
const char *ptrCmd = cli_log_get_next_cmd();
if ( ptrCmd != NULL)
cli_input_refresh(ptrCmd);
}
break;
case CLI_KEY_UP: {
const char *ptrCmd = cli_log_get_last_cmd();
if ( ptrCmd != NULL)
cli_input_refresh(ptrCmd);
}
break;
case CLI_KEY_LEFT:
cli_input_cursor_to_left();
break;
case CLI_KEY_RIGHT:
cli_input_cursor_to_right();
break;
case CLI_KEY_DEL:
cli_input_delete();
break;
case CLI_KEY_HOME:
cli_input_cursor_to_home();
break;
case CLI_KEY_END:
cli_input_cursor_to_end();
break;
case CLI_KEY_CLEAR_SCR:
_clear_screen();
CLI_PRINTF(STRING_TERM_ARROW);
break;
default: {
if ( iv.isAlphaBet && !cli_input_is_full())
cli_input_add_char(c);
}
break;
}
} else {
return CLI_APPEND_BufFull;
}
return CLI_APPEND_OK;
}
void SysTick_CLI(void)
{
_tick++;
}