Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/CoilData.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class CoilData {
void init(bool value = false);

// get size in coils
inline const uint16_t coils() const { return CDsize; }
inline uint16_t coils() const { return CDsize; }

// Raw access to coil data buffer
inline uint8_t *data() const { return CDbuffer; };
Expand All @@ -107,8 +107,8 @@ class CoilData {
// bit masks for bits left of a bit index in a byte
const uint8_t CDfilter[8] = { 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF };
// Calculate byte index and bit index within that byte
inline const uint8_t byteIndex(uint16_t index) const { return index >> 3; }
inline const uint8_t bitIndex(uint16_t index) const { return index & 0x07; }
inline uint8_t byteIndex(uint16_t index) const { return index >> 3; }
inline uint8_t bitIndex(uint16_t index) const { return index & 0x07; }
// Calculate reversed bit sequence for a byte (taken from http://graphics.stanford.edu/~seander/bithacks.html#ReverseByteWith32Bits)
inline uint8_t reverseBits(uint8_t b) { return ((b * 0x0802LU & 0x22110LU) | (b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16; }
// (Re-)init with bit image vector
Expand Down
4 changes: 2 additions & 2 deletions src/ModbusTypeDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ FCType FCT::table[] = {
};

// FCT::getType: get the function code type for a given function code
const FCType FCT::getType(uint8_t functionCode) {
FCType FCT::getType(uint8_t functionCode) {
return table[functionCode & 0x7F];
}

// setType: change the type of a function code.
// This is possible only for the codes undefined yet and will return
// the effective type
const FCType FCT::redefineType(uint8_t functionCode, const FCType type) {
FCType FCT::redefineType(uint8_t functionCode, const FCType type) {
uint8_t fc = functionCode & 0x7F;

// Allow modifications for yet undefined codes only
Expand Down
4 changes: 2 additions & 2 deletions src/ModbusTypeDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ class FCT {
FCT& operator=(const FCT& other) = delete; // No assignment either
public:
// getType: get the function code type for a given function code
static const FCType getType(uint8_t functionCode);
static FCType getType(uint8_t functionCode);

// setType: change the type of a function code.
// This is possible only for the codes undefined yet and will return
// the effective type
static const FCType redefineType(uint8_t functionCode, const FCType type = FCUSER);
static FCType redefineType(uint8_t functionCode, const FCType type = FCUSER);
};

#endif
Expand Down
6 changes: 3 additions & 3 deletions src/RTUutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int RTUutils::UARTinit(HardwareSerial& serial, int thresholdBytes) {
if (thresholdBytes > 0 && thresholdBytes < 128) {
// Yes, it is. Try to identify the Serial/Serial1/Serial2 the user has provided.
uart_dev_t *uart = nullptr;
uint8_t uart_num = 0;
uint8_t uart_num = 99;
if (&serial == &Serial) {
uart_num = 0;
uart = &UART0;
Expand All @@ -143,7 +143,7 @@ int RTUutils::UARTinit(HardwareSerial& serial, int thresholdBytes) {
}
}
// Is it a defined serial?
if (uart != nullptr) {
if (uart_num != 99) {
// Yes. get the current value and set ours instead
rc = uart->conf1.rxfifo_full_thrhd;
uart->conf1.rxfifo_full_thrhd = thresholdBytes;
Expand Down Expand Up @@ -237,7 +237,7 @@ ModbusMessage RTUutils::receive(HardwareSerial& serial, uint32_t timeout, unsign
// Index into buffer
uint16_t bufferPtr = 0;
// Byte read
int b;
int b = 0;

// State machine states, RTU mode
enum STATES : uint8_t { WAIT_DATA = 0, IN_PACKET, DATA_READ, FINISHED };
Expand Down