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 
210  bool init(industrial::byte_array::ByteArray & msg);
211 
218  void toByteArray(industrial::byte_array::ByteArray & msg);
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 
274  industrial::byte_array::ByteArray & getData() {return this->data_;};
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 
346  void setData(industrial::byte_array::ByteArray & data);
347 };
348 
349 }//namespace simple_message
350 }//namespace industrial
351 
352 #endif //SIMPLE_MSG_
int getDataLength()
Gets length of message data portion.
void init(const M_string &remappings)
void setReplyCode(int replyCode)
Sets reply code.
static const unsigned int LENGTH_SIZE
Size (in bytes) of message length parameter (fixed)
void setMessageType(int msgType)
Sets message type.
ReplyTypes::ReplyType ReplyType
static unsigned int getHeaderSize()
Gets size of message header in bytes(fixed)
This class defines a simple messaging protocol for communicating with an industrial robot controller...
int getMessageType()
Gets message type(see StandardMsgType)
industrial::shared_types::shared_int reply_code_
Reply code(see ReplyType)
The byte array wraps a dynamic array of bytes (i.e. char).
Definition: byte_array.h:80
industrial::shared_types::shared_int message_type_
Message type(see StandardMsgType)
static const unsigned int HEADER_SIZE
Size(in bytes) of message header (fixed)
industrial::byte_array::ByteArray data_
Message data portion.
static unsigned int getLengthSize()
Gets size of message length member in bytes (fixed)
industrial::byte_array::ByteArray & getData()
Returns a reference to the internal data member.
void setCommType(int commType)
Sets communications type.
int getMsgLength()
Gets message length (total size, HEADER + data)
CommTypes::CommType CommType
int getReplyCode()
Gets reply code(see ReplyType)
int getCommType()
Gets message type(see CommType)
industrial::shared_types::shared_int comm_type_
Communications type(see CommType)


simple_message
Author(s): Shaun Edwards
autogenerated on Mon Jul 19 2021 12:45:19