| 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 | |
| Jagpal Singh Gill | cf77ef5 | 2025-09-02 15:19:29 -0700 | [diff] [blame^] | 42 | // Device Firmware Testing Constants |
| 43 | constexpr uint16_t testReadHoldingRegisterFirmwareVersionOffset = 0x0115; |
| 44 | constexpr uint16_t testReadHoldingRegisterFirmwareVersionCount = 0x2; |
| 45 | const std::vector<uint16_t> testReadHoldingRegisterFirmwareVersion = { |
| 46 | 0x5244, 0x4630}; |
| 47 | constexpr std::string testReadHoldingRegisterFirmwareVersionStr = "RDF0"; |
| 48 | |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 49 | static const std::map<uint16_t, std::tuple<uint16_t, std::vector<uint16_t>>> |
| 50 | testReadHoldingRegisterMap = { |
| 51 | {testSuccessReadHoldingRegisterOffset, |
| 52 | {testSuccessReadHoldingRegisterCount, |
| 53 | testSuccessReadHoldingRegisterResponse}}, |
| 54 | {testSuccessReadHoldingRegisterSegmentedOffset, |
| 55 | {testSuccessReadHoldingRegisterCount, |
| 56 | testSuccessReadHoldingRegisterResponse}}, |
| 57 | {testReadHoldingRegisterModelOffset, |
| 58 | {testReadHoldingRegisterModelCount, testReadHoldingRegisterModel}}, |
| 59 | {testReadHoldingRegisterTempUnsignedOffset, |
| 60 | {testReadHoldingRegisterTempCount, |
| 61 | testReadHoldingRegisterTempUnsigned}}, |
| 62 | {testReadHoldingRegisterTempSignedOffset, |
| 63 | {testReadHoldingRegisterTempCount, testReadHoldingRegisterTempSigned}}, |
| Jagpal Singh Gill | cf77ef5 | 2025-09-02 15:19:29 -0700 | [diff] [blame^] | 64 | {testReadHoldingRegisterFirmwareVersionOffset, |
| 65 | {testReadHoldingRegisterFirmwareVersionCount, |
| 66 | testReadHoldingRegisterFirmwareVersion}}, |
| Jagpal Singh Gill | e92aba4 | 2025-10-16 00:00:13 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
| Jagpal Singh Gill | a32d241 | 2025-10-01 14:55:05 -0700 | [diff] [blame] | 69 | class ServerTester |
| 70 | { |
| 71 | public: |
| 72 | explicit ServerTester(sdbusplus::async::context& ctx, int fd); |
| 73 | |
| 74 | auto processRequests() -> sdbusplus::async::task<void>; |
| 75 | |
| 76 | private: |
| 77 | void processMessage(MessageIntf& request, size_t requestSize, |
| 78 | MessageIntf& response, bool& segmentedResponse); |
| 79 | |
| 80 | void processReadHoldingRegisters(MessageIntf& request, size_t requestSize, |
| 81 | MessageIntf& response, |
| 82 | bool& segmentedResponse); |
| 83 | |
| 84 | int fd; |
| 85 | sdbusplus::async::fdio fdioInstance; |
| Jagpal Singh Gill | cad9ecf | 2025-10-22 19:53:16 -0700 | [diff] [blame] | 86 | sdbusplus::async::mutex mutex; |
| Jagpal Singh Gill | a32d241 | 2025-10-01 14:55:05 -0700 | [diff] [blame] | 87 | }; |
| 88 | } // namespace phosphor::modbus::test |