MT7687 API Reference  LinkIt SDK v4
cli.h
1 /* Copyright Statement:
2  *
3  * (C) 2005-2016 MediaTek Inc. All rights reserved.
4  *
5  * This software/firmware and related documentation ("MediaTek Software") are
6  * protected under relevant copyright laws. The information contained herein
7  * is confidential and proprietary to MediaTek Inc. ("MediaTek") and/or its licensors.
8  * Without the prior written permission of MediaTek and/or its licensors,
9  * any reproduction, modification, use or disclosure of MediaTek Software,
10  * and information contained herein, in whole or in part, shall be strictly prohibited.
11  * You may only use, reproduce, modify, or distribute (as applicable) MediaTek Software
12  * if you have agreed to and been bound by the applicable license agreement with
13  * MediaTek ("License Agreement") and been granted explicit permission to do so within
14  * the License Agreement ("Permitted User"). If you are not a Permitted User,
15  * please cease any access or use of MediaTek Software immediately.
16  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
17  * THAT MEDIATEK SOFTWARE RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES
18  * ARE PROVIDED TO RECEIVER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
19  * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
21  * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
22  * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
23  * SUPPLIED WITH MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
24  * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
25  * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
26  * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
27  * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
28  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
29  * CUMULATIVE LIABILITY WITH RESPECT TO MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
30  * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE MEDIATEK SOFTWARE AT ISSUE,
31  * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
32  * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
33  */
34 
35 #ifndef __CLI_H__
36 #define __CLI_H__
37 
38 #include <stdint.h>
39 
40 #include "putter.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
200 /****************************************************************************
201  *
202  * Constants.
203  *
204  ****************************************************************************/
205 
218 #define CLI_MAX_TOKENS (20)
219 
224 /****************************************************************************
225  *
226  * Types.
227  *
228  ****************************************************************************/
229 
246 typedef int (*getchar_fptr_t)(void);
247 
248 
259 typedef int (*putchar_fptr_t)(int);
260 
261 
268 typedef uint8_t (*knock_fptr_t)(char *id, char *pass);
269 
270 
280 typedef uint8_t (*cli_cmd_handler_t)(uint8_t len, char *param[]);
281 
286 /*****************************************************************************
287 * Structures
288 *****************************************************************************/
289 
299 typedef struct cmd_s cmd_t;
300 
301 
312 struct cmd_s {
313  char *cmd;
314  char *help;
317 };
318 
319 
320 #if !defined(CLI_DISABLE_LINE_EDIT) && !defined(CLI_DISABLE_HISTORY)
321 
327 
335  char **history;
336  char *input;
337  char *parse_token;
340  uint16_t history_max;
341  uint16_t line_max;
342  uint16_t index;
344  uint16_t position;
346  uint8_t full;
348 };
349 #endif /* !CLI_DISABLE_LINE_EDIT && !CLI_DISABLE_HISTORY */
350 
351 
357 typedef struct cli_s cli_t;
358 
365 struct cli_s {
366  uint8_t state;
368  char echo;
372  char *tok[CLI_MAX_TOKENS];
374 #if !defined(CLI_DISABLE_LINE_EDIT) && !defined(CLI_DISABLE_HISTORY)
376 #endif /* !CLI_DISABLE_LINE_EDIT && !CLI_DISABLE_HISTORY */
377 };
378 
382 /****************************************************************************
383  *
384  * Function prototypes.
385  *
386  ****************************************************************************/
387 
388 
404 void cli_init(cli_t *cli);
405 
406 
413 void cli_line(char *line);
414 
415 
423 void cli_tokens(uint8_t argc, char *argv[]);
424 
425 
433 void cli_task(void);
434 
435 
443 uint8_t cli_logout(uint8_t len, char *param[]);
444 
445 
454 uint8_t cli_hardcode_login(char *id, char *password);
455 
456 
460 #ifdef __cplusplus
461 }
462 #endif
463 
464 #endif /* __CLI_H__ */
465 
uint16_t line_max
The size of one history line.
Definition: cli.h:341
uint8_t state
Defines the login status.
Definition: cli.h:366
char ** history
The pointers to history_max lines of buffer for input.
Definition: cli.h:335
knock_fptr_t knock
An authentication function pointer.
Definition: cli.h:371
uint8_t(* cli_cmd_handler_t)(uint8_t len, char *param[])
Function pointer type of CLI command handlers.
Definition: cli.h:280
The MiniCLI control block definition.
Definition: cli.h:334
char * cmd
Command string.
Definition: cli.h:313
The MiniCLI control block definition.
Definition: cli.h:365
void cli_task(void)
The top-level function of the actual CLI.
cli_history_t history
The command history record.
Definition: cli.h:375
cmd_t * sub
Sub-commands.
Definition: cli.h:316
int(* getchar_fptr_t)(void)
A function pointer prototype to get a characeter from an input source.
Definition: cli.h:246
cmd_t * cmd
A pointer to the CLI commands.
Definition: cli.h:367
uint8_t cli_logout(uint8_t len, char *param[])
This function implements the logout function.
uint16_t index
When the user types a command and presses enter, index is the index that will be saved in...
Definition: cli.h:342
#define CLI_MAX_TOKENS
Controls the number of tokens to parse in a single command.
Definition: cli.h:218
uint8_t full
Represents whether the number of history commands exceeded history_max if it is 0, history commands are not full, otherwise the commands are full.
Definition: cli.h:346
uint16_t position
When the user presses up/down, position is the history index displayed on the terminal.
Definition: cli.h:344
putchar_fptr_t put
A function pointer to write a characeter to output sink.
Definition: cli.h:370
char echo
Determines if user input should be printed on the screen or not.
Definition: cli.h:368
uint16_t history_max
The maximum number of the lines in history.
Definition: cli.h:340
int(* putchar_fptr_t)(int)
A function pointer prototype to write a character to the output.
Definition: cli.h:259
void cli_init(cli_t *cli)
MiniCLI initialization.
void cli_tokens(uint8_t argc, char *argv[])
Process a tokenized command in array of string pointers format.
void cli_line(char *line)
Process one line of command in plain text format.
cli_cmd_handler_t fptr
The function pointer to call when an input string matches with the command in MiniCLI engine...
Definition: cli.h:315
char * input
used to save the current input before pressing "up" the first time
Definition: cli.h:336
uint8_t(* knock_fptr_t)(char *id, char *pass)
This is the callback function to authenticate the user, if login is enabled and the credentials are n...
Definition: cli.h:268
The MiniCLI command declaration structure.
Definition: cli.h:312
char * parse_token
In cli.c, _cli_do_cmd() will result in the history command to be parsed into tokens, an additional array is required as an input to the #_cli_do_cmd() function to preserve the command history.
Definition: cli.h:337
uint8_t cli_hardcode_login(char *id, char *password)
A sample login function implementation.
char * help
Type &#39;?&#39; to retrieve help message.
Definition: cli.h:314