From 8b3cb142d82e95f249e41e90dafec04ad50bb6ee Mon Sep 17 00:00:00 2001 From: Zip <76966589@qq.com> Date: Tue, 29 Jan 2019 13:50:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96log=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/main.c | 29 +++++++++++++++-------------- TC1/user_function.c | 39 +++++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/TC1/main.c b/TC1/main.c index 877cef1..d525efd 100644 --- a/TC1/main.c +++ b/TC1/main.c @@ -51,20 +51,6 @@ int application_start( void ) err = mico_system_init( sys_config ); require_noerr( err, exit ); - os_log( "idx:%d",user_config->idx ); - for ( i = 0; i < PLUG_NUM; i++ ) - { - os_log("plug_%d:",i); - os_log("\tname:%s:",user_config->plug[i].name); - os_log("\tidx:%d:",user_config->plug[i].idx); - for ( j = 0; j < PLUG_TIME_TASK_NUM; j++ ) - { - os_log("\t\ton:%d\t %02d:%02d repeat:0x%X",user_config->plug[i].task[j].on, - user_config->plug[i].task[j].hour,user_config->plug[i].task[j].minute, - user_config->plug[i].task[j].repeat); - } - } - for ( i = 0; i < Relay_NUM; i++ ) { MicoGpioInitialize( Relay[i], OUTPUT_PUSH_PULL ); @@ -87,6 +73,21 @@ int application_start( void ) err = mico_system_context_restore( sys_config ); require_noerr( err, exit ); } + os_log( "idx:%d",user_config->idx ); + for ( i = 0; i < PLUG_NUM; i++ ) + { + os_log("plug_%d:",i); + os_log("\tname:%s:",user_config->plug[i].name); + os_log("\tidx:%d:",user_config->plug[i].idx); + for ( j = 0; j < PLUG_TIME_TASK_NUM; j++ ) + { + os_log("\t\ton:%d\t %02d:%02d repeat:0x%X",user_config->plug[i].task[j].on, + user_config->plug[i].task[j].hour,user_config->plug[i].task[j].minute, + user_config->plug[i].task[j].repeat); + } + } + + wifi_init( ); key_init( ); diff --git a/TC1/user_function.c b/TC1/user_function.c index 348aed4..571f156 100644 --- a/TC1/user_function.c +++ b/TC1/user_function.c @@ -1,4 +1,4 @@ -#define os_log(format, ...) custom_log("KEY", format, ##__VA_ARGS__) +#define os_log(format, ...) custom_log("FUNCTION", format, ##__VA_ARGS__) #include "main.h" #include "user_key.h" @@ -14,7 +14,7 @@ typedef struct _user_json_context_t void user_function_cmd_received( uint8_t *pusrdata ) { - + OSStatus err = kNoErr; char *out; cJSON * pJsonRoot = cJSON_Parse( pusrdata ); if ( !pJsonRoot ) @@ -27,16 +27,39 @@ void user_function_cmd_received( uint8_t *pusrdata ) 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) //idx - || (p_description && cJSON_IsString( p_description ) && strcmp( p_description->valuestring, "123" ) == 0) //description mqttid - || (p_name && cJSON_IsString( p_name ) && strcmp( p_name->valuestring, sys_config->micoSystemConfig.name ) == 0) //name - ) + if ( p_idx && cJSON_IsNumber( p_idx ) && p_idx->valueint == 2 ) //idx { cJSON *p_nvalue = cJSON_GetObjectItem( pJsonRoot, "nvalue" ); - if ( p_nvalue ) led( p_nvalue->valueint ); + if ( p_nvalue ) + { + led( p_nvalue->valueint ); + + user_config->idx++; + sys_config->micoSystemConfig.name[0]++; + err=mico_system_context_update( sys_config ); + os_log("err:%d[%d]",err,kNoErr); + } + } + else if ( p_idx && cJSON_IsNumber( p_idx ) && p_idx->valueint == 3 ) //idx + { + + + os_log("val:%d",user_config->idx); + os_log("name:%s",sys_config->micoSystemConfig.name); + os_log("seed:%d",sys_config->micoSystemConfig.seed); } + /* + if ( + (p_idx && cJSON_IsNumber( p_idx ) && p_idx->valueint == 2) //idx + || (p_description && cJSON_IsString( p_description ) && strcmp( p_description->valuestring, "123" ) == 0) //description mqttid + || (p_name && cJSON_IsString( p_name ) && strcmp( p_name->valuestring, sys_config->micoSystemConfig.name ) == 0) //name + ) + { + cJSON *p_nvalue = cJSON_GetObjectItem( pJsonRoot, "nvalue" ); + if ( p_nvalue ) led( p_nvalue->valueint ); + } + */ cJSON_Delete( pJsonRoot ); free( out );