/src/opendnp3/cpp/lib/include/opendnp3/outstation/SimpleCommandHandler.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2013-2022 Step Function I/O, LLC |
3 | | * |
4 | | * Licensed to Green Energy Corp (www.greenenergycorp.com) and Step Function I/O |
5 | | * LLC (https://stepfunc.io) under one or more contributor license agreements. |
6 | | * See the NOTICE file distributed with this work for additional information |
7 | | * regarding copyright ownership. Green Energy Corp and Step Function I/O LLC license |
8 | | * this file to you under the Apache License, Version 2.0 (the "License"); you |
9 | | * may not use this file except in compliance with the License. You may obtain |
10 | | * a copy of the License at: |
11 | | * |
12 | | * http://www.apache.org/licenses/LICENSE-2.0 |
13 | | * |
14 | | * Unless required by applicable law or agreed to in writing, software |
15 | | * distributed under the License is distributed on an "AS IS" BASIS, |
16 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 | | * See the License for the specific language governing permissions and |
18 | | * limitations under the License. |
19 | | */ |
20 | | #ifndef OPENDNP3_SIMPLECOMMANDHANDLER_H |
21 | | #define OPENDNP3_SIMPLECOMMANDHANDLER_H |
22 | | |
23 | | #include "opendnp3/outstation/ICommandHandler.h" |
24 | | |
25 | | #include <memory> |
26 | | |
27 | | namespace opendnp3 |
28 | | { |
29 | | |
30 | | /** |
31 | | * Mock ICommandHandler used for examples and demos |
32 | | */ |
33 | | class SimpleCommandHandler : public ICommandHandler |
34 | | { |
35 | | public: |
36 | | /** |
37 | | * @param status The status value to return in response to all commands |
38 | | */ |
39 | | SimpleCommandHandler(CommandStatus status); |
40 | | |
41 | | virtual void Begin() override; |
42 | | virtual void End() override; |
43 | | |
44 | | CommandStatus Select(const ControlRelayOutputBlock& command, uint16_t index) override; |
45 | | CommandStatus Operate(const ControlRelayOutputBlock& command, |
46 | | uint16_t index, |
47 | | IUpdateHandler& handler, |
48 | | OperateType opType) override; |
49 | | |
50 | | CommandStatus Select(const AnalogOutputInt16& command, uint16_t index) override; |
51 | | CommandStatus Operate(const AnalogOutputInt16& command, |
52 | | uint16_t index, |
53 | | IUpdateHandler& handler, |
54 | | OperateType opType) override; |
55 | | |
56 | | CommandStatus Select(const AnalogOutputInt32& command, uint16_t index) override; |
57 | | CommandStatus Operate(const AnalogOutputInt32& command, |
58 | | uint16_t index, |
59 | | IUpdateHandler& handler, |
60 | | OperateType opType) override; |
61 | | |
62 | | CommandStatus Select(const AnalogOutputFloat32& command, uint16_t index) override; |
63 | | CommandStatus Operate(const AnalogOutputFloat32& command, |
64 | | uint16_t index, |
65 | | IUpdateHandler& handler, |
66 | | OperateType opType) override; |
67 | | |
68 | | CommandStatus Select(const AnalogOutputDouble64& command, uint16_t index) override; |
69 | | CommandStatus Operate(const AnalogOutputDouble64& command, |
70 | | uint16_t index, |
71 | | IUpdateHandler& handler, |
72 | | OperateType opType) override; |
73 | | |
74 | | protected: |
75 | 1.27k | virtual void DoSelect(const ControlRelayOutputBlock& command, uint16_t index) {} |
76 | 0 | virtual void DoOperate(const ControlRelayOutputBlock& command, uint16_t index, OperateType opType) {} |
77 | | |
78 | 5.88k | virtual void DoSelect(const AnalogOutputInt16& command, uint16_t index) {} |
79 | 0 | virtual void DoOperate(const AnalogOutputInt16& command, uint16_t index, OperateType opType) {} |
80 | | |
81 | 2.40k | virtual void DoSelect(const AnalogOutputInt32& command, uint16_t index) {} |
82 | 0 | virtual void DoOperate(const AnalogOutputInt32& command, uint16_t index, OperateType opType) {} |
83 | | |
84 | 1.90k | virtual void DoSelect(const AnalogOutputFloat32& command, uint16_t index) {} |
85 | 0 | virtual void DoOperate(const AnalogOutputFloat32& command, uint16_t index, OperateType opType) {} |
86 | | |
87 | 3.10k | virtual void DoSelect(const AnalogOutputDouble64& command, uint16_t index) {} |
88 | 0 | virtual void DoOperate(const AnalogOutputDouble64& command, uint16_t index, OperateType opType) {} |
89 | | |
90 | | CommandStatus status; |
91 | | |
92 | | public: |
93 | | uint32_t numOperate; |
94 | | uint32_t numSelect; |
95 | | uint32_t numStart; |
96 | | uint32_t numEnd; |
97 | | }; |
98 | | |
99 | | /** |
100 | | * A singleton command handler that always returns success |
101 | | */ |
102 | | class SuccessCommandHandler : public SimpleCommandHandler |
103 | | { |
104 | | public: |
105 | | static std::shared_ptr<ICommandHandler> Create() |
106 | 0 | { |
107 | 0 | return std::make_shared<SuccessCommandHandler>(); |
108 | 0 | } |
109 | | |
110 | 0 | SuccessCommandHandler() : SimpleCommandHandler(CommandStatus::SUCCESS) {} |
111 | | }; |
112 | | |
113 | | } // namespace opendnp3 |
114 | | |
115 | | #endif |