simple_message.h
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 SIMPLE_MSG_H
33 #define SIMPLE_MSG_H
34 
35 #ifndef FLATHEADERS
39 #else
40 #include "simple_serialize.h"
41 #include "byte_array.h"
42 #include "shared_types.h"
43 #endif
44 
45 
46 namespace industrial
47 {
48 
49 namespace simple_message
50 {
51 
56 namespace StandardMsgTypes
57 {
59  {
60  INVALID = 0,
61  PING = 1,
62 
63  //TODO: Keeping these message type for the time being. Refactoring
64  // the messages should remove the need for this message.
66  JOINT = 10,
67  READ_INPUT = 20,
69 
70  JOINT_TRAJ_PT = 11, //Joint trajectory point message (typically for streaming)
71  JOINT_TRAJ = 12, //Joint trajectory message (typically for trajectory downloading)
72  STATUS = 13, //Robot status message (for reporting the robot state)
73  JOINT_TRAJ_PT_FULL = 14, // Joint trajectory point message (all message fields)
74  JOINT_FEEDBACK = 15, // Feedback of joint pos/vel/accel
75 
76  // Begin vendor specific message types (only define the beginning enum value,
77  // specific enum values should be defined locally, within in the range reserved
78  // here. Each vendor can reserve up 100 types
79 
81  UR_MSG_BEGIN = 1100,
83  ABB_MSG_BEGIN = 1300,
86  };
87 }
89 
93 namespace CommTypes
94 {
95  enum CommType
96  {
97  INVALID = 0,
98  TOPIC = 1,
101  };
102 }
104 
109 namespace ReplyTypes
110 {
112  {
113  INVALID = 0,
114  SUCCESS = 1,
116  };
117 }
119 
120 
121 
165 {
166 
167 
168 public:
172  SimpleMessage();
173 
177  ~SimpleMessage(void);
188  bool init(int msgType, int commType, int replyCode,
190 
200  bool init(int msgType, int commType, int replyCode);
201 
211 
219 
225  static unsigned int getHeaderSize() { return SimpleMessage::HEADER_SIZE; };
226 
232  static unsigned int getLengthSize() { return SimpleMessage::LENGTH_SIZE; };
233 
239  int getMessageType() {return this->message_type_;};
240 
246  int getCommType() {return this->comm_type_;};
247 
253  int getReplyCode() {return this->reply_code_;};
254 
260  int getMsgLength() {return this->getHeaderSize() + this->data_.getBufferSize();};
261 
267  int getDataLength() {return this->data_.getBufferSize();};
268 
275 
282  bool validateMessage();
283 
284 
285 
286 private:
287 
292 
297 
302 
307 
311  static const unsigned int HEADER_SIZE = sizeof(industrial::shared_types::shared_int) +
314 
318  static const unsigned int LENGTH_SIZE = sizeof(industrial::shared_types::shared_int);
319 
325  void setMessageType(int msgType) {this->message_type_ = msgType;};
326 
332  void setCommType(int commType) {this->comm_type_ = commType;};
333 
339  void setReplyCode(int replyCode) {this->reply_code_ = replyCode;};
340 
347 };
348 
349 }//namespace simple_message
350 }//namespace industrial
351 
352 #endif //SIMPLE_MSG_
industrial::simple_message::SimpleMessage::message_type_
industrial::shared_types::shared_int message_type_
Message type(see StandardMsgType)
Definition: simple_message.h:291
industrial::simple_message::StandardMsgTypes::SWRI_MSG_BEGIN
@ SWRI_MSG_BEGIN
Definition: simple_message.h:80
industrial::simple_message::SimpleMessage::init
bool init(int msgType, int commType, int replyCode, industrial::byte_array::ByteArray &data)
Initializes a fully populated simple message.
Definition: simple_message.cpp:70
industrial::simple_message::SimpleMessage::data_
industrial::byte_array::ByteArray data_
Message data portion.
Definition: simple_message.h:306
industrial::simple_message::ReplyTypes::SUCCESS
@ SUCCESS
Definition: simple_message.h:114
industrial
Definition: byte_array.h:45
industrial::simple_message::SimpleMessage::HEADER_SIZE
static const unsigned int HEADER_SIZE
Size(in bytes) of message header (fixed)
Definition: simple_message.h:311
industrial::simple_message::StandardMsgTypes::JOINT
@ JOINT
Definition: simple_message.h:66
industrial::simple_message::SimpleMessage::getLengthSize
static unsigned int getLengthSize()
Gets size of message length member in bytes (fixed)
Definition: simple_message.h:232
industrial::simple_message::StandardMsgTypes::WRITE_OUTPUT
@ WRITE_OUTPUT
Definition: simple_message.h:68
industrial::simple_message::SimpleMessage::~SimpleMessage
~SimpleMessage(void)
Destructs a message.
Definition: simple_message.cpp:57
industrial::simple_message::SimpleMessage::getData
industrial::byte_array::ByteArray & getData()
Returns a reference to the internal data member.
Definition: simple_message.h:274
industrial::simple_message::SimpleMessage::setCommType
void setCommType(int commType)
Sets communications type.
Definition: simple_message.h:332
byte_array.h
industrial::simple_message::SimpleMessage::getMsgLength
int getMsgLength()
Gets message length (total size, HEADER + data)
Definition: simple_message.h:260
industrial::simple_message::StandardMsgTypes::JOINT_POSITION
@ JOINT_POSITION
Definition: simple_message.h:65
industrial::simple_message::SimpleMessage::getReplyCode
int getReplyCode()
Gets reply code(see ReplyType)
Definition: simple_message.h:253
industrial::simple_message::StandardMsgTypes::StandardMsgType
StandardMsgType
Definition: simple_message.h:58
industrial::simple_message::ReplyTypes::ReplyType
ReplyType
Definition: simple_message.h:111
industrial::simple_message::SimpleMessage::getCommType
int getCommType()
Gets message type(see CommType)
Definition: simple_message.h:246
industrial::simple_message::StandardMsgTypes::JOINT_FEEDBACK
@ JOINT_FEEDBACK
Definition: simple_message.h:74
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
industrial::simple_message::ReplyTypes::INVALID
@ INVALID
Definition: simple_message.h:113
industrial::simple_message::StandardMsgTypes::ADEPT_MSG_BEGIN
@ ADEPT_MSG_BEGIN
Definition: simple_message.h:82
industrial::simple_message::SimpleMessage::comm_type_
industrial::shared_types::shared_int comm_type_
Communications type(see CommType)
Definition: simple_message.h:296
industrial::simple_message::CommType
CommTypes::CommType CommType
Definition: simple_message.h:103
industrial::simple_message::SimpleMessage::getDataLength
int getDataLength()
Gets length of message data portion.
Definition: simple_message.h:267
industrial::simple_message::SimpleMessage::toByteArray
void toByteArray(industrial::byte_array::ByteArray &msg)
Populates a raw byte array with the message. Any data stored in the passed in byte array is deleted.
Definition: simple_message.cpp:113
industrial::simple_message::StandardMsgTypes::READ_INPUT
@ READ_INPUT
Definition: simple_message.h:67
industrial::simple_message::StandardMsgTypes::INVALID
@ INVALID
Definition: simple_message.h:60
industrial::simple_message::SimpleMessage::setReplyCode
void setReplyCode(int replyCode)
Sets reply code.
Definition: simple_message.h:339
shared_types.h
industrial::simple_message::SimpleMessage::validateMessage
bool validateMessage()
performs logical checks to ensure that the message is fully defined and adheres to the message conven...
Definition: simple_message.cpp:134
industrial::shared_types::shared_int
int shared_int
Definition: shared_types.h:62
industrial::simple_message::SimpleMessage::setData
void setData(industrial::byte_array::ByteArray &data)
Sets data portion.
Definition: simple_message.cpp:128
industrial::simple_message::CommTypes::CommType
CommType
Definition: simple_message.h:95
industrial::simple_message::SimpleMessage::LENGTH_SIZE
static const unsigned int LENGTH_SIZE
Size (in bytes) of message length parameter (fixed)
Definition: simple_message.h:318
industrial::simple_message::StandardMsgTypes::FANUC_MSG_BEGIN
@ FANUC_MSG_BEGIN
Definition: simple_message.h:84
industrial::simple_message::StandardMsgTypes::UR_MSG_BEGIN
@ UR_MSG_BEGIN
Definition: simple_message.h:81
industrial::simple_message::CommTypes::INVALID
@ INVALID
Definition: simple_message.h:97
industrial::simple_message::StandardMsgTypes::MOTOMAN_MSG_BEGIN
@ MOTOMAN_MSG_BEGIN
Definition: simple_message.h:85
industrial::simple_message::SimpleMessage::setMessageType
void setMessageType(int msgType)
Sets message type.
Definition: simple_message.h:325
industrial::simple_message::StandardMsgTypes::PING
@ PING
Definition: simple_message.h:61
industrial::simple_message::CommTypes::TOPIC
@ TOPIC
Definition: simple_message.h:98
industrial::simple_message::CommTypes::SERVICE_REQUEST
@ SERVICE_REQUEST
Definition: simple_message.h:99
industrial::simple_message::SimpleMessage::getHeaderSize
static unsigned int getHeaderSize()
Gets size of message header in bytes(fixed)
Definition: simple_message.h:225
industrial::simple_message::ReplyTypes::FAILURE
@ FAILURE
Definition: simple_message.h:115
industrial::simple_message::StandardMsgType
StandardMsgTypes::StandardMsgType StandardMsgType
Definition: simple_message.h:88
industrial::simple_message::StandardMsgTypes::STATUS
@ STATUS
Definition: simple_message.h:72
industrial::simple_message::StandardMsgTypes::ABB_MSG_BEGIN
@ ABB_MSG_BEGIN
Definition: simple_message.h:83
industrial::simple_message::SimpleMessage::getMessageType
int getMessageType()
Gets message type(see StandardMsgType)
Definition: simple_message.h:239
industrial::simple_message::StandardMsgTypes::JOINT_TRAJ_PT_FULL
@ JOINT_TRAJ_PT_FULL
Definition: simple_message.h:73
industrial::simple_message::CommTypes::SERVICE_REPLY
@ SERVICE_REPLY
Definition: simple_message.h:100
industrial::simple_message::ReplyType
ReplyTypes::ReplyType ReplyType
Definition: simple_message.h:118
industrial::simple_message::SimpleMessage::SimpleMessage
SimpleMessage()
Constructs an empty message.
Definition: simple_message.cpp:53
industrial::simple_message::StandardMsgTypes::JOINT_TRAJ_PT
@ JOINT_TRAJ_PT
Definition: simple_message.h:70
industrial::byte_array::ByteArray::getBufferSize
unsigned int getBufferSize()
gets current buffer size
Definition: byte_array.cpp:387
simple_serialize.h
industrial::simple_message::StandardMsgTypes::JOINT_TRAJ
@ JOINT_TRAJ
Definition: simple_message.h:71
industrial::simple_message::SimpleMessage::reply_code_
industrial::shared_types::shared_int reply_code_
Reply code(see ReplyType)
Definition: simple_message.h:301


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