Skip to content

Commit

Permalink
Reduce compiler warnings for -Wall -Wpedantic -Wextra
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Jul 27, 2022
1 parent 25d840e commit e38a406
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 97 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"lwevt_type.h": "c",
"lwevt.h": "c",
"string.h": "c",
"lwevt_opt.h": "c"
"lwevt_opt.h": "c",
"cli.h": "c",
"windows.h": "c"
},
"esbonio.sphinx.confDir": ""
}
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ target_sources(${PROJECT_NAME} PUBLIC
# Port specific
${CMAKE_CURRENT_LIST_DIR}/lwesp/src/system/lwesp_sys_win32.c
${CMAKE_CURRENT_LIST_DIR}/lwesp/src/system/lwesp_ll_win32.c
)
)

# Add key include paths
target_include_directories(${PROJECT_NAME} PUBLIC
Expand All @@ -41,15 +41,22 @@ target_include_directories(${PROJECT_NAME} PUBLIC

# Port specifics
${CMAKE_CURRENT_LIST_DIR}/lwesp/src/include/system/port/win32
)
)

# Compilation definition information
target_compile_definitions(${PROJECT_NAME} PUBLIC
WIN32
_DEBUG
CONSOLE
LWESP_DEV
)
)

# Compiler options
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Wpedantic
)

# Add subdir with lwesp and link to the project
add_subdirectory("lwesp")
Expand Down
77 changes: 13 additions & 64 deletions dev/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ cmd_commands[] = {
{ 0, "join", "<ssid> [<pwd> [<mac>]]", "Join to access point" },
{ 0, "reconn_set", "<interval> <repeat>", "Set reconnect config" },
{ 0, "quit", "", "Quit from access point" },
{ 1, "IP management" },
{ 1, "IP management", NULL, NULL},
{ 0, "stagetip", "", "Get station IP address" },
{ 0, "stasetip", "<ip>", "Set station IP address" },
{ 0, "apgetip", "", "Get Soft Access point IP address" },
{ 0, "apsetip", "<ip>", "Set Soft Access point IP address" },
{ 0, "setdhcp", "<enable>", "Enable or disable DHCP" },
{ 1, "MAC management" },
{ 1, "MAC management", NULL, NULL },
{ 0, "stagetmac", "", "Get station MAC address" },
{ 0, "stasetmac", "<mac>", "Set station MAC address" },
{ 0, "apgetmac", "", "Get Soft Access point MAC address" },
{ 0, "apsetmac", "<mac>", "Set Soft Access point MAC address" },
{ 1, "Access point" },
{ 1, "Access point", NULL, NULL },
{ 0, "apconfig", "<enable> [<ssid> <pass> <enc> <ch>]", "Configure Soft Access point" },
{ 0, "apliststa", "", "List stations connected to access point" },
{ 0, "apquitsta", "<mac>", "Disconnect station for Soft access point" },
{ 1, "Hostname" },
{ 1, "Hostname", NULL, NULL },
{ 0, "hnset", "<hostname>", "Set station hostname" },
{ 0, "hnget", "", "Get station hostname" },
{ 1, "Misc" },
{ 1, "Misc", NULL, NULL },
{ 0, "ping", "<host>", "Ping domain or IP address"},
{ 1, "Separate threads" },
{ 1, "Separate threads", NULL, NULL },
{ 0, "netconn_client", "", "Start netconn client thread"},
{ 0, "netconn_server", "", "Start netconn server thread"},
{ 0, "mqtt_client_api", "", "Start mqtt client API thread"},
Expand Down Expand Up @@ -155,8 +155,7 @@ static uint8_t
parse_num_u64(char** str, uint64_t* out) {
uint64_t r, num = 0;
char* s = *str;
char c;
uint8_t is_quote = 0;
unsigned char c;

*out = 0;
for (; s != NULL && *s != '\0' && *s == ' '; ++s) {}
Expand Down Expand Up @@ -233,6 +232,8 @@ input_thread(void* arg) {

#define IS_LINE(s) (strncmp(buff, (s), sizeof(s) - 1) == 0)

LWESP_UNUSED(arg);

/* Notify user */
safeprintf("Start by writing commands..\r\n");

Expand Down Expand Up @@ -361,6 +362,10 @@ main_thread(void* arg) {
char hn[10];
uint32_t ping_time;

LWESP_UNUSED(hn);
LWESP_UNUSED(arg);
LWESP_UNUSED(ping_time);

/* Init ESP library */
lwesp_init(lwesp_evt, 1);
if (0) {
Expand Down Expand Up @@ -560,59 +565,3 @@ lwesp_evt(lwesp_evt_t* evt) {
}
return lwespOK;
}

static lwespr_t
lwesp_conn_evt(lwesp_evt_t* evt) {
static char data[] = "test data string\r\n";
lwesp_conn_p conn;

conn = lwesp_conn_get_from_evt(evt);

switch (evt->type) {
case LWESP_EVT_CONN_ACTIVE: {
safeprintf("Connection active!\r\n");
safeprintf("Send API call: %d\r\n", (int)lwesp_conn_send(conn, data, sizeof(data) - 1, NULL, 0));
safeprintf("Send API call: %d\r\n", (int)lwesp_conn_send(conn, data, sizeof(data) - 1, NULL, 0));
safeprintf("Send API call: %d\r\n", (int)lwesp_conn_send(conn, data, sizeof(data) - 1, NULL, 0));
safeprintf("Close API call: %d\r\n", (int)lwesp_conn_close(conn, 0));
safeprintf("Send API call: %d\r\n", (int)lwesp_conn_send(conn, data, sizeof(data) - 1, NULL, 0));
safeprintf("Close API call: %d\r\n", (int)lwesp_conn_close(conn, 0));

/*
lwesp_conn_send(conn, data, sizeof(data) - 1, NULL, 0);
lwesp_conn_send(conn, data, sizeof(data) - 1, NULL, 0);
*/
break;
}
case LWESP_EVT_CONN_SEND: {
lwespr_t res = lwesp_evt_conn_send_get_result(evt);
if (res == lwespOK) {
safeprintf("Connection data sent!\r\n");
} else {
safeprintf("Connect data send error!\r\n");
}
break;
}
case LWESP_EVT_CONN_RECV: {
lwesp_pbuf_p pbuf = lwesp_evt_conn_recv_get_buff(evt);
lwesp_conn_p conn = lwesp_evt_conn_recv_get_conn(evt);
safeprintf("\r\nConnection data received: %d / %d bytes\r\n",
(int)lwesp_pbuf_length(pbuf, 1),
(int)lwesp_conn_get_total_recved_count(conn)
);
lwesp_conn_recved(conn, pbuf);
break;
}
case LWESP_EVT_CONN_CLOSE: {
safeprintf("Connection closed!\r\n");
//lwesp_conn_start(NULL, LWESP_CONN_TYPE_TCP, "majerle.eu", 80, NULL, lwesp_conn_evt, 0);
break;
}
case LWESP_EVT_CONN_ERROR: {
safeprintf("Connection error!\r\n");
break;
}
default: break;
}
return lwespOK;
}
4 changes: 2 additions & 2 deletions lwesp/src/apps/cayenne/lwesp_cayenne.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,8 @@ prv_mqtt_client_evt_cb(lwesp_mqtt_client_p client, lwesp_mqtt_evt_t* evt) {
size_t payload_len = lwesp_mqtt_client_evt_publish_recv_get_payload_len(client, evt);

LWESP_DEBUGF(LWESP_CFG_DBG_CAYENNE_TRACE, "[LWESP CAYENNE] Publish rcved\r\n");
LWESP_DEBUGF(LWESP_CFG_DBG_CAYENNE_TRACE, "[LWESP CAYENNE] Publish rcv topic: %.*s\r\n", (int)topic_len, (const void*)topic);
LWESP_DEBUGF(LWESP_CFG_DBG_CAYENNE_TRACE, "[LWESP CAYENNE] Publish rcv data : %.*s\r\n", (int)payload_len, (const void*)payload);
LWESP_DEBUGF(LWESP_CFG_DBG_CAYENNE_TRACE, "[LWESP CAYENNE] Publish rcv topic: %.*s\r\n", (int)topic_len, (char*)topic);
LWESP_DEBUGF(LWESP_CFG_DBG_CAYENNE_TRACE, "[LWESP CAYENNE] Publish rcv data : %.*s\r\n", (int)payload_len, (char*)payload);

/* Try to parse received topic and respective payload */
if (lwesp_cayenne_parse_topic(c, topic, topic_len) == lwespOK
Expand Down
2 changes: 2 additions & 0 deletions lwesp/src/apps/http_server/lwesp_http_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,8 @@ static void
send_response(http_state_t* hs, uint8_t ft) {
uint8_t close = 0;

LWESP_UNUSED(ft);

if (!hs->process_resp || /* Not yet ready to process response? */
(hs->written_total > 0 && hs->written_total != hs->sent_total)) { /* Did we wrote something but didn't send yet? */
return;
Expand Down
2 changes: 2 additions & 0 deletions lwesp/src/apps/mqtt/lwesp_mqtt_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,8 @@ prv_mqtt_closed_cb(lwesp_mqtt_client_p client, lwespr_t res, uint8_t forced) {
lwesp_mqtt_state_t state = client->conn_state;
lwesp_mqtt_request_t* request;

LWESP_UNUSED(res);

/*
* Call user function only if connection was closed
* when we are connected or in disconnecting mode
Expand Down
5 changes: 4 additions & 1 deletion lwesp/src/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
* Author: Miha CESNIK <>
* Version: v1.1.2-dev
*/

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include "cli/cli.h"
#include "lwesp/lwesp_private.h"

static cli_commands_t cli_command_table[CLI_MAX_MODULES];
static size_t num_of_modules;
Expand Down Expand Up @@ -205,6 +205,9 @@ static void
cli_list(cli_printf cliprintf, int argc, char** argv) {
uint32_t module_index, command_index;

LWESP_UNUSED(argc);
LWESP_UNUSED(argv);

cliprintf("%-20s%s"CLI_NL, "Command", "Description");
cliprintf("-----------------------------------------------------------"CLI_NL);

Expand Down
6 changes: 3 additions & 3 deletions lwesp/src/include/lwesp/lwesp_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@ extern lwesp_t esp;
#define LWESP_MSG_VAR_DEFINE(name) lwesp_msg_t* name
#define LWESP_MSG_VAR_ALLOC(name, blocking) do {\
(name) = lwesp_mem_malloc(sizeof(*(name))); \
LWESP_DEBUGW(LWESP_CFG_DBG_VAR | LWESP_DBG_TYPE_TRACE, (name) != NULL, "[MSG VAR] Allocated %d bytes at %p\r\n", sizeof(*(name)), (name)); \
LWESP_DEBUGW(LWESP_CFG_DBG_VAR | LWESP_DBG_TYPE_TRACE, (name) == NULL, "[MSG VAR] Error allocating %d bytes\r\n", sizeof(*(name))); \
LWESP_DEBUGW(LWESP_CFG_DBG_VAR | LWESP_DBG_TYPE_TRACE, (name) != NULL, "[MSG VAR] Allocated %d bytes at %p\r\n", (int)sizeof(*(name)), (void *)(name)); \
LWESP_DEBUGW(LWESP_CFG_DBG_VAR | LWESP_DBG_TYPE_TRACE, (name) == NULL, "[MSG VAR] Error allocating %d bytes\r\n", (int)sizeof(*(name))); \
if ((name) == NULL) { \
return lwespERRMEM; \
} \
Expand All @@ -624,7 +624,7 @@ extern lwesp_t esp;
} while (0)
#define LWESP_MSG_VAR_REF(name) (*(name))
#define LWESP_MSG_VAR_FREE(name) do {\
LWESP_DEBUGF(LWESP_CFG_DBG_VAR | LWESP_DBG_TYPE_TRACE, "[MSG VAR] Free memory: %p\r\n", (name)); \
LWESP_DEBUGF(LWESP_CFG_DBG_VAR | LWESP_DBG_TYPE_TRACE, "[MSG VAR] Free memory: %p\r\n", (void *)(name)); \
if (lwesp_sys_sem_isvalid(&((name)->sem))) { \
lwesp_sys_sem_delete(&((name)->sem)); \
lwesp_sys_sem_invalid(&((name)->sem)); \
Expand Down
31 changes: 18 additions & 13 deletions lwesp/src/lwesp/lwesp_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* \param[in] arg: Timeout callback custom argument
*/
static void
conn_timeout_cb(void* arg) {
prv_conn_timeout_cb(void* arg) {
lwesp_conn_p conn = arg; /* Argument is actual connection */

if (conn->status.f.active) { /* Handle only active connections */
Expand All @@ -68,7 +68,7 @@ conn_timeout_cb(void* arg) {

lwespi_conn_start_timeout(conn); /* Schedule new timeout */
LWESP_DEBUGF(LWESP_CFG_DBG_CONN | LWESP_DBG_TYPE_TRACE,
"[LWESP CONN] Poll event: %p\r\n", conn);
"[LWESP CONN] Poll event: %p\r\n", (void *)conn);
}

#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
Expand All @@ -82,7 +82,7 @@ conn_timeout_cb(void* arg) {
*/
void
lwespi_conn_start_timeout(lwesp_conn_p conn) {
lwesp_timeout_add(LWESP_CFG_CONN_POLL_INTERVAL, conn_timeout_cb, conn); /* Add connection timeout */
lwesp_timeout_add(LWESP_CFG_CONN_POLL_INTERVAL, prv_conn_timeout_cb, conn); /* Add connection timeout */
}

#if LWESP_CFG_CONN_MANUAL_TCP_RECEIVE
Expand All @@ -93,9 +93,11 @@ lwespi_conn_start_timeout(lwesp_conn_p conn) {
* \param[in] arg: Custom user argument
*/
static void
manual_tcp_read_data_evt_fn(lwespr_t res, void* arg) {
prv_manual_tcp_read_data_evt_fn(lwespr_t res, void* arg) {
lwesp_conn_p conn = arg;

LWESP_UNUSED(res);

conn->status.f.receive_is_command_queued = 0;
lwespi_conn_manual_tcp_try_read_data(conn);
}
Expand Down Expand Up @@ -127,7 +129,7 @@ lwespi_conn_manual_tcp_try_read_data(lwesp_conn_p conn) {
}

LWESP_MSG_VAR_ALLOC(msg, blocking); /* Allocate first, will return on failure */
LWESP_MSG_VAR_SET_EVT(msg, manual_tcp_read_data_evt_fn, conn); /* Set event callback function */
LWESP_MSG_VAR_SET_EVT(msg, prv_manual_tcp_read_data_evt_fn, conn); /* Set event callback function */
LWESP_MSG_VAR_REF(msg).cmd_def = LWESP_CMD_TCPIP_CIPRECVDATA;
LWESP_MSG_VAR_REF(msg).cmd = LWESP_CMD_TCPIP_CIPRECVLEN;
LWESP_MSG_VAR_REF(msg).msg.ciprecvdata.len = 0; /* Filled after RECVLEN received */
Expand All @@ -147,7 +149,10 @@ lwespi_conn_manual_tcp_try_read_data(lwesp_conn_p conn) {
* \param[in] arg: Custom user argument
*/
static void
check_available_rx_data_evt_fn(lwespr_t res, void* arg) {
prv_check_available_rx_data_evt_fn(lwespr_t res, void* arg) {
LWESP_UNUSED(arg);
LWESP_UNUSED(res);

/* Try to read data if possible */
for (size_t i = 0; i < LWESP_CFG_MAX_CONNS; ++i) {
lwespi_conn_manual_tcp_try_read_data(&esp.m.conns[i]);
Expand All @@ -163,7 +168,7 @@ lwespi_conn_check_available_rx_data(void) {
LWESP_MSG_VAR_DEFINE(msg);

LWESP_MSG_VAR_ALLOC(msg, 0); /* Allocate first, will return on failure */
LWESP_MSG_VAR_SET_EVT(msg, check_available_rx_data_evt_fn, NULL); /* Set event callback function */
LWESP_MSG_VAR_SET_EVT(msg, prv_check_available_rx_data_evt_fn, NULL); /* Set event callback function */
LWESP_MSG_VAR_REF(msg).cmd_def = LWESP_CMD_TCPIP_CIPRECVLEN;

return lwespi_send_msg_to_producer_mbox(&LWESP_MSG_VAR_REF(msg), lwespi_initiate_cmd, 1000);
Expand Down Expand Up @@ -199,7 +204,7 @@ lwespi_conn_get_val_id(lwesp_conn_p conn) {
* \return \ref lwespOK on success, member of \ref lwespr_t enumeration otherwise
*/
static lwespr_t
conn_send(lwesp_conn_p conn, const lwesp_ip_t* const ip, lwesp_port_t port, const void* data,
prv_conn_send(lwesp_conn_p conn, const lwesp_ip_t* const ip, lwesp_port_t port, const void* data,
size_t btw, size_t* const bw, uint8_t fau, const uint32_t blocking) {
LWESP_MSG_VAR_DEFINE(msg);

Expand Down Expand Up @@ -254,7 +259,7 @@ flush_buff(lwesp_conn_p conn) {
* simply free the memory and stop execution
*/
if (conn->buff.ptr > 0) { /* Anything to send at the moment? */
res = conn_send(conn, NULL, 0, conn->buff.buff, conn->buff.ptr, NULL, 1, 0);
res = prv_conn_send(conn, NULL, 0, conn->buff.buff, conn->buff.ptr, NULL, 1, 0);
} else {
res = lwespERR;
}
Expand Down Expand Up @@ -401,7 +406,7 @@ lwesp_conn_sendto(lwesp_conn_p conn, const lwesp_ip_t* const ip, lwesp_port_t po
LWESP_ASSERT("conn != NULL", conn != NULL);

flush_buff(conn); /* Flush currently written memory if exists */
return conn_send(conn, ip, port, data, btw, bw, 0, blocking);
return prv_conn_send(conn, ip, port, data, btw, bw, 0, blocking);
}

/**
Expand Down Expand Up @@ -438,7 +443,7 @@ lwesp_conn_send(lwesp_conn_p conn, const void* data, size_t btw, size_t* const b
lwesp_core_unlock();
res = flush_buff(conn); /* Flush currently written memory if exists */
if (btw > 0) { /* Check for remaining data */
res = conn_send(conn, NULL, 0, d, btw, bw, 0, blocking);
res = prv_conn_send(conn, NULL, 0, d, btw, bw, 0, blocking);
}
return res;
}
Expand Down Expand Up @@ -687,7 +692,7 @@ lwesp_conn_write(lwesp_conn_p conn, const void* data, size_t btw, uint8_t flush,
/* Step 1.1 */
if (conn->buff.ptr == conn->buff.len || flush) {
/* Try to send to processing queue in non-blocking way */
if (conn_send(conn, NULL, 0, conn->buff.buff, conn->buff.ptr, NULL, 1, 0) != lwespOK) {
if (prv_conn_send(conn, NULL, 0, conn->buff.buff, conn->buff.ptr, NULL, 1, 0) != lwespOK) {
LWESP_DEBUGF(LWESP_CFG_DBG_CONN | LWESP_DBG_TYPE_TRACE,
"[LWESP CONN] Free write buffer: %p\r\n", conn->buff.buff);
lwesp_mem_free_s((void**)&conn->buff.buff);
Expand All @@ -702,7 +707,7 @@ lwesp_conn_write(lwesp_conn_p conn, const void* data, size_t btw, uint8_t flush,
buff = lwesp_mem_malloc(sizeof(*buff) * LWESP_CFG_CONN_MAX_DATA_LEN);
if (buff != NULL) {
LWESP_MEMCPY(buff, d, LWESP_CFG_CONN_MAX_DATA_LEN); /* Copy data to buffer */
if (conn_send(conn, NULL, 0, buff, LWESP_CFG_CONN_MAX_DATA_LEN, NULL, 1, 0) != lwespOK) {
if (prv_conn_send(conn, NULL, 0, buff, LWESP_CFG_CONN_MAX_DATA_LEN, NULL, 1, 0) != lwespOK) {
LWESP_DEBUGF(LWESP_CFG_DBG_CONN | LWESP_DBG_TYPE_TRACE,
"[LWESP CONN] Free write buffer: %p\r\n", (void*)buff);
lwesp_mem_free_s((void**)&buff);
Expand Down
8 changes: 4 additions & 4 deletions lwesp/src/lwesp/lwesp_pbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ lwesp_pbuf_new(size_t len) {
LWESP_DEBUGW(LWESP_CFG_DBG_PBUF | LWESP_DBG_TYPE_TRACE, p == NULL,
"[LWESP PBUF] Failed to allocate %d bytes\r\n", (int)len);
LWESP_DEBUGW(LWESP_CFG_DBG_PBUF | LWESP_DBG_TYPE_TRACE, p != NULL,
"[LWESP PBUF] Allocated %d bytes on %p\r\n", (int)len, p);
"[LWESP PBUF] Allocated %d bytes on %p\r\n", (int)len, (void *)p);
if (p != NULL) {
p->next = NULL; /* No next element in chain */
p->tot_len = len; /* Set total length of pbuf chain */
Expand Down Expand Up @@ -109,7 +109,7 @@ lwesp_pbuf_free(lwesp_pbuf_p pbuf) {
lwesp_core_unlock();
if (ref == 0) { /* Did we reach 0 and are ready to free it? */
LWESP_DEBUGF(LWESP_CFG_DBG_PBUF | LWESP_DBG_TYPE_TRACE,
"[LWESP PBUF] Deallocating %p with len/tot_len: %d/%d\r\n", p, (int)p->len, (int)p->tot_len);
"[LWESP PBUF] Deallocating %p with len/tot_len: %d/%d\r\n", (void *)p, (int)p->len, (int)p->tot_len);
pn = p->next; /* Save next entry */
lwesp_mem_free_s((void**)&p); /* Free memory for pbuf */
p = pn; /* Restore with next entry */
Expand Down Expand Up @@ -561,11 +561,11 @@ void
lwesp_pbuf_dump(lwesp_pbuf_p p, uint8_t seq) {
if (p != NULL) {
LWESP_DEBUGF(LWESP_CFG_DBG_PBUF | LWESP_DBG_TYPE_TRACE,
"[LWESP PBUF] Dump start: %p\r\n", p);
"[LWESP PBUF] Dump start: %p\r\n", (void *)p);
for (; p != NULL; p = p->next) {
LWESP_DEBUGF(LWESP_CFG_DBG_PBUF | LWESP_DBG_TYPE_TRACE,
"[LWESP PBUF] Dump %p; ref: %d; len: %d; tot_len: %d, next: %p\r\n",
p, (int)p->ref, (int)p->len, (int)p->tot_len, p->next);
(void *)p, (int)p->ref, (int)p->len, (int)p->tot_len, (void *)p->next);
if (!seq) {
break;
}
Expand Down

0 comments on commit e38a406

Please sign in to comment.