diff --git a/TC1/main.c b/TC1/main.c index 59ab81c..25b911a 100644 --- a/TC1/main.c +++ b/TC1/main.c @@ -14,9 +14,9 @@ char rtc_init = 0; //sntp校时成功标志位 -uint32_t total_time=0; +uint32_t total_time = 0; char strMac[16] = { 0 }; -uint32_t power=0; +uint32_t power = 0; system_config_t * sys_config; user_config_t * user_config; @@ -76,7 +76,7 @@ int application_start(void) int i; os_log("Start %s",VERSION); - uint8_t main_num=0; + char main_num=0; uint32_t power_last = 0xffffffff; OSStatus err = kNoErr; @@ -174,11 +174,11 @@ int application_start(void) { power_last = power; main_num =0; - uint8_t *power_buf = NULL; - power_buf = malloc(128); + char* power_buf = malloc(128); if (power_buf != NULL) { - sprintf(power_buf, "{\"mac\":\"%s\",\"power\":\"%d.%d\",\"total_time\":%d}", strMac, power / 10, power % 10, total_time); + sprintf(power_buf, "{\"mac\":\"%s\",\"power\":\"%u.%u\",\"total_time\":%u}", + strMac, (unsigned int)(power/10), (unsigned int)(power%10), (unsigned int)total_time); user_send(0, power_buf); free(power_buf); } diff --git a/TC1/main.h b/TC1/main.h index c755ee0..181b566 100644 --- a/TC1/main.h +++ b/TC1/main.h @@ -37,7 +37,7 @@ typedef struct { char hour; //小时 char minute; //分钟 - uint8_t repeat; //bit7:一次 bit6-0:周日-周一 + char repeat; //bit7:一次 bit6-0:周日-周一 char action; //动作 char on; //开关 } user_plug_task_config_t; diff --git a/TC1/ota_server/ota_server.c b/TC1/ota_server/ota_server.c index 0d9d6fe..6fef706 100644 --- a/TC1/ota_server/ota_server.c +++ b/TC1/ota_server/ota_server.c @@ -50,11 +50,11 @@ static uint32_t offset = 0; static OSStatus onReceivedData(struct _HTTPHeader_t * httpHeader, uint32_t pos, - uint8_t *data, + char *data, size_t len, void * userContext); -static void hex2str(uint8_t *hex, int hex_len, char *str) +static void hex2str(char *hex, int hex_len, char *str) { int i = 0; for(i=0; idownload_url.HTTP_SECURITY == HTTP_SECURITY_HTTP){ @@ -173,7 +173,7 @@ static int ota_server_send_header(void) j += sprintf(header + j, "\r\n"); - ret = ota_server_send((uint8_t *) header, strlen(header)); + ret = ota_server_send((char *) header, strlen(header)); // ota_server_log("send: %d\r\n%s", strlen(header), header); if (header != NULL) free(header); @@ -322,7 +322,7 @@ static void ota_server_thread(mico_thread_arg_t arg) CRC16_Final(&crc_context, &crc16); if(ota_server_context->ota_check.is_md5 == true){ Md5Final(&md5, (unsigned char *) md5_value); - hex2str((uint8_t *)md5_value, 16, md5_value_string); + hex2str((char *)md5_value, 16, md5_value_string); } if (memcmp(md5_value_string, ota_server_context->ota_check.md5, OTA_MD5_LENTH) == 0){ ota_server_progress_set(OTA_SUCCE); @@ -358,7 +358,7 @@ DELETE: } /*one request may receive multi reply*/ -static OSStatus onReceivedData(struct _HTTPHeader_t * inHeader, uint32_t inPos, uint8_t * inData, +static OSStatus onReceivedData(struct _HTTPHeader_t * inHeader, uint32_t inPos, char * inData, size_t inLen, void * inUserContext) { OSStatus err = kNoErr; @@ -373,7 +373,7 @@ static OSStatus onReceivedData(struct _HTTPHeader_t * inHeader, uint32_t inPos, Md5Update(&md5, inData, inLen); } - MicoFlashWrite(MICO_PARTITION_OTA_TEMP, &offset, (uint8_t *) inData, inLen); + MicoFlashWrite(MICO_PARTITION_OTA_TEMP, &offset, (char *) inData, inLen); ota_server_progress_set(OTA_LOADING); diff --git a/TC1/user_function.c b/TC1/user_function.c index 8381dd9..52cac80 100644 --- a/TC1/user_function.c +++ b/TC1/user_function.c @@ -27,7 +27,7 @@ void user_send(int udp_flag, char *s) user_mqtt_send(s); } -void user_function_cmd_received(int udp_flag, uint8_t *pusrdata) +void user_function_cmd_received(int udp_flag, char* pusrdata) { unsigned char i; @@ -100,7 +100,7 @@ void user_function_cmd_received(int udp_flag, uint8_t *pusrdata) cJSON *p_power = cJSON_GetObjectItem(pJsonRoot, "power"); if (p_power) { - uint8_t *temp_buf = malloc(16); + char *temp_buf = malloc(16); if (temp_buf != NULL) { sprintf(temp_buf, "%d.%d", power / 10, power % 10); diff --git a/TC1/user_function.h b/TC1/user_function.h index c5e6eeb..aa340cf 100644 --- a/TC1/user_function.h +++ b/TC1/user_function.h @@ -7,7 +7,7 @@ #include "micokit_ext.h" void user_send(int udp_flag, char *s); -void user_function_cmd_received(int udp_flag,uint8_t *pusrdata); +void user_function_cmd_received(int udp_flag, char* pusrdata); unsigned char strtohex(char a, char b); diff --git a/TC1/user_gpio.c b/TC1/user_gpio.c index 1ea63fb..67f49c2 100644 --- a/TC1/user_gpio.c +++ b/TC1/user_gpio.c @@ -106,9 +106,8 @@ static void key_long_press(void) static void key_long_10s_press(void) { - OSStatus err; - char i = 0; os_log("WARNGIN: user params restored!"); +// char i = 0; // for (i = 0; i < 3; i++) // { // user_led_set(1); @@ -123,7 +122,6 @@ static void key_long_10s_press(void) static void key_short_press(void) { char i; - OSStatus err; if (relay_out()) { @@ -138,9 +136,6 @@ static void key_short_press(void) { user_mqtt_send_plug_state(i); } - - - } mico_timer_t user_key_timer; uint16_t key_time = 0; @@ -148,11 +143,9 @@ uint16_t key_time = 0; static void key_timeout_handler(void* arg) { - - static uint8_t key_trigger, key_continue; - static uint8_t key_last; + static char key_trigger, key_continue; //按键扫描程序 - uint8_t tmp = ~(0xfe | MicoGpioInputGet(Button)); + char tmp = ~(0xfe | MicoGpioInputGet(Button)); key_trigger = tmp & (tmp ^ key_continue); key_continue = tmp; // os_log("button scan:%02x %02x",key_trigger,key_continue); @@ -161,9 +154,7 @@ static void key_timeout_handler(void* arg) { //any button pressed key_time++; - if (key_time < BUTTON_LONG_PRESS_TIME) - key_last = key_continue; - else + if (key_time <= BUTTON_LONG_PRESS_TIME) { os_log("button long pressed:%d",key_time); @@ -198,7 +189,6 @@ static void key_timeout_handler(void* arg) { MicoSystemReboot(); } - key_last = 0; mico_rtos_stop_timer(&user_key_timer); } } diff --git a/TC1/user_mqtt_client.c b/TC1/user_mqtt_client.c index 0c00f04..5ad49a4 100644 --- a/TC1/user_mqtt_client.c +++ b/TC1/user_mqtt_client.c @@ -72,7 +72,7 @@ typedef struct char qos; char retained; - uint8_t data[MAX_MQTT_DATA_SIZE]; + char data[MAX_MQTT_DATA_SIZE]; uint32_t datalen; } mqtt_recv_msg_t, *p_mqtt_recv_msg_t, mqtt_send_msg_t, *p_mqtt_send_msg_t; @@ -99,10 +99,10 @@ char topic_state[MAX_MQTT_TOPIC_SIZE]; char topic_set[MAX_MQTT_TOPIC_SIZE]; mico_timer_t timer_handle; -static uint8_t timer_status = 0; +static char timer_status = 0; void user_mqtt_timer_func(void *arg) { - uint8_t *buf1 = NULL; + char* buf1 = malloc(1024); //idx涓1浣嶆椂闀垮害涓24 LinkStatusTypeDef LinkStatus; micoWlanGetLinkStatus(&LinkStatus); @@ -159,21 +159,14 @@ void user_mqtt_timer_func(void *arg) user_mqtt_hass_auto_power_name(); break; case 15: - - buf1 = malloc(1024); //idx涓1浣嶆椂闀垮害涓24 - if (buf1 != NULL) - { - sprintf( - buf1, - "{\"mac\":\"%s\",\"version\":null,\"plug_0\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_1\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_2\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_3\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_4\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_5\":{\"on\":null,\"setting\":{\"name\":null}}}", - strMac); - user_function_cmd_received(0, buf1); - free(buf1); - } + if (buf1 == NULL) break; + sprintf(buf1, "{\"mac\":\"%s\",\"version\":null,\"plug_0\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_1\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_2\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_3\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_4\":{\"on\":null,\"setting\":{\"name\":null}},\"plug_5\":{\"on\":null,\"setting\":{\"name\":null}}}", strMac); + user_function_cmd_received(0, buf1); + free(buf1); break; default: mico_stop_timer(&timer_handle); -// mico_deinit_timer(&timer_handle); +// mico_deinit_timer(&timer_handle); break; } } @@ -514,8 +507,8 @@ OSStatus user_mqtt_send(char *arg) OSStatus user_mqtt_send_plug_state(char plug_id) { - uint8_t *send_buf = NULL; - uint8_t *topic_buf = NULL; + char *send_buf = NULL; + char *topic_buf = NULL; send_buf = malloc(64); // topic_buf = malloc(64); // if (send_buf != NULL && topic_buf != NULL) @@ -531,9 +524,9 @@ OSStatus user_mqtt_send_plug_state(char plug_id) //hass mqtt鑷姩鍙戠幇鏁版嵁寮鍏冲彂閫 void user_mqtt_hass_auto(char plug_id) { - uint8_t i; - uint8_t *send_buf = NULL; - uint8_t *topic_buf = NULL; + char i; + char *send_buf = NULL; + char *topic_buf = NULL; send_buf = malloc(512); // topic_buf = malloc(128); // if (send_buf != NULL && topic_buf != NULL) @@ -555,10 +548,10 @@ void user_mqtt_hass_auto(char plug_id) } void user_mqtt_hass_auto_name(char plug_id) { - uint8_t *send_buf = NULL; - uint8_t *topic_buf = NULL; - send_buf = (uint8_t *) malloc(300); - topic_buf = (uint8_t *) malloc(64); + char *send_buf = NULL; + char *topic_buf = NULL; + send_buf = (char *) malloc(300); + topic_buf = (char *) malloc(64); if (send_buf != NULL && topic_buf != NULL) { sprintf(topic_buf, "homeassistant/switch/%s/plug_%d/config", strMac, plug_id); @@ -580,9 +573,9 @@ void user_mqtt_hass_auto_name(char plug_id) //hass mqtt鑷姩鍙戠幇鏁版嵁鍔熺巼鍙戦 void user_mqtt_hass_auto_power(void) { - uint8_t i; - uint8_t *send_buf = NULL; - uint8_t *topic_buf = NULL; + char i; + char *send_buf = NULL; + char *topic_buf = NULL; send_buf = malloc(512); // topic_buf = malloc(128); // if (send_buf != NULL && topic_buf != NULL) @@ -604,10 +597,10 @@ void user_mqtt_hass_auto_power(void) } void user_mqtt_hass_auto_power_name(void) { - uint8_t *send_buf = NULL; - uint8_t *topic_buf = NULL; - send_buf = (uint8_t *) malloc(300); // - topic_buf = (uint8_t *) malloc(64); // + char *send_buf = NULL; + char *topic_buf = NULL; + send_buf = (char *) malloc(300); // + topic_buf = (char *) malloc(64); // if (send_buf != NULL && topic_buf != NULL) { sprintf(topic_buf, "homeassistant/sensor/%s/power/config", strMac); @@ -635,9 +628,9 @@ void user_mqtt_hass_auto_power_name(void) void user_mqtt_hass_power(void) { - uint8_t i; - uint8_t *send_buf = NULL; - uint8_t *topic_buf = NULL; + char i; + char *send_buf = NULL; + char *topic_buf = NULL; send_buf = malloc(512); // topic_buf = malloc(128); // if (send_buf != NULL && topic_buf != NULL) diff --git a/TC1/user_power.c b/TC1/user_power.c index b99b749..0a32ff7 100644 --- a/TC1/user_power.c +++ b/TC1/user_power.c @@ -17,7 +17,7 @@ static uint32_t timer_irq_count = 0; static void power_timer_handler(void* arg) { -// uint8_t pin_input = MicoGpioInputGet(POWER); +// char pin_input = MicoGpioInputGet(POWER); uint32_t timer = 0; if (timer_irq_count > 1) diff --git a/TC1/user_rtc.c b/TC1/user_rtc.c index c880ba1..571a77e 100644 --- a/TC1/user_rtc.c +++ b/TC1/user_rtc.c @@ -156,7 +156,7 @@ void rtc_thread(mico_thread_arg_t arg) if (utc_time_last != utc_time) { - utc_time_last == utc_time; + utc_time_last = utc_time; total_time++; } @@ -183,7 +183,7 @@ void rtc_thread(mico_thread_arg_t arg) if (user_config->plug[i].task[j].on != 0) { - uint8_t repeat = user_config->plug[i].task[j].repeat; + char repeat = user_config->plug[i].task[j].repeat; if ( //符合条件则改变继电器状态: 秒为0 时分符合设定值, 重复符合设定值 rtc_time.sec == 0 && rtc_time.min == user_config->plug[i].task[j].minute && rtc_time.hr == user_config->plug[i].task[j].hour diff --git a/TC1/user_udp.c b/TC1/user_udp.c index 9da4018..38b59f3 100644 --- a/TC1/user_udp.c +++ b/TC1/user_udp.c @@ -13,7 +13,7 @@ mico_queue_t udp_msg_send_queue = NULL; typedef struct { uint32_t datalen; - uint8_t data[MAX_UDP_DATA_SIZE]; + char data[MAX_UDP_DATA_SIZE]; } udp_send_msg_t, *p_udp_send_msg_t; static OSStatus udp_msg_send(int socket, const unsigned char* msg, uint32_t msg_len); @@ -49,7 +49,7 @@ void udp_thread(void *arg) p_udp_send_msg_t p_send_msg = NULL; int msg_send_event_fd = -1; char ip_address[16]; - uint8_t *buf = NULL; + char *buf = NULL; /* create udp msg send queue */ err = mico_rtos_init_queue(&udp_msg_send_queue, "uqp_msg_send_queue", sizeof(p_udp_send_msg_t), @@ -125,7 +125,6 @@ void udp_thread(void *arg) static OSStatus udp_msg_send(int socket, const unsigned char* msg, uint32_t msg_len) { OSStatus err = kUnknownErr; - int ret = 0; require(msg_len && msg, exit); @@ -139,7 +138,7 @@ static OSStatus udp_msg_send(int socket, const unsigned char* msg, uint32_t msg_ /*the receiver should bind at port=20000*/ sendto(socket, msg, msg_len, 0, (struct sockaddr *) &addr, sizeof(addr)); - exit: +exit: return err; } diff --git a/TC1/user_wifi.c b/TC1/user_wifi.c index 0533fa6..4629dbf 100644 --- a/TC1/user_wifi.c +++ b/TC1/user_wifi.c @@ -4,6 +4,7 @@ #include "mico_socket.h" #include "user_gpio.h" #include "user_sntp.h" +#include "user_function.h" #define os_log(format, ...) custom_log("WIFI", format, ##__VA_ARGS__) @@ -11,6 +12,7 @@ char wifi_status = WIFI_STATE_NOCONNECT; mico_timer_t wifi_led_timer; +/* static void wifi_connect_sys_config(void) { if (strlen(sys_config->micoSystemConfig.ssid) > 0) @@ -28,6 +30,7 @@ static void wifi_connect_sys_config(void) } else wifi_status = WIFI_STATE_FAIL; } +*/ void wifi_start_easylink() { wifi_status = WIFI_STATE_EASYLINK;