io_state.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 
33 using namespace industrial::shared_types;
34 
35 namespace fsrobo_r_driver
36 {
37 namespace simple_message
38 {
39 namespace io_state
40 {
41 
42 IOState::IOState(void)
43 {
44  this->init();
45 }
46 
47 IOState::~IOState(void)
48 {
49 
50 }
51 
52 void IOState::init()
53 {
54  this->setDigital(0, 0);
55  this->setDigital(1, 0);
56  this->setAnalog(0, 0);
57 }
58 
59 void IOState::copyFrom(IOState &src)
60 {
61  this->setDigital(0, src.getDigital(0));
62  this->setDigital(1, src.getDigital(1));
63  this->setAnalog(0, src.getAnalog(0));
64 }
65 
66 bool IOState::operator==(IOState &rhs)
67 {
68  return this->digital_[0] == rhs.digital_[0] && this->digital_[1] == rhs.digital_[1]
69  && this->analog_[0] == rhs.analog_[0];
70 }
71 
72 bool IOState::load(industrial::byte_array::ByteArray *buffer)
73 {
74  bool rtn = false;
75 
76  LOG_COMM("Executing I/O state load");
77 
78  if (buffer->load(this->digital_[0]) && buffer->load(this->digital_[1]) && buffer->load(this->analog_[0]))
79  {
80 
81  LOG_COMM("I/O state successfully loaded");
82  rtn = true;
83  }
84  else
85  {
86  LOG_COMM("I/O state not loaded");
87  rtn = false;
88  }
89 
90  return rtn;
91 }
92 
93 bool IOState::unload(industrial::byte_array::ByteArray *buffer)
94 {
95  bool rtn = false;
96 
97  LOG_COMM("Executing I/O state unload");
98  if (buffer->unload(this->analog_[0]) && buffer->unload(this->digital_[1]) && buffer->unload(this->digital_[0]))
99  {
100  rtn = true;
101  LOG_COMM("I/O state successfully unloaded");
102  }
103 
104  else
105  {
106  LOG_ERROR("Failed to unload I/O state");
107  rtn = false;
108  }
109 
110  return rtn;
111 }
112 
113 }
114 }
115 }
industrial::shared_types::shared_int getAnalog(int idx)
Definition: io_state.h:105
industrial::shared_types::shared_int getDigital(int idx)
Initializes a full robot status message.
Definition: io_state.h:100
#define LOG_COMM(format,...)
industrial::shared_types::shared_int digital_[2]
Digital.
Definition: io_state.h:146
bool load(industrial::shared_types::shared_bool value)
#define LOG_ERROR(format,...)
Class encapsulated robot status data. The robot status data is meant to mirror the industrial_msgs/Ro...
Definition: io_state.h:70
industrial::shared_types::shared_int analog_[1]
Analog.
Definition: io_state.h:151
bool unload(industrial::shared_types::shared_bool &value)


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