set_io.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * FSRobo-R Package BSDL
3 * ---------
4 * Copyright (C) 2019 FUJISOFT. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without modification,
7 * are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation and/or
12 * other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors
14 * may be used to endorse or promote products derived from this software without
15 * specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *********************************************************************/
28 
32 #include <vector>
33 
35 using std::vector;
36 
37 namespace fsrobo_r_driver
38 {
39 namespace simple_message
40 {
41 namespace io_control
42 {
43 
45 {
46  this->init();
47 }
48 
50 {
51 }
52 
54 {
55  vector<shared_int> data(32, 0);
56 
57  // TODO: is '0' a good initial value?
58  this->init(0, 0, data);
59 }
60 
61 void SetIO::init(shared_int fun, shared_int address, vector<shared_int> &data)
62 {
63  this->setFun(fun);
64  this->setAddress(address);
65 
66  std::size_t size = data.size();
67  this->setDataSize(size);
68 
69  int i = 0;
70  for (auto &x : this->data_)
71  {
72  if (i < size) {
73  x = data[i];
74  }
75  i++;
76  }
77 }
78 
80 {
81  this->setFun(src.getFun());
82  this->setAddress(src.getAddress());
83  this->setDataSize(src.getDataSize());
84 
85  shared_int *data = src.getData();
86  for (int i = 0; i < 32; i++)
87  {
88  this->data_[i] = data[i];
89  }
90 }
91 
93 {
94  bool rslt = this->fun_ == rhs.fun_ &&
95  this->address_ == rhs.address_ &&
96  this->data_ == rhs.data_;
97 
98  return rslt;
99 }
100 
102 {
103  LOG_COMM("Executing SetIO command load");
104 
105  if (!buffer->load(this->fun_))
106  {
107  LOG_ERROR("Failed to load SetIO fun");
108  return false;
109  }
110 
111  if (!buffer->load(this->address_))
112  {
113  LOG_ERROR("Failed to load SetIO address");
114  return false;
115  }
116 
117  if (!buffer->load(this->data_size_))
118  {
119  LOG_ERROR("Failed to load SetIO data size");
120  return false;
121  }
122 
123  for (auto x : this->data_)
124  {
125  if (!buffer->load(x))
126  {
127  LOG_ERROR("Failed to load SetIO data");
128  return false;
129  }
130  }
131 
132  LOG_COMM("SetIO data successfully loaded");
133  return true;
134 }
135 
137 {
138  LOG_COMM("Executing SetIO command unload");
139 
140  for (auto &x : this->data_)
141  {
142  if (!buffer->unload(x))
143  {
144  LOG_ERROR("Failed to unload SetIO data");
145  return false;
146  }
147  }
148 
149  if (!buffer->unload(this->data_size_))
150  {
151  LOG_ERROR("Failed to unload SetIO data size");
152  return false;
153  }
154 
155  if (!buffer->unload(this->address_))
156  {
157  LOG_ERROR("Failed to unload SetIO address");
158  return false;
159  }
160 
161  if (!buffer->unload(this->fun_))
162  {
163  LOG_ERROR("Failed to unload SetIO fun");
164  return false;
165  }
166 
167  LOG_COMM("SetIO data successfully unloaded");
168  return true;
169 }
170 
171 }
172 }
173 }
industrial::shared_types::shared_int * getData()
Returns the value of the IO element.
Definition: set_io.h:154
void init()
Initializes a empty write single io command.
Definition: set_io.cpp:53
void setDataSize(industrial::shared_types::shared_int data_size)
Sets value.
Definition: set_io.h:114
#define LOG_COMM(format,...)
bool load(industrial::shared_types::shared_bool value)
#define LOG_ERROR(format,...)
industrial::shared_types::shared_int address_
Address of IO element.
Definition: set_io.h:190
void setAddress(industrial::shared_types::shared_int address)
Sets address.
Definition: set_io.h:94
industrial::shared_types::shared_int getAddress()
Returns the address of the IO element.
Definition: set_io.h:124
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool load(industrial::byte_array::ByteArray *buffer)
Definition: set_io.cpp:101
void setFun(industrial::shared_types::shared_int fun)
Sets value.
Definition: set_io.h:104
void copyFrom(SetIO &src)
Copies the passed in value.
Definition: set_io.cpp:79
industrial::shared_types::shared_int getFun()
Returns the value of the IO element.
Definition: set_io.h:134
industrial::shared_types::shared_int fun_
Value of IO element.
Definition: set_io.h:185
bool unload(industrial::byte_array::ByteArray *buffer)
Definition: set_io.cpp:136
industrial::shared_types::shared_int getDataSize()
Returns the value of the IO element.
Definition: set_io.h:144
Class encapsulated write single io data. FSRobo-R specific interface to set IO element on the control...
Definition: set_io.h:60
bool operator==(SetIO &rhs)
== operator implementation
Definition: set_io.cpp:92
bool unload(industrial::shared_types::shared_bool &value)
industrial::shared_types::shared_int data_[32]
Definition: set_io.h:193


fsrobo_r_driver
Author(s): F-ROSROBO
autogenerated on Sun Feb 9 2020 03:58:29