Fixes to integer types
This commit is contained in:
parent
76f28fefb9
commit
83fb04392b
@ -170,11 +170,11 @@ void close_server() {
|
|||||||
|
|
||||||
// Read/write/sleep platform functions
|
// Read/write/sleep platform functions
|
||||||
|
|
||||||
int read_fd_linux(uint8_t* buf, uint32_t count, int32_t timeout_ms, void* arg) {
|
int32_t read_fd_linux(uint8_t* buf, uint16_t count, int32_t timeout_ms, void* arg) {
|
||||||
int fd = *(int*) arg;
|
int fd = *(int*) arg;
|
||||||
|
|
||||||
int32_t total = 0;
|
uint16_t total = 0;
|
||||||
while (total != (int32_t) count) {
|
while (total != count) {
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_SET(fd, &rfds);
|
FD_SET(fd, &rfds);
|
||||||
@ -200,7 +200,7 @@ int read_fd_linux(uint8_t* buf, uint32_t count, int32_t timeout_ms, void* arg) {
|
|||||||
else if (r < 0)
|
else if (r < 0)
|
||||||
return -1;
|
return -1;
|
||||||
else {
|
else {
|
||||||
total += (int32_t) r;
|
total += r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -211,11 +211,11 @@ int read_fd_linux(uint8_t* buf, uint32_t count, int32_t timeout_ms, void* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t write_fd_linux(const uint8_t* buf, uint32_t count, int32_t timeout_ms, void* arg) {
|
int32_t write_fd_linux(const uint8_t* buf, uint16_t count, int32_t timeout_ms, void* arg) {
|
||||||
int fd = *(int*) arg;
|
int fd = *(int*) arg;
|
||||||
|
|
||||||
int32_t total = 0;
|
uint16_t total = 0;
|
||||||
while (total != (int32_t) count) {
|
while (total != count) {
|
||||||
fd_set wfds;
|
fd_set wfds;
|
||||||
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
||||||
FD_SET(fd, &wfds);
|
FD_SET(fd, &wfds);
|
||||||
|
|||||||
25
nanomodbus.c
25
nanomodbus.c
@ -191,13 +191,14 @@ static uint16_t crc_calc(const uint8_t* data, uint32_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static nmbs_error recv(nmbs_t* nmbs, uint32_t count) {
|
static nmbs_error recv(nmbs_t* nmbs, uint16_t count) {
|
||||||
int ret = nmbs->platform.read(nmbs->msg.buf + nmbs->msg.buf_idx, count, nmbs->byte_timeout_ms, nmbs->platform.arg);
|
int32_t ret =
|
||||||
|
nmbs->platform.read(nmbs->msg.buf + nmbs->msg.buf_idx, count, nmbs->byte_timeout_ms, nmbs->platform.arg);
|
||||||
|
|
||||||
if (ret == (int) count)
|
if (ret == count)
|
||||||
return NMBS_ERROR_NONE;
|
return NMBS_ERROR_NONE;
|
||||||
|
|
||||||
if (ret < (int) count) {
|
if (ret < count) {
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return NMBS_ERROR_TRANSPORT;
|
return NMBS_ERROR_TRANSPORT;
|
||||||
|
|
||||||
@ -208,13 +209,13 @@ static nmbs_error recv(nmbs_t* nmbs, uint32_t count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static nmbs_error send(nmbs_t* nmbs, uint32_t count) {
|
static nmbs_error send(nmbs_t* nmbs, uint16_t count) {
|
||||||
int ret = nmbs->platform.write(nmbs->msg.buf, count, nmbs->byte_timeout_ms, nmbs->platform.arg);
|
int32_t ret = nmbs->platform.write(nmbs->msg.buf, count, nmbs->byte_timeout_ms, nmbs->platform.arg);
|
||||||
|
|
||||||
if (ret == (int) count)
|
if (ret == count)
|
||||||
return NMBS_ERROR_NONE;
|
return NMBS_ERROR_NONE;
|
||||||
|
|
||||||
if (ret < (int) count) {
|
if (ret < count) {
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return NMBS_ERROR_TRANSPORT;
|
return NMBS_ERROR_TRANSPORT;
|
||||||
|
|
||||||
@ -1237,12 +1238,12 @@ nmbs_error nmbs_write_multiple_registers(nmbs_t* nmbs, uint16_t address, uint16_
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
nmbs_error nmbs_send_raw_pdu(nmbs_t* nmbs, uint8_t fc, const void* data, uint32_t data_len) {
|
nmbs_error nmbs_send_raw_pdu(nmbs_t* nmbs, uint8_t fc, const void* data, uint16_t data_len) {
|
||||||
msg_state_req(nmbs, fc);
|
msg_state_req(nmbs, fc);
|
||||||
send_msg_header(nmbs, data_len);
|
send_msg_header(nmbs, data_len);
|
||||||
|
|
||||||
DEBUG("raw ");
|
DEBUG("raw ");
|
||||||
for (uint32_t i = 0; i < data_len; i++) {
|
for (uint16_t i = 0; i < data_len; i++) {
|
||||||
put_1(nmbs, ((uint8_t*) (data))[i]);
|
put_1(nmbs, ((uint8_t*) (data))[i]);
|
||||||
DEBUG("%d ", ((uint8_t*) (data))[i]);
|
DEBUG("%d ", ((uint8_t*) (data))[i]);
|
||||||
}
|
}
|
||||||
@ -1251,7 +1252,7 @@ nmbs_error nmbs_send_raw_pdu(nmbs_t* nmbs, uint8_t fc, const void* data, uint32_
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nmbs_error nmbs_receive_raw_pdu_response(nmbs_t* nmbs, void* data_out, uint32_t data_out_len) {
|
nmbs_error nmbs_receive_raw_pdu_response(nmbs_t* nmbs, void* data_out, uint16_t data_out_len) {
|
||||||
nmbs_error err = recv_res_header(nmbs);
|
nmbs_error err = recv_res_header(nmbs);
|
||||||
if (err != NMBS_ERROR_NONE)
|
if (err != NMBS_ERROR_NONE)
|
||||||
return err;
|
return err;
|
||||||
@ -1260,7 +1261,7 @@ nmbs_error nmbs_receive_raw_pdu_response(nmbs_t* nmbs, void* data_out, uint32_t
|
|||||||
if (err != NMBS_ERROR_NONE)
|
if (err != NMBS_ERROR_NONE)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
for (uint32_t i = 0; i < data_out_len; i++) {
|
for (uint16_t i = 0; i < data_out_len; i++) {
|
||||||
((uint8_t*) (data_out))[i] = get_1(nmbs);
|
((uint8_t*) (data_out))[i] = get_1(nmbs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -131,9 +131,9 @@ typedef enum nmbs_transport {
|
|||||||
*/
|
*/
|
||||||
typedef struct nmbs_platform_conf {
|
typedef struct nmbs_platform_conf {
|
||||||
nmbs_transport transport; /*!< Transport type */
|
nmbs_transport transport; /*!< Transport type */
|
||||||
int32_t (*read)(uint8_t* buf, uint32_t count, int32_t byte_timeout_ms,
|
int32_t (*read)(uint8_t* buf, uint16_t count, int32_t byte_timeout_ms,
|
||||||
void* arg); /*!< Bytes read transport function pointer */
|
void* arg); /*!< Bytes read transport function pointer */
|
||||||
int32_t (*write)(const uint8_t* buf, uint32_t count, int32_t byte_timeout_ms,
|
int32_t (*write)(const uint8_t* buf, uint16_t count, int32_t byte_timeout_ms,
|
||||||
void* arg); /*!< Bytes write transport function pointer */
|
void* arg); /*!< Bytes write transport function pointer */
|
||||||
void* arg; /*!< User data, will be passed to functions above */
|
void* arg; /*!< User data, will be passed to functions above */
|
||||||
} nmbs_platform_conf;
|
} nmbs_platform_conf;
|
||||||
@ -352,7 +352,7 @@ nmbs_error nmbs_write_multiple_registers(nmbs_t* nmbs, uint16_t address, uint16_
|
|||||||
*
|
*
|
||||||
* @return NMBS_ERROR_NONE if successful, other errors otherwise.
|
* @return NMBS_ERROR_NONE if successful, other errors otherwise.
|
||||||
*/
|
*/
|
||||||
nmbs_error nmbs_send_raw_pdu(nmbs_t* nmbs, uint8_t fc, const void* data, uint32_t data_len);
|
nmbs_error nmbs_send_raw_pdu(nmbs_t* nmbs, uint8_t fc, const void* data, uint16_t data_len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NMBS_CLIENT_DISABLED
|
#ifndef NMBS_CLIENT_DISABLED
|
||||||
@ -363,7 +363,7 @@ nmbs_error nmbs_send_raw_pdu(nmbs_t* nmbs, uint8_t fc, const void* data, uint32_
|
|||||||
*
|
*
|
||||||
* @return NMBS_ERROR_NONE if successful, other errors otherwise.
|
* @return NMBS_ERROR_NONE if successful, other errors otherwise.
|
||||||
*/
|
*/
|
||||||
nmbs_error nmbs_receive_raw_pdu_response(nmbs_t* nmbs, void* data_out, uint32_t data_out_len);
|
nmbs_error nmbs_receive_raw_pdu_response(nmbs_t* nmbs, void* data_out, uint16_t data_out_len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NMBS_STRERROR_DISABLED
|
#ifndef NMBS_STRERROR_DISABLED
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#define UNUSED_PARAM(x) ((x) = (x))
|
#define UNUSED_PARAM(x) ((x) = (x))
|
||||||
|
|
||||||
|
|
||||||
int read_empty(uint8_t* b, uint32_t count, int32_t timeout, void* arg) {
|
int32_t read_empty(uint8_t* b, uint16_t count, int32_t timeout, void* arg) {
|
||||||
UNUSED_PARAM(b);
|
UNUSED_PARAM(b);
|
||||||
UNUSED_PARAM(count);
|
UNUSED_PARAM(count);
|
||||||
UNUSED_PARAM(timeout);
|
UNUSED_PARAM(timeout);
|
||||||
@ -14,7 +14,7 @@ int read_empty(uint8_t* b, uint32_t count, int32_t timeout, void* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int write_empty(const uint8_t* b, uint32_t count, int32_t timeout, void* arg) {
|
int32_t write_empty(const uint8_t* b, uint16_t count, int32_t timeout, void* arg) {
|
||||||
UNUSED_PARAM(b);
|
UNUSED_PARAM(b);
|
||||||
UNUSED_PARAM(count);
|
UNUSED_PARAM(count);
|
||||||
UNUSED_PARAM(timeout);
|
UNUSED_PARAM(timeout);
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
int read_empty(uint8_t* b, uint32_t count, int32_t timeout, void* arg) {
|
int32_t read_empty(uint8_t* b, uint16_t count, int32_t timeout, void* arg) {
|
||||||
UNUSED_PARAM(b);
|
UNUSED_PARAM(b);
|
||||||
UNUSED_PARAM(count);
|
UNUSED_PARAM(count);
|
||||||
UNUSED_PARAM(timeout);
|
UNUSED_PARAM(timeout);
|
||||||
@ -14,7 +14,7 @@ int read_empty(uint8_t* b, uint32_t count, int32_t timeout, void* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int write_empty(const uint8_t* b, uint32_t count, int32_t timeout, void* arg) {
|
int32_t write_empty(const uint8_t* b, uint16_t count, int32_t timeout, void* arg) {
|
||||||
UNUSED_PARAM(b);
|
UNUSED_PARAM(b);
|
||||||
UNUSED_PARAM(count);
|
UNUSED_PARAM(count);
|
||||||
UNUSED_PARAM(timeout);
|
UNUSED_PARAM(timeout);
|
||||||
@ -73,7 +73,7 @@ void test_server_create(nmbs_transport transport) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int read_timeout(uint8_t* buf, uint32_t count, int32_t timeout, void* arg) {
|
int32_t read_timeout(uint8_t* buf, uint16_t count, int32_t timeout, void* arg) {
|
||||||
UNUSED_PARAM(buf);
|
UNUSED_PARAM(buf);
|
||||||
UNUSED_PARAM(count);
|
UNUSED_PARAM(count);
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
@ -82,7 +82,7 @@ int read_timeout(uint8_t* buf, uint32_t count, int32_t timeout, void* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Timeouts on the second read
|
// Timeouts on the second read
|
||||||
int read_timeout_second(uint8_t* buf, uint32_t count, int32_t timeout, void* arg) {
|
int32_t read_timeout_second(uint8_t* buf, uint16_t count, int32_t timeout, void* arg) {
|
||||||
UNUSED_PARAM(count);
|
UNUSED_PARAM(count);
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
|
|
||||||
|
|||||||
@ -47,12 +47,6 @@ uint64_t now_ms() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void platform_sleep(uint32_t milliseconds, void* arg) {
|
|
||||||
UNUSED_PARAM(arg);
|
|
||||||
usleep(milliseconds * 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void reset_sockets() {
|
void reset_sockets() {
|
||||||
if (sockets[0] != -1)
|
if (sockets[0] != -1)
|
||||||
close(sockets[0]);
|
close(sockets[0]);
|
||||||
@ -64,9 +58,9 @@ void reset_sockets() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t read_fd(int fd, uint8_t* buf, uint32_t count, int32_t timeout_ms) {
|
int32_t read_fd(int fd, uint8_t* buf, uint16_t count, int32_t timeout_ms) {
|
||||||
int32_t total = 0;
|
uint16_t total = 0;
|
||||||
while (total != (int32_t) count) {
|
while (total != count) {
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_SET(fd, &rfds);
|
FD_SET(fd, &rfds);
|
||||||
@ -88,7 +82,7 @@ int32_t read_fd(int fd, uint8_t* buf, uint32_t count, int32_t timeout_ms) {
|
|||||||
if (r <= 0)
|
if (r <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
else {
|
else {
|
||||||
total += (int32_t) r;
|
total += r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -99,9 +93,9 @@ int32_t read_fd(int fd, uint8_t* buf, uint32_t count, int32_t timeout_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int write_fd(int fd, const uint8_t* buf, uint32_t count, int32_t timeout_ms) {
|
int32_t write_fd(int fd, const uint8_t* buf, uint16_t count, int32_t timeout_ms) {
|
||||||
int32_t total = 0;
|
uint16_t total = 0;
|
||||||
while (total != (int32_t) count) {
|
while (total != count) {
|
||||||
fd_set wfds;
|
fd_set wfds;
|
||||||
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
||||||
FD_SET(fd, &wfds);
|
FD_SET(fd, &wfds);
|
||||||
@ -123,7 +117,7 @@ int write_fd(int fd, const uint8_t* buf, uint32_t count, int32_t timeout_ms) {
|
|||||||
if (w <= 0)
|
if (w <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
else {
|
else {
|
||||||
total += (int32_t) w;
|
total += w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -134,25 +128,25 @@ int write_fd(int fd, const uint8_t* buf, uint32_t count, int32_t timeout_ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int read_socket_server(uint8_t* buf, uint32_t count, int32_t timeout_ms, void* arg) {
|
int32_t read_socket_server(uint8_t* buf, uint16_t count, int32_t timeout_ms, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
return read_fd(sockets[0], buf, count, timeout_ms);
|
return read_fd(sockets[0], buf, count, timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int write_socket_server(const uint8_t* buf, uint32_t count, int32_t timeout_ms, void* arg) {
|
int32_t write_socket_server(const uint8_t* buf, uint16_t count, int32_t timeout_ms, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
return write_fd(sockets[0], buf, count, timeout_ms);
|
return write_fd(sockets[0], buf, count, timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int read_socket_client(uint8_t* buf, uint32_t count, int32_t timeout_ms, void* arg) {
|
int32_t read_socket_client(uint8_t* buf, uint16_t count, int32_t timeout_ms, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
return read_fd(sockets[1], buf, count, timeout_ms);
|
return read_fd(sockets[1], buf, count, timeout_ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int write_socket_client(const uint8_t* buf, uint32_t count, int32_t timeout_ms, void* arg) {
|
int32_t write_socket_client(const uint8_t* buf, uint16_t count, int32_t timeout_ms, void* arg) {
|
||||||
UNUSED_PARAM(arg);
|
UNUSED_PARAM(arg);
|
||||||
return write_fd(sockets[1], buf, count, timeout_ms);
|
return write_fd(sockets[1], buf, count, timeout_ms);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#define UNUSED_PARAM(x) ((x) = (x))
|
#define UNUSED_PARAM(x) ((x) = (x))
|
||||||
|
|
||||||
|
|
||||||
int read_empty(uint8_t* b, uint32_t count, int32_t timeout, void* arg) {
|
int32_t read_empty(uint8_t* b, uint16_t count, int32_t timeout, void* arg) {
|
||||||
UNUSED_PARAM(b);
|
UNUSED_PARAM(b);
|
||||||
UNUSED_PARAM(count);
|
UNUSED_PARAM(count);
|
||||||
UNUSED_PARAM(timeout);
|
UNUSED_PARAM(timeout);
|
||||||
@ -14,7 +14,7 @@ int read_empty(uint8_t* b, uint32_t count, int32_t timeout, void* arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int write_empty(const uint8_t* b, uint32_t count, int32_t timeout, void* arg) {
|
int32_t write_empty(const uint8_t* b, uint16_t count, int32_t timeout, void* arg) {
|
||||||
UNUSED_PARAM(b);
|
UNUSED_PARAM(b);
|
||||||
UNUSED_PARAM(count);
|
UNUSED_PARAM(count);
|
||||||
UNUSED_PARAM(timeout);
|
UNUSED_PARAM(timeout);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user