146 lines
3.8 KiB
C
146 lines
3.8 KiB
C
/*
|
|
* uartshCommands.c
|
|
*
|
|
* Created on: Feb 2, 2019
|
|
* Author: cm943953
|
|
*/
|
|
/*-----------------------------------------------*/
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <stddef.h>
|
|
#include <stdarg.h>
|
|
#include <stdint.h>
|
|
|
|
#include "uartsh.h"
|
|
#include "hal_api.h"
|
|
#include "app_inc.h"
|
|
#include "ql_uart.h"
|
|
|
|
/*-----------------------------------------------*/
|
|
|
|
sh_cust_type_t cust_uartsh;
|
|
int g_testmode = 0;
|
|
extern int8 output_uuid[];
|
|
|
|
UARTSH_INCLUDE_CMD(uartshCommand_reboot);
|
|
UARTSH_INCLUDE_CMD(uartshCommand_get);
|
|
UARTSH_INCLUDE_CMD(uartshCommand_set);
|
|
UARTSH_INCLUDE_CMD(uartshCommand_time);
|
|
UARTSH_INCLUDE_CMD(uartshCommand_testmode);
|
|
/*-----------------------------------------------*/
|
|
|
|
// ------------- register user commands
|
|
UartshCommand gcUartshCommands[] = {
|
|
UARTSH_REGISTER_CMD("reboot", uartshCommand_reboot),
|
|
UARTSH_REGISTER_CMD("get", uartshCommand_get),
|
|
UARTSH_REGISTER_CMD("set", uartshCommand_set),
|
|
UARTSH_REGISTER_CMD("time", uartshCommand_time),
|
|
UARTSH_REGISTER_CMD("testmode", uartshCommand_testmode),
|
|
// last must end with null
|
|
UARTSH_REGISTER_CMD(NULL, NULL),
|
|
};
|
|
/*-----------------------------------------------*/
|
|
|
|
|
|
int app_uartsh_init()
|
|
{
|
|
cust_uartsh.name = "uartsh";
|
|
cust_uartsh.cmd_list = gcUartshCommands;
|
|
cust_uartsh.port = 1; //
|
|
cust_uartsh.configbuf="115200,8,n,1";
|
|
cust_uartsh.open_func = hal_dev_uart_open;
|
|
cust_uartsh.write_func = hal_dev_uart_write;
|
|
cust_uartsh.read_func = hal_dev_uart_read;
|
|
cust_uartsh.close_func = hal_dev_uart_close;
|
|
cust_uartsh.run_flag = -1;
|
|
cust_uartsh.timeout_enable = 1;
|
|
return uartshInit(&cust_uartsh);
|
|
}
|
|
|
|
|
|
int app_uartsh_running()
|
|
{
|
|
return uartshRunning(&cust_uartsh);
|
|
}
|
|
|
|
int uartshCommand_reboot(void *cust, int argc, char* argv[])
|
|
{
|
|
hal_os_reboot(0);
|
|
return 0;
|
|
}
|
|
|
|
int uartshCommand_get(void *cust, int argc, char* argv[])
|
|
{
|
|
char tempbuf[128]={0};
|
|
#if 0
|
|
memset(tempbuf,0,sizeof(tempbuf));
|
|
hal_os_get_localtime(tempbuf);
|
|
uartsh_printf(cust, "NOW TIME:%04d-%02d-%02d %02d:%02d:%02d\n",tempbuf[0]+2000,tempbuf[1],tempbuf[2],tempbuf[3],tempbuf[4],tempbuf[5]);
|
|
memset(tempbuf,0,sizeof(tempbuf));
|
|
hal_os_get_boottime(tempbuf);
|
|
uartsh_printf(cust, "BOOT TIME:%04d-%02d-%02d %02d:%02d:%02d\n",tempbuf[0]+2000,tempbuf[1],tempbuf[2],tempbuf[3],tempbuf[4],tempbuf[5]);
|
|
memset(tempbuf,0,sizeof(tempbuf));
|
|
hal_os_get_build_time(tempbuf);
|
|
uartsh_printf(cust, "BUILD TIME:%s\n",tempbuf);
|
|
memset(tempbuf,0,sizeof(tempbuf));
|
|
hal_os_get_build_ver(tempbuf);
|
|
uartsh_printf(cust, "VERSION:%s\n",tempbuf);
|
|
#endif
|
|
memset(tempbuf,0,sizeof(tempbuf));
|
|
hal_os_get_device_id(tempbuf);
|
|
uartsh_printf(cust, "DID:%s\n",tempbuf);
|
|
|
|
memset(tempbuf,0,sizeof(tempbuf));
|
|
hal_os_get_device_sn(tempbuf);
|
|
uartsh_printf(cust, "DSN:%s\n",tempbuf);
|
|
|
|
memset(tempbuf,0,sizeof(tempbuf));
|
|
uartsh_printf(cust,"UUID:%s\n",output_uuid);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int uartshCommand_set(void *cust, int argc, char* argv[])
|
|
{
|
|
if(argc<3){
|
|
uartsh_printf(cust, "param error\r\n");
|
|
return -1;
|
|
}
|
|
if(!strcmp("id",argv[1])){
|
|
return hal_os_set_device_id(argv[2]);
|
|
}
|
|
|
|
if(!strcmp("sn",argv[1])){
|
|
return hal_os_set_device_sn(argv[2]);
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
int uartshCommand_time(void *cust, int argc, char* argv[])
|
|
{
|
|
int time;
|
|
char tempbuf[32]={0};
|
|
|
|
if(argc<2){
|
|
//uartsh_printf(cust,"%lld\n",hal_os_timestamp_ms());
|
|
memset(tempbuf,0,sizeof(tempbuf));
|
|
hal_os_get_localtime(tempbuf);
|
|
uartsh_printf(cust, "%04d-%02d-%02d %02d:%02d:%02d\n",tempbuf[0]+2000,tempbuf[1],tempbuf[2],tempbuf[3],tempbuf[4],tempbuf[5]);
|
|
return 0;
|
|
}else if(argc==3 && !strcmp(argv[1],"set"))
|
|
{
|
|
time = (int)strtoul(argv[2], NULL, 0);
|
|
uartsh_printf(cust,"set %d\n",time);
|
|
return hal_os_set_time_sec(time);
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int uartshCommand_testmode(void *cust, int argc, char* argv[])
|
|
{
|
|
g_testmode = 1;
|
|
return 0;
|
|
} |