Personal fork

Dependencies:   MODSERIAL

Dependents:   rosserial_mbed

Fork of rosserial_mbed_lib by nucho

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_rosserial_msgs_Log_h
nucho 1:ff0ec969dad1 2 #define ros_rosserial_msgs_Log_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 0:77afd7560544 9 namespace rosserial_msgs
nucho 0:77afd7560544 10 {
nucho 0:77afd7560544 11
nucho 0:77afd7560544 12 class Log : public ros::Msg
nucho 0:77afd7560544 13 {
nucho 0:77afd7560544 14 public:
nucho 0:77afd7560544 15 unsigned char level;
nucho 0:77afd7560544 16 char * msg;
nucho 0:77afd7560544 17 enum { DEBUG = 0 };
nucho 0:77afd7560544 18 enum { INFO = 1 };
nucho 0:77afd7560544 19 enum { WARN = 2 };
nucho 0:77afd7560544 20 enum { ERROR = 3 };
nucho 0:77afd7560544 21 enum { FATAL = 4 };
nucho 0:77afd7560544 22
nucho 0:77afd7560544 23 virtual int serialize(unsigned char *outbuffer)
nucho 0:77afd7560544 24 {
nucho 0:77afd7560544 25 int offset = 0;
nucho 0:77afd7560544 26 union {
nucho 0:77afd7560544 27 unsigned char real;
nucho 0:77afd7560544 28 unsigned char base;
nucho 0:77afd7560544 29 } u_level;
nucho 0:77afd7560544 30 u_level.real = this->level;
nucho 0:77afd7560544 31 *(outbuffer + offset + 0) = (u_level.base >> (8 * 0)) & 0xFF;
nucho 0:77afd7560544 32 offset += sizeof(this->level);
nucho 0:77afd7560544 33 long * length_msg = (long *)(outbuffer + offset);
nucho 0:77afd7560544 34 *length_msg = strlen( (const char*) this->msg);
nucho 0:77afd7560544 35 offset += 4;
nucho 0:77afd7560544 36 memcpy(outbuffer + offset, this->msg, *length_msg);
nucho 0:77afd7560544 37 offset += *length_msg;
nucho 0:77afd7560544 38 return offset;
nucho 0:77afd7560544 39 }
nucho 0:77afd7560544 40
nucho 0:77afd7560544 41 virtual int deserialize(unsigned char *inbuffer)
nucho 0:77afd7560544 42 {
nucho 0:77afd7560544 43 int offset = 0;
nucho 0:77afd7560544 44 union {
nucho 0:77afd7560544 45 unsigned char real;
nucho 0:77afd7560544 46 unsigned char base;
nucho 0:77afd7560544 47 } u_level;
nucho 0:77afd7560544 48 u_level.base = 0;
nucho 0:77afd7560544 49 u_level.base |= ((typeof(u_level.base)) (*(inbuffer + offset + 0))) << (8 * 0);
nucho 0:77afd7560544 50 this->level = u_level.real;
nucho 0:77afd7560544 51 offset += sizeof(this->level);
nucho 0:77afd7560544 52 uint32_t length_msg = *(uint32_t *)(inbuffer + offset);
nucho 0:77afd7560544 53 offset += 4;
nucho 0:77afd7560544 54 for(unsigned int k= offset; k< offset+length_msg; ++k){
nucho 0:77afd7560544 55 inbuffer[k-1]=inbuffer[k];
nucho 0:77afd7560544 56 }
nucho 0:77afd7560544 57 inbuffer[offset+length_msg-1]=0;
nucho 0:77afd7560544 58 this->msg = (char *)(inbuffer + offset-1);
nucho 0:77afd7560544 59 offset += length_msg;
nucho 0:77afd7560544 60 return offset;
nucho 0:77afd7560544 61 }
nucho 0:77afd7560544 62
nucho 0:77afd7560544 63 virtual const char * getType(){ return "rosserial_msgs/Log"; };
nucho 0:77afd7560544 64
nucho 0:77afd7560544 65 };
nucho 0:77afd7560544 66
nucho 0:77afd7560544 67 }
nucho 0:77afd7560544 68 #endif