diff --git a/src/httpclient/http_client.c b/src/httpclient/http_client.c index fb72274ba..08022c3cd 100644 --- a/src/httpclient/http_client.c +++ b/src/httpclient/http_client.c @@ -241,7 +241,7 @@ int httpclient_get_info(httpclient_t *client, char *send_buf, int *send_idx, cha return SUCCESS_RETURN; } -void httpclient_set_custom_header(httpclient_t *client, char *header) +void httpclient_set_custom_header(httpclient_t *client, const char *header) { client->header = header; } @@ -353,7 +353,7 @@ int httpclient_send_header(httpclient_t *client, const char *url, int method, ht } if (client_data->post_buf != NULL) { - snprintf(buf, HTTPCLIENT_SEND_BUF_SIZE, "Content-Length: %u\r\n", client_data->post_buf_len); + snprintf(buf, HTTPCLIENT_SEND_BUF_SIZE, "Content-Length: %u\r\n", (unsigned int)client_data->post_buf_len); httpclient_get_info(client, send_buf, &len, buf, os_strlen(buf)); if (client_data->post_content_type != NULL) { @@ -457,7 +457,7 @@ int httpclient_retrieve_content(httpclient_t *client, char *data, int len, uint3 //int count = 0; //int templen = 0; //int crlf_pos; - iotx_time_t timer; + //iotx_time_t timer; //char * b_data = NULL; //iotx_time_init(&timer); @@ -772,7 +772,7 @@ int httpclient_response_parse(httpclient_t *client, char *data, int len, uint32_ if (n == 2) { log_debug("Read header : %s: %s\r\n", key, value); if (!os_strcmp(key, "Content-Length")) { - sscanf(value, "%d", &(client_data->response_content_len)); + sscanf(value, "%d", (int *)&(client_data->response_content_len)); client_data->retrieve_len = client_data->response_content_len; } else if (!os_strcmp(key, "Transfer-Encoding")) { if (!os_strcmp(value, "Chunked") || !os_strcmp(value, "chunked")) { @@ -980,7 +980,7 @@ static void httprequest_thread( beken_thread_arg_t arg ) const char *header = request->header; int port = request->port; const char *ca_crt = request->ca_crt; - uint32_t timeout = request->timeout; + //uint32_t timeout = request->timeout; httpclient_data_t *client_data = &request->client_data; int method = request->method; int timeout_ms = request->timeout; diff --git a/src/httpclient/http_client.h b/src/httpclient/http_client.h index 5e3952125..1157d27e5 100644 --- a/src/httpclient/http_client.h +++ b/src/httpclient/http_client.h @@ -64,7 +64,7 @@ typedef struct { int remote_port; /**< HTTP or HTTPS port. */ utils_network_t net; int response_code; /**< Response code. */ - char *header; /**< Custom header. */ + const char *header; /**< Custom header. */ char *auth_user; /**< Username for basic authentication. */ char *auth_password; /**< Password for basic authentication. */ } httpclient_t; @@ -143,7 +143,7 @@ typedef struct httprequest_t_tag{ * @endcode */ int async_request(httprequest_t *request); -void httpclient_set_custom_header(httpclient_t *client, char *header); +void httpclient_set_custom_header(httpclient_t *client, const char *header); #ifdef __cplusplus } diff --git a/src/httpclient/utils_timer.c b/src/httpclient/utils_timer.c index fdd579d9a..3af4dbb34 100644 --- a/src/httpclient/utils_timer.c +++ b/src/httpclient/utils_timer.c @@ -94,7 +94,7 @@ uint32_t utils_time_get_ms(void) uint64_t utils_time_left(uint64_t t_end, uint64_t t_now) { - uint64_t t_left; + //uint64_t t_left; return (1!=(hal_machw_time_past(t_end*1000))); } diff --git a/src/httpserver/http_tcp_server.c b/src/httpserver/http_tcp_server.c index 10310fb28..9a300e60d 100644 --- a/src/httpserver/http_tcp_server.c +++ b/src/httpserver/http_tcp_server.c @@ -5,6 +5,7 @@ #include "lwip/inet.h" #include "../logging/logging.h" #include "new_http.h" +#include "str_pub.h" static void tcp_server_thread( beken_thread_arg_t arg ); static void tcp_client_thread( beken_thread_arg_t arg ); diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index 908c35427..f38b2805d 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -1,11 +1,13 @@ #include "../new_common.h" +#include "ctype.h" #include "str_pub.h" #include "new_http.h" #include "../new_pins.h" #include "../new_cfg.h" #include "../ota/ota.h" +#include "tuya_hal_storge.h" /* GET / HTTP/1.1 @@ -116,8 +118,9 @@ const char *http_checkArg(const char *p, const char *n) { } return p; } -void http_copyCarg(const char *at, char *to, int maxSize) { - char a, b; +void http_copyCarg(const char *atin, char *to, int maxSize) { + int a, b; + const unsigned char *at = (unsigned char *)atin; while(*at != 0 && *at != '&' && *at != ' ' && maxSize > 1) { #if 0 @@ -257,7 +260,7 @@ int HTTP_ProcessPacket(const char *recvbuf, char *outbuf, int outBufSize) { char tmpA[128]; char tmpB[64]; char tmpC[64]; - int bChanged = 0; + //int bChanged = 0; const char *urlStr; *outbuf = '\0'; diff --git a/src/logging/logging.c b/src/logging/logging.c index 6f35ebcf0..78db380ae 100644 --- a/src/logging/logging.c +++ b/src/logging/logging.c @@ -2,6 +2,7 @@ #include "../new_common.h" #include "../logging/logging.h" #include "../httpserver/new_http.h" +#include "str_pub.h" static int http_getlog(const char *payload, char *outbuf, int outBufSize); diff --git a/src/new_cfg.c b/src/new_cfg.c index 4dbd59f57..aac73370e 100644 --- a/src/new_cfg.c +++ b/src/new_cfg.c @@ -1,7 +1,4 @@ - - - #include "new_common.h" #include "httpserver/new_http.h" #include "new_pins.h" @@ -34,7 +31,7 @@ const char *CFG_GetShortDeviceName(){ } void CFG_CreateDeviceNameUnique() { - u8 mac[32]; + char mac[32]; #if WINDOWS #else @@ -100,7 +97,7 @@ void CFG_SaveWiFi() { ITEM_NEW_WIFI_CONFIG container; strcpy_safe(container.ssid, g_wifi_ssid, sizeof(container.ssid)); strcpy_safe(container.pass, g_wifi_pass, sizeof(container.pass)); - save_info_item(NEW_WIFI_CONFIG,&container, 0, 0); + save_info_item(NEW_WIFI_CONFIG,(UINT8 *)&container, 0, 0); #endif } void CFG_LoadWiFi() { @@ -108,7 +105,7 @@ void CFG_LoadWiFi() { #else ITEM_NEW_WIFI_CONFIG container; - if(get_info_item(NEW_WIFI_CONFIG,&container, 0, 0) != 0) { + if(get_info_item(NEW_WIFI_CONFIG,(UINT8 *)&container, 0, 0) != 0) { strcpy_safe(g_wifi_ssid,container.ssid,sizeof(g_wifi_ssid)); strcpy_safe(g_wifi_pass,container.pass,sizeof(g_wifi_pass)); } @@ -125,7 +122,7 @@ void CFG_SaveMQTT() { strcpy_safe(container.hostName, g_mqtt_host, sizeof(container.hostName)); strcpy_safe(container.brokerName, g_mqtt_brokerName, sizeof(container.brokerName)); container.port = g_mqtt_port; - save_info_item(NEW_MQTT_CONFIG,&container, 0, 0); + save_info_item(NEW_MQTT_CONFIG,(UINT8 *)&container, 0, 0); #endif } @@ -134,7 +131,7 @@ void CFG_LoadMQTT() { #else ITEM_NEW_MQTT_CONFIG container; - if(get_info_item(NEW_MQTT_CONFIG,&container, 0, 0) != 0) { + if(get_info_item(NEW_MQTT_CONFIG,(UINT8 *)&container, 0, 0) != 0) { strcpy_safe(g_mqtt_userName,container.userName,sizeof(g_mqtt_userName)); strcpy_safe(g_mqtt_pass,container.pass,sizeof(g_mqtt_pass)); strcpy_safe(g_mqtt_host,container.hostName,sizeof(g_mqtt_host)); diff --git a/src/new_common.h b/src/new_common.h index edb8ae676..416dc553b 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -48,5 +48,6 @@ typedef unsigned char byte; int strcat_safe(char *tg, const char *src, int tgMaxLen); - +int strcpy_safe(char *tg, const char *src, int tgMaxLen); +void urldecode2_safe(char *dst, const char *srcin, int maxDstLen); diff --git a/src/new_pins.c b/src/new_pins.c index 1a66392b4..261d20d36 100644 --- a/src/new_pins.c +++ b/src/new_pins.c @@ -12,6 +12,8 @@ #else #include "../../beken378/func/include/net_param_pub.h" #include "../../beken378/func/user_driver/BkDriverPwm.h" +#undef PR_DEBUG +#undef PR_NOTICE #define PR_DEBUG addLog #define PR_NOTICE addLog @@ -79,14 +81,14 @@ void (*g_doubleClickCallback)(int pinIndex) = 0; void PIN_SaveToFlash() { #if WINDOWS #else - save_info_item(NEW_PINS_CONFIG,&g_pins, 0, 0); + save_info_item(NEW_PINS_CONFIG,(UINT8 *)&g_pins, 0, 0); #endif } void PIN_LoadFromFlash() { int i; #if WINDOWS #else - get_info_item(NEW_PINS_CONFIG,&g_pins, 0, 0); + get_info_item(NEW_PINS_CONFIG,(UINT8 *)&g_pins, 0, 0); #endif for(i = 0; i < GPIO_MAX; i++) { PIN_SetPinRoleForPinIndex(i,g_pins.roles[i]); @@ -158,7 +160,7 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { #else { - BUTTON_S *bt = &g_buttons[index]; + //BUTTON_S *bt = &g_buttons[index]; // TODO: disable button } #endif @@ -177,7 +179,7 @@ void PIN_SetPinRoleForPinIndex(int index, int role) { case IOR_PWM: { int pwmIndex; - int channelIndex; + //int channelIndex; pwmIndex = PIN_GetPWMIndexForPinIndex(index); #if WINDOWS diff --git a/src/new_pins.h b/src/new_pins.h index 969ce8d42..6d1509797 100644 --- a/src/new_pins.h +++ b/src/new_pins.h @@ -21,6 +21,7 @@ enum IORole { #define GPIO_MAX 27 #define CHANNEL_MAX 32 +void PIN_Init(void); void PIN_ClearPins(); int PIN_GetPinRoleForPinIndex(int index); int PIN_GetPinChannelForPinIndex(int index); diff --git a/src/ota/ota.c b/src/ota/ota.c index 44c88336d..361f24ea5 100644 --- a/src/ota/ota.c +++ b/src/ota/ota.c @@ -14,7 +14,13 @@ unsigned int addr = 0xff000; static void store_sector(unsigned int addr, unsigned char *data); extern void flash_protection_op(UINT8 mode,PROTECT_TYPE type); +// from wlan_ui.c +void bk_reboot(void); +// from flash.c +extern UINT32 flash_read(char *user_buf, UINT32 count, UINT32 address); +extern UINT32 flash_write(char *user_buf, UINT32 count, UINT32 address); +extern UINT32 flash_ctrl(UINT32 cmd, void *parm); int init_ota(unsigned int startaddr){ @@ -84,7 +90,7 @@ static void store_sector(unsigned int addr, unsigned char *data){ flash_ctrl(CMD_FLASH_WRITE_ENABLE, (void *)0); flash_ctrl(CMD_FLASH_ERASE_SECTOR, &addr); flash_ctrl(CMD_FLASH_WRITE_ENABLE, (void *)0); - flash_write(data , SECTOR_SIZE, addr); + flash_write((char *)data , SECTOR_SIZE, addr); } @@ -93,7 +99,7 @@ int total_bytes = 0; int myhttpclientcallback(httprequest_t* request){ - httpclient_t *client = &request->client; + //httpclient_t *client = &request->client; httpclient_data_t *client_data = &request->client_data; // NOTE: Called from the client thread, beware @@ -137,7 +143,7 @@ int myhttpclientcallback(httprequest_t* request){ // NOTE: these MUST persist // note: url must have a '/' after host, else it can;t parse it.. static char url[256] = "http://raspberrypi:1880/firmware"; -static char *header = ""; +static const char *header = ""; static char *content_type = "text/csv"; static char *post_data = ""; #define BUF_SIZE 1024 @@ -168,7 +174,7 @@ void otarequest(const char *urlin){ } client_data->response_buf = http_buf; //Sets a buffer to store the result. client_data->response_buf_len = BUF_SIZE; //Sets the buffer size. - httpclient_set_custom_header(&client, header); //Sets the custom header if needed. + httpclient_set_custom_header(client, header); //Sets the custom header if needed. client_data->post_buf = post_data; //Sets the user data to be posted. client_data->post_buf_len = strlen(post_data); //Sets the post data length. client_data->post_content_type = content_type; //Sets the content type. diff --git a/src/ota/ota.h b/src/ota/ota.h index 476be5e41..8baf0ebc9 100644 --- a/src/ota/ota.h +++ b/src/ota/ota.h @@ -8,3 +8,5 @@ void add_otadata(unsigned char *data, int len); // finalise OTA flash (write last sector if incomplete) int close_ota(); + +void otarequest(const char *urlin); \ No newline at end of file diff --git a/src/printnetinfo/printnetinfo.c b/src/printnetinfo/printnetinfo.c index 37eae5e5c..4e39e85d8 100644 --- a/src/printnetinfo/printnetinfo.c +++ b/src/printnetinfo/printnetinfo.c @@ -3,6 +3,7 @@ #include "../new_common.h" #include "str_pub.h" #include "wlan_ui_pub.h" +#include "net.h" #include "../logging/logging.h" #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] diff --git a/src/tuya_device.c b/src/tuya_device.c index d28457a76..584212e27 100644 --- a/src/tuya_device.c +++ b/src/tuya_device.c @@ -66,6 +66,10 @@ int g_my_reconnect_mqtt_after_time = -1; #define tcp_server_log(M, ...) os_printf("TCP", M, ##__VA_ARGS__) + +// from wlan_ui.c, no header +void bk_wlan_status_register_cb(FUNC_1PARAM_PTR cb); + int unw_recv(const int fd, void *buf, u32 nbytes) { fd_set readfds, errfds; @@ -316,11 +320,9 @@ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection void example_do_connect(mqtt_client_t *client) { - err_t err; const char *mqtt_userName, *mqtt_host, *mqtt_pass, *mqtt_clientID; int mqtt_port; - mqtt_userName = CFG_GetMQTTUserName(); mqtt_pass = CFG_GetMQTTPass(); mqtt_clientID = CFG_GetMQTTBrokerName(); @@ -344,12 +346,6 @@ void example_do_connect(mqtt_client_t *client) &mqtt_ip, mqtt_port, mqtt_connection_cb, LWIP_CONST_CAST(void*, &mqtt_client_info), &mqtt_client_info); - - - /* For now just print the result code if something goes wrong */ - if(err != ERR_OK) { - PR_NOTICE("mqtt_connect return %d\n", err); - } } @@ -439,10 +435,10 @@ static int setup_wifi_open_access_point(void) bk_wlan_ap_set_default_channel(ap_info.chann); - len = os_strlen(ap_info.ssid.array); + len = os_strlen((char *)ap_info.ssid.array); - os_strcpy((char *)wNetConfig.wifi_ssid, ap_info.ssid.array); - os_strcpy((char *)wNetConfig.wifi_key, ap_info.key); + os_strcpy((char *)wNetConfig.wifi_ssid, (char *)ap_info.ssid.array); + os_strcpy((char *)wNetConfig.wifi_key, (char *)ap_info.key); wNetConfig.wifi_mode = SOFT_AP; wNetConfig.dhcp_mode = DHCP_SERVER; @@ -521,7 +517,7 @@ void user_main(void) int bForceOpenAP = 0; const char *wifi_ssid, *wifi_pass; - OPERATE_RET op_ret = OPRT_OK; + //OPERATE_RET op_ret = OPRT_OK; CFG_CreateDeviceNameUnique(); @@ -575,6 +571,4 @@ void user_main(void) err = rtos_start_timer(&led_timer); ASSERT(kNoErr == err); - - return op_ret; }