mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-11 04:28:14 +08:00
fix:优化定时任务值逻辑
fix:优化获取idx数据处理返回内容 fix:按键返回数据逻辑 del:删除多余的调试信息
This commit is contained in:
@@ -54,7 +54,7 @@ void appRestoreDefault_callback( void * const user_config_data, uint32_t size )
|
||||
{
|
||||
userConfigDefault->plug[i].task[j].hour = 0;
|
||||
userConfigDefault->plug[i].task[j].minute = 0;
|
||||
userConfigDefault->plug[i].task[j].repeat = 0x80;
|
||||
userConfigDefault->plug[i].task[j].repeat = 0x00;
|
||||
userConfigDefault->plug[i].task[j].on = 0;
|
||||
userConfigDefault->plug[i].task[j].action = 1;
|
||||
}
|
||||
|
||||
@@ -83,6 +83,16 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata )
|
||||
cJSON *json_send = cJSON_CreateObject( );
|
||||
cJSON_AddNumberToObject( json_send, "idx", user_config->plug[i].idx );
|
||||
cJSON_AddNumberToObject( json_send, "nvalue", user_config->plug[i].on );
|
||||
cJSON_AddStringToObject( json_send, "mac", strMac );
|
||||
|
||||
char strTemp1[] = "plug_X";
|
||||
strTemp1[5] = i + '0';
|
||||
cJSON *json_send_plug_on = cJSON_CreateObject( );
|
||||
cJSON_AddNumberToObject( json_send_plug_on, "on", p_nvalue->valueint );
|
||||
|
||||
cJSON_AddItemToObject( json_send, strTemp1, json_send_plug_on );
|
||||
|
||||
|
||||
char *json_str = cJSON_Print( json_send );
|
||||
user_send( udp_flag, json_str ); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
free( json_str );
|
||||
@@ -111,7 +121,7 @@ void user_function_cmd_received( int udp_flag, uint8_t *pusrdata )
|
||||
{
|
||||
uint32_t now_time = UpTicks( );
|
||||
os_log( "system_get_time:%d,%d = %09d\r\n", last_time, now_time, (now_time - last_time) );
|
||||
if ( now_time - last_time < 1000 && p_idx )
|
||||
if ( now_time - last_time < 1000 && p_idx )
|
||||
{
|
||||
return_flag = false;
|
||||
} else
|
||||
|
||||
@@ -98,21 +98,20 @@ static void key_short_press( void )
|
||||
user_relay_set_all( 1 );
|
||||
}
|
||||
|
||||
if ( user_config->idx >= 0 )
|
||||
uint8_t * buf = NULL; //[64] = { 0 };
|
||||
buf = malloc( 64 );
|
||||
if ( buf != NULL )
|
||||
{
|
||||
uint8_t * buf = NULL; //[64] = { 0 };
|
||||
buf = malloc( 64 );
|
||||
if ( buf != NULL )
|
||||
{
|
||||
|
||||
if ( user_config->idx >= 0 )
|
||||
sprintf( buf, "{\"idx\" : %d,\"mac\" : \"%s\",\"nvalue\" : %d}", user_config->idx, strMac, relay_out( ) );
|
||||
os_log("send %s", buf);
|
||||
if ( !user_mqtt_isconnect( ) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
user_udp_send( buf );
|
||||
else
|
||||
user_mqtt_send( buf );
|
||||
free( buf );
|
||||
}
|
||||
else
|
||||
sprintf( buf, "{\"mac\" : \"%s\",\"nvalue\" : %d}", strMac, relay_out( ) );
|
||||
os_log("send %s", buf);
|
||||
if ( !user_mqtt_isconnect( ) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
user_udp_send( buf );
|
||||
else
|
||||
user_mqtt_send( buf );
|
||||
free( buf );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -156,7 +155,7 @@ static void key_timeout_handler( void* arg )
|
||||
else if ( key_time == 103 )
|
||||
{
|
||||
user_led_set( 0 );
|
||||
key_time=101;
|
||||
key_time = 101;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +167,7 @@ static void key_timeout_handler( void* arg )
|
||||
key_time = 0;
|
||||
os_log("button short pressed:%d",key_time);
|
||||
key_short_press( );
|
||||
} else if(key_time > 100)
|
||||
} else if ( key_time > 100 )
|
||||
{
|
||||
MicoSystemReboot( );
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ void mqtt_client_thread( mico_thread_arg_t arg )
|
||||
|
||||
require_noerr_string( err, MQTT_reconnect, "ERROR: MQTT publish data err" );
|
||||
|
||||
mqtt_log("MQTT publish data success! send_topic=[%s], msg=[%ld][%s].\r\n", p_send_msg->topic, p_send_msg->datalen, p_send_msg->data);
|
||||
mqtt_log("MQTT publish data success! send_topic=[%s], msg=[%ld].\r\n", p_send_msg->topic, p_send_msg->datalen);
|
||||
no_mqtt_msg_exchange = false;
|
||||
free( p_send_msg );
|
||||
p_send_msg = NULL;
|
||||
|
||||
@@ -161,11 +161,11 @@ void rtc_thread( mico_thread_arg_t arg )
|
||||
if ( //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>̵<EFBFBD><CCB5><EFBFBD>״̬: <20><>Ϊ0 ʱ<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>趨ֵ, <20>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>趨ֵ
|
||||
rtc_time.sec == 0 && rtc_time.min == user_config->plug[i].task[j].minute
|
||||
&& rtc_time.hr == user_config->plug[i].task[j].hour
|
||||
&& ((repeat == 0x80) || repeat & (1 << (rtc_time.weekday - 1)))
|
||||
&& ((repeat == 0x00) || repeat & (1 << (rtc_time.weekday - 1)))
|
||||
)
|
||||
{
|
||||
user_relay_set( i, user_config->plug[i].task[j].action );
|
||||
if ( repeat == 0x80 )
|
||||
if ( repeat == 0x00 )
|
||||
{
|
||||
user_config->plug[i].task[j].on = 0;
|
||||
update_user_config_flag = 1;
|
||||
|
||||
@@ -89,7 +89,7 @@ void udp_thread( void *arg )
|
||||
|
||||
strcpy( ip_address, inet_ntoa( addr.sin_addr ) );
|
||||
if(len<1024) buf[len]=0;
|
||||
os_log( "udp recv from %s:%d, len:%d :%s", ip_address,addr.sin_port, len ,buf);
|
||||
os_log( "udp recv from %s:%d, len:%d ", ip_address,addr.sin_port, len );
|
||||
user_function_cmd_received(1,buf);
|
||||
// sendto( udp_fd, buf, len, 0, (struct sockaddr *) &addr, sizeof(struct sockaddr_in) );
|
||||
}
|
||||
@@ -107,7 +107,7 @@ void udp_thread( void *arg )
|
||||
err = udp_msg_send( udp_fd, p_send_msg->data, p_send_msg->datalen );
|
||||
// require_noerr_string( err, MQTT_reconnect, "ERROR: udp publish data err" );
|
||||
|
||||
os_log( "udp send data success! msg=[%ld][%s].\r\n", p_send_msg->datalen, p_send_msg->data );
|
||||
os_log( "udp send data success! msg=[%ld].\r\n", p_send_msg->datalen);
|
||||
free( p_send_msg );
|
||||
p_send_msg = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user