joint_message.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, 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 "joint_message.h"
39 #include "joint_data.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::joint_data;
48 
49 namespace industrial
50 {
51 namespace joint_message
52 {
53 
54 JointMessage::JointMessage(void)
55 {
56  this->setMessageType(StandardMsgTypes::JOINT_POSITION);
57  this->init();
58 }
59 
60 JointMessage::~JointMessage(void)
61 {
62 
63 }
64 
65 bool JointMessage::init(industrial::simple_message::SimpleMessage & msg)
66 {
67  bool rtn = false;
68  ByteArray data = msg.getData();
69 
70  this->setMessageType(StandardMsgTypes::JOINT_POSITION);
71 
72  if (data.unload(this->joints_))
73  {
74  if (data.unload(this->sequence_))
75  {
76  rtn = true;
77  }
78  else
79  {
80  rtn = false;
81  LOG_ERROR("Failed to unload sequence data");
82  }
83  }
84  else
85  {
86  LOG_ERROR("Failed to unload joint data");
87  }
88  return rtn;
89 }
90 
91 void JointMessage::setSequence(shared_int sequence)
92 {
93  this->sequence_ = sequence;
94 }
95 
96 void JointMessage::init(shared_int seq, JointData& joints)
97 {
98  this->setSequence(seq);
99  this->joints_.copyFrom(joints);
100 }
101 
102 void JointMessage::init()
103 {
104  this->setSequence(0);
105  this->joints_.init();
106 }
107 
108 bool JointMessage::load(ByteArray *buffer)
109 {
110  bool rtn = false;
111  LOG_COMM("Executing joint message load");
112  if (buffer->load(this->getSequence()))
113  {
114 
115  if (buffer->load(this->joints_))
116  {
117  rtn = true;
118  }
119  else
120  {
121  rtn = false;
122  LOG_ERROR("Failed to load sequence data");
123  }
124  }
125  else
126  {
127  rtn = false;
128  LOG_ERROR("Failed to load sequence data");
129  }
130  return rtn;
131 }
132 
133 bool JointMessage::unload(ByteArray *buffer)
134 {
135  bool rtn = false;
136  LOG_COMM("Executing joint message unload");
137 
138  if (buffer->unload(this->joints_))
139  {
140 
141  if (buffer->unload(this->sequence_))
142  {
143  rtn = true;
144  }
145  else
146  {
147  rtn = false;
148  LOG_ERROR("Failed to unload sequence data");
149  }
150  }
151  else
152  {
153  rtn = false;
154  LOG_ERROR("Failed to unload joint data");
155  }
156  return rtn;
157 }
158 
159 }
160 }
161 
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
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
Class encapsulated joint data (positions, accelerations, velocity, torque, and/or effort)...
Definition: joint_data.h:68
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


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