1a32d241bSJagpal Singh Gill #pragma once 2a32d241bSJagpal Singh Gill 3a32d241bSJagpal Singh Gill #include "modbus/modbus_message.hpp" 4a32d241bSJagpal Singh Gill 5a32d241bSJagpal Singh Gill #include <sdbusplus/async.hpp> 6a32d241bSJagpal Singh Gill 7a32d241bSJagpal Singh Gill using MessageBase = phosphor::modbus::rtu::Message; 8a32d241bSJagpal Singh Gill 9a32d241bSJagpal Singh Gill namespace phosphor::modbus::test 10a32d241bSJagpal Singh Gill { 11a32d241bSJagpal Singh Gill 12a32d241bSJagpal Singh Gill class MessageIntf : public MessageBase 13a32d241bSJagpal Singh Gill { 14a32d241bSJagpal Singh Gill friend class ServerTester; 15a32d241bSJagpal Singh Gill }; 16a32d241bSJagpal Singh Gill 17*cad9ecf6SJagpal Singh Gill // Read Holding Registers Testing Constants 18a32d241bSJagpal Singh Gill static constexpr uint8_t testDeviceAddress = 0xa; 19a32d241bSJagpal Singh Gill constexpr uint16_t testSuccessReadHoldingRegisterOffset = 0x0102; 20a32d241bSJagpal Singh Gill constexpr uint16_t testSuccessReadHoldingRegisterCount = 0x2; 21a32d241bSJagpal Singh Gill constexpr uint16_t testSuccessReadHoldingRegisterSegmentedOffset = 0x0103; 22a32d241bSJagpal Singh Gill constexpr std::array<uint16_t, testSuccessReadHoldingRegisterCount> 23a32d241bSJagpal Singh Gill testSuccessReadHoldingRegisterResponse = {0x1234, 0x5678}; 24a32d241bSJagpal Singh Gill constexpr uint16_t testFailureReadHoldingRegister = 0x0105; 25a32d241bSJagpal Singh Gill 26*cad9ecf6SJagpal Singh Gill // Device Inventory Testing Constants 27*cad9ecf6SJagpal Singh Gill constexpr uint16_t testReadHoldingRegisterModelOffset = 0x0112; 28*cad9ecf6SJagpal Singh Gill constexpr uint16_t testReadHoldingRegisterModelCount = 0x8; 29*cad9ecf6SJagpal Singh Gill constexpr std::array<uint16_t, testReadHoldingRegisterModelCount> 30*cad9ecf6SJagpal Singh Gill testReadHoldingRegisterModel = {0x5244, 0x4630, 0x3430, 0x4453, 31*cad9ecf6SJagpal Singh Gill 0x5335, 0x3139, 0x0000, 0x3000}; 32*cad9ecf6SJagpal Singh Gill constexpr std::string testReadHoldingRegisterModelStr = "RDF040DSS519"; 33*cad9ecf6SJagpal Singh Gill 34a32d241bSJagpal Singh Gill class ServerTester 35a32d241bSJagpal Singh Gill { 36a32d241bSJagpal Singh Gill public: 37a32d241bSJagpal Singh Gill explicit ServerTester(sdbusplus::async::context& ctx, int fd); 38a32d241bSJagpal Singh Gill 39a32d241bSJagpal Singh Gill auto processRequests() -> sdbusplus::async::task<void>; 40a32d241bSJagpal Singh Gill 41a32d241bSJagpal Singh Gill private: 42a32d241bSJagpal Singh Gill void processMessage(MessageIntf& request, size_t requestSize, 43a32d241bSJagpal Singh Gill MessageIntf& response, bool& segmentedResponse); 44a32d241bSJagpal Singh Gill 45a32d241bSJagpal Singh Gill void processReadHoldingRegisters(MessageIntf& request, size_t requestSize, 46a32d241bSJagpal Singh Gill MessageIntf& response, 47a32d241bSJagpal Singh Gill bool& segmentedResponse); 48a32d241bSJagpal Singh Gill 49a32d241bSJagpal Singh Gill int fd; 50a32d241bSJagpal Singh Gill sdbusplus::async::fdio fdioInstance; 51*cad9ecf6SJagpal Singh Gill sdbusplus::async::mutex mutex; 52a32d241bSJagpal Singh Gill }; 53a32d241bSJagpal Singh Gill } // namespace phosphor::modbus::test 54