/src/opendnp3/cpp/lib/include/opendnp3/app/EventTriggers.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_EVENTTRIGGERS_H |
21 | | #define OPENDNP3_EVENTTRIGGERS_H |
22 | | |
23 | | #include "opendnp3/app/BaseMeasurementTypes.h" |
24 | | |
25 | | namespace opendnp3 |
26 | | { |
27 | | namespace measurements |
28 | | { |
29 | | template<class T, class U> bool IsEvent(const T& val1, const T& val2, T deadband) |
30 | 27.0k | { |
31 | | // T can be unsigned data type so std::abs won't work since it only directly supports signed data types |
32 | | // If one uses std::abs and T is unsigned one will get an ambiguous override error. |
33 | | |
34 | 27.0k | U diff = (val2 > val1) ? (static_cast<U>(val2) - static_cast<U>(val1)) |
35 | 27.0k | : (static_cast<U>(val1) - static_cast<U>(val2)); |
36 | | |
37 | 27.0k | return diff > deadband; |
38 | 27.0k | } |
39 | | |
40 | | bool IsEvent(const TypedMeasurement<double>& newMeas, const TypedMeasurement<double>& oldMeas, double deadband); |
41 | | |
42 | | } // namespace measurements |
43 | | } // namespace opendnp3 |
44 | | |
45 | | #endif |