Removed example files (can be recovered later)

Now it compiles with test main code
This commit is contained in:
Emanuele Trabattoni
2025-06-26 12:44:20 +02:00
parent b54c0e5018
commit 4acce987de
22 changed files with 63 additions and 1385 deletions

View File

@@ -1,4 +1,4 @@
#include "WS_RS485.h"
#include "RS485_driver.h"
#include <algorithm>
#include <cstring>
#include <endian.h>
@@ -69,6 +69,7 @@ namespace drivers
data.resize(avail);
m_serial->readBytesUntil(ch, data.data(), avail);
data.shrink_to_fit();
return true;
}
////////////////////////////////
@@ -85,7 +86,7 @@ namespace drivers
{
constexpr uint8_t func = 0x01;
log_d("Read coils: dev[%02x], reg[%04x], num[%d]", device, reg, num);
readBinary(func, device, reg, num, coils);
return readBinary(func, device, reg, num, coils);
}
// Func 0x02
@@ -93,7 +94,7 @@ namespace drivers
{
constexpr uint8_t func = 0x01;
log_d("Read multi inputs: dev[%02x], reg[%04x], num[%d]", device, reg, num);
readBinary(func, device, reg, num, inputs);
return readBinary(func, device, reg, num, inputs);
}
// Func 0x03
@@ -101,7 +102,7 @@ namespace drivers
{
constexpr uint8_t func = 0x03;
log_d("Read multi holding registers: dev[%02x], reg[%04x], num[%d]", device, reg, num);
readInteger(func, device, reg, num, values);
return readInteger(func, device, reg, num, values);
}
// Func 0x04
@@ -109,7 +110,7 @@ namespace drivers
{
constexpr uint8_t func = 0x04;
log_d("Read multi input registers: dev[%02x], reg[%04x], num[%d]", device, reg, num);
readInteger(func, device, reg, num, values);
return readInteger(func, device, reg, num, values);
}
// Func 0x05
@@ -192,6 +193,7 @@ namespace drivers
bitNum++;
}
}
return true;
}
const bool MODBUS::readInteger(const uint8_t func, const uint8_t device, const uint16_t reg, const uint16_t num, std::vector<uint16_t> &out)
@@ -233,6 +235,7 @@ namespace drivers
const uint16_t val(0xFFFF & ((hi << 8) | lo));
out.push_back(be16toh(val));
}
return true;
}
const bool MODBUS::writeBinary(const uint8_t func, const uint8_t device, const uint16_t reg, const uint16_t bits, const std::vector<bool> &in)
@@ -313,7 +316,7 @@ namespace drivers
// compute crc for header + data
m_crc.reset();
m_crc.add((uint8_t *)&header, headerBytes); // exclude last two bytes of crc
const uint16_t crc(htole16(m_crc.getCRC()));
const uint16_t crc(htole16(m_crc.calc()));
std::vector<uint8_t> dataOut(headerBytes + crcBytes, 0);
std::memcpy(dataOut.data(), &header, headerBytes);
@@ -344,7 +347,7 @@ namespace drivers
m_crc.reset();
m_crc.add((uint8_t *)&header, headerBytes); // add the request excluding the CRC code
m_crc.add((uint8_t *)dataBe.data(), dataBytes);
const uint16_t crc(htole16(m_crc.getCRC()));
const uint16_t crc(htole16(m_crc.calc()));
std::vector<uint8_t> dataOut;
dataOut.resize(headerBytes + dataBytes + crcBytes); // header message + data values + crc code
@@ -359,7 +362,7 @@ namespace drivers
// compute crc of current message
m_crc.reset();
m_crc.add(data.data(), data.size());
const uint16_t computedCrc(m_crc.getCRC());
const uint16_t computedCrc(m_crc.calc());
// extract crc from response
const uint16_t size(data.size());
const uint8_t crcLo(data.at(size - 2));

View File

@@ -16,14 +16,6 @@
#define Extension_ALL_ON 9 // Expansion ALL ON
#define Extension_ALL_OFF 10 // Expansion ALL OFF
void SetData(uint8_t *data, size_t length); // Send data from the RS485
void ReadData(uint8_t *buf, uint8_t length); // Data is received over RS485
void RS485_Analysis(uint8_t *buf); // External relay control
void RS485_Init(); // Example Initialize the system serial port and RS485
void RS485_Loop(); // Read RS485 data, parse and control relays
void RS485Task(void *parameter);
namespace drivers
{
class RS485