| Directory: | src/ |
|---|---|
| File: | src/UserParameter.cpp |
| Date: | 2026-09-03 17:04:53 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 27 | 34 | 79.4% |
| Branches: | 13 | 26 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * Copyright (C) 2021 Jonathan Grahl <jonathan.grahl@igh.de> | ||
| 4 | * 2021 Florian Pose <florian.pose@igh.de> | ||
| 5 | * | ||
| 6 | * This file is part of the reta library (realtime-automation). | ||
| 7 | * | ||
| 8 | * The reta library is free software: you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU Lesser General Public License as published | ||
| 10 | * by the Free Software Foundation, either version 3 of the License, or (at | ||
| 11 | * your option) any later version. | ||
| 12 | * | ||
| 13 | * The reta library is distributed in the hope that it will be useful, but | ||
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
| 16 | * General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public License | ||
| 19 | * along with the reta library. If not, see <http://www.gnu.org/licenses/>. | ||
| 20 | * | ||
| 21 | ****************************************************************************/ | ||
| 22 | |||
| 23 | #include "reta/UserParameter.h" | ||
| 24 | |||
| 25 | #include "Base.h" | ||
| 26 | |||
| 27 | using namespace Reta; | ||
| 28 | using namespace std; | ||
| 29 | |||
| 30 | /****************************************************************************/ | ||
| 31 | |||
| 32 | 181 | struct RETA_LOCAL UserParameter::Impl : public Base | |
| 33 | { | ||
| 34 | Impl(shared_ptr<Task>, const string &, unsigned int width); | ||
| 35 | |||
| 36 | shared_ptr<Task> task; | ||
| 37 | |||
| 38 | vector<uint8_t> value; | ||
| 39 | vector<uint8_t> lastValue; | ||
| 40 | vector<uint8_t> changed; | ||
| 41 | }; | ||
| 42 | |||
| 43 | /****************************************************************************/ | ||
| 44 | |||
| 45 | 185 | UserParameter::Impl::Impl( | |
| 46 | shared_ptr<Task> task, | ||
| 47 | const string &prefix, | ||
| 48 | 185 | unsigned int width) : | |
| 49 | Base {prefix}, | ||
| 50 | task {task}, | ||
| 51 | value(width, 0U), | ||
| 52 | lastValue(width, 0U), | ||
| 53 |
3/6✓ Branch 4 taken 185 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 185 times.
✗ Branch 10 not taken.
✓ Branch 14 taken 185 times.
✗ Branch 15 not taken.
|
189 | changed(width, false) |
| 54 | { | ||
| 55 |
2/2✓ Branch 1 taken 181 times.
✓ Branch 2 taken 4 times.
|
185 | checkZeroWidth(width); |
| 56 | |||
| 57 |
1/2✓ Branch 2 taken 181 times.
✗ Branch 3 not taken.
|
181 | pdserv *pdserv {task->getPdServ()}; |
| 58 |
1/2✓ Branch 2 taken 181 times.
✗ Branch 3 not taken.
|
181 | pdtask *pdtask {task->getPdTask()}; |
| 59 | |||
| 60 |
1/2✓ Branch 3 taken 181 times.
✗ Branch 4 not taken.
|
362 | pdserv_parameter( |
| 61 |
1/2✓ Branch 1 taken 181 times.
✗ Branch 2 not taken.
|
362 | pdserv, (prefix + "/Value").c_str(), 0666, pd_uint8_T, |
| 62 | 181 | value.data(), value.size(), NULL, NULL, NULL); | |
| 63 |
1/2✓ Branch 3 taken 181 times.
✗ Branch 4 not taken.
|
362 | pdserv_signal( |
| 64 |
1/2✓ Branch 1 taken 181 times.
✗ Branch 2 not taken.
|
362 | pdtask, 1, (prefix + "/Changed").c_str(), pd_boolean_T, |
| 65 | 181 | changed.data(), changed.size(), NULL); | |
| 66 | 181 | } | |
| 67 | |||
| 68 | /****************************************************************************/ | ||
| 69 | |||
| 70 | 185 | UserParameter::UserParameter( | |
| 71 | shared_ptr<Task> task, | ||
| 72 | const std::string &prefix, | ||
| 73 | 185 | unsigned int width) : | |
| 74 | 185 | impl {make_unique<Impl>(task, prefix, width)} | |
| 75 | 181 | {} | |
| 76 | |||
| 77 | /****************************************************************************/ | ||
| 78 | |||
| 79 | 181 | UserParameter::~UserParameter() | |
| 80 | 181 | {} | |
| 81 | |||
| 82 | /****************************************************************************/ | ||
| 83 | |||
| 84 | 615 | void UserParameter::update() | |
| 85 | { | ||
| 86 |
2/2✓ Branch 2 taken 729 times.
✓ Branch 3 taken 615 times.
|
1344 | for (unsigned int i = 0; i < impl->value.size(); i++) { |
| 87 | 729 | impl->changed.at(i) = impl->value.at(i) != impl->lastValue.at(i); | |
| 88 | 729 | impl->lastValue.at(i) = impl->value.at(i); | |
| 89 | } | ||
| 90 | 615 | } | |
| 91 | |||
| 92 | /****************************************************************************/ | ||
| 93 | |||
| 94 | 568 | bool UserParameter::getChanged(unsigned int i) const | |
| 95 | { | ||
| 96 | 568 | return impl->changed.at(i); | |
| 97 | } | ||
| 98 | |||
| 99 | /****************************************************************************/ | ||
| 100 | |||
| 101 | ✗ | vector<uint8_t> UserParameter::getChangedVector() const | |
| 102 | { | ||
| 103 | ✗ | return impl->changed; | |
| 104 | } | ||
| 105 | |||
| 106 | /****************************************************************************/ | ||
| 107 | |||
| 108 | ✗ | bool UserParameter::anyChanged() const | |
| 109 | { | ||
| 110 | ✗ | for (auto state : impl->changed) { | |
| 111 | ✗ | if (state) { | |
| 112 | ✗ | return state; | |
| 113 | } | ||
| 114 | } | ||
| 115 | |||
| 116 | ✗ | return false; | |
| 117 | } | ||
| 118 | |||
| 119 | /****************************************************************************/ | ||
| 120 |