robot_status_message.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Southwest Research Institute
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * * Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * * Neither the name of the Southwest Research Institute, nor the names
16  * of its contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef FLATHEADERS
37 #else
38 #include "robot_status_message.h"
39 #include "robot_status.h"
40 #include "byte_array.h"
41 #include "log_wrapper.h"
42 #endif
43 
44 using namespace industrial::shared_types;
45 using namespace industrial::byte_array;
46 using namespace industrial::simple_message;
47 using namespace industrial::robot_status;
48 
49 namespace industrial
50 {
51 namespace robot_status_message
52 {
53 
54 RobotStatusMessage::RobotStatusMessage(void)
55 {
56  this->init();
57 }
58 
59 RobotStatusMessage::~RobotStatusMessage(void)
60 {
61 
62 }
63 
64 bool RobotStatusMessage::init(industrial::simple_message::SimpleMessage & msg)
65 {
66  bool rtn = false;
67  ByteArray data = msg.getData();
68  this->init();
69  this->setCommType(msg.getCommType());
70 
71  if (data.unload(this->status_))
72  {
73  rtn = true;
74  }
75  else
76  {
77  LOG_ERROR("Failed to unload robot status data");
78  }
79  return rtn;
80 }
81 
82 void RobotStatusMessage::init(industrial::robot_status::RobotStatus & status)
83 {
84  this->init();
85  this->status_.copyFrom(status);
86 }
87 
88 void RobotStatusMessage::init()
89 {
90  this->setMessageType(StandardMsgTypes::STATUS);
91  this->status_.init();
92 }
93 
94 bool RobotStatusMessage::load(ByteArray *buffer)
95 {
96  bool rtn = false;
97  LOG_COMM("Executing robot status message load");
98  if (buffer->load(this->status_))
99  {
100  rtn = true;
101  }
102  else
103  {
104  rtn = false;
105  LOG_ERROR("Failed to load robot status data");
106  }
107  return rtn;
108 }
109 
110 bool RobotStatusMessage::unload(ByteArray *buffer)
111 {
112  bool rtn = false;
113  LOG_COMM("Executing robot status message unload");
114 
115  if (buffer->unload(this->status_))
116  {
117  rtn = true;
118  }
119  else
120  {
121  rtn = false;
122  LOG_ERROR("Failed to unload robot status data");
123  }
124  return rtn;
125 }
126 
127 }
128 }
129 
robot_status_message.h
industrial::robot_status
Definition: robot_status.h:47
industrial::shared_types
Contains platform specific type definitions that guarantee the size of primitive data types.
Definition: shared_types.h:52
industrial
Definition: byte_array.h:45
industrial::byte_array::ByteArray::unload
bool unload(industrial::shared_types::shared_bool &value)
unloads a boolean value from the byte array
Definition: byte_array.cpp:233
industrial::simple_message::SimpleMessage::getData
industrial::byte_array::ByteArray & getData()
Returns a reference to the internal data member.
Definition: simple_message.h:274
byte_array.h
LOG_ERROR
#define LOG_ERROR(format,...)
Definition: log_wrapper.h:134
industrial::simple_message::SimpleMessage::getCommType
int getCommType()
Gets message type(see CommType)
Definition: simple_message.h:246
industrial::simple_message::SimpleMessage
This class defines a simple messaging protocol for communicating with an industrial robot controller.
Definition: simple_message.h:164
industrial::byte_array::ByteArray
The byte array wraps a dynamic array of bytes (i.e. char).
Definition: byte_array.h:80
LOG_COMM
#define LOG_COMM(format,...)
Definition: log_wrapper.h:130
industrial::simple_message
Definition: simple_message.h:49
industrial::robot_status::RobotStatus
Class encapsulated robot status data. The robot status data is meant to mirror the industrial_msgs/Ro...
Definition: robot_status.h:118
log_wrapper.h
industrial::byte_array
Definition: byte_array.h:56
industrial::byte_array::ByteArray::load
bool load(industrial::shared_types::shared_bool value)
loads a boolean into the byte array
Definition: byte_array.cpp:142
init
void init(const M_string &remappings)
industrial::simple_message::StandardMsgTypes::STATUS
@ STATUS
Definition: simple_message.h:72
robot_status.h


simple_message
Author(s): Shaun Edwards
autogenerated on Wed Mar 2 2022 00:24:53