S-ROV main board firmware

Dependencies:   mbed pca9685 ros_lib_kinetic ads1015

Committer:
YJ_Kim
Date:
Thu Jan 26 18:02:42 2017 +0000
Revision:
4:62c92aa48842
add ads1015 library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YJ_Kim 4:62c92aa48842 1 #ifndef _ROS_s_rov_msgs_s_rov_state_h
YJ_Kim 4:62c92aa48842 2 #define _ROS_s_rov_msgs_s_rov_state_h
YJ_Kim 4:62c92aa48842 3
YJ_Kim 4:62c92aa48842 4 #include <stdint.h>
YJ_Kim 4:62c92aa48842 5 #include <string.h>
YJ_Kim 4:62c92aa48842 6 #include <stdlib.h>
YJ_Kim 4:62c92aa48842 7 #include "ros/msg.h"
YJ_Kim 4:62c92aa48842 8
YJ_Kim 4:62c92aa48842 9 namespace s_rov_msgs
YJ_Kim 4:62c92aa48842 10 {
YJ_Kim 4:62c92aa48842 11
YJ_Kim 4:62c92aa48842 12 class s_rov_state : public ros::Msg
YJ_Kim 4:62c92aa48842 13 {
YJ_Kim 4:62c92aa48842 14 public:
YJ_Kim 4:62c92aa48842 15 float Voltage;
YJ_Kim 4:62c92aa48842 16 float Current;
YJ_Kim 4:62c92aa48842 17
YJ_Kim 4:62c92aa48842 18 s_rov_state():
YJ_Kim 4:62c92aa48842 19 Voltage(0),
YJ_Kim 4:62c92aa48842 20 Current(0)
YJ_Kim 4:62c92aa48842 21 {
YJ_Kim 4:62c92aa48842 22 }
YJ_Kim 4:62c92aa48842 23
YJ_Kim 4:62c92aa48842 24 virtual int serialize(unsigned char *outbuffer) const
YJ_Kim 4:62c92aa48842 25 {
YJ_Kim 4:62c92aa48842 26 int offset = 0;
YJ_Kim 4:62c92aa48842 27 union {
YJ_Kim 4:62c92aa48842 28 float real;
YJ_Kim 4:62c92aa48842 29 uint32_t base;
YJ_Kim 4:62c92aa48842 30 } u_Voltage;
YJ_Kim 4:62c92aa48842 31 u_Voltage.real = this->Voltage;
YJ_Kim 4:62c92aa48842 32 *(outbuffer + offset + 0) = (u_Voltage.base >> (8 * 0)) & 0xFF;
YJ_Kim 4:62c92aa48842 33 *(outbuffer + offset + 1) = (u_Voltage.base >> (8 * 1)) & 0xFF;
YJ_Kim 4:62c92aa48842 34 *(outbuffer + offset + 2) = (u_Voltage.base >> (8 * 2)) & 0xFF;
YJ_Kim 4:62c92aa48842 35 *(outbuffer + offset + 3) = (u_Voltage.base >> (8 * 3)) & 0xFF;
YJ_Kim 4:62c92aa48842 36 offset += sizeof(this->Voltage);
YJ_Kim 4:62c92aa48842 37 union {
YJ_Kim 4:62c92aa48842 38 float real;
YJ_Kim 4:62c92aa48842 39 uint32_t base;
YJ_Kim 4:62c92aa48842 40 } u_Current;
YJ_Kim 4:62c92aa48842 41 u_Current.real = this->Current;
YJ_Kim 4:62c92aa48842 42 *(outbuffer + offset + 0) = (u_Current.base >> (8 * 0)) & 0xFF;
YJ_Kim 4:62c92aa48842 43 *(outbuffer + offset + 1) = (u_Current.base >> (8 * 1)) & 0xFF;
YJ_Kim 4:62c92aa48842 44 *(outbuffer + offset + 2) = (u_Current.base >> (8 * 2)) & 0xFF;
YJ_Kim 4:62c92aa48842 45 *(outbuffer + offset + 3) = (u_Current.base >> (8 * 3)) & 0xFF;
YJ_Kim 4:62c92aa48842 46 offset += sizeof(this->Current);
YJ_Kim 4:62c92aa48842 47 return offset;
YJ_Kim 4:62c92aa48842 48 }
YJ_Kim 4:62c92aa48842 49
YJ_Kim 4:62c92aa48842 50 virtual int deserialize(unsigned char *inbuffer)
YJ_Kim 4:62c92aa48842 51 {
YJ_Kim 4:62c92aa48842 52 int offset = 0;
YJ_Kim 4:62c92aa48842 53 union {
YJ_Kim 4:62c92aa48842 54 float real;
YJ_Kim 4:62c92aa48842 55 uint32_t base;
YJ_Kim 4:62c92aa48842 56 } u_Voltage;
YJ_Kim 4:62c92aa48842 57 u_Voltage.base = 0;
YJ_Kim 4:62c92aa48842 58 u_Voltage.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
YJ_Kim 4:62c92aa48842 59 u_Voltage.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
YJ_Kim 4:62c92aa48842 60 u_Voltage.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
YJ_Kim 4:62c92aa48842 61 u_Voltage.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
YJ_Kim 4:62c92aa48842 62 this->Voltage = u_Voltage.real;
YJ_Kim 4:62c92aa48842 63 offset += sizeof(this->Voltage);
YJ_Kim 4:62c92aa48842 64 union {
YJ_Kim 4:62c92aa48842 65 float real;
YJ_Kim 4:62c92aa48842 66 uint32_t base;
YJ_Kim 4:62c92aa48842 67 } u_Current;
YJ_Kim 4:62c92aa48842 68 u_Current.base = 0;
YJ_Kim 4:62c92aa48842 69 u_Current.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
YJ_Kim 4:62c92aa48842 70 u_Current.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
YJ_Kim 4:62c92aa48842 71 u_Current.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
YJ_Kim 4:62c92aa48842 72 u_Current.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
YJ_Kim 4:62c92aa48842 73 this->Current = u_Current.real;
YJ_Kim 4:62c92aa48842 74 offset += sizeof(this->Current);
YJ_Kim 4:62c92aa48842 75 return offset;
YJ_Kim 4:62c92aa48842 76 }
YJ_Kim 4:62c92aa48842 77
YJ_Kim 4:62c92aa48842 78 const char * getType(){ return "s_rov_msgs/s_rov_state"; };
YJ_Kim 4:62c92aa48842 79 const char * getMD5(){ return "e2848ca8a25ac096219c461e07bcd312"; };
YJ_Kim 4:62c92aa48842 80
YJ_Kim 4:62c92aa48842 81 };
YJ_Kim 4:62c92aa48842 82
YJ_Kim 4:62c92aa48842 83 }
YJ_Kim 4:62c92aa48842 84 #endif