diff --git a/src/Framework/json_utils/json_struct.c b/src/Framework/json_utils/json_struct.c index 032face..f6c94b0 100644 --- a/src/Framework/json_utils/json_struct.c +++ b/src/Framework/json_utils/json_struct.c @@ -169,7 +169,7 @@ static const char* __shadow2Json(void* pData) return pJsonS; } -static void* json2RegDev(const char* pJsonS) +static void* __json2RegDev(const char* pJsonS) { PREGIST_DEVICE pInfo = NULL; cJSON *pItem = NULL; @@ -210,6 +210,7 @@ static void* json2RegDev(const char* pJsonS) return pInfo; } +#if 0 static void* __json2ProRsp(const char* pJsonS) { PPRO_RESPONSE pRsp = NULL; @@ -450,18 +451,68 @@ static void* __json2ProGetDevList(const char* pJsonS) cJSON_Delete(pRoot); return pRsp; } +#endif +static void* __json2RouterCmd(const char* pJsonS) +{ + PROUTER_CMD pInfo = NULL; + cJSON *pRoot = cJSON_Parse(pJsonS); + + if(pRoot == NULL) + { + LOG_EX(LOG_Error, "Json Format Error: [%s]\n", pJsonS); + return NULL; + } + + pInfo = (PROUTER_CMD)malloc(sizeof(ROUTER_CMD)); + + if(pInfo == NULL) + { + LOG_EX(LOG_Error, "Malloc BYPASS_INFO Error\n"); + cJSON_Delete(pRoot); + return NULL; + } + + pInfo->cmd = __jsonSafeDecodeStr(pRoot, "cmd"); + pInfo->data = __jsonSafeDecodeStr(pRoot, "data"); + + cJSON_Delete(pRoot); + return pInfo; +} + +static const char* __routerRsp2Json(void* pData) +{ + PROUTER_RSP pInfo = (PROUTER_RSP)pData; + const char* pJsonS; + + s2j_create_json_obj(jObject); + + if(pInfo->data) + { + s2j_json_set_basic_element(jObject, pInfo, string, data); + } + + pJsonS = cJSON_Print(jObject); + + cJSON_Delete(jObject); + + return pJsonS; +} static JSON_ENGINE g_jSonEngine[] = { {JE_PROMAIN, __pro2Json, __json2pro, NULL}, {JE_BYPASS, __bypass2Json, __json2bypass, NULL}, {JE_SHADOWUP, __shadow2Json, NULL, NULL}, - {JE_REGDEVICE, NULL, json2RegDev, NULL}, + {JE_REGDEVICE, NULL, __json2RegDev, NULL}, + {JE_ROUTERCMD, NULL, __json2RouterCmd, NULL}, + {JE_ROUTERRSP, __routerRsp2Json, NULL, NULL}, +#if 0 {JE_PRO_GETVERSION, NULL, __json2ProGetVer, NULL}, {JE_PRO_ADMINLOGON, __logon2Json, __json2Prologon, NULL}, {JE_PRO_GETSPEED, NULL, __json2ProGetSpeed, NULL}, {JE_PRO_GETDEVLIST, NULL, __json2ProGetDevList, NULL}, +#endif // {, , , NULL}, }; @@ -539,3 +590,16 @@ const char* Struct2Json(void* pStruct, JSON_ENGINE_TYPE type, int cryptoType, in return NULL; } } + +int json_is_valid(char* pJsonS) +{ + cJSON *pRoot = cJSON_Parse(pJsonS); + + if(pRoot == NULL) + { + return FALSE; + } + + cJSON_Delete(pRoot); + return TRUE; +} diff --git a/src/include/hal_mtk.h b/src/include/hal_mtk.h index efd7fb3..9f81140 100644 --- a/src/include/hal_mtk.h +++ b/src/include/hal_mtk.h @@ -1,6 +1,8 @@ #ifndef HAL_MTK_H #define HAL_MTK_H +#include + #ifdef __cplusplus extern "C" { #endif @@ -24,11 +26,14 @@ const char* hal_get_device_name(void); int hal_device_name_to_id(void); const char* hal_get_device_secret(void); int hal_save_device_register_info(unsigned char* pRegInfo, int iSize); +int hal_cleanup_device_register_info(void); int hal_get_regist_info(const char* pMsg); int hal_init(void); int hal_is_device_registed(void); int hal_get_exec_message(const char *pCmd, char **pResult); +int hal_get_exec_message_v2(const char *pCmd, UT_string **pResult); + #ifdef __cplusplus } #endif diff --git a/src/include/mqtt.h b/src/include/mqtt.h index 38d4280..1fa99b2 100644 --- a/src/include/mqtt.h +++ b/src/include/mqtt.h @@ -7,6 +7,7 @@ extern "C" { void mqtt_proxy_setup(void); int mqtt_publish_shadow_msg(unsigned char* pData, int msgSize); +int mqtt_publish_rrpc_msg(char* pTopic, unsigned char* pData, int msgSize); #ifdef __cplusplus }