aciodrv: fix build warnings for logging format strings

This commit is contained in:
Will Xyen
2021-03-16 22:06:21 +00:00
committed by Will Xyen
parent 5ae0ed21cd
commit e23661ae45
2 changed files with 22 additions and 20 deletions
+17 -16
View File
@@ -1,5 +1,6 @@
#define LOG_MODULE "aciodrv-device" #define LOG_MODULE "aciodrv-device"
#include <inttypes.h>
#include <string.h> #include <string.h>
#include "aciodrv/device.h" #include "aciodrv/device.h"
@@ -8,6 +9,7 @@
#include "util/hex.h" #include "util/hex.h"
#include "util/log.h" #include "util/log.h"
#include "util/mem.h"
/* Enable to dump all data to the logger */ /* Enable to dump all data to the logger */
//#define AC_IO_MSG_LOG //#define AC_IO_MSG_LOG
@@ -58,7 +60,7 @@ aciodrv_device_log_buffer(struct aciodrv_device_ctx *device, const char *msg, co
char str[4096]; char str[4096];
hex_encode_uc((const void *) buffer, length, str, sizeof(str)); hex_encode_uc((const void *) buffer, length, str, sizeof(str));
log_misc("[%x] %s, length %d: %s", device->fd, msg, length, str); log_misc("[%" PRIXPTR "] %s, length %d: %s", (uintptr_t)device->fd, msg, length, str);
} }
#endif #endif
@@ -69,7 +71,7 @@ static bool aciodrv_device_send(struct aciodrv_device_ctx *device, const uint8_t
uint8_t checksum = 0; uint8_t checksum = 0;
if (length > sizeof(send_buf)) { if (length > sizeof(send_buf)) {
log_warning("[%x] Send buffer overflow", device->fd); log_warning("[%" PRIXPTR "] Send buffer overflow", (uintptr_t)device->fd);
return false; return false;
} }
@@ -104,7 +106,7 @@ static bool aciodrv_device_send(struct aciodrv_device_ctx *device, const uint8_t
#endif #endif
if (aciodrv_port_write(device->fd, send_buf, send_buf_pos) != send_buf_pos) { if (aciodrv_port_write(device->fd, send_buf, send_buf_pos) != send_buf_pos) {
log_warning("[%x] Sending data with length %d failed", device->fd, send_buf_pos); log_warning("[%" PRIXPTR "] Sending data with length %d failed", (uintptr_t)device->fd, send_buf_pos);
return false; return false;
} }
@@ -180,7 +182,7 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu
/* recv_size - 1: omit checksum for checksum calc */ /* recv_size - 1: omit checksum for checksum calc */
if ((recv_size - 1) > max_resp_size) { if ((recv_size - 1) > max_resp_size) {
log_warning("[%x] Expected %d got %d", device->fd, max_resp_size - 6, recv_buf[4]); log_warning("[%" PRIXPTR "] Expected %d got %d", (uintptr_t)device->fd, max_resp_size - 6, recv_buf[4]);
return -1; return -1;
} }
for (int i = 0; i < recv_size - 1; i++) { for (int i = 0; i < recv_size - 1; i++) {
@@ -196,8 +198,8 @@ static int aciodrv_device_receive(struct aciodrv_device_ctx *device, uint8_t *bu
if (checksum != recv_buf[recv_size - 1]) { if (checksum != recv_buf[recv_size - 1]) {
log_warning( log_warning(
"[%x] Invalid message checksum: %02X != %02X", "[%" PRIXPTR "] Invalid message checksum: %02X != %02X",
device->fd, (uintptr_t)device->fd,
checksum, checksum,
recv_buf[recv_size - 1]); recv_buf[recv_size - 1]);
return -1; return -1;
@@ -330,7 +332,7 @@ struct aciodrv_device_ctx *aciodrv_device_open(const char *port_path, int baud)
} }
} }
log_info("Opening ACIO device on [%x]", device->fd); log_info("Opening ACIO device on [%" PRIXPTR "]", (uintptr_t)device->fd);
return device; return device;
} }
@@ -339,7 +341,7 @@ uint8_t aciodrv_device_get_node_count(struct aciodrv_device_ctx *device)
return device->node_count; return device->node_count;
} }
bool aciodrv_device_get_node_product_ident(struct aciodrv_device_ctx *device, uint8_t node_id, char product[4]) bool aciodrv_device_get_node_product_ident(struct aciodrv_device_ctx *device, uint8_t node_id, char product[ACIO_NODE_PRODUCT_CODE_LEN])
{ {
if (device->node_count == 0 || node_id > device->node_count) { if (device->node_count == 0 || node_id > device->node_count) {
return false; return false;
@@ -356,8 +358,8 @@ bool aciodrv_send_and_recv(struct aciodrv_device_ctx *device, struct ac_io_messa
#ifdef AC_IO_MSG_LOG #ifdef AC_IO_MSG_LOG
log_info( log_info(
"[%x] Beginning send on %d: %04x (%d b)", "[%" PRIXPTR "] Beginning send on %d: %04x (%d b)",
device->fd, (uintptr_t)device->fd,
msg->addr, msg->addr,
msg->cmd.code, msg->cmd.code,
send_size); send_size);
@@ -369,7 +371,7 @@ bool aciodrv_send_and_recv(struct aciodrv_device_ctx *device, struct ac_io_messa
uint16_t req_code = msg->cmd.code; uint16_t req_code = msg->cmd.code;
#ifdef AC_IO_MSG_LOG #ifdef AC_IO_MSG_LOG
log_info("[%x] Beginning recv: (%d b)", device->fd, max_resp_size); log_info("[%" PRIXPTR "] Beginning recv: (%d b)", (uintptr_t)device->fd, max_resp_size);
#endif #endif
if (aciodrv_device_receive(device, (uint8_t *) msg, max_resp_size) <= 0) { if (aciodrv_device_receive(device, (uint8_t *) msg, max_resp_size) <= 0) {
return false; return false;
@@ -377,11 +379,10 @@ bool aciodrv_send_and_recv(struct aciodrv_device_ctx *device, struct ac_io_messa
if (req_code != msg->cmd.code) { if (req_code != msg->cmd.code) {
log_warning( log_warning(
"[%x] Received invalid response %04X for request %04X on fd %x", "[%" PRIXPTR "] Received invalid response %04X for request %04X",
device->fd, (uintptr_t)device->fd,
msg->cmd.code, msg->cmd.code,
req_code, req_code);
device->fd);
return false; return false;
} }
@@ -392,7 +393,7 @@ void aciodrv_device_close(struct aciodrv_device_ctx *device)
{ {
log_assert(device); log_assert(device);
log_info("Closing ACIO on [%x]", device->fd); log_info("Closing ACIO on [%" PRIXPTR "]", (uintptr_t)device->fd);
aciodrv_port_close(device->fd); aciodrv_port_close(device->fd);
+5 -4
View File
@@ -1,5 +1,6 @@
#define LOG_MODULE "aciodrv-port" #define LOG_MODULE "aciodrv-port"
#include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
@@ -100,7 +101,7 @@ HANDLE aciodrv_port_open(const char *port_path, int baud)
goto fail; goto fail;
} }
log_info("[%x] Opened ACIO device on %s", port_fd, port_path); log_info("[%" PRIXPTR "] Opened ACIO device on %s", (uintptr_t)port_fd, port_path);
return port_fd; return port_fd;
@@ -122,13 +123,13 @@ int aciodrv_port_read(HANDLE port_fd, void *bytes, int nbytes)
} }
if (!ClearCommError(port_fd, NULL, NULL)) { if (!ClearCommError(port_fd, NULL, NULL)) {
log_warning("[%x] ClearCommError failed", port_fd); log_warning("[%" PRIXPTR "] ClearCommError failed", (uintptr_t)port_fd);
return -1; return -1;
} }
if (!ReadFile(port_fd, bytes, nbytes, &nread, NULL)) { if (!ReadFile(port_fd, bytes, nbytes, &nread, NULL)) {
log_warning("[%x] ReadFile failed: err = %lu", port_fd, GetLastError()); log_warning("[%" PRIXPTR "] ReadFile failed: err = %lu", (uintptr_t)port_fd, GetLastError());
return -1; return -1;
} }
@@ -147,7 +148,7 @@ int aciodrv_port_write(HANDLE port_fd, const void *bytes, int nbytes)
} }
if (!WriteFile(port_fd, bytes, nbytes, &nwrit, NULL)) { if (!WriteFile(port_fd, bytes, nbytes, &nwrit, NULL)) {
log_warning("[%x] WriteFile failed: err = %lu", port_fd, GetLastError()); log_warning("[%" PRIXPTR "] WriteFile failed: err = %lu", (uintptr_t)port_fd, GetLastError());
return -1; return -1;
} }