/src/opendnp3/cpp/lib/src/app/AppControlField.cpp
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 | | #include "AppControlField.h" |
21 | | |
22 | | namespace opendnp3 |
23 | | { |
24 | | |
25 | | const AppControlField AppControlField::DEFAULT(true, true, false, false, 0); |
26 | | |
27 | | AppControlField::AppControlField(uint8_t byte) |
28 | 36.0k | : FIR((byte & FIR_MASK) != 0), |
29 | 36.0k | FIN((byte & FIN_MASK) != 0), |
30 | 36.0k | CON((byte & CON_MASK) != 0), |
31 | 36.0k | UNS((byte & UNS_MASK) != 0), |
32 | 36.0k | SEQ(byte & SEQ_MASK) |
33 | 36.0k | { |
34 | 36.0k | } |
35 | | |
36 | | AppControlField AppControlField::Request(uint8_t seq) |
37 | 0 | { |
38 | 0 | return AppControlField(true, true, false, false, seq); |
39 | 0 | } |
40 | | |
41 | | AppControlField::AppControlField(bool fir, bool fin, bool con, bool uns, uint8_t seq) |
42 | 8.91k | : FIR(fir), FIN(fin), CON(con), UNS(uns), SEQ(seq) |
43 | 8.91k | { |
44 | 8.91k | } |
45 | | |
46 | | uint8_t AppControlField::ToByte() const |
47 | 8.90k | { |
48 | 8.90k | uint8_t ret = 0; |
49 | | |
50 | 8.90k | if (FIR) |
51 | 8.90k | { |
52 | 8.90k | ret |= FIR_MASK; |
53 | 8.90k | } |
54 | 8.90k | if (FIN) |
55 | 8.90k | { |
56 | 8.90k | ret |= FIN_MASK; |
57 | 8.90k | } |
58 | 8.90k | if (CON) |
59 | 0 | { |
60 | 0 | ret |= CON_MASK; |
61 | 0 | } |
62 | 8.90k | if (UNS) |
63 | 0 | { |
64 | 0 | ret |= UNS_MASK; |
65 | 0 | } |
66 | | |
67 | 8.90k | uint8_t seq = SEQ % 16; |
68 | | |
69 | 8.90k | return ret | seq; |
70 | 8.90k | } |
71 | | |
72 | | } // namespace opendnp3 |