Coverage Report

Created: 2025-07-18 06:55

/src/opendnp3/cpp/lib/src/master/PollTaskBase.cpp
Line
Count
Source (jump to first uncovered line)
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 "PollTaskBase.h"
21
22
#include "logging/LogMacros.h"
23
#include "master/MeasurementHandler.h"
24
25
#include "opendnp3/logging/LogLevels.h"
26
27
namespace opendnp3
28
{
29
30
PollTaskBase::PollTaskBase(const std::shared_ptr<TaskContext>& context,
31
                           IMasterApplication& application,
32
                           std::shared_ptr<ISOEHandler> handler,
33
                           const TaskBehavior& behavior,
34
                           const Logger& logger,
35
                           TaskConfig config)
36
13.5k
    : IMasterTask(context, application, behavior, logger, config), handler(std::move(handler))
37
13.5k
{
38
13.5k
}
39
40
void PollTaskBase::Initialize()
41
7
{
42
7
    this->rxCount = 0;
43
7
}
44
45
IMasterTask::ResponseResult PollTaskBase::ProcessResponse(const APDUResponseHeader& header,
46
                                                          const ser4cpp::rseq_t& objects)
47
0
{
48
0
    if (header.control.FIR)
49
0
    {
50
0
        if (this->rxCount > 0)
51
0
        {
52
0
            SIMPLE_LOG_BLOCK(logger, flags::WARN, "Ignoring unexpected FIR frame");
53
0
            return ResponseResult::ERROR_BAD_RESPONSE;
54
0
        }
55
56
0
        return ProcessMeasurements(header, objects);
57
0
    }
58
0
    else
59
0
    {
60
0
        if (this->rxCount > 0)
61
0
        {
62
0
            return ProcessMeasurements(header, objects);
63
0
        }
64
65
0
        SIMPLE_LOG_BLOCK(logger, flags::WARN, "Ignoring unexpected non-FIR frame");
66
0
        return ResponseResult::ERROR_BAD_RESPONSE;
67
0
    }
68
0
}
69
70
IMasterTask::ResponseResult PollTaskBase::ProcessMeasurements(const APDUResponseHeader& header,
71
                                                              const ser4cpp::rseq_t& objects)
72
0
{
73
0
    ++rxCount;
74
75
0
    if (MeasurementHandler::ProcessMeasurements(header.as_response_info(), objects, logger, handler.get())
76
0
        == ParseResult::OK)
77
0
    {
78
0
        return header.control.FIN ? ResponseResult::OK_FINAL : ResponseResult::OK_CONTINUE;
79
0
    }
80
81
0
    return ResponseResult::ERROR_BAD_RESPONSE;
82
0
}
83
84
} // namespace opendnp3