Commit 6e247767 authored by 尹佳钦's avatar 尹佳钦

去除 json中mac条目的0x

parent 5f1910e5
...@@ -73,7 +73,7 @@ static int send_result(struct jrpc_connection * conn, cJSON * result, ...@@ -73,7 +73,7 @@ static int send_result(struct jrpc_connection * conn, cJSON * result,
} }
static int invoke_procedure(struct jrpc_server *server, static int invoke_procedure(struct jrpc_server *server,
struct jrpc_connection * conn, char *name, cJSON *params, cJSON *id) { struct jrpc_connection * conn, char *name, cJSON *params, cJSON *id,cJSON * mac) {
cJSON *returned = NULL; cJSON *returned = NULL;
int procedure_found = 0; int procedure_found = 0;
jrpc_context ctx; jrpc_context ctx;
...@@ -84,7 +84,7 @@ static int invoke_procedure(struct jrpc_server *server, ...@@ -84,7 +84,7 @@ static int invoke_procedure(struct jrpc_server *server,
if (!strcmp(server->procedures[i].name, name)) { if (!strcmp(server->procedures[i].name, name)) {
procedure_found = 1; procedure_found = 1;
ctx.data = server->procedures[i].data; ctx.data = server->procedures[i].data;
returned = server->procedures[i].function(&ctx, params, id); returned = server->procedures[i].function(&ctx, params, id,mac);
break; break;
} }
} }
...@@ -119,8 +119,9 @@ static int eval_request(struct jrpc_server *server, ...@@ -119,8 +119,9 @@ static int eval_request(struct jrpc_server *server,
rpc_cJSON_CreateNumber(id->valueint); rpc_cJSON_CreateNumber(id->valueint);
if (server->debug_level) if (server->debug_level)
printf("Method Invoked[2]: %s\n", method->valuestring); printf("Method Invoked[2]: %s\n", method->valuestring);
cJSON *mac =NULL;
return invoke_procedure(server, conn, method->valuestring, return invoke_procedure(server, conn, method->valuestring,
params, id_copy); params, id_copy,mac);
} }
} }
} }
......
...@@ -37,7 +37,7 @@ typedef struct { ...@@ -37,7 +37,7 @@ typedef struct {
char * error_message; char * error_message;
} jrpc_context; } jrpc_context;
typedef cJSON* (*jrpc_function)(jrpc_context *context, cJSON *params, cJSON* id); typedef cJSON* (*jrpc_function)(jrpc_context *context, cJSON *params, cJSON* id,cJSON* mac);
struct jrpc_procedure { struct jrpc_procedure {
char * name; char * name;
......
...@@ -73,7 +73,7 @@ bool kk_rpc_report_LightStatus(EmberEUI64 mac,bool LightStatus) ...@@ -73,7 +73,7 @@ bool kk_rpc_report_LightStatus(EmberEUI64 mac,bool LightStatus)
cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id) cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id,cJSON *mac)
{ {
rpc_nwk_info_s info; rpc_nwk_info_s info;
EmberStatus status; EmberStatus status;
...@@ -82,18 +82,17 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id) ...@@ -82,18 +82,17 @@ cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id)
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS); set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return; goto error_return;
}else{ }else{
cJSON *mac_item= rpc_cJSON_GetObjectItem(params, "mac");
cJSON *LightStatus_item = rpc_cJSON_GetObjectItem(params, "LightStatus"); cJSON *LightStatus_item = rpc_cJSON_GetObjectItem(params, "LightStatus");
uint8_t LightStatus = rpc_get_u8(LightStatus_item->valuestring); uint8_t LightStatus = rpc_get_u8(LightStatus_item->valuestring);
uint8_t mac[EUI64_SIZE]; uint8_t eui64[EUI64_SIZE];
bool flag= rpc_get_mac(mac_item->valuestring,mac); bool flag= rpc_get_mac(mac->valuestring,eui64);
emberAfCorePrintBuffer(mac,EUI64_SIZE,true); emberAfCorePrintBuffer(eui64,EUI64_SIZE,true);
for(int i=0;i<EUI64_SIZE;i++){ for(int i=0;i<EUI64_SIZE;i++){
emberAfCorePrintln("i=%d,val=%02x",i,mac[i]); emberAfCorePrintln("i=%d,val=%02x",i,eui64[i]);
} }
EmberNodeId node = emberAfDeviceTableGetNodeIdFromEui64(mac); EmberNodeId node = emberAfDeviceTableGetNodeIdFromEui64(eui64);
if(node==0xffff){ if(node==0xffff){
emberAfCorePrintln("\r\n not find device!\r\n" ); emberAfCorePrintln("\r\n not find device!\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS); set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
......
...@@ -11,9 +11,7 @@ ...@@ -11,9 +11,7 @@
#define KK_REPORT_ATTRIBUTE_METHOD "thing.service.property.report" #define KK_REPORT_ATTRIBUTE_METHOD "thing.service.property.report"
cJSON *rpc_Control(jrpc_context * ctx, cJSON * params, cJSON *id); cJSON *rpc_Control(jrpc_context * ctx, cJSON * params, cJSON *id,cJSON *mac);
......
...@@ -395,7 +395,7 @@ void rpc_printfJSON(char* str,cJSON* item) ...@@ -395,7 +395,7 @@ void rpc_printfJSON(char* str,cJSON* item)
void rpc_eui64ToString(EmberEUI64 eui, char* euiString) void rpc_eui64ToString(EmberEUI64 eui, char* euiString)
{ {
sprintf(euiString, "0x%02X%02X%02X%02X%02X%02X%02X%02X", sprintf(euiString, "%02X%02X%02X%02X%02X%02X%02X%02X",
eui[7], eui[7],
eui[6], eui[6],
eui[5], eui[5],
......
...@@ -90,8 +90,10 @@ static int send_result_resp(cJSON * result, ...@@ -90,8 +90,10 @@ static int send_result_resp(cJSON * result,
cJSON *result_root = rpc_cJSON_CreateObject(); cJSON *result_root = rpc_cJSON_CreateObject();
if (result) if (result)
rpc_cJSON_AddItemToObject(result_root, "code", result); rpc_cJSON_AddItemToObject(result_root, "code", result);
if(id){
printf("id json:\n%s\n",id->valuestring); printf("id json:\n%s\n",id->valuestring);
rpc_cJSON_AddItemToObject(result_root, "msgId", id); rpc_cJSON_AddItemToObject(result_root, "msgId", id);
}
char * str_result = rpc_cJSON_Print(result_root); char * str_result = rpc_cJSON_Print(result_root);
printf("send json:\n%s\n",str_result); printf("send json:\n%s\n",str_result);
...@@ -122,7 +124,7 @@ static int send_error_resp(int code, char* message, ...@@ -122,7 +124,7 @@ static int send_error_resp(int code, char* message,
} }
static int invoke_procedure(struct jrpc_server *server, static int invoke_procedure(struct jrpc_server *server,
char *name, cJSON *params, cJSON *id) { char *name, cJSON *params, cJSON *id,cJSON *mac) {
cJSON *returned = NULL; cJSON *returned = NULL;
int procedure_found = 0; int procedure_found = 0;
jrpc_context ctx; jrpc_context ctx;
...@@ -133,7 +135,7 @@ static int invoke_procedure(struct jrpc_server *server, ...@@ -133,7 +135,7 @@ static int invoke_procedure(struct jrpc_server *server,
if (!strcmp(server->procedures[i].name, name)) { if (!strcmp(server->procedures[i].name, name)) {
procedure_found = 1; procedure_found = 1;
ctx.data = server->procedures[i].data; ctx.data = server->procedures[i].data;
returned = server->procedures[i].function(&ctx, params, id); returned = server->procedures[i].function(&ctx, params, id,mac);
break; break;
} }
} }
...@@ -149,7 +151,7 @@ static int invoke_procedure(struct jrpc_server *server, ...@@ -149,7 +151,7 @@ static int invoke_procedure(struct jrpc_server *server,
} }
static int eval_request(struct jrpc_server *server, cJSON *root) { static int eval_request(struct jrpc_server *server, cJSON *root) {
cJSON *method, *params, *id; cJSON *method, *params, *id,*mac;
method = rpc_cJSON_GetObjectItem(root, "method"); method = rpc_cJSON_GetObjectItem(root, "method");
if (method != NULL && method->type == cJSON_String) { if (method != NULL && method->type == cJSON_String) {
params = rpc_cJSON_GetObjectItem(root, "params"); params = rpc_cJSON_GetObjectItem(root, "params");
...@@ -158,6 +160,8 @@ static int eval_request(struct jrpc_server *server, cJSON *root) { ...@@ -158,6 +160,8 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
id = rpc_cJSON_GetObjectItem(root, "msgId"); id = rpc_cJSON_GetObjectItem(root, "msgId");
if (id == NULL|| id->type == cJSON_String if (id == NULL|| id->type == cJSON_String
|| id->type == cJSON_Number) { || id->type == cJSON_Number) {
mac = rpc_cJSON_GetObjectItem(root, "mac");
if(mac->type = cJSON_String){
//We have to copy ID because using it on the reply and deleting the response Object will also delete ID //We have to copy ID because using it on the reply and deleting the response Object will also delete ID
cJSON * id_copy = NULL; cJSON * id_copy = NULL;
if (id != NULL) if (id != NULL)
...@@ -168,7 +172,8 @@ static int eval_request(struct jrpc_server *server, cJSON *root) { ...@@ -168,7 +172,8 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
if (server->debug_level) if (server->debug_level)
printf("Method Invoked[2]: %s\n", method->valuestring); printf("Method Invoked[2]: %s\n", method->valuestring);
return invoke_procedure(server, method->valuestring, return invoke_procedure(server, method->valuestring,
params, id_copy); params, id_copy,mac);
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment