LAB
Dependencies: BufferedSerial
Fork of ros_lib_indigo by
std_srvs/Trigger.h@1:1523bf60b9a9, 2018-04-19 (annotated)
- Committer:
- MechanicalThomas
- Date:
- Thu Apr 19 14:57:05 2018 +0000
- Revision:
- 1:1523bf60b9a9
- Parent:
- 0:fd24f7ca9688
000;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garyservin | 0:fd24f7ca9688 | 1 | #ifndef _ROS_SERVICE_Trigger_h |
garyservin | 0:fd24f7ca9688 | 2 | #define _ROS_SERVICE_Trigger_h |
garyservin | 0:fd24f7ca9688 | 3 | #include <stdint.h> |
garyservin | 0:fd24f7ca9688 | 4 | #include <string.h> |
garyservin | 0:fd24f7ca9688 | 5 | #include <stdlib.h> |
garyservin | 0:fd24f7ca9688 | 6 | #include "ros/msg.h" |
garyservin | 0:fd24f7ca9688 | 7 | |
garyservin | 0:fd24f7ca9688 | 8 | namespace std_srvs |
garyservin | 0:fd24f7ca9688 | 9 | { |
garyservin | 0:fd24f7ca9688 | 10 | |
garyservin | 0:fd24f7ca9688 | 11 | static const char TRIGGER[] = "std_srvs/Trigger"; |
garyservin | 0:fd24f7ca9688 | 12 | |
garyservin | 0:fd24f7ca9688 | 13 | class TriggerRequest : public ros::Msg |
garyservin | 0:fd24f7ca9688 | 14 | { |
garyservin | 0:fd24f7ca9688 | 15 | public: |
garyservin | 0:fd24f7ca9688 | 16 | |
garyservin | 0:fd24f7ca9688 | 17 | TriggerRequest() |
garyservin | 0:fd24f7ca9688 | 18 | { |
garyservin | 0:fd24f7ca9688 | 19 | } |
garyservin | 0:fd24f7ca9688 | 20 | |
garyservin | 0:fd24f7ca9688 | 21 | virtual int serialize(unsigned char *outbuffer) const |
garyservin | 0:fd24f7ca9688 | 22 | { |
garyservin | 0:fd24f7ca9688 | 23 | int offset = 0; |
garyservin | 0:fd24f7ca9688 | 24 | return offset; |
garyservin | 0:fd24f7ca9688 | 25 | } |
garyservin | 0:fd24f7ca9688 | 26 | |
garyservin | 0:fd24f7ca9688 | 27 | virtual int deserialize(unsigned char *inbuffer) |
garyservin | 0:fd24f7ca9688 | 28 | { |
garyservin | 0:fd24f7ca9688 | 29 | int offset = 0; |
garyservin | 0:fd24f7ca9688 | 30 | return offset; |
garyservin | 0:fd24f7ca9688 | 31 | } |
garyservin | 0:fd24f7ca9688 | 32 | |
garyservin | 0:fd24f7ca9688 | 33 | const char * getType(){ return TRIGGER; }; |
garyservin | 0:fd24f7ca9688 | 34 | const char * getMD5(){ return "d41d8cd98f00b204e9800998ecf8427e"; }; |
garyservin | 0:fd24f7ca9688 | 35 | |
garyservin | 0:fd24f7ca9688 | 36 | }; |
garyservin | 0:fd24f7ca9688 | 37 | |
garyservin | 0:fd24f7ca9688 | 38 | class TriggerResponse : public ros::Msg |
garyservin | 0:fd24f7ca9688 | 39 | { |
garyservin | 0:fd24f7ca9688 | 40 | public: |
garyservin | 0:fd24f7ca9688 | 41 | bool success; |
garyservin | 0:fd24f7ca9688 | 42 | const char* message; |
garyservin | 0:fd24f7ca9688 | 43 | |
garyservin | 0:fd24f7ca9688 | 44 | TriggerResponse(): |
garyservin | 0:fd24f7ca9688 | 45 | success(0), |
garyservin | 0:fd24f7ca9688 | 46 | message("") |
garyservin | 0:fd24f7ca9688 | 47 | { |
garyservin | 0:fd24f7ca9688 | 48 | } |
garyservin | 0:fd24f7ca9688 | 49 | |
garyservin | 0:fd24f7ca9688 | 50 | virtual int serialize(unsigned char *outbuffer) const |
garyservin | 0:fd24f7ca9688 | 51 | { |
garyservin | 0:fd24f7ca9688 | 52 | int offset = 0; |
garyservin | 0:fd24f7ca9688 | 53 | union { |
garyservin | 0:fd24f7ca9688 | 54 | bool real; |
garyservin | 0:fd24f7ca9688 | 55 | uint8_t base; |
garyservin | 0:fd24f7ca9688 | 56 | } u_success; |
garyservin | 0:fd24f7ca9688 | 57 | u_success.real = this->success; |
garyservin | 0:fd24f7ca9688 | 58 | *(outbuffer + offset + 0) = (u_success.base >> (8 * 0)) & 0xFF; |
garyservin | 0:fd24f7ca9688 | 59 | offset += sizeof(this->success); |
garyservin | 0:fd24f7ca9688 | 60 | uint32_t length_message = strlen(this->message); |
garyservin | 0:fd24f7ca9688 | 61 | memcpy(outbuffer + offset, &length_message, sizeof(uint32_t)); |
garyservin | 0:fd24f7ca9688 | 62 | offset += 4; |
garyservin | 0:fd24f7ca9688 | 63 | memcpy(outbuffer + offset, this->message, length_message); |
garyservin | 0:fd24f7ca9688 | 64 | offset += length_message; |
garyservin | 0:fd24f7ca9688 | 65 | return offset; |
garyservin | 0:fd24f7ca9688 | 66 | } |
garyservin | 0:fd24f7ca9688 | 67 | |
garyservin | 0:fd24f7ca9688 | 68 | virtual int deserialize(unsigned char *inbuffer) |
garyservin | 0:fd24f7ca9688 | 69 | { |
garyservin | 0:fd24f7ca9688 | 70 | int offset = 0; |
garyservin | 0:fd24f7ca9688 | 71 | union { |
garyservin | 0:fd24f7ca9688 | 72 | bool real; |
garyservin | 0:fd24f7ca9688 | 73 | uint8_t base; |
garyservin | 0:fd24f7ca9688 | 74 | } u_success; |
garyservin | 0:fd24f7ca9688 | 75 | u_success.base = 0; |
garyservin | 0:fd24f7ca9688 | 76 | u_success.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0); |
garyservin | 0:fd24f7ca9688 | 77 | this->success = u_success.real; |
garyservin | 0:fd24f7ca9688 | 78 | offset += sizeof(this->success); |
garyservin | 0:fd24f7ca9688 | 79 | uint32_t length_message; |
garyservin | 0:fd24f7ca9688 | 80 | memcpy(&length_message, (inbuffer + offset), sizeof(uint32_t)); |
garyservin | 0:fd24f7ca9688 | 81 | offset += 4; |
garyservin | 0:fd24f7ca9688 | 82 | for(unsigned int k= offset; k< offset+length_message; ++k){ |
garyservin | 0:fd24f7ca9688 | 83 | inbuffer[k-1]=inbuffer[k]; |
garyservin | 0:fd24f7ca9688 | 84 | } |
garyservin | 0:fd24f7ca9688 | 85 | inbuffer[offset+length_message-1]=0; |
garyservin | 0:fd24f7ca9688 | 86 | this->message = (char *)(inbuffer + offset-1); |
garyservin | 0:fd24f7ca9688 | 87 | offset += length_message; |
garyservin | 0:fd24f7ca9688 | 88 | return offset; |
garyservin | 0:fd24f7ca9688 | 89 | } |
garyservin | 0:fd24f7ca9688 | 90 | |
garyservin | 0:fd24f7ca9688 | 91 | const char * getType(){ return TRIGGER; }; |
garyservin | 0:fd24f7ca9688 | 92 | const char * getMD5(){ return "937c9679a518e3a18d831e57125ea522"; }; |
garyservin | 0:fd24f7ca9688 | 93 | |
garyservin | 0:fd24f7ca9688 | 94 | }; |
garyservin | 0:fd24f7ca9688 | 95 | |
garyservin | 0:fd24f7ca9688 | 96 | class Trigger { |
garyservin | 0:fd24f7ca9688 | 97 | public: |
garyservin | 0:fd24f7ca9688 | 98 | typedef TriggerRequest Request; |
garyservin | 0:fd24f7ca9688 | 99 | typedef TriggerResponse Response; |
garyservin | 0:fd24f7ca9688 | 100 | }; |
garyservin | 0:fd24f7ca9688 | 101 | |
garyservin | 0:fd24f7ca9688 | 102 | } |
garyservin | 0:fd24f7ca9688 | 103 | #endif |