1. Add cleanup register configure function

2. Add run system command and get return value function
This commit is contained in:
HuangXin 2019-01-16 17:24:33 +08:00
parent 17dcce230c
commit b139124166
1 changed files with 53 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "protocol.h" #include "protocol.h"
#include "hal_mtk.h" #include "hal_mtk.h"
@ -19,6 +20,14 @@ static char* g_pIoTId = NULL;
if(val) src = strdup(val); \ if(val) src = strdup(val); \
} while (0) } while (0)
int hal_cleanup_device_register_info(void)
{
if(is_file_exists(CFG_SAVE_PATH))
{
unlink(CFG_SAVE_PATH);
}
}
int hal_save_device_register_info(unsigned char* pRegInfo, int iSize) int hal_save_device_register_info(unsigned char* pRegInfo, int iSize)
{ {
FILE* fp = fopen(CFG_SAVE_PATH, "w"); FILE* fp = fopen(CFG_SAVE_PATH, "w");
@ -145,9 +154,10 @@ int hal_device_name_to_id(void)
#define MQTT_BROADCAST_MAX_GROUP 90 #define MQTT_BROADCAST_MAX_GROUP 90
if(g_pDeviceName) if(g_pDeviceName)
{ {
int i;
int val = 0; int val = 0;
int len = strlen(g_pDeviceName); int len = strlen(g_pDeviceName);
for(int i = 0; i < len; i++) for(i = 0; i < len; i++)
{ {
val += g_pDeviceName[i]; val += g_pDeviceName[i];
} }
@ -184,6 +194,48 @@ int hal_init(void)
return 0; return 0;
} }
int hal_get_exec_message_v2(const char *pCmd, UT_string **pResult)
{
FILE *pFile = NULL;
unsigned int uRdSize = 0;
UT_string *pCmdOut;
char readBuf[256];
*pResult = NULL;
if(pCmd == NULL || strlen(pCmd) == 0)
{
return (-ERR_INPUT_PARAMS);
}
pFile = popen(pCmd, "r");
if(pFile == NULL)
{
return (-ERR_OPEN_FILE);
}
utstring_new(*pResult);
pCmdOut = *pResult;
do
{
uRdSize = fread(readBuf, sizeof(char), 256, pFile);
if(uRdSize > 0)
{
utstring_bincpy(pCmdOut, readBuf, uRdSize);
}
} while(uRdSize);
pclose(pFile);
fprintf(stdout, "%s --> [%s](%u)\n", pCmd, utstring_body(pCmdOut), utstring_len(pCmdOut));
return (0);
}
int hal_get_exec_message(const char *pCmd, char **pResult) int hal_get_exec_message(const char *pCmd, char **pResult)
{ {
FILE *pFile = NULL; FILE *pFile = NULL;