Improve RTU handling

This commit is contained in:
Daniel Öster 2023-02-27 13:12:18 -08:00 committed by GitHub
parent 2f7e5fb1fa
commit 9c694058cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 819 additions and 822 deletions

View file

@ -9,7 +9,7 @@
#include <soc/uart_struct.h>
#endif
#include <vector>
#include "HardwareSerial.h"
#include "Stream.h"
#include "ModbusTypeDefs.h"
#include <functional>
@ -47,11 +47,17 @@ public:
static void addCRC(ModbusMessage& raw);
// calculateInterval: determine the minimal gap time between messages
static uint32_t calculateInterval(HardwareSerial& s, uint32_t overwrite);
static uint32_t calculateInterval(uint32_t baudRate);
// RTSauto: dummy callback for auto half duplex RS485 boards
inline static void RTSauto(bool level) { return; } // NOLINT
// Necessary preparations for a HardwareSerial
static void prepareHardwareSerial(HardwareSerial& s, uint16_t bufferSize = 260) {
s.setRxBufferSize(bufferSize);
s.setTxBufferSize(bufferSize);
}
protected:
// Printable characters for ASCII protocol: 012345678ABCDEF
static const char ASCIIwrite[];
@ -59,15 +65,12 @@ protected:
RTUutils() = delete;
// UARTinit: modify the UART FIFO copy trigger threshold
static int UARTinit(HardwareSerial& serial, int thresholdBytes = 1);
// receive: get a Modbus message from serial, maintaining timeouts etc.
static ModbusMessage receive(HardwareSerial& serial, uint32_t timeout, unsigned long& lastMicros, uint32_t interval, bool ASCIImode, bool skipLeadingZeroBytes = false);
static ModbusMessage receive(uint8_t caller, Stream& serial, uint32_t timeout, unsigned long& lastMicros, uint32_t interval, bool ASCIImode, bool skipLeadingZeroBytes = false);
// send: send a Modbus message in either format (ModbusMessage or data/len)
static void send(HardwareSerial& serial, unsigned long& lastMicros, uint32_t interval, RTScallback r, const uint8_t *data, uint16_t len, bool ASCIImode);
static void send(HardwareSerial& serial, unsigned long& lastMicros, uint32_t interval, RTScallback r, ModbusMessage raw, bool ASCIImode);
static void send(Stream& serial, unsigned long& lastMicros, uint32_t interval, RTScallback r, const uint8_t *data, uint16_t len, bool ASCIImode);
static void send(Stream& serial, unsigned long& lastMicros, uint32_t interval, RTScallback r, ModbusMessage raw, bool ASCIImode);
};
#endif