Commit bb116cc5ff94ce83f8b52010b14b31801d353eeb

Authored by Peter M. Groen
1 parent 21acd140

Intermediate Commit

include/request.h
... ... @@ -38,15 +38,16 @@ public:
38 38 enum class FunctionCode
39 39 {
40 40 FC_UNKNOWN,
41   - READ_COILS,
42   - READ_DISCRETE_INPUTS,
43   - READ_HOLDING_REGISTERS,
44   - READ_INPUT_REGISTERS,
45   - WRITE_SINGLE_COIL,
46   - WRITE_SINGLE_REGISTER,
47   - WRITE_MULTIPLE_COILS,
48   - WRITE_MULTIPLE_REGISTERS,
49   - WRITE_FILE_RECORD,
  41 + FC_READ_COILS,
  42 + FC_READ_DISCRETE_INPUTS,
  43 + FC_READ_HOLDING_REGISTERS,
  44 + FC_READ_INPUT_REGISTERS,
  45 + FC_WRITE_SINGLE_COIL,
  46 + FC_WRITE_SINGLE_REGISTER,
  47 + FC_WRITE_MULTIPLE_COILS,
  48 + FC_WRITE_MULTIPLE_REGISTERS,
  49 + FC_READ_FILE_RECORD,
  50 + FC_WRITE_FILE_RECORD,
50 51 };
51 52  
52 53 explicit Request()
... ...
src/modbus.cpp
... ... @@ -4,12 +4,19 @@ using namespace osdev::components::modbus;
4 4  
5 5 ModBus::ModBus()
6 6 {
7   -
8 7 }
9 8  
10 9 bool ModBus::Open(const ConnectionConfig &connection_config)
11 10 {
12   - (void)connection_config;
  11 + switch(connection_config.getConnectionType())
  12 + {
  13 + case ConnectionConfig::E_CONNECTIONTYPE::SERIAL:
  14 + break;
  15 + case ConnectionConfig::E_CONNECTIONTYPE::TCP:
  16 + break;
  17 + case ConnectionConfig::E_CONNECTIONTYPE::UNKNOWN:
  18 + break;
  19 + }
13 20  
14 21 return true;
15 22 }
... ... @@ -21,9 +28,35 @@ bool ModBus::Close()
21 28  
22 29 std::vector<uint8_t> ModBus::Read(const Request &request)
23 30 {
24   - (void)request;
  31 + std::vector<uint8_t> vecResult;
25 32  
26   - return std::vector<uint8_t>();
  33 + switch(request.getFunctionCode())
  34 + {
  35 + case Request::FunctionCode::FC_UNKNOWN:
  36 + break;
  37 + case Request::FunctionCode::FC_READ_COILS:
  38 + break;
  39 + case Request::FunctionCode::FC_READ_DISCRETE_INPUTS:
  40 + break;
  41 + case Request::FunctionCode::FC_READ_HOLDING_REGISTERS:
  42 + break;
  43 + case Request::FunctionCode::FC_READ_INPUT_REGISTERS:
  44 + break;
  45 + case Request::FunctionCode::FC_WRITE_SINGLE_COIL:
  46 + break;
  47 + case Request::FunctionCode::FC_WRITE_SINGLE_REGISTER:
  48 + break;
  49 + case Request::FunctionCode::FC_WRITE_MULTIPLE_COILS:
  50 + break;
  51 + case Request::FunctionCode::FC_WRITE_MULTIPLE_REGISTERS:
  52 + break;
  53 + case Request::FunctionCode::FC_READ_FILE_RECORD:
  54 + break;
  55 + case Request::FunctionCode::FC_WRITE_FILE_RECORD:
  56 + break;
  57 + }
  58 +
  59 + return vecResult;
27 60 }
28 61  
29 62 std::vector<uint8_t> ModBus::Write(const Request &request)
... ...
src/modbus.h
... ... @@ -17,18 +17,20 @@ namespace modbus {
17 17 class ModBus : public IModBus
18 18 {
19 19 public:
  20 + /// Default CTor
20 21 ModBus();
21 22  
  23 + /// Default DTor
22 24 virtual ~ModBus() {}
23 25  
24   - // Implementation
  26 + // Implementation of IModBus
25 27 virtual bool Open(const ConnectionConfig &connection_config) override;
26 28 virtual bool Close() override;
27 29 virtual std::vector<uint8_t> Read(const Request &request) override;
28 30 virtual std::vector<uint8_t> Write(const Request &request) override;
29 31  
30 32 private:
31   - std::unique_ptr<ModbusBase> m_modbus;
  33 + std::unique_ptr<ModbusBase> m_modbus = nullptr;
32 34 };
33 35  
34 36 } /* End namespace modbus */
... ...
tests/requesttest.cpp
... ... @@ -50,71 +50,71 @@ TEST(RequestTest, RequestNumberOfRegisters)
50 50 TEST(RequestTest, RequestReadCoils)
51 51 {
52 52 Request oRequest;
53   - oRequest.setFunctionCode(Request::FunctionCode::READ_COILS);
  53 + oRequest.setFunctionCode(Request::FunctionCode::FC_READ_COILS);
54 54  
55   - EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::READ_COILS);
  55 + EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::FC_READ_COILS);
56 56 }
57 57  
58 58 TEST(RequestTest, RequestReadDiscreteInputs)
59 59 {
60 60 Request oRequest;
61   - oRequest.setFunctionCode(Request::FunctionCode::READ_DISCRETE_INPUTS);
  61 + oRequest.setFunctionCode(Request::FunctionCode::FC_READ_DISCRETE_INPUTS);
62 62  
63   - EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::READ_DISCRETE_INPUTS);
  63 + EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::FC_READ_DISCRETE_INPUTS);
64 64 }
65 65  
66 66 TEST(RequestTest, RequestReadHoldingRegisters)
67 67 {
68 68 Request oRequest;
69   - oRequest.setFunctionCode(Request::FunctionCode::READ_HOLDING_REGISTERS);
  69 + oRequest.setFunctionCode(Request::FunctionCode::FC_READ_HOLDING_REGISTERS);
70 70  
71   - EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::READ_HOLDING_REGISTERS);
  71 + EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::FC_READ_HOLDING_REGISTERS);
72 72 }
73 73  
74 74 TEST(RequestTest, RequestReadInputRegisters)
75 75 {
76 76 Request oRequest;
77   - oRequest.setFunctionCode(Request::FunctionCode::READ_INPUT_REGISTERS);
  77 + oRequest.setFunctionCode(Request::FunctionCode::FC_READ_INPUT_REGISTERS);
78 78  
79   - EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::READ_INPUT_REGISTERS);
  79 + EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::FC_READ_INPUT_REGISTERS);
80 80 }
81 81  
82 82 TEST(RequestTest, RequestWriteSingleCoil)
83 83 {
84 84 Request oRequest;
85   - oRequest.setFunctionCode(Request::FunctionCode::WRITE_SINGLE_COIL);
  85 + oRequest.setFunctionCode(Request::FunctionCode::FC_WRITE_SINGLE_COIL);
86 86  
87   - EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::WRITE_SINGLE_COIL);
  87 + EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::FC_WRITE_SINGLE_COIL);
88 88 }
89 89  
90 90 TEST(RequestTest, RequestWriteSingleRegister)
91 91 {
92 92 Request oRequest;
93   - oRequest.setFunctionCode(Request::FunctionCode::WRITE_SINGLE_REGISTER);
  93 + oRequest.setFunctionCode(Request::FunctionCode::FC_WRITE_SINGLE_REGISTER);
94 94  
95   - EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::WRITE_SINGLE_REGISTER);
  95 + EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::FC_WRITE_SINGLE_REGISTER);
96 96 }
97 97  
98 98 TEST(RequestTest, RequestWriteMultipleCoils)
99 99 {
100 100 Request oRequest;
101   - oRequest.setFunctionCode(Request::FunctionCode::WRITE_MULTIPLE_COILS);
  101 + oRequest.setFunctionCode(Request::FunctionCode::FC_WRITE_MULTIPLE_COILS);
102 102  
103   - EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::WRITE_MULTIPLE_COILS);
  103 + EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::FC_WRITE_MULTIPLE_COILS);
104 104 }
105 105  
106 106 TEST(RequestTest, RequestWriteMultipleRegisters)
107 107 {
108 108 Request oRequest;
109   - oRequest.setFunctionCode(Request::FunctionCode::WRITE_MULTIPLE_REGISTERS);
  109 + oRequest.setFunctionCode(Request::FunctionCode::FC_WRITE_MULTIPLE_REGISTERS);
110 110  
111   - EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::WRITE_MULTIPLE_REGISTERS);
  111 + EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::FC_WRITE_MULTIPLE_REGISTERS);
112 112 }
113 113  
114 114 TEST(RequestTest, RequestWriteFileRecord)
115 115 {
116 116 Request oRequest;
117   - oRequest.setFunctionCode(Request::FunctionCode::WRITE_FILE_RECORD);
  117 + oRequest.setFunctionCode(Request::FunctionCode::FC_WRITE_FILE_RECORD);
118 118  
119   - EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::WRITE_FILE_RECORD);
  119 + EXPECT_EQ(oRequest.getFunctionCode(), Request::FunctionCode::FC_WRITE_FILE_RECORD);
120 120 }
... ...