mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 21:18:13 +08:00
重命名socket_configs
This commit is contained in:
34
TC1/main.c
34
TC1/main.c
@@ -43,25 +43,25 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
|
|||||||
int i, j;
|
int i, j;
|
||||||
for (i = 0; i < SOCKET_NUM; i++)
|
for (i = 0; i < SOCKET_NUM; i++)
|
||||||
{
|
{
|
||||||
userConfigDefault->socket[i].on = 1;
|
userConfigDefault->socket_configs[i].on = 1;
|
||||||
//插座名称 插口1-6
|
//插座名称 插口1-6
|
||||||
userConfigDefault->socket[i].name[0] = 0xe6;
|
userConfigDefault->socket_configs[i].name[0] = 0xe6;
|
||||||
userConfigDefault->socket[i].name[1] = 0x8f;
|
userConfigDefault->socket_configs[i].name[1] = 0x8f;
|
||||||
userConfigDefault->socket[i].name[2] = 0x92;
|
userConfigDefault->socket_configs[i].name[2] = 0x92;
|
||||||
userConfigDefault->socket[i].name[3] = 0xe5;
|
userConfigDefault->socket_configs[i].name[3] = 0xe5;
|
||||||
userConfigDefault->socket[i].name[4] = 0x8f;
|
userConfigDefault->socket_configs[i].name[4] = 0x8f;
|
||||||
userConfigDefault->socket[i].name[5] = 0xa3;
|
userConfigDefault->socket_configs[i].name[5] = 0xa3;
|
||||||
userConfigDefault->socket[i].name[6] = i + '1';
|
userConfigDefault->socket_configs[i].name[6] = i + '1';
|
||||||
userConfigDefault->socket[i].name[7] = 0;
|
userConfigDefault->socket_configs[i].name[7] = 0;
|
||||||
//sprintf(userConfigDefault->socket[i].name, "插座%d", i);//编码异常
|
//sprintf(userConfigDefault->socket[i].name, "插座%d", i);//编码异常
|
||||||
|
|
||||||
for (j = 0; j < 5; j++)
|
for (j = 0; j < 5; j++)
|
||||||
{
|
{
|
||||||
userConfigDefault->socket[i].time_tasks[j].hour = 0;
|
userConfigDefault->socket_configs[i].time_tasks[j].hour = 0;
|
||||||
userConfigDefault->socket[i].time_tasks[j].minute = 0;
|
userConfigDefault->socket_configs[i].time_tasks[j].minute = 0;
|
||||||
userConfigDefault->socket[i].time_tasks[j].repeat = 0x00;
|
userConfigDefault->socket_configs[i].time_tasks[j].repeat = 0x00;
|
||||||
userConfigDefault->socket[i].time_tasks[j].on = 0;
|
userConfigDefault->socket_configs[i].time_tasks[j].on = 0;
|
||||||
userConfigDefault->socket[i].time_tasks[j].action = 1;
|
userConfigDefault->socket_configs[i].time_tasks[j].action = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//mico_system_context_update(sys_config);
|
//mico_system_context_update(sys_config);
|
||||||
@@ -102,13 +102,13 @@ int application_start(void)
|
|||||||
for (i = 0; i < Relay_NUM; i++)
|
for (i = 0; i < Relay_NUM; i++)
|
||||||
{
|
{
|
||||||
MicoGpioInitialize(Relay[i], OUTPUT_PUSH_PULL);
|
MicoGpioInitialize(Relay[i], OUTPUT_PUSH_PULL);
|
||||||
UserRelaySet(i, user_config->socket[i].on);
|
UserRelaySet(i, user_config->socket_configs[i].on);
|
||||||
}
|
}
|
||||||
MicoSysLed(0);
|
MicoSysLed(0);
|
||||||
|
|
||||||
if (user_config->version != USER_CONFIG_VERSION
|
if (user_config->version != USER_CONFIG_VERSION
|
||||||
|| user_config->socket[0].time_tasks[0].hour < 0
|
|| user_config->socket_configs[0].time_tasks[0].hour < 0
|
||||||
|| user_config->socket[0].time_tasks[0].hour > 23)
|
|| user_config->socket_configs[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);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ typedef struct
|
|||||||
char mqtt_password[SETTING_MQTT_STRING_LENGTH_MAX]; //mqtt service user
|
char mqtt_password[SETTING_MQTT_STRING_LENGTH_MAX]; //mqtt service user
|
||||||
// char mqtt_device_id[SETTING_MQTT_STRING_LENGTH_MAX]; //mqtt service user device name
|
// char mqtt_device_id[SETTING_MQTT_STRING_LENGTH_MAX]; //mqtt service user device name
|
||||||
char version;
|
char version;
|
||||||
user_socket_config_t socket[SOCKET_NUM];
|
user_socket_config_t socket_configs[SOCKET_NUM];
|
||||||
char user[maxNameLen];
|
char user[maxNameLen];
|
||||||
WiFiEvent last_wifi_status;
|
WiFiEvent last_wifi_status;
|
||||||
} user_config_t;
|
} user_config_t;
|
||||||
|
|||||||
@@ -251,10 +251,10 @@ bool json_socket_analysis(int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSO
|
|||||||
if (cJSON_IsString(p_socket_setting_name))
|
if (cJSON_IsString(p_socket_setting_name))
|
||||||
{
|
{
|
||||||
return_flag = true;
|
return_flag = true;
|
||||||
sprintf(user_config->socket[x].name, p_socket_setting_name->valuestring);
|
sprintf(user_config->socket_configs[x].name, p_socket_setting_name->valuestring);
|
||||||
user_mqtt_hass_auto_name(x);
|
user_mqtt_hass_auto_name(x);
|
||||||
}
|
}
|
||||||
cJSON_AddStringToObject(json_socket_setting_send, "name", user_config->socket[x].name);
|
cJSON_AddStringToObject(json_socket_setting_send, "name", user_config->socket_configs[x].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
//解析socket中setting中task----------------------------------------
|
//解析socket中setting中task----------------------------------------
|
||||||
@@ -267,7 +267,7 @@ bool json_socket_analysis(int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSO
|
|||||||
cJSON_AddItemToObject(json_socket_send, "setting", json_socket_setting_send);
|
cJSON_AddItemToObject(json_socket_send, "setting", json_socket_setting_send);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cJSON_AddNumberToObject(json_socket_send, "on", user_config->socket[x].on);
|
cJSON_AddNumberToObject(json_socket_send, "on", user_config->socket_configs[x].on);
|
||||||
|
|
||||||
cJSON_AddItemToObject(pJsonSend, socket_str, json_socket_send);
|
cJSON_AddItemToObject(pJsonSend, socket_str, json_socket_send);
|
||||||
return return_flag;
|
return return_flag;
|
||||||
@@ -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].time_tasks[y].hour = p_socket_task_hour->valueint;
|
user_config->socket_configs[x].time_tasks[y].hour = p_socket_task_hour->valueint;
|
||||||
user_config->socket[x].time_tasks[y].minute = p_socket_task_minute->valueint;
|
user_config->socket_configs[x].time_tasks[y].minute = p_socket_task_minute->valueint;
|
||||||
user_config->socket[x].time_tasks[y].repeat = p_socket_task_repeat->valueint;
|
user_config->socket_configs[x].time_tasks[y].repeat = p_socket_task_repeat->valueint;
|
||||||
user_config->socket[x].time_tasks[y].action = p_socket_task_action->valueint;
|
user_config->socket_configs[x].time_tasks[y].action = p_socket_task_action->valueint;
|
||||||
user_config->socket[x].time_tasks[y].on = p_socket_task_on->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[x].time_tasks[y].hour);
|
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[x].time_tasks[y].minute);
|
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[x].time_tasks[y].repeat);
|
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[x].time_tasks[y].action);
|
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[x].time_tasks[y].on);
|
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);
|
cJSON_AddItemToObject(pJsonSend, socket_task_str, json_socket_task_send);
|
||||||
return return_flag;
|
return return_flag;
|
||||||
|
|||||||
@@ -519,7 +519,7 @@ OSStatus user_mqtt_send_socket_state(char socket_id)
|
|||||||
if (send_buf != NULL && topic_buf != NULL)
|
if (send_buf != NULL && topic_buf != NULL)
|
||||||
{
|
{
|
||||||
sprintf(topic_buf, "homeassistant/switch/%s/socket_%d/state", strMac, (int)socket_id);
|
sprintf(topic_buf, "homeassistant/switch/%s/socket_%d/state", strMac, (int)socket_id);
|
||||||
sprintf(send_buf, "{\"mac\":\"%s\",\"socket_%d\":{\"on\":%d}}", strMac, socket_id, (int)user_config->socket[(int)socket_id].on);
|
sprintf(send_buf, "{\"mac\":\"%s\",\"socket_%d\":{\"on\":%d}}", strMac, socket_id, (int)user_config->socket_configs[(int)socket_id].on);
|
||||||
oss_status = user_mqtt_send_topic(topic_buf, send_buf, 1);
|
oss_status = user_mqtt_send_topic(topic_buf, send_buf, 1);
|
||||||
}
|
}
|
||||||
if (send_buf) free(send_buf);
|
if (send_buf) free(send_buf);
|
||||||
@@ -568,7 +568,7 @@ void user_mqtt_hass_auto_name(char socket_id)
|
|||||||
"\"pl_on\":\"{\\\"mac\\\":\\\"%s\\\",\\\"socket_%d\\\":{\\\"on\\\":1}}\","
|
"\"pl_on\":\"{\\\"mac\\\":\\\"%s\\\",\\\"socket_%d\\\":{\\\"on\\\":1}}\","
|
||||||
"\"pl_off\":\"{\\\"mac\\\":\\\"%s\\\",\\\"socket_%d\\\":{\\\"on\\\":0}}\""
|
"\"pl_off\":\"{\\\"mac\\\":\\\"%s\\\",\\\"socket_%d\\\":{\\\"on\\\":0}}\""
|
||||||
"}",
|
"}",
|
||||||
user_config->socket[(int)socket_id].name, strMac, socket_id, strMac, socket_id, strMac, socket_id);
|
user_config->socket_configs[(int)socket_id].name, strMac, socket_id, strMac, socket_id, strMac, socket_id);
|
||||||
user_mqtt_send_topic(topic_buf, send_buf, 0);
|
user_mqtt_send_topic(topic_buf, send_buf, 0);
|
||||||
}
|
}
|
||||||
if (send_buf)
|
if (send_buf)
|
||||||
|
|||||||
@@ -139,26 +139,26 @@ void rtc_thread(mico_thread_arg_t arg)
|
|||||||
{
|
{
|
||||||
for (j = 0; j < 5; j++)
|
for (j = 0; j < 5; j++)
|
||||||
{
|
{
|
||||||
if (user_config->socket[i].time_tasks[j].on != 0)
|
if (user_config->socket_configs[i].time_tasks[j].on != 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
char repeat = user_config->socket[i].time_tasks[j].repeat;
|
char repeat = user_config->socket_configs[i].time_tasks[j].repeat;
|
||||||
if ( //符合条件则改变继电器状态: 秒为0 时分符合设定值, 重复符合设定值
|
if ( //符合条件则改变继电器状态: 秒为0 时分符合设定值, 重复符合设定值
|
||||||
rtc_time.sec == 0 && rtc_time.min == user_config->socket[i].time_tasks[j].minute
|
rtc_time.sec == 0 && rtc_time.min == user_config->socket_configs[i].time_tasks[j].minute
|
||||||
&& rtc_time.hr == user_config->socket[i].time_tasks[j].hour
|
&& rtc_time.hr == user_config->socket_configs[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].time_tasks[j].action)
|
if (user_config->socket_configs[i].on != user_config->socket_configs[i].time_tasks[j].action)
|
||||||
{
|
{
|
||||||
UserRelaySet(i, user_config->socket[i].time_tasks[j].action);
|
UserRelaySet(i, user_config->socket_configs[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].time_tasks[j].on = 0;
|
user_config->socket_configs[i].time_tasks[j].on = 0;
|
||||||
update_user_config_flag = 1;
|
update_user_config_flag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ void rtc_thread(mico_thread_arg_t arg)
|
|||||||
char strTemp1[] = "socket_X";
|
char strTemp1[] = "socket_X";
|
||||||
strTemp1[5] = i + '0';
|
strTemp1[5] = i + '0';
|
||||||
cJSON *json_send_socket = cJSON_CreateObject();
|
cJSON *json_send_socket = cJSON_CreateObject();
|
||||||
cJSON_AddNumberToObject(json_send_socket, "on", user_config->socket[i].on);
|
cJSON_AddNumberToObject(json_send_socket, "on", user_config->socket_configs[i].on);
|
||||||
|
|
||||||
if (task_flag[i] >= 0)
|
if (task_flag[i] >= 0)
|
||||||
{
|
{
|
||||||
@@ -191,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].time_tasks[j].hour);
|
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[i].time_tasks[j].minute);
|
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[i].time_tasks[j].repeat);
|
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[i].time_tasks[j].action);
|
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[i].time_tasks[j].on);
|
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, 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);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ bool RelayOut(void)
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < SOCKET_NUM; i++)
|
for (i = 0; i < SOCKET_NUM; i++)
|
||||||
{
|
{
|
||||||
if (user_config->socket[i].on != 0)
|
if (user_config->socket_configs[i].on != 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -35,12 +35,12 @@ bool RelayOut(void)
|
|||||||
const unsigned char* GetSocketStatus()
|
const unsigned char* GetSocketStatus()
|
||||||
{
|
{
|
||||||
sprintf(socket_status, "%d,%d,%d,%d,%d,%d",
|
sprintf(socket_status, "%d,%d,%d,%d,%d,%d",
|
||||||
user_config->socket[0].on,
|
user_config->socket_configs[0].on,
|
||||||
user_config->socket[1].on,
|
user_config->socket_configs[1].on,
|
||||||
user_config->socket[2].on,
|
user_config->socket_configs[2].on,
|
||||||
user_config->socket[3].on,
|
user_config->socket_configs[3].on,
|
||||||
user_config->socket[4].on,
|
user_config->socket_configs[4].on,
|
||||||
user_config->socket[5].on);
|
user_config->socket_configs[5].on);
|
||||||
return (const unsigned char*)socket_status;
|
return (const unsigned char*)socket_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +74,7 @@ void UserRelaySet(unsigned char i, unsigned char on)
|
|||||||
MicoGpioOutputLow(relay[i]);
|
MicoGpioOutputLow(relay[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
user_config->socket[i].on = on;
|
user_config->socket_configs[i].on = on;
|
||||||
|
|
||||||
if (RelayOut())
|
if (RelayOut())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user