mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 04:58:17 +08:00
去除旧的定时任务
This commit is contained in:
15
TC1/main.c
15
TC1/main.c
@@ -40,7 +40,7 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
|
||||
userConfigDefault->mqtt_password[0] = 0;
|
||||
userConfigDefault->version = USER_CONFIG_VERSION;
|
||||
|
||||
int i, j;
|
||||
int i;
|
||||
for (i = 0; i < SOCKET_NUM; i++)
|
||||
{
|
||||
userConfigDefault->socket_configs[i].on = 1;
|
||||
@@ -54,15 +54,6 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
|
||||
userConfigDefault->socket_configs[i].name[6] = i + '1';
|
||||
userConfigDefault->socket_configs[i].name[7] = 0;
|
||||
//sprintf(userConfigDefault->socket[i].name, "插座%d", i);//编码异常
|
||||
|
||||
for (j = 0; j < 5; j++)
|
||||
{
|
||||
userConfigDefault->socket_configs[i].time_tasks[j].hour = 0;
|
||||
userConfigDefault->socket_configs[i].time_tasks[j].minute = 0;
|
||||
userConfigDefault->socket_configs[i].time_tasks[j].repeat = 0x00;
|
||||
userConfigDefault->socket_configs[i].time_tasks[j].on = 0;
|
||||
userConfigDefault->socket_configs[i].time_tasks[j].action = 1;
|
||||
}
|
||||
}
|
||||
//mico_system_context_update(sys_config);
|
||||
}
|
||||
@@ -106,9 +97,7 @@ int application_start(void)
|
||||
}
|
||||
MicoSysLed(0);
|
||||
|
||||
if (user_config->version != USER_CONFIG_VERSION
|
||||
|| user_config->socket_configs[0].time_tasks[0].hour < 0
|
||||
|| user_config->socket_configs[0].time_tasks[0].hour > 23)
|
||||
if (user_config->version != USER_CONFIG_VERSION)
|
||||
{
|
||||
os_log("WARNGIN: user params restored!");
|
||||
err = mico_system_context_restore(sys_config);
|
||||
|
||||
10
TC1/main.h
10
TC1/main.h
@@ -32,20 +32,10 @@
|
||||
#define Relay_5 MICO_GPIO_18
|
||||
#define Relay_NUM SOCKET_NUM
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char hour; //小时
|
||||
char minute; //分钟
|
||||
char repeat; //bit7:一次 bit6-0:周日-周一
|
||||
char action; //动作
|
||||
char on; //开关
|
||||
} user_socket_task_config_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[SOCKET_NAME_LENGTH];
|
||||
char on; //记录当前开关
|
||||
user_socket_task_config_t time_tasks[5];
|
||||
} user_socket_config_t;
|
||||
|
||||
//用户保存参数结构体
|
||||
|
||||
@@ -18,7 +18,6 @@ void user_function_set_last_time()
|
||||
}
|
||||
|
||||
bool json_socket_analysis(int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSON * pJsonSend);
|
||||
bool json_socket_task_analysis(unsigned char x, unsigned char y, cJSON * pJsonRoot, cJSON * pJsonSend);
|
||||
|
||||
void user_send(int udp_flag, char *s)
|
||||
{
|
||||
@@ -215,7 +214,6 @@ bool json_socket_analysis(int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSO
|
||||
{
|
||||
if (!pJsonRoot) return false;
|
||||
if (!pJsonSend) return false;
|
||||
char i;
|
||||
bool return_flag = false;
|
||||
char socket_str[] = "socket_X";
|
||||
socket_str[5] = x + '0';
|
||||
@@ -257,13 +255,6 @@ bool json_socket_analysis(int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSO
|
||||
cJSON_AddStringToObject(json_socket_setting_send, "name", user_config->socket_configs[x].name);
|
||||
}
|
||||
|
||||
//解析socket中setting中task----------------------------------------
|
||||
for (i = 0; i < 5; i++)
|
||||
{
|
||||
if (json_socket_task_analysis(x, i, p_socket_setting, json_socket_setting_send))
|
||||
return_flag = true;
|
||||
}
|
||||
|
||||
cJSON_AddItemToObject(json_socket_send, "setting", json_socket_setting_send);
|
||||
}
|
||||
}
|
||||
@@ -273,59 +264,6 @@ bool json_socket_analysis(int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSO
|
||||
return return_flag;
|
||||
}
|
||||
|
||||
/*
|
||||
*解析处理定时任务json
|
||||
*x:插座编号 y:任务编号
|
||||
*/
|
||||
bool json_socket_task_analysis(unsigned char x, unsigned char y, cJSON * pJsonRoot, cJSON * pJsonSend)
|
||||
{
|
||||
if (!pJsonRoot) return false;
|
||||
bool return_flag = false;
|
||||
|
||||
char socket_task_str[] = "task_X";
|
||||
socket_task_str[5] = y + '0';
|
||||
|
||||
cJSON *p_socket_task = cJSON_GetObjectItem(pJsonRoot, socket_task_str);
|
||||
if (!p_socket_task) return false;
|
||||
|
||||
cJSON *json_socket_task_send = cJSON_CreateObject();
|
||||
|
||||
cJSON *p_socket_task_hour = cJSON_GetObjectItem(p_socket_task, "hour");
|
||||
cJSON *p_socket_task_minute = cJSON_GetObjectItem(p_socket_task, "minute");
|
||||
cJSON *p_socket_task_repeat = cJSON_GetObjectItem(p_socket_task, "repeat");
|
||||
cJSON *p_socket_task_action = cJSON_GetObjectItem(p_socket_task, "action");
|
||||
cJSON *p_socket_task_on = cJSON_GetObjectItem(p_socket_task, "on");
|
||||
|
||||
if (p_socket_task_hour && p_socket_task_minute && p_socket_task_repeat &&
|
||||
p_socket_task_action
|
||||
&& p_socket_task_on)
|
||||
{
|
||||
|
||||
if (cJSON_IsNumber(p_socket_task_hour)
|
||||
&& cJSON_IsNumber(p_socket_task_minute)
|
||||
&& cJSON_IsNumber(p_socket_task_repeat)
|
||||
&& cJSON_IsNumber(p_socket_task_action)
|
||||
&& cJSON_IsNumber(p_socket_task_on))
|
||||
{
|
||||
return_flag = true;
|
||||
user_config->socket_configs[x].time_tasks[y].hour = p_socket_task_hour->valueint;
|
||||
user_config->socket_configs[x].time_tasks[y].minute = p_socket_task_minute->valueint;
|
||||
user_config->socket_configs[x].time_tasks[y].repeat = p_socket_task_repeat->valueint;
|
||||
user_config->socket_configs[x].time_tasks[y].action = p_socket_task_action->valueint;
|
||||
user_config->socket_configs[x].time_tasks[y].on = p_socket_task_on->valueint;
|
||||
}
|
||||
|
||||
}
|
||||
cJSON_AddNumberToObject(json_socket_task_send, "hour", user_config->socket_configs[x].time_tasks[y].hour);
|
||||
cJSON_AddNumberToObject(json_socket_task_send, "minute", user_config->socket_configs[x].time_tasks[y].minute);
|
||||
cJSON_AddNumberToObject(json_socket_task_send, "repeat", user_config->socket_configs[x].time_tasks[y].repeat);
|
||||
cJSON_AddNumberToObject(json_socket_task_send, "action", user_config->socket_configs[x].time_tasks[y].action);
|
||||
cJSON_AddNumberToObject(json_socket_task_send, "on", user_config->socket_configs[x].time_tasks[y].on);
|
||||
|
||||
cJSON_AddItemToObject(pJsonSend, socket_task_str, json_socket_task_send);
|
||||
return return_flag;
|
||||
}
|
||||
|
||||
unsigned char strtohex(char a, char b)
|
||||
{
|
||||
if (a >= 0x30 && a <= 0x39)
|
||||
|
||||
@@ -82,13 +82,10 @@ OSStatus user_rtc_init(void)
|
||||
|
||||
void rtc_thread(mico_thread_arg_t arg)
|
||||
{
|
||||
int i, j;
|
||||
char task_flag[SOCKET_NUM] = { -1, -1, -1, -1, -1, -1 }; //记录每个插座哪个任务需要返回数据
|
||||
OSStatus err = kUnknownErr;
|
||||
LinkStatusTypeDef LinkStatus;
|
||||
mico_rtc_time_t rtc_time;
|
||||
|
||||
|
||||
mico_utc_time_t utc_time;
|
||||
mico_utc_time_t utc_time_last = 0;
|
||||
while (1)
|
||||
@@ -104,7 +101,6 @@ void rtc_thread(mico_thread_arg_t arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mico_rtos_thread_sleep(3);
|
||||
}
|
||||
|
||||
@@ -131,88 +127,6 @@ void rtc_thread(mico_thread_arg_t arg)
|
||||
|
||||
// MicoRtcSetTime(&rtc_time); //MicoRtc不自动走时!
|
||||
|
||||
//if (rtc_time.sec == 0)
|
||||
//os_log("time1:20%02d/%02d/%02d %d %02d:%02d:%02d",rtc_time.year,rtc_time.month,rtc_time.date,rtc_time.weekday,rtc_time.hr,rtc_time.min,rtc_time.sec);
|
||||
|
||||
char update_user_config_flag = 0;
|
||||
for (i = 0; i < SOCKET_NUM; i++)
|
||||
{
|
||||
for (j = 0; j < 5; j++)
|
||||
{
|
||||
if (user_config->socket_configs[i].time_tasks[j].on != 0)
|
||||
{
|
||||
|
||||
char repeat = user_config->socket_configs[i].time_tasks[j].repeat;
|
||||
if ( //符合条件则改变继电器状态: 秒为0 时分符合设定值, 重复符合设定值
|
||||
rtc_time.sec == 0 && rtc_time.min == user_config->socket_configs[i].time_tasks[j].minute
|
||||
&& rtc_time.hr == user_config->socket_configs[i].time_tasks[j].hour
|
||||
&& ((repeat == 0x00) || repeat & (1 << (rtc_time.weekday - 1)))
|
||||
)
|
||||
{
|
||||
if (user_config->socket_configs[i].on != user_config->socket_configs[i].time_tasks[j].action)
|
||||
{
|
||||
UserRelaySet(i, user_config->socket_configs[i].time_tasks[j].action);
|
||||
update_user_config_flag = 1;
|
||||
user_mqtt_send_socket_state(i);
|
||||
}
|
||||
if (repeat == 0x00)
|
||||
{
|
||||
task_flag[i] = j;
|
||||
user_config->socket_configs[i].time_tasks[j].on = 0;
|
||||
update_user_config_flag = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//更新储存数据 更新定时任务数据
|
||||
if (update_user_config_flag == 1)
|
||||
{
|
||||
os_log("update_user_config_flag");
|
||||
mico_system_context_update(sys_config);
|
||||
update_user_config_flag = 0;
|
||||
|
||||
cJSON *json_send = cJSON_CreateObject();
|
||||
cJSON_AddStringToObject(json_send, "mac", strMac);
|
||||
|
||||
for (i = 0; i < SOCKET_NUM; i++)
|
||||
{
|
||||
char strTemp1[] = "socket_X";
|
||||
strTemp1[5] = i + '0';
|
||||
cJSON *json_send_socket = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(json_send_socket, "on", user_config->socket_configs[i].on);
|
||||
|
||||
if (task_flag[i] >= 0)
|
||||
{
|
||||
cJSON *json_send_socket_setting = cJSON_CreateObject();
|
||||
|
||||
j = task_flag[i];
|
||||
char strTemp2[] = "task_X";
|
||||
strTemp2[5] = j + '0';
|
||||
cJSON *json_send_socket_task = cJSON_CreateObject();
|
||||
cJSON_AddNumberToObject(json_send_socket_task, "hour", user_config->socket_configs[i].time_tasks[j].hour);
|
||||
cJSON_AddNumberToObject(json_send_socket_task, "minute", user_config->socket_configs[i].time_tasks[j].minute);
|
||||
cJSON_AddNumberToObject(json_send_socket_task, "repeat", user_config->socket_configs[i].time_tasks[j].repeat);
|
||||
cJSON_AddNumberToObject(json_send_socket_task, "action", user_config->socket_configs[i].time_tasks[j].action);
|
||||
cJSON_AddNumberToObject(json_send_socket_task, "on", user_config->socket_configs[i].time_tasks[j].on);
|
||||
cJSON_AddItemToObject(json_send_socket_setting, strTemp2, json_send_socket_task);
|
||||
|
||||
cJSON_AddItemToObject(json_send_socket, "setting", json_send_socket_setting);
|
||||
|
||||
task_flag[i] = -1;
|
||||
}
|
||||
cJSON_AddItemToObject(json_send, strTemp1, json_send_socket);
|
||||
}
|
||||
|
||||
char *json_str = cJSON_Print(json_send);
|
||||
user_send(false, json_str); //发送数据
|
||||
|
||||
free(json_str);
|
||||
cJSON_Delete(json_send);
|
||||
// os_log("cJSON_Delete");
|
||||
}
|
||||
|
||||
//SNTP服务 开机及每小时校准一次
|
||||
if (rtc_init != 1 || (rtc_time.sec == 0 && rtc_time.min == 0))
|
||||
{
|
||||
@@ -227,8 +141,6 @@ void rtc_thread(mico_thread_arg_t arg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
mico_rtos_thread_msleep(900);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user