1*a32d241bSJagpal Singh Gill #pragma once 2*a32d241bSJagpal Singh Gill 3*a32d241bSJagpal Singh Gill #include "modbus/modbus_message.hpp" 4*a32d241bSJagpal Singh Gill 5*a32d241bSJagpal Singh Gill #include <sdbusplus/async.hpp> 6*a32d241bSJagpal Singh Gill 7*a32d241bSJagpal Singh Gill using MessageBase = phosphor::modbus::rtu::Message; 8*a32d241bSJagpal Singh Gill 9*a32d241bSJagpal Singh Gill namespace phosphor::modbus::test 10*a32d241bSJagpal Singh Gill { 11*a32d241bSJagpal Singh Gill 12*a32d241bSJagpal Singh Gill class MessageIntf : public MessageBase 13*a32d241bSJagpal Singh Gill { 14*a32d241bSJagpal Singh Gill friend class ServerTester; 15*a32d241bSJagpal Singh Gill }; 16*a32d241bSJagpal Singh Gill 17*a32d241bSJagpal Singh Gill static constexpr uint8_t testDeviceAddress = 0xa; 18*a32d241bSJagpal Singh Gill constexpr uint16_t testSuccessReadHoldingRegisterOffset = 0x0102; 19*a32d241bSJagpal Singh Gill constexpr uint16_t testSuccessReadHoldingRegisterCount = 0x2; 20*a32d241bSJagpal Singh Gill constexpr uint16_t testSuccessReadHoldingRegisterSegmentedOffset = 0x0103; 21*a32d241bSJagpal Singh Gill constexpr std::array<uint16_t, testSuccessReadHoldingRegisterCount> 22*a32d241bSJagpal Singh Gill testSuccessReadHoldingRegisterResponse = {0x1234, 0x5678}; 23*a32d241bSJagpal Singh Gill constexpr uint16_t testFailureReadHoldingRegister = 0x0105; 24*a32d241bSJagpal Singh Gill 25*a32d241bSJagpal Singh Gill class ServerTester 26*a32d241bSJagpal Singh Gill { 27*a32d241bSJagpal Singh Gill public: 28*a32d241bSJagpal Singh Gill explicit ServerTester(sdbusplus::async::context& ctx, int fd); 29*a32d241bSJagpal Singh Gill 30*a32d241bSJagpal Singh Gill auto processRequests() -> sdbusplus::async::task<void>; 31*a32d241bSJagpal Singh Gill 32*a32d241bSJagpal Singh Gill private: 33*a32d241bSJagpal Singh Gill void processMessage(MessageIntf& request, size_t requestSize, 34*a32d241bSJagpal Singh Gill MessageIntf& response, bool& segmentedResponse); 35*a32d241bSJagpal Singh Gill 36*a32d241bSJagpal Singh Gill void processReadHoldingRegisters(MessageIntf& request, size_t requestSize, 37*a32d241bSJagpal Singh Gill MessageIntf& response, 38*a32d241bSJagpal Singh Gill bool& segmentedResponse); 39*a32d241bSJagpal Singh Gill 40*a32d241bSJagpal Singh Gill int fd; 41*a32d241bSJagpal Singh Gill sdbusplus::async::fdio fdioInstance; 42*a32d241bSJagpal Singh Gill }; 43*a32d241bSJagpal Singh Gill } // namespace phosphor::modbus::test 44