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