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,
}
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;
int procedure_found = 0;
jrpc_context ctx;
......@@ -84,7 +84,7 @@ static int invoke_procedure(struct jrpc_server *server,
if (!strcmp(server->procedures[i].name, name)) {
procedure_found = 1;
ctx.data = server->procedures[i].data;
returned = server->procedures[i].function(&ctx, params, id);
returned = server->procedures[i].function(&ctx, params, id,mac);
break;
}
}
......@@ -119,8 +119,9 @@ static int eval_request(struct jrpc_server *server,
rpc_cJSON_CreateNumber(id->valueint);
if (server->debug_level)
printf("Method Invoked[2]: %s\n", method->valuestring);
cJSON *mac =NULL;
return invoke_procedure(server, conn, method->valuestring,
params, id_copy);
params, id_copy,mac);
}
}
}
......
......@@ -37,7 +37,7 @@ typedef struct {
char * error_message;
} 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 {
char * name;
......
......@@ -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;
EmberStatus status;
......@@ -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);
goto error_return;
}else{
cJSON *mac_item= rpc_cJSON_GetObjectItem(params, "mac");
cJSON *LightStatus_item = rpc_cJSON_GetObjectItem(params, "LightStatus");
uint8_t LightStatus = rpc_get_u8(LightStatus_item->valuestring);
uint8_t mac[EUI64_SIZE];
bool flag= rpc_get_mac(mac_item->valuestring,mac);
emberAfCorePrintBuffer(mac,EUI64_SIZE,true);
uint8_t eui64[EUI64_SIZE];
bool flag= rpc_get_mac(mac->valuestring,eui64);
emberAfCorePrintBuffer(eui64,EUI64_SIZE,true);
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){
emberAfCorePrintln("\r\n not find device!\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
......
......@@ -11,9 +11,7 @@
#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)
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[6],
eui[5],
......
......@@ -90,8 +90,10 @@ static int send_result_resp(cJSON * result,
cJSON *result_root = rpc_cJSON_CreateObject();
if (result)
rpc_cJSON_AddItemToObject(result_root, "code", result);
if(id){
printf("id json:\n%s\n",id->valuestring);
rpc_cJSON_AddItemToObject(result_root, "msgId", id);
}
char * str_result = rpc_cJSON_Print(result_root);
printf("send json:\n%s\n",str_result);
......@@ -122,7 +124,7 @@ static int send_error_resp(int code, char* message,
}
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;
int procedure_found = 0;
jrpc_context ctx;
......@@ -133,7 +135,7 @@ static int invoke_procedure(struct jrpc_server *server,
if (!strcmp(server->procedures[i].name, name)) {
procedure_found = 1;
ctx.data = server->procedures[i].data;
returned = server->procedures[i].function(&ctx, params, id);
returned = server->procedures[i].function(&ctx, params, id,mac);
break;
}
}
......@@ -149,7 +151,7 @@ static int invoke_procedure(struct jrpc_server *server,
}
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");
if (method != NULL && method->type == cJSON_String) {
params = rpc_cJSON_GetObjectItem(root, "params");
......@@ -158,6 +160,8 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
id = rpc_cJSON_GetObjectItem(root, "msgId");
if (id == NULL|| id->type == cJSON_String
|| 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
cJSON * id_copy = NULL;
if (id != NULL)
......@@ -168,7 +172,8 @@ static int eval_request(struct jrpc_server *server, cJSON *root) {
if (server->debug_level)
printf("Method Invoked[2]: %s\n", 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