forked from pelud/modbus-potato
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModbusMasterHandlerHolding.cpp
More file actions
34 lines (28 loc) · 936 Bytes
/
ModbusMasterHandlerHolding.cpp
File metadata and controls
34 lines (28 loc) · 936 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "ModbusMasterHandlerHolding.h"
namespace ModbusPotato
{
bool CModbusMasterHandlerHolding::sanity_check (const uint16_t address, const size_t n) const
{
return ((n <= m_len) && (address < m_len) && ((size_t) (address + n) <= m_len));
}
CModbusMasterHandlerHolding::CModbusMasterHandlerHolding(uint16_t* array, size_t len)
: m_array(array)
, m_len(len)
{
}
bool CModbusMasterHandlerHolding::read_holding_registers_rsp(uint16_t address, size_t n, const uint16_t* values)
{
if (!sanity_check(address, n))
return false;
// copy in the values
while (n--)
m_array[address++] = *values++;
return true;
}
bool CModbusMasterHandlerHolding::write_multiple_registers_rsp(uint16_t address, size_t count)
{
if (!sanity_check(address, count))
return false;
return true;
}
}