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

Dependencies:  

Dependents:   rosserial_mbed robot_S2

Committer:
nucho
Date:
Sun Oct 16 07:19:36 2011 +0000
Revision:
1:ff0ec969dad1
Parent:
0:77afd7560544
Child:
3:1cf99502f396
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 1:ff0ec969dad1 1 #ifndef ros_diagnostic_msgs_KeyValue_h
nucho 1:ff0ec969dad1 2 #define ros_diagnostic_msgs_KeyValue_h
nucho 0:77afd7560544 3
nucho 0:77afd7560544 4 #include <stdint.h>
nucho 0:77afd7560544 5 #include <string.h>
nucho 0:77afd7560544 6 #include <stdlib.h>
nucho 0:77afd7560544 7 #include "../ros/msg.h"
nucho 0:77afd7560544 8
nucho 1:ff0ec969dad1 9 namespace diagnostic_msgs {
nucho 0:77afd7560544 10
nucho 1:ff0ec969dad1 11 class KeyValue : public ros::Msg {
nucho 1:ff0ec969dad1 12 public:
nucho 1:ff0ec969dad1 13 char * key;
nucho 1:ff0ec969dad1 14 char * value;
nucho 0:77afd7560544 15
nucho 1:ff0ec969dad1 16 virtual int serialize(unsigned char *outbuffer) {
nucho 1:ff0ec969dad1 17 int offset = 0;
nucho 1:ff0ec969dad1 18 long * length_key = (long *)(outbuffer + offset);
nucho 1:ff0ec969dad1 19 *length_key = strlen( (const char*) this->key);
nucho 1:ff0ec969dad1 20 offset += 4;
nucho 1:ff0ec969dad1 21 memcpy(outbuffer + offset, this->key, *length_key);
nucho 1:ff0ec969dad1 22 offset += *length_key;
nucho 1:ff0ec969dad1 23 long * length_value = (long *)(outbuffer + offset);
nucho 1:ff0ec969dad1 24 *length_value = strlen( (const char*) this->value);
nucho 1:ff0ec969dad1 25 offset += 4;
nucho 1:ff0ec969dad1 26 memcpy(outbuffer + offset, this->value, *length_value);
nucho 1:ff0ec969dad1 27 offset += *length_value;
nucho 1:ff0ec969dad1 28 return offset;
nucho 0:77afd7560544 29 }
nucho 0:77afd7560544 30
nucho 1:ff0ec969dad1 31 virtual int deserialize(unsigned char *inbuffer) {
nucho 1:ff0ec969dad1 32 int offset = 0;
nucho 1:ff0ec969dad1 33 uint32_t length_key = *(uint32_t *)(inbuffer + offset);
nucho 1:ff0ec969dad1 34 offset += 4;
nucho 1:ff0ec969dad1 35 for (unsigned int k= offset; k< offset+length_key; ++k) {
nucho 1:ff0ec969dad1 36 inbuffer[k-1]=inbuffer[k];
nucho 1:ff0ec969dad1 37 }
nucho 1:ff0ec969dad1 38 inbuffer[offset+length_key-1]=0;
nucho 1:ff0ec969dad1 39 this->key = (char *)(inbuffer + offset-1);
nucho 1:ff0ec969dad1 40 offset += length_key;
nucho 1:ff0ec969dad1 41 uint32_t length_value = *(uint32_t *)(inbuffer + offset);
nucho 1:ff0ec969dad1 42 offset += 4;
nucho 1:ff0ec969dad1 43 for (unsigned int k= offset; k< offset+length_value; ++k) {
nucho 1:ff0ec969dad1 44 inbuffer[k-1]=inbuffer[k];
nucho 1:ff0ec969dad1 45 }
nucho 1:ff0ec969dad1 46 inbuffer[offset+length_value-1]=0;
nucho 1:ff0ec969dad1 47 this->value = (char *)(inbuffer + offset-1);
nucho 1:ff0ec969dad1 48 offset += length_value;
nucho 1:ff0ec969dad1 49 return offset;
nucho 0:77afd7560544 50 }
nucho 0:77afd7560544 51
nucho 1:ff0ec969dad1 52 virtual const char * getType() {
nucho 1:ff0ec969dad1 53 return "diagnostic_msgs/KeyValue";
nucho 1:ff0ec969dad1 54 };
nucho 0:77afd7560544 55
nucho 1:ff0ec969dad1 56 };
nucho 0:77afd7560544 57
nucho 0:77afd7560544 58 }
nucho 0:77afd7560544 59 #endif