Merge pull request #2 from btsimonh/btsimonh

All warnings eliminated, 1 bug sorted.
This commit is contained in:
openshwprojects
2022-02-02 18:49:14 +01:00
committed by GitHub
14 changed files with 51 additions and 42 deletions

View File

@@ -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;

View File

@@ -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
}

View File

@@ -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)));
}

View File

@@ -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 );

View File

@@ -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';

View File

@@ -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);

View File

@@ -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));

View File

@@ -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);

View File

@@ -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

View File

@@ -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);

View File

@@ -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.

View File

@@ -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);

View File

@@ -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]

View File

@@ -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;
}