diff options
Diffstat (limited to 'src/modbus.h')
| -rw-r--r-- | src/modbus.h | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/modbus.h b/src/modbus.h index 32ca596..f7553dd 100644 --- a/src/modbus.h +++ b/src/modbus.h @@ -1,8 +1,8 @@ #ifndef _MODBUS_H #define _MODBUS_H -#include "stm32f1xx_hal.h" -#include "string.h" +#include <string.h> +#include <inttypes.h> #define read_holding_regs 0x03 #define read_input_regs 0x04 @@ -12,26 +12,29 @@ #define highByte(w) ((uint8_t) ((w) >> 8)) #define word(h, l) ((h << 8) | l) -#define MODBUS_TIMEOUT 50 +/* #define MODBUS_TIMEOUT 50 */ #define MAX_BUFSIZE 64 typedef struct { uint8_t slave_id; uint16_t response_buffer[MAX_BUFSIZE]; uint8_t rbuf_len; - UART_HandleTypeDef modbus_uart; + uint8_t modbus_timeout; + void* modbus_uart; } modbus_slave_device; typedef enum { MB_OK = 0x0, - MB_SLAVE_ID_ERR = 0x1, - MB_FUNC_ERR = 0x2, - MB_CRC_ERR = 0x3, - MB_UART_ERR = 0x4, - MB_BUSY_ERR = 0x5, - MB_TIMEOUT_ERR = 0x6 + MB_UART_ERR_1 = 0x1, + MB_UART_ERR_2 = 0x2, + MB_UART_ERR_3 = 0x3, + MB_SLAVE_ID_ERR = 0x4, + MB_FUNC_ERR = 0x5, + MB_CRC_ERR = 0x6 } MB_StatusTypeDef; +extern MB_StatusTypeDef (*MB_UART_Tx)(void*, uint16_t*, uint8_t*, uint8_t*); +extern MB_StatusTypeDef (*MB_UART_Rx)(void*, uint16_t*, uint8_t*, uint8_t*); uint16_t crc16_update(uint16_t crc, uint8_t a); MB_StatusTypeDef modbus_transaction (uint8_t func, modbus_slave_device *device, |
