Files

62 lines
2.0 KiB
C

/*
* Author: Chandra Mohan C (willvalab@gmail.com)
* All rights reserved.
*
* Use of this source code is governed by a MIT-style license that can be found
* in the LICENSE file.
*
**-----------------------------------------------*/
#ifndef UARTSH_H
#define UARTSH_H
#include <stdint.h>
/*-----------------------------------------------*/
typedef int (*UartshCommandHandler)(void* cust, int argc, char* argv[]);
typedef void * (*sh_cust_com_open)(uint8_t argc, char* configbuf);
typedef int32_t (*sh_cust_com_write)(void *handler, unsigned char *buf, uint32_t len, uint32_t timeout_ms);
typedef int32_t (*sh_cust_com_read)(void *handler, unsigned char *buf, uint32_t len, uint32_t timeout_ms);
typedef int (*sh_cust_com_close)(void *handler);
#define UARTSH_INCLUDE_CMD(handler) extern int handler(void* cust, int argc, char* argv[])
#define UARTSH_REGISTER_CMD( _name, _handler) { _name, (UartshCommandHandler)_handler }
typedef struct sh_cust_type_struct
{
char *name;
void *cmd_list;
char run_flag;
char timeout_enable;
uint64_t time_out_uptime;
uint32_t time_out;
void *thread;
void *handler;
uint8_t port;
char *configbuf;
sh_cust_com_open open_func;
sh_cust_com_write write_func;
sh_cust_com_read read_func;
sh_cust_com_close close_func;
} sh_cust_type_t;
typedef struct UartshCommand
{
char const* name;
UartshCommandHandler handler;
} UartshCommand;
/*-----------------------------------------------*/
int uartsh_printf(sh_cust_type_t *cust_sh, const char *fmt, ...);
unsigned int uartsh_gets(sh_cust_type_t *cust_sh, char** input);
void uartsh_puts(sh_cust_type_t *cust_sh, char const* s);
int uartshTokenize(char commandString[], char const tokens[], int argcMax, char* argv[]);
UartshCommandHandler uartshGetHandler(UartshCommand cmdlist[], char command[]);
int uartshInit(sh_cust_type_t *cust_sh);
int uartshExit(sh_cust_type_t *cust_sh);
int uartshRunning(sh_cust_type_t *cust_sh);
/*-----------------------------------------------*/
#endif /* UARTSH_H */