This program is porting rosserial_arduino for mbed http://www.ros.org/wiki/rosserial_arduino This program supported the revision of 169 of rosserial. This program contains an example.

Dependencies:   rosserial_mbed_lib mbed Servo

Committer:
nucho
Date:
Sun Oct 16 07:17:43 2011 +0000
Revision:
1:098e75fd5ad2
Parent:
0:06fc856e99ca
Child:
3:dff241b66f84
This program supported the revision of 143 of rosserial.
And the bug fix of receive of array data.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucho 0:06fc856e99ca 1 #ifndef ros_Int64_h
nucho 0:06fc856e99ca 2 #define ros_Int64_h
nucho 0:06fc856e99ca 3
nucho 0:06fc856e99ca 4 #include <stdint.h>
nucho 0:06fc856e99ca 5 #include <string.h>
nucho 0:06fc856e99ca 6 #include <stdlib.h>
nucho 0:06fc856e99ca 7 #include "../ros/msg.h"
nucho 0:06fc856e99ca 8
nucho 1:098e75fd5ad2 9 namespace std_msgs {
nucho 0:06fc856e99ca 10
nucho 1:098e75fd5ad2 11 class Int64 : public ros::Msg {
nucho 1:098e75fd5ad2 12 public:
nucho 1:098e75fd5ad2 13 int64_t data;
nucho 0:06fc856e99ca 14
nucho 1:098e75fd5ad2 15 virtual int serialize(unsigned char *outbuffer) {
nucho 1:098e75fd5ad2 16 int offset = 0;
nucho 1:098e75fd5ad2 17 union {
nucho 1:098e75fd5ad2 18 int64_t real;
nucho 1:098e75fd5ad2 19 uint64_t base;
nucho 1:098e75fd5ad2 20 } u_data;
nucho 1:098e75fd5ad2 21 u_data.real = this->data;
nucho 1:098e75fd5ad2 22 *(outbuffer + offset + 0) = (u_data.base >> (8 * 0)) & 0xFF;
nucho 1:098e75fd5ad2 23 *(outbuffer + offset + 1) = (u_data.base >> (8 * 1)) & 0xFF;
nucho 1:098e75fd5ad2 24 *(outbuffer + offset + 2) = (u_data.base >> (8 * 2)) & 0xFF;
nucho 1:098e75fd5ad2 25 *(outbuffer + offset + 3) = (u_data.base >> (8 * 3)) & 0xFF;
nucho 1:098e75fd5ad2 26 *(outbuffer + offset + 4) = (u_data.base >> (8 * 4)) & 0xFF;
nucho 1:098e75fd5ad2 27 *(outbuffer + offset + 5) = (u_data.base >> (8 * 5)) & 0xFF;
nucho 1:098e75fd5ad2 28 *(outbuffer + offset + 6) = (u_data.base >> (8 * 6)) & 0xFF;
nucho 1:098e75fd5ad2 29 *(outbuffer + offset + 7) = (u_data.base >> (8 * 7)) & 0xFF;
nucho 1:098e75fd5ad2 30
nucho 1:098e75fd5ad2 31 offset += sizeof(this->data);
nucho 1:098e75fd5ad2 32 return offset;
nucho 0:06fc856e99ca 33 }
nucho 0:06fc856e99ca 34
nucho 1:098e75fd5ad2 35 virtual int deserialize(unsigned char *inbuffer) {
nucho 1:098e75fd5ad2 36 int offset = 0;
nucho 1:098e75fd5ad2 37 union {
nucho 1:098e75fd5ad2 38 int64_t real;
nucho 1:098e75fd5ad2 39 uint64_t base;
nucho 1:098e75fd5ad2 40 } u_data;
nucho 1:098e75fd5ad2 41 u_data.base = 0;
nucho 1:098e75fd5ad2 42 u_data.base |= ((typeof(u_data.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 1:098e75fd5ad2 43 u_data.base |= ((typeof(u_data.base)) (*(inbuffer + offset + 1))) << (8 * 1);
nucho 1:098e75fd5ad2 44 u_data.base |= ((typeof(u_data.base)) (*(inbuffer + offset + 2))) << (8 * 2);
nucho 1:098e75fd5ad2 45 u_data.base |= ((typeof(u_data.base)) (*(inbuffer + offset + 3))) << (8 * 3);
nucho 1:098e75fd5ad2 46 u_data.base |= ((typeof(u_data.base)) (*(inbuffer + offset + 4))) << (8 * 4);
nucho 1:098e75fd5ad2 47 u_data.base |= ((typeof(u_data.base)) (*(inbuffer + offset + 5))) << (8 * 5);
nucho 1:098e75fd5ad2 48 u_data.base |= ((typeof(u_data.base)) (*(inbuffer + offset + 6))) << (8 * 6);
nucho 1:098e75fd5ad2 49 u_data.base |= ((typeof(u_data.base)) (*(inbuffer + offset + 7))) << (8 * 7);
nucho 1:098e75fd5ad2 50
nucho 1:098e75fd5ad2 51 this->data = u_data.real;
nucho 1:098e75fd5ad2 52 offset += sizeof(this->data);
nucho 1:098e75fd5ad2 53 return offset;
nucho 0:06fc856e99ca 54 }
nucho 1:098e75fd5ad2 55 /*
nucho 1:098e75fd5ad2 56 public:
nucho 1:098e75fd5ad2 57 long data;
nucho 0:06fc856e99ca 58
nucho 1:098e75fd5ad2 59 virtual int serialize(unsigned char *outbuffer)
nucho 1:098e75fd5ad2 60 {
nucho 1:098e75fd5ad2 61 int offset = 0;
nucho 1:098e75fd5ad2 62 *(outbuffer + offset++) = (data >> (8 * 0)) & 0xFF;
nucho 1:098e75fd5ad2 63 *(outbuffer + offset++) = (data >> (8 * 1)) & 0xFF;
nucho 1:098e75fd5ad2 64 *(outbuffer + offset++) = (data >> (8 * 2)) & 0xFF;
nucho 1:098e75fd5ad2 65 *(outbuffer + offset++) = (data >> (8 * 3)) & 0xFF;
nucho 1:098e75fd5ad2 66 *(outbuffer + offset++) = (data > 0) ? 0: 255;
nucho 1:098e75fd5ad2 67 *(outbuffer + offset++) = (data > 0) ? 0: 255;
nucho 1:098e75fd5ad2 68 *(outbuffer + offset++) = (data > 0) ? 0: 255;
nucho 1:098e75fd5ad2 69 *(outbuffer + offset++) = (data > 0) ? 0: 255;
nucho 1:098e75fd5ad2 70 return offset;
nucho 1:098e75fd5ad2 71 }
nucho 0:06fc856e99ca 72
nucho 1:098e75fd5ad2 73 virtual int deserialize(unsigned char *inbuffer)
nucho 1:098e75fd5ad2 74 {
nucho 1:098e75fd5ad2 75 int offset = 0;
nucho 1:098e75fd5ad2 76 data = 0;
nucho 1:098e75fd5ad2 77 data += ((long)(*(inbuffer + offset++))) >> (8 * 0);
nucho 1:098e75fd5ad2 78 data += ((long)(*(inbuffer + offset++))) >> (8 * 1);
nucho 1:098e75fd5ad2 79 data += ((long)(*(inbuffer + offset++))) >> (8 * 2);
nucho 1:098e75fd5ad2 80 data += ((long)(*(inbuffer + offset++))) >> (8 * 3);
nucho 1:098e75fd5ad2 81 offset += 4;
nucho 1:098e75fd5ad2 82 return offset;
nucho 1:098e75fd5ad2 83 }
nucho 1:098e75fd5ad2 84 */
nucho 1:098e75fd5ad2 85
nucho 1:098e75fd5ad2 86 virtual const char * getType() {
nucho 1:098e75fd5ad2 87 return "std_msgs/Int64";
nucho 1:098e75fd5ad2 88 };
nucho 1:098e75fd5ad2 89
nucho 1:098e75fd5ad2 90 };
nucho 0:06fc856e99ca 91
nucho 0:06fc856e99ca 92 }
nucho 0:06fc856e99ca 93 #endif