RTXI  3.0.0
The Real-Time eXperiment Interface Reference Manual
io.cpp
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah,
4  Will Cornell Medical College
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 
21 #include <algorithm>
22 #include <queue>
23 #include <string>
24 
25 #include "io.hpp"
26 
27 #include "debug.hpp"
28 // NOLINTBEGIN(cppcoreguidelines-pro-bounds-constant-array-index)
29 IO::Block::Block(std::string blockname,
30  const std::vector<IO::channel_t>& channels,
31  bool isdependent)
32  : name(std::move(blockname))
33  , isInputDependent(isdependent)
34 {
35  port_t port = {};
36  for (const auto& channel : channels) {
37  port.channel_info = channel;
38  port.value = 0.0;
39  port.buff_value = 0.0;
40  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
41  ports[channel.flags].push_back(port);
42  port = {};
43  }
44 }
45 
46 size_t IO::Block::getCount(IO::flags_t type) const
47 {
48  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
49  return this->ports[type].size();
50 }
51 
52 std::string IO::Block::getChannelName(IO::flags_t type, size_t index) const
53 {
54  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
55  return this->ports[type][index].channel_info.name;
56 }
57 
59  size_t index) const
60 {
61  // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index)
62  return this->ports[type][index].channel_info.description;
63 }
64 
65 void IO::Block::writeinput(size_t index, const double& data)
66 {
67  this->ports[IO::INPUT][index].buff_value += data;
68 }
69 
70 double& IO::Block::readinput(size_t index)
71 {
72  // We must reset input values to zero so that the next cycle doesn't use these
73  // values
74  this->ports[IO::INPUT][index].value =
75  this->ports[IO::INPUT][index].buff_value;
76  this->ports[IO::INPUT][index].buff_value = 0.0;
77  return this->ports[IO::INPUT][index].value;
78 }
79 
80 void IO::Block::writeoutput(size_t index, const double& data)
81 {
82  this->ports[IO::OUTPUT][index].value = data;
83 }
84 
85 const double& IO::Block::readPort(IO::flags_t direction, size_t index)
86 {
87  return this->ports[direction][index].value;
88 }
89 // NOLINTEND(cppcoreguidelines-pro-bounds-constant-array-index)
double & readinput(size_t index)
Definition: io.cpp:70
void writeoutput(size_t index, const double &data)
Definition: io.cpp:80
Block(std::string blockname, const std::vector< channel_t > &channels, bool isdependent)
Definition: io.cpp:29
std::string getChannelName(IO::flags_t type, size_t index) const
Definition: io.cpp:52
std::string getChannelDescription(IO::flags_t type, size_t index) const
Definition: io.cpp:58
size_t getCount(flags_t type) const
Definition: io.cpp:46
void writeinput(size_t index, const double &data)
Definition: io.cpp:65
const double & readPort(IO::flags_t direction, size_t index)
Definition: io.cpp:85
flags_t
Definition: io.hpp:52
@ INPUT
Definition: io.hpp:54
@ OUTPUT
Definition: io.hpp:53