mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 04:58:17 +08:00
重命名time_tasks
This commit is contained in:
16
TC1/main.c
16
TC1/main.c
@@ -55,13 +55,13 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
|
|||||||
userConfigDefault->socket[i].name[7] = 0;
|
userConfigDefault->socket[i].name[7] = 0;
|
||||||
//sprintf(userConfigDefault->socket[i].name, "插座%d", i);//编码异常
|
//sprintf(userConfigDefault->socket[i].name, "插座%d", i);//编码异常
|
||||||
|
|
||||||
for (j = 0; j < SOCKET_TIME_TASK_NUM; j++)
|
for (j = 0; j < 5; j++)
|
||||||
{
|
{
|
||||||
userConfigDefault->socket[i].task[j].hour = 0;
|
userConfigDefault->socket[i].time_tasks[j].hour = 0;
|
||||||
userConfigDefault->socket[i].task[j].minute = 0;
|
userConfigDefault->socket[i].time_tasks[j].minute = 0;
|
||||||
userConfigDefault->socket[i].task[j].repeat = 0x00;
|
userConfigDefault->socket[i].time_tasks[j].repeat = 0x00;
|
||||||
userConfigDefault->socket[i].task[j].on = 0;
|
userConfigDefault->socket[i].time_tasks[j].on = 0;
|
||||||
userConfigDefault->socket[i].task[j].action = 1;
|
userConfigDefault->socket[i].time_tasks[j].action = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//mico_system_context_update(sys_config);
|
//mico_system_context_update(sys_config);
|
||||||
@@ -107,8 +107,8 @@ int application_start(void)
|
|||||||
MicoSysLed(0);
|
MicoSysLed(0);
|
||||||
|
|
||||||
if (user_config->version != USER_CONFIG_VERSION
|
if (user_config->version != USER_CONFIG_VERSION
|
||||||
|| user_config->socket[0].task[0].hour < 0
|
|| user_config->socket[0].time_tasks[0].hour < 0
|
||||||
|| user_config->socket[0].task[0].hour > 23)
|
|| user_config->socket[0].time_tasks[0].hour > 23)
|
||||||
{
|
{
|
||||||
os_log("WARNGIN: user params restored!");
|
os_log("WARNGIN: user params restored!");
|
||||||
err = mico_system_context_restore(sys_config);
|
err = mico_system_context_restore(sys_config);
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#define SOCKET_NAME_LENGTH 32
|
#define SOCKET_NAME_LENGTH 32
|
||||||
#define SOCKET_NUM 6 //插座数量
|
#define SOCKET_NUM 6 //插座数量
|
||||||
#define SOCKET_TIME_TASK_NUM 5 //每个插座最多5组定时任务
|
|
||||||
|
|
||||||
#define Led MICO_GPIO_5
|
#define Led MICO_GPIO_5
|
||||||
#define Button MICO_GPIO_23
|
#define Button MICO_GPIO_23
|
||||||
@@ -46,7 +45,7 @@ typedef struct
|
|||||||
{
|
{
|
||||||
char name[SOCKET_NAME_LENGTH];
|
char name[SOCKET_NAME_LENGTH];
|
||||||
char on; //记录当前开关
|
char on; //记录当前开关
|
||||||
user_socket_task_config_t task[SOCKET_TIME_TASK_NUM];
|
user_socket_task_config_t time_tasks[5];
|
||||||
} user_socket_config_t;
|
} user_socket_config_t;
|
||||||
|
|
||||||
//用户保存参数结构体
|
//用户保存参数结构体
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ bool json_socket_analysis(int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSO
|
|||||||
}
|
}
|
||||||
|
|
||||||
//解析socket中setting中task----------------------------------------
|
//解析socket中setting中task----------------------------------------
|
||||||
for (i = 0; i < SOCKET_TIME_TASK_NUM; i++)
|
for (i = 0; i < 5; i++)
|
||||||
{
|
{
|
||||||
if (json_socket_task_analysis(x, i, p_socket_setting, json_socket_setting_send))
|
if (json_socket_task_analysis(x, i, p_socket_setting, json_socket_setting_send))
|
||||||
return_flag = true;
|
return_flag = true;
|
||||||
@@ -308,19 +308,19 @@ bool json_socket_task_analysis(unsigned char x, unsigned char y, cJSON * pJsonRo
|
|||||||
&& cJSON_IsNumber(p_socket_task_on))
|
&& cJSON_IsNumber(p_socket_task_on))
|
||||||
{
|
{
|
||||||
return_flag = true;
|
return_flag = true;
|
||||||
user_config->socket[x].task[y].hour = p_socket_task_hour->valueint;
|
user_config->socket[x].time_tasks[y].hour = p_socket_task_hour->valueint;
|
||||||
user_config->socket[x].task[y].minute = p_socket_task_minute->valueint;
|
user_config->socket[x].time_tasks[y].minute = p_socket_task_minute->valueint;
|
||||||
user_config->socket[x].task[y].repeat = p_socket_task_repeat->valueint;
|
user_config->socket[x].time_tasks[y].repeat = p_socket_task_repeat->valueint;
|
||||||
user_config->socket[x].task[y].action = p_socket_task_action->valueint;
|
user_config->socket[x].time_tasks[y].action = p_socket_task_action->valueint;
|
||||||
user_config->socket[x].task[y].on = p_socket_task_on->valueint;
|
user_config->socket[x].time_tasks[y].on = p_socket_task_on->valueint;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
cJSON_AddNumberToObject(json_socket_task_send, "hour", user_config->socket[x].task[y].hour);
|
cJSON_AddNumberToObject(json_socket_task_send, "hour", user_config->socket[x].time_tasks[y].hour);
|
||||||
cJSON_AddNumberToObject(json_socket_task_send, "minute", user_config->socket[x].task[y].minute);
|
cJSON_AddNumberToObject(json_socket_task_send, "minute", user_config->socket[x].time_tasks[y].minute);
|
||||||
cJSON_AddNumberToObject(json_socket_task_send, "repeat", user_config->socket[x].task[y].repeat);
|
cJSON_AddNumberToObject(json_socket_task_send, "repeat", user_config->socket[x].time_tasks[y].repeat);
|
||||||
cJSON_AddNumberToObject(json_socket_task_send, "action", user_config->socket[x].task[y].action);
|
cJSON_AddNumberToObject(json_socket_task_send, "action", user_config->socket[x].time_tasks[y].action);
|
||||||
cJSON_AddNumberToObject(json_socket_task_send, "on", user_config->socket[x].task[y].on);
|
cJSON_AddNumberToObject(json_socket_task_send, "on", user_config->socket[x].time_tasks[y].on);
|
||||||
|
|
||||||
cJSON_AddItemToObject(pJsonSend, socket_task_str, json_socket_task_send);
|
cJSON_AddItemToObject(pJsonSend, socket_task_str, json_socket_task_send);
|
||||||
return return_flag;
|
return return_flag;
|
||||||
|
|||||||
@@ -68,23 +68,6 @@ OSStatus user_rtc_init(void)
|
|||||||
{
|
{
|
||||||
OSStatus err = kNoErr;
|
OSStatus err = kNoErr;
|
||||||
|
|
||||||
// mico_rtc_time_t rtc_time;
|
|
||||||
// rtc_time.sec = 0;
|
|
||||||
// rtc_time.min = 0;
|
|
||||||
// rtc_time.hr = 0;
|
|
||||||
//
|
|
||||||
// rtc_time.date = 1;
|
|
||||||
// rtc_time.weekday = 1;
|
|
||||||
// rtc_time.month = 1;
|
|
||||||
// rtc_time.year = 1;
|
|
||||||
//
|
|
||||||
// MicoRtcSetTime(&rtc_time);
|
|
||||||
|
|
||||||
// /* create mqtt msg send queue */
|
|
||||||
// err = mico_rtos_init_queue(&mqtt_msg_send_queue, "mqtt_msg_send_queue", sizeof(p_mqtt_send_msg_t),
|
|
||||||
// MAX_MQTT_SEND_QUEUE_SIZE);
|
|
||||||
// require_noerr_action(err, exit, app_log("ERROR: create mqtt msg send queue err=%d.", err));
|
|
||||||
|
|
||||||
/* start rtc client */
|
/* start rtc client */
|
||||||
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "rtc",
|
err = mico_rtos_create_thread(NULL, MICO_APPLICATION_PRIORITY, "rtc",
|
||||||
(mico_thread_function_t) rtc_thread,
|
(mico_thread_function_t) rtc_thread,
|
||||||
@@ -154,28 +137,28 @@ void rtc_thread(mico_thread_arg_t arg)
|
|||||||
char update_user_config_flag = 0;
|
char update_user_config_flag = 0;
|
||||||
for (i = 0; i < SOCKET_NUM; i++)
|
for (i = 0; i < SOCKET_NUM; i++)
|
||||||
{
|
{
|
||||||
for (j = 0; j < SOCKET_TIME_TASK_NUM; j++)
|
for (j = 0; j < 5; j++)
|
||||||
{
|
{
|
||||||
if (user_config->socket[i].task[j].on != 0)
|
if (user_config->socket[i].time_tasks[j].on != 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
char repeat = user_config->socket[i].task[j].repeat;
|
char repeat = user_config->socket[i].time_tasks[j].repeat;
|
||||||
if ( //符合条件则改变继电器状态: 秒为0 时分符合设定值, 重复符合设定值
|
if ( //符合条件则改变继电器状态: 秒为0 时分符合设定值, 重复符合设定值
|
||||||
rtc_time.sec == 0 && rtc_time.min == user_config->socket[i].task[j].minute
|
rtc_time.sec == 0 && rtc_time.min == user_config->socket[i].time_tasks[j].minute
|
||||||
&& rtc_time.hr == user_config->socket[i].task[j].hour
|
&& rtc_time.hr == user_config->socket[i].time_tasks[j].hour
|
||||||
&& ((repeat == 0x00) || repeat & (1 << (rtc_time.weekday - 1)))
|
&& ((repeat == 0x00) || repeat & (1 << (rtc_time.weekday - 1)))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (user_config->socket[i].on != user_config->socket[i].task[j].action)
|
if (user_config->socket[i].on != user_config->socket[i].time_tasks[j].action)
|
||||||
{
|
{
|
||||||
UserRelaySet(i, user_config->socket[i].task[j].action);
|
UserRelaySet(i, user_config->socket[i].time_tasks[j].action);
|
||||||
update_user_config_flag = 1;
|
update_user_config_flag = 1;
|
||||||
user_mqtt_send_socket_state(i);
|
user_mqtt_send_socket_state(i);
|
||||||
}
|
}
|
||||||
if (repeat == 0x00)
|
if (repeat == 0x00)
|
||||||
{
|
{
|
||||||
task_flag[i] = j;
|
task_flag[i] = j;
|
||||||
user_config->socket[i].task[j].on = 0;
|
user_config->socket[i].time_tasks[j].on = 0;
|
||||||
update_user_config_flag = 1;
|
update_user_config_flag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,11 +191,11 @@ void rtc_thread(mico_thread_arg_t arg)
|
|||||||
char strTemp2[] = "task_X";
|
char strTemp2[] = "task_X";
|
||||||
strTemp2[5] = j + '0';
|
strTemp2[5] = j + '0';
|
||||||
cJSON *json_send_socket_task = cJSON_CreateObject();
|
cJSON *json_send_socket_task = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(json_send_socket_task, "hour", user_config->socket[i].task[j].hour);
|
cJSON_AddNumberToObject(json_send_socket_task, "hour", user_config->socket[i].time_tasks[j].hour);
|
||||||
cJSON_AddNumberToObject(json_send_socket_task, "minute", user_config->socket[i].task[j].minute);
|
cJSON_AddNumberToObject(json_send_socket_task, "minute", user_config->socket[i].time_tasks[j].minute);
|
||||||
cJSON_AddNumberToObject(json_send_socket_task, "repeat", user_config->socket[i].task[j].repeat);
|
cJSON_AddNumberToObject(json_send_socket_task, "repeat", user_config->socket[i].time_tasks[j].repeat);
|
||||||
cJSON_AddNumberToObject(json_send_socket_task, "action", user_config->socket[i].task[j].action);
|
cJSON_AddNumberToObject(json_send_socket_task, "action", user_config->socket[i].time_tasks[j].action);
|
||||||
cJSON_AddNumberToObject(json_send_socket_task, "on", user_config->socket[i].task[j].on);
|
cJSON_AddNumberToObject(json_send_socket_task, "on", user_config->socket[i].time_tasks[j].on);
|
||||||
cJSON_AddItemToObject(json_send_socket_setting, strTemp2, json_send_socket_task);
|
cJSON_AddItemToObject(json_send_socket_setting, strTemp2, json_send_socket_task);
|
||||||
|
|
||||||
cJSON_AddItemToObject(json_send_socket, "setting", json_send_socket_setting);
|
cJSON_AddItemToObject(json_send_socket, "setting", json_send_socket_setting);
|
||||||
|
|||||||
Reference in New Issue
Block a user