blob: c9b44166474d93fb224af35c7b12351fbb533a39 [file] [log] [blame]
Jagpal Singh Gilla32d2412025-10-01 14:55:05 -07001#pragma once
2
3#include "modbus/modbus_message.hpp"
4
5#include <sdbusplus/async.hpp>
6
7using MessageBase = phosphor::modbus::rtu::Message;
8
9namespace phosphor::modbus::test
10{
11
12class MessageIntf : public MessageBase
13{
14 friend class ServerTester;
15};
16
Jagpal Singh Gillcad9ecf2025-10-22 19:53:16 -070017// Read Holding Registers Testing Constants
Jagpal Singh Gilla32d2412025-10-01 14:55:05 -070018static constexpr uint8_t testDeviceAddress = 0xa;
19constexpr uint16_t testSuccessReadHoldingRegisterOffset = 0x0102;
20constexpr uint16_t testSuccessReadHoldingRegisterCount = 0x2;
21constexpr uint16_t testSuccessReadHoldingRegisterSegmentedOffset = 0x0103;
22constexpr std::array<uint16_t, testSuccessReadHoldingRegisterCount>
23 testSuccessReadHoldingRegisterResponse = {0x1234, 0x5678};
24constexpr uint16_t testFailureReadHoldingRegister = 0x0105;
25
Jagpal Singh Gillcad9ecf2025-10-22 19:53:16 -070026// Device Inventory Testing Constants
27constexpr uint16_t testReadHoldingRegisterModelOffset = 0x0112;
28constexpr uint16_t testReadHoldingRegisterModelCount = 0x8;
29constexpr std::array<uint16_t, testReadHoldingRegisterModelCount>
30 testReadHoldingRegisterModel = {0x5244, 0x4630, 0x3430, 0x4453,
31 0x5335, 0x3139, 0x0000, 0x3000};
32constexpr std::string testReadHoldingRegisterModelStr = "RDF040DSS519";
33
Jagpal Singh Gilla32d2412025-10-01 14:55:05 -070034class 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 Gillcad9ecf2025-10-22 19:53:16 -070051 sdbusplus::async::mutex mutex;
Jagpal Singh Gilla32d2412025-10-01 14:55:05 -070052};
53} // namespace phosphor::modbus::test