1*9695bd28SJagpal Singh Gill #pragma once 2*9695bd28SJagpal Singh Gill 3*9695bd28SJagpal Singh Gill #include "modbus_message.hpp" 4*9695bd28SJagpal Singh Gill 5*9695bd28SJagpal Singh Gill #include <vector> 6*9695bd28SJagpal Singh Gill 7*9695bd28SJagpal Singh Gill namespace phosphor::modbus::rtu 8*9695bd28SJagpal Singh Gill { 9*9695bd28SJagpal Singh Gill 10*9695bd28SJagpal Singh Gill static constexpr uint8_t ReadHoldingRegistersFunctionCode = 0x03; 11*9695bd28SJagpal Singh Gill 12*9695bd28SJagpal Singh Gill class ReadHoldingRegistersRequest : public Message 13*9695bd28SJagpal Singh Gill { 14*9695bd28SJagpal Singh Gill public: 15*9695bd28SJagpal Singh Gill ReadHoldingRegistersRequest() = delete; 16*9695bd28SJagpal Singh Gill ReadHoldingRegistersRequest(const ReadHoldingRegistersRequest&) = delete; 17*9695bd28SJagpal Singh Gill ReadHoldingRegistersRequest& operator=(const ReadHoldingRegistersRequest&) = 18*9695bd28SJagpal Singh Gill delete; 19*9695bd28SJagpal Singh Gill ReadHoldingRegistersRequest(ReadHoldingRegistersRequest&&) = delete; 20*9695bd28SJagpal Singh Gill ReadHoldingRegistersRequest& operator=(ReadHoldingRegistersRequest&&) = 21*9695bd28SJagpal Singh Gill delete; 22*9695bd28SJagpal Singh Gill 23*9695bd28SJagpal Singh Gill explicit ReadHoldingRegistersRequest( 24*9695bd28SJagpal Singh Gill uint8_t deviceAddress, uint16_t registerOffset, uint16_t registerCount); 25*9695bd28SJagpal Singh Gill 26*9695bd28SJagpal Singh Gill auto encode() -> void; 27*9695bd28SJagpal Singh Gill 28*9695bd28SJagpal Singh Gill private: 29*9695bd28SJagpal Singh Gill static constexpr uint8_t commandCode = ReadHoldingRegistersFunctionCode; 30*9695bd28SJagpal Singh Gill const uint8_t deviceAddress; 31*9695bd28SJagpal Singh Gill const uint16_t registerOffset; 32*9695bd28SJagpal Singh Gill const uint16_t registerCount; 33*9695bd28SJagpal Singh Gill }; 34*9695bd28SJagpal Singh Gill 35*9695bd28SJagpal Singh Gill class Response : public Message 36*9695bd28SJagpal Singh Gill { 37*9695bd28SJagpal Singh Gill public: 38*9695bd28SJagpal Singh Gill auto decode() -> void; 39*9695bd28SJagpal Singh Gill }; 40*9695bd28SJagpal Singh Gill 41*9695bd28SJagpal Singh Gill class ReadHoldingRegistersResponse : public Response 42*9695bd28SJagpal Singh Gill { 43*9695bd28SJagpal Singh Gill public: 44*9695bd28SJagpal Singh Gill ReadHoldingRegistersResponse() = delete; 45*9695bd28SJagpal Singh Gill ReadHoldingRegistersResponse(const ReadHoldingRegistersResponse&) = delete; 46*9695bd28SJagpal Singh Gill ReadHoldingRegistersResponse& operator=( 47*9695bd28SJagpal Singh Gill const ReadHoldingRegistersResponse&) = delete; 48*9695bd28SJagpal Singh Gill ReadHoldingRegistersResponse(ReadHoldingRegistersResponse&&) = delete; 49*9695bd28SJagpal Singh Gill ReadHoldingRegistersResponse& operator=(ReadHoldingRegistersResponse&&) = 50*9695bd28SJagpal Singh Gill delete; 51*9695bd28SJagpal Singh Gill 52*9695bd28SJagpal Singh Gill explicit ReadHoldingRegistersResponse(uint8_t deviceAddress, 53*9695bd28SJagpal Singh Gill std::vector<uint16_t>& registers); 54*9695bd28SJagpal Singh Gill 55*9695bd28SJagpal Singh Gill auto decode() -> void; 56*9695bd28SJagpal Singh Gill 57*9695bd28SJagpal Singh Gill private: 58*9695bd28SJagpal Singh Gill static constexpr uint8_t expectedCommandCode = 59*9695bd28SJagpal Singh Gill ReadHoldingRegistersFunctionCode; 60*9695bd28SJagpal Singh Gill const uint8_t expectedDeviceAddress; 61*9695bd28SJagpal Singh Gill // The returned response is stored in the registers vector 62*9695bd28SJagpal Singh Gill std::vector<uint16_t>& registers; 63*9695bd28SJagpal Singh Gill }; 64*9695bd28SJagpal Singh Gill 65*9695bd28SJagpal Singh Gill } // namespace phosphor::modbus::rtu 66