/src/opendnp3/cpp/lib/src/app/MeasurementFactory.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_MEASUREMENTFACTORY_H |
21 | | #define OPENDNP3_MEASUREMENTFACTORY_H |
22 | | |
23 | | #include "opendnp3/app/AnalogCommandEvent.h" |
24 | | #include "opendnp3/app/AnalogOutput.h" |
25 | | #include "opendnp3/app/BinaryCommandEvent.h" |
26 | | #include "opendnp3/app/ControlRelayOutputBlock.h" |
27 | | #include "opendnp3/app/MeasurementTypes.h" |
28 | | #include "opendnp3/util/StaticOnly.h" |
29 | | |
30 | | namespace opendnp3 |
31 | | { |
32 | | |
33 | | struct BinaryFactory : private StaticOnly |
34 | | { |
35 | | inline static Binary From(uint8_t flags) |
36 | 8.89k | { |
37 | 8.89k | return Binary(Flags(flags)); |
38 | 8.89k | } |
39 | | |
40 | | inline static Binary From(uint8_t flags, uint16_t time) |
41 | 2.75k | { |
42 | 2.75k | return From(flags, DNPTime(time)); |
43 | 2.75k | } |
44 | | |
45 | | inline static Binary From(uint8_t flags, DNPTime time) |
46 | 3.80k | { |
47 | 3.80k | return Binary(Flags(flags), time); |
48 | 3.80k | } |
49 | | }; |
50 | | |
51 | | struct DoubleBitBinaryFactory : private StaticOnly |
52 | | { |
53 | | inline static DoubleBitBinary From(uint8_t flags) |
54 | 10.0k | { |
55 | 10.0k | return DoubleBitBinary(Flags(flags)); |
56 | 10.0k | } |
57 | | |
58 | | inline static DoubleBitBinary From(uint8_t flags, uint16_t time) |
59 | 4.48k | { |
60 | 4.48k | return From(flags, DNPTime(time)); |
61 | 4.48k | } |
62 | | |
63 | | inline static DoubleBitBinary From(uint8_t flags, DNPTime time) |
64 | 6.53k | { |
65 | 6.53k | return DoubleBitBinary(Flags(flags), time); |
66 | 6.53k | } |
67 | | }; |
68 | | |
69 | | struct AnalogFactory : private StaticOnly |
70 | | { |
71 | | static Analog From(int32_t count) |
72 | 7.23k | { |
73 | 7.23k | return Analog(count); |
74 | 7.23k | } |
75 | | static Analog From(uint8_t flags, double value) |
76 | 20.7k | { |
77 | 20.7k | return Analog(value, Flags(flags)); |
78 | 20.7k | } |
79 | | static Analog From(uint8_t flags, double value, DNPTime time) |
80 | 6.49k | { |
81 | 6.49k | return Analog(value, Flags(flags), time); |
82 | 6.49k | } |
83 | | }; |
84 | | |
85 | | struct CounterFactory : private StaticOnly |
86 | | { |
87 | | inline static Counter From(uint32_t count) |
88 | 5.88k | { |
89 | 5.88k | return Counter(count); |
90 | 5.88k | } |
91 | | inline static Counter From(uint8_t flags, uint32_t count) |
92 | 9.41k | { |
93 | 9.41k | return Counter(count, Flags(flags)); |
94 | 9.41k | } |
95 | | inline static Counter From(uint8_t flags, uint32_t count, DNPTime time) |
96 | 2.65k | { |
97 | 2.65k | return Counter(count, Flags(flags), time); |
98 | 2.65k | } |
99 | | }; |
100 | | |
101 | | struct FrozenCounterFactory : private StaticOnly |
102 | | { |
103 | | inline static FrozenCounter From(uint32_t count) |
104 | 11.2k | { |
105 | 11.2k | return FrozenCounter(count); |
106 | 11.2k | } |
107 | | inline static FrozenCounter From(uint8_t flags, uint32_t count) |
108 | 11.6k | { |
109 | 11.6k | return FrozenCounter(count, Flags(flags)); |
110 | 11.6k | } |
111 | | inline static FrozenCounter From(uint8_t flags, uint32_t count, DNPTime time) |
112 | 6.54k | { |
113 | 6.54k | return FrozenCounter(count, Flags(flags), time); |
114 | 6.54k | } |
115 | | }; |
116 | | |
117 | | struct TimeAndIntervalFactory : private StaticOnly |
118 | | { |
119 | | inline static TimeAndInterval From(DNPTime time, uint32_t interval, uint8_t units) |
120 | 3.80k | { |
121 | 3.80k | return TimeAndInterval(time, interval, units); |
122 | 3.80k | } |
123 | | }; |
124 | | |
125 | | struct ControlRelayOutputBlockFactory : private StaticOnly |
126 | | { |
127 | | inline static ControlRelayOutputBlock From( |
128 | | uint8_t code, uint8_t count, uint32_t onTime, uint32_t offTime, uint8_t status) |
129 | 7.11k | { |
130 | 7.11k | return ControlRelayOutputBlock(code, count, onTime, offTime, CommandStatusSpec::from_type(status)); |
131 | 7.11k | } |
132 | | }; |
133 | | |
134 | | struct BinaryOutputStatusFactory : private StaticOnly |
135 | | { |
136 | | inline static BinaryOutputStatus From(uint8_t flags) |
137 | 13.4k | { |
138 | 13.4k | return BinaryOutputStatus(Flags(flags)); |
139 | 13.4k | } |
140 | | |
141 | | inline static BinaryOutputStatus From(uint8_t flags, DNPTime time) |
142 | 1.66k | { |
143 | 1.66k | return BinaryOutputStatus(Flags(flags), time); |
144 | 1.66k | } |
145 | | }; |
146 | | |
147 | | struct BinaryCommandEventFactory : private StaticOnly |
148 | | { |
149 | | inline static BinaryCommandEvent From(uint8_t flags) |
150 | 15.2k | { |
151 | 15.2k | return BinaryCommandEvent(Flags(flags)); |
152 | 15.2k | } |
153 | | |
154 | | inline static BinaryCommandEvent From(uint8_t flags, DNPTime time) |
155 | 2.79k | { |
156 | 2.79k | return BinaryCommandEvent(Flags(flags), time); |
157 | 2.79k | } |
158 | | }; |
159 | | |
160 | | struct AnalogOutputStatusFactory : private StaticOnly |
161 | | { |
162 | | inline static AnalogOutputStatus From(uint8_t flags, double value) |
163 | 23.6k | { |
164 | 23.6k | return AnalogOutputStatus(value, Flags(flags)); |
165 | 23.6k | } |
166 | | |
167 | | inline static AnalogOutputStatus From(uint8_t flags, double value, DNPTime time) |
168 | 7.32k | { |
169 | 7.32k | return AnalogOutputStatus(value, Flags(flags), time); |
170 | 7.32k | } |
171 | | }; |
172 | | |
173 | | struct AnalogCommandEventFactory : private StaticOnly |
174 | | { |
175 | | inline static AnalogCommandEvent From(uint8_t status, double value) |
176 | 11.0k | { |
177 | 11.0k | return AnalogCommandEvent(value, CommandStatusSpec::from_type(status)); |
178 | 11.0k | } |
179 | | |
180 | | inline static AnalogCommandEvent From(uint8_t status, double value, DNPTime time) |
181 | 7.05k | { |
182 | 7.05k | return AnalogCommandEvent(value, CommandStatusSpec::from_type(status), time); |
183 | 7.05k | } |
184 | | }; |
185 | | |
186 | | template<class Target, class ValueType> struct AnalogOutputFactory : private StaticOnly |
187 | | { |
188 | | inline static Target From(ValueType value, uint8_t status) |
189 | 58.4k | { |
190 | 58.4k | return Target(value, CommandStatusSpec::from_type(status)); |
191 | 58.4k | } opendnp3::AnalogOutputFactory<opendnp3::AnalogOutputInt32, int>::From(int, unsigned char) Line | Count | Source | 189 | 8.71k | { | 190 | 8.71k | return Target(value, CommandStatusSpec::from_type(status)); | 191 | 8.71k | } |
opendnp3::AnalogOutputFactory<opendnp3::AnalogOutputInt16, short>::From(short, unsigned char) Line | Count | Source | 189 | 25.6k | { | 190 | 25.6k | return Target(value, CommandStatusSpec::from_type(status)); | 191 | 25.6k | } |
opendnp3::AnalogOutputFactory<opendnp3::AnalogOutputFloat32, float>::From(float, unsigned char) Line | Count | Source | 189 | 13.6k | { | 190 | 13.6k | return Target(value, CommandStatusSpec::from_type(status)); | 191 | 13.6k | } |
opendnp3::AnalogOutputFactory<opendnp3::AnalogOutputDouble64, double>::From(double, unsigned char) Line | Count | Source | 189 | 10.3k | { | 190 | 10.3k | return Target(value, CommandStatusSpec::from_type(status)); | 191 | 10.3k | } |
|
192 | | }; |
193 | | |
194 | | using AnalogOutputInt32Factory = AnalogOutputFactory<AnalogOutputInt32, int32_t>; |
195 | | using AnalogOutputInt16Factory = AnalogOutputFactory<AnalogOutputInt16, int16_t>; |
196 | | using AnalogOutputFloat32Factory = AnalogOutputFactory<AnalogOutputFloat32, float>; |
197 | | using AnalogOutputDouble64Factory = AnalogOutputFactory<AnalogOutputDouble64, double>; |
198 | | |
199 | | } // namespace opendnp3 |
200 | | |
201 | | #endif |