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 
void init(const M_string &remappings)
Contains platform specific type definitions that guarantee the size of primitive data types...
Definition: shared_types.h:52
This class defines a simple messaging protocol for communicating with an industrial robot controller...
#define LOG_COMM(format,...)
Definition: log_wrapper.h:104
Class encapsulated robot status data. The robot status data is meant to mirror the industrial_msgs/Ro...
Definition: robot_status.h:116
bool load(industrial::shared_types::shared_bool value)
loads a boolean into the byte array
Definition: byte_array.cpp:142
#define LOG_ERROR(format,...)
Definition: log_wrapper.h:108
The byte array wraps a dynamic array of bytes (i.e. char).
Definition: byte_array.h:80
industrial::byte_array::ByteArray & getData()
Returns a reference to the internal data member.
bool unload(industrial::shared_types::shared_bool &value)
unloads a boolean value from the byte array
Definition: byte_array.cpp:233
int getCommType()
Gets message type(see CommType)


simple_message
Author(s): Shaun Edwards
autogenerated on Sat Sep 21 2019 03:30:09