mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 21:48:25 +08:00
add:json解析
This commit is contained in:
43
TC1/user_function.c
Normal file
43
TC1/user_function.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#define os_log(format, ...) custom_log("KEY", format, ##__VA_ARGS__)
|
||||
|
||||
#include "main.h"
|
||||
#include "user_key.h"
|
||||
#include "cJSON.h"
|
||||
|
||||
typedef struct _user_json_context_t
|
||||
{
|
||||
int8_t idx;
|
||||
char name[maxNameLen];
|
||||
|
||||
int8_t val;
|
||||
} user_json_context_t;
|
||||
|
||||
void user_function_cmd_received( uint8_t *pusrdata )
|
||||
{
|
||||
|
||||
char *out;
|
||||
cJSON * pJsonRoot = cJSON_Parse( pusrdata );
|
||||
if ( !pJsonRoot )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>idx<64>ֶ<EFBFBD>int<6E><74><EFBFBD><EFBFBD> description<6F>ֶ<EFBFBD>string<6E><67><EFBFBD><EFBFBD> name<6D>ֶ<EFBFBD>string<6E><67><EFBFBD><EFBFBD>
|
||||
cJSON *p_idx = cJSON_GetObjectItem( pJsonRoot, "idx" );
|
||||
cJSON *p_description = cJSON_GetObjectItem( pJsonRoot, "description" );
|
||||
cJSON *p_name = cJSON_GetObjectItem( pJsonRoot, "name" );
|
||||
|
||||
if (
|
||||
(p_idx && cJSON_IsNumber( p_idx ) && p_idx->valueint == 2)
|
||||
|| (p_description && cJSON_IsString( p_description ) && strcmp( p_description->valuestring, "123" ) == 0)
|
||||
|| (p_name && cJSON_IsString( p_name ) && strcmp( p_name->valuestring, sys_config->micoSystemConfig.name ) == 0)
|
||||
)
|
||||
{
|
||||
cJSON *p_nvalue = cJSON_GetObjectItem( pJsonRoot, "nvalue" );
|
||||
if ( p_nvalue ) led( p_nvalue->valueint );
|
||||
}
|
||||
|
||||
cJSON_Delete( pJsonRoot );
|
||||
free( out );
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user