| Jagpal Singh Gill | a32d241 | 2025-10-01 14:55:05 -0700 | [diff] [blame] | 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 | |
| Jagpal Singh Gill | cad9ecf | 2025-10-22 19:53:16 -0700 | [diff] [blame^] | 17 | // Read Holding Registers Testing Constants |
| Jagpal Singh Gill | a32d241 | 2025-10-01 14:55:05 -0700 | [diff] [blame] | 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 | |
| Jagpal Singh Gill | cad9ecf | 2025-10-22 19:53:16 -0700 | [diff] [blame^] | 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 | |
| Jagpal Singh Gill | a32d241 | 2025-10-01 14:55:05 -0700 | [diff] [blame] | 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; |
| Jagpal Singh Gill | cad9ecf | 2025-10-22 19:53:16 -0700 | [diff] [blame^] | 51 | sdbusplus::async::mutex mutex; |
| Jagpal Singh Gill | a32d241 | 2025-10-01 14:55:05 -0700 | [diff] [blame] | 52 | }; |
| 53 | } // namespace phosphor::modbus::test |