| 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; |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 22 | const std::vector<uint16_t> testSuccessReadHoldingRegisterResponse = { |
| 23 | 0x1234, 0x5678}; |
| Jagpal Singh Gill | a32d241 | 2025-10-01 14:55:05 -0700 | [diff] [blame] | 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; |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 29 | const std::vector<uint16_t> testReadHoldingRegisterModel = { |
| 30 | 0x5244, 0x4630, 0x3430, 0x4453, 0x5335, 0x3139, 0x0000, 0x3000}; |
| Jagpal Singh Gill | cad9ecf | 2025-10-22 19:53:16 -0700 | [diff] [blame] | 31 | constexpr std::string testReadHoldingRegisterModelStr = "RDF040DSS519"; |
| 32 | |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 33 | // Device Sensors Testing Constants |
| 34 | constexpr uint16_t testReadHoldingRegisterTempCount = 0x1; |
| 35 | constexpr uint16_t testReadHoldingRegisterTempUnsignedOffset = 0x0113; |
| 36 | const std::vector<uint16_t> testReadHoldingRegisterTempUnsigned = { |
| 37 | 0x0050}; // 80.0 |
| 38 | constexpr uint16_t testReadHoldingRegisterTempSignedOffset = 0x0114; |
| 39 | const std::vector<uint16_t> testReadHoldingRegisterTempSigned = { |
| 40 | 0xFFB0}; // -80.0 |
| 41 | |
| 42 | static const std::map<uint16_t, std::tuple<uint16_t, std::vector<uint16_t>>> |
| 43 | testReadHoldingRegisterMap = { |
| 44 | {testSuccessReadHoldingRegisterOffset, |
| 45 | {testSuccessReadHoldingRegisterCount, |
| 46 | testSuccessReadHoldingRegisterResponse}}, |
| 47 | {testSuccessReadHoldingRegisterSegmentedOffset, |
| 48 | {testSuccessReadHoldingRegisterCount, |
| 49 | testSuccessReadHoldingRegisterResponse}}, |
| 50 | {testReadHoldingRegisterModelOffset, |
| 51 | {testReadHoldingRegisterModelCount, testReadHoldingRegisterModel}}, |
| 52 | {testReadHoldingRegisterTempUnsignedOffset, |
| 53 | {testReadHoldingRegisterTempCount, |
| 54 | testReadHoldingRegisterTempUnsigned}}, |
| 55 | {testReadHoldingRegisterTempSignedOffset, |
| 56 | {testReadHoldingRegisterTempCount, testReadHoldingRegisterTempSigned}}, |
| 57 | }; |
| 58 | |
| Jagpal Singh Gill | a32d241 | 2025-10-01 14:55:05 -0700 | [diff] [blame] | 59 | class ServerTester |
| 60 | { |
| 61 | public: |
| 62 | explicit ServerTester(sdbusplus::async::context& ctx, int fd); |
| 63 | |
| 64 | auto processRequests() -> sdbusplus::async::task<void>; |
| 65 | |
| 66 | private: |
| 67 | void processMessage(MessageIntf& request, size_t requestSize, |
| 68 | MessageIntf& response, bool& segmentedResponse); |
| 69 | |
| 70 | void processReadHoldingRegisters(MessageIntf& request, size_t requestSize, |
| 71 | MessageIntf& response, |
| 72 | bool& segmentedResponse); |
| 73 | |
| 74 | int fd; |
| 75 | sdbusplus::async::fdio fdioInstance; |
| Jagpal Singh Gill | cad9ecf | 2025-10-22 19:53:16 -0700 | [diff] [blame] | 76 | sdbusplus::async::mutex mutex; |
| Jagpal Singh Gill | a32d241 | 2025-10-01 14:55:05 -0700 | [diff] [blame] | 77 | }; |
| 78 | } // namespace phosphor::modbus::test |