PLUG -> SOCKET

This commit is contained in:
zogodo
2019-10-09 18:19:57 +08:00
parent 58eec84eec
commit d916d01092
6 changed files with 26 additions and 22 deletions

View File

@@ -39,7 +39,7 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
userConfigDefault->version = USER_CONFIG_VERSION;
int i, j;
for (i = 0; i < PLUG_NUM; i++)
for (i = 0; i < SOCKET_NUM; i++)
{
userConfigDefault->plug[i].on = 1;
//插座名称 插口1-6
@@ -53,7 +53,7 @@ void appRestoreDefault_callback(void * const user_config_data, uint32_t size)
userConfigDefault->plug[i].name[7] = 0;
// sprintf(userConfigDefault->plug[i].name, "插座%d", i);//编码异常
for (j = 0; j < PLUG_TIME_TASK_NUM; j++)
for (j = 0; j < SOCKET_TIME_TASK_NUM; j++)
{
userConfigDefault->plug[i].task[j].hour = 0;
userConfigDefault->plug[i].task[j].minute = 0;
@@ -134,11 +134,11 @@ int application_start(void)
os_log("mqtt_password:%s",user_config->mqtt_password);
os_log("version:%d",user_config->version);
// for (i = 0; i < PLUG_NUM; i++)
// for (i = 0; i < SOCKET_NUM; i++)
// {
// os_log("plug_%d:",i);
// os_log("\tname:%s:",user_config->plug[i].name);
// for (j = 0; j < PLUG_TIME_TASK_NUM; j++)
// for (j = 0; j < SOCKET_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,

View File

@@ -14,9 +14,9 @@
#define USER_CONFIG_VERSION 2
#define SETTING_MQTT_STRING_LENGTH_MAX 32 //必须4字节对齐。
#define PLUG_NAME_LENGTH 32
#define PLUG_NUM 6 //插座数量
#define PLUG_TIME_TASK_NUM 5 //每个插座最多5组定时任务
#define SOCKET_NAME_LENGTH 32
#define SOCKET_NUM 6 //插座数量
#define SOCKET_TIME_TASK_NUM 5 //每个插座最多5组定时任务
#define Led MICO_GPIO_5
#define Button MICO_GPIO_23
@@ -31,7 +31,7 @@
#define Relay_3 MICO_GPIO_7
#define Relay_4 MICO_GPIO_9
#define Relay_5 MICO_GPIO_18
#define Relay_NUM PLUG_NUM
#define Relay_NUM SOCKET_NUM
typedef struct
{
@@ -44,9 +44,9 @@ typedef struct
typedef struct
{
char name[PLUG_NAME_LENGTH];
char name[SOCKET_NAME_LENGTH];
char on; //记录当前开关
user_plug_task_config_t task[PLUG_TIME_TASK_NUM];
user_plug_task_config_t task[SOCKET_TIME_TASK_NUM];
} user_plug_config_t;
//用户保存参数结构体
@@ -58,7 +58,7 @@ typedef struct
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 version;
user_plug_config_t plug[PLUG_NUM];
user_plug_config_t plug[SOCKET_NUM];
char user[maxNameLen];
WiFiEvent last_wifi_status;
} user_config_t;

View File

@@ -181,7 +181,7 @@ void user_function_cmd_received(int udp_flag, char* pusrdata)
}
//解析plug-----------------------------------------------------------------
for (i = 0; i < PLUG_NUM; i++)
for (i = 0; i < SOCKET_NUM; i++)
{
if (json_plug_analysis(udp_flag, i, pJsonRoot, json_send))
update_user_config_flag = true;
@@ -261,7 +261,7 @@ bool json_plug_analysis(int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSON
}
//解析plug中setting中task----------------------------------------
for (i = 0; i < PLUG_TIME_TASK_NUM; i++)
for (i = 0; i < SOCKET_TIME_TASK_NUM; i++)
{
if (json_plug_task_analysis(x, i, p_plug_setting, json_plug_setting_send))
return_flag = true;

View File

@@ -21,7 +21,7 @@ void UserLedSet(char x)
bool RelayOut(void)
{
int i;
for (i = 0; i < PLUG_NUM; i++)
for (i = 0; i < SOCKET_NUM; i++)
{
if (user_config->plug[i].on != 0)
{
@@ -49,7 +49,7 @@ void SetSocketStatus(char* socket_status)
sscanf(socket_status, "%d,%d,%d,%d,%d,%d,",
&ons[0], &ons[1], &ons[2], &ons[3], &ons[4], &ons[5]);
int i = 0;
for (i = 0; i < PLUG_NUM; i++)
for (i = 0; i < SOCKET_NUM; i++)
{
UserRelaySet(i, ons[i]);
}
@@ -62,7 +62,7 @@ void SetSocketStatus(char* socket_status)
*/
void UserRelaySet(unsigned char i, unsigned char on)
{
if (i >= PLUG_NUM) return;
if (i >= SOCKET_NUM) return;
if (on == Relay_ON)
{
@@ -93,7 +93,7 @@ void UserRelaySet(unsigned char i, unsigned char on)
void UserRelaySetAll(char y)
{
int i;
for (i = 0; i < PLUG_NUM; i++)
for (i = 0; i < SOCKET_NUM; i++)
UserRelaySet(i, y);
}
@@ -132,7 +132,7 @@ static void KeyShortPress(void)
UserRelaySetAll(1);
}
for (i = 0; i < PLUG_NUM; i++)
for (i = 0; i < SOCKET_NUM; i++)
{
user_mqtt_send_plug_state(i);
}

View File

@@ -124,7 +124,7 @@ OSStatus user_rtc_init(void)
void rtc_thread(mico_thread_arg_t arg)
{
int i, j;
char task_flag[PLUG_NUM] = { -1, -1, -1, -1, -1, -1 }; //记录每个插座哪个任务需要返回数据
char task_flag[SOCKET_NUM] = { -1, -1, -1, -1, -1, -1 }; //记录每个插座哪个任务需要返回数据
OSStatus err = kUnknownErr;
LinkStatusTypeDef LinkStatus;
mico_rtc_time_t rtc_time;
@@ -176,9 +176,9 @@ void rtc_thread(mico_thread_arg_t arg)
os_log("time: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 < PLUG_NUM; i++)
for (i = 0; i < SOCKET_NUM; i++)
{
for (j = 0; j < PLUG_TIME_TASK_NUM; j++)
for (j = 0; j < SOCKET_TIME_TASK_NUM; j++)
{
if (user_config->plug[i].task[j].on != 0)
{
@@ -217,7 +217,7 @@ void rtc_thread(mico_thread_arg_t arg)
cJSON *json_send = cJSON_CreateObject();
cJSON_AddStringToObject(json_send, "mac", strMac);
for (i = 0; i < PLUG_NUM; i++)
for (i = 0; i < SOCKET_NUM; i++)
{
char strTemp1[] = "plug_X";
strTemp1[5] = i + '0';