ROS Serial library for Mbed platforms for ROS Melodic Morenia. Check http://wiki.ros.org/rosserial_mbed/ for more information.

Dependencies:   BufferedSerial

Dependents:   rosserial_mbed_hello_world_publisher_melodic Motortest Nucleo_vr_servo_project NucleoFM ... more

ROSSerial_mbed for Melodic Distribution

The Robot Operating System (ROS) is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms.

The rosserial_mbed package allows to write ROS nodes on any mbed enabled devices and have them connected to a running ROS system on your computer using the serial port.

Hello World (example publisher)

Import programrosserial_mbed_hello_world_publisher_melodic

rosserial_mbed Hello World example for Melodic Morenia distribution

Running the Code

Now, launch the roscore in a new terminal window:

Quote:

$ roscore

Next, run the rosserial client application that forwards your MBED messages to the rest of ROS. Make sure to use the correct serial port:

Quote:

$ rosrun rosserial_python serial_node.py /dev/ttyACM0

Finally, watch the greetings come in from your MBED by launching a new terminal window and entering :

Quote:

$ rostopic echo chatter

See Also

More examples

Blink

/*
 * rosserial Subscriber Example
 * Blinks an LED on callback
 */
#include "mbed.h"
#include <ros.h>
#include <std_msgs/Empty.h>

ros::NodeHandle nh;
DigitalOut myled(LED1);

void messageCb(const std_msgs::Empty& toggle_msg){
    myled = !myled;   // blink the led
}

ros::Subscriber<std_msgs::Empty> sub("toggle_led", &messageCb);

int main() {
    nh.initNode();
    nh.subscribe(sub);

    while (1) {
        nh.spinOnce();
        wait_ms(1);
    }
}

Push

/*
 * Button Example for Rosserial
 */

#include "mbed.h"
#include <ros.h>
#include <std_msgs/Bool.h>

PinName button = p20;

ros::NodeHandle nh;

std_msgs::Bool pushed_msg;
ros::Publisher pub_button("pushed", &pushed_msg);

DigitalIn button_pin(button);
DigitalOut led_pin(LED1);

bool last_reading;
long last_debounce_time=0;
long debounce_delay=50;
bool published = true;

Timer t;
int main() {
    t.start();
    nh.initNode();
    nh.advertise(pub_button);

    //Enable the pullup resistor on the button
    button_pin.mode(PullUp);

    //The button is a normally button
    last_reading = ! button_pin;

    while (1) {
        bool reading = ! button_pin;

        if (last_reading!= reading) {
            last_debounce_time = t.read_ms();
            published = false;
        }

        //if the button value has not changed for the debounce delay, we know its stable
        if ( !published && (t.read_ms() - last_debounce_time)  > debounce_delay) {
            led_pin = reading;
            pushed_msg.data = reading;
            pub_button.publish(&pushed_msg);
            published = true;
        }

        last_reading = reading;

        nh.spinOnce();
    }
}
Committer:
Gary Servin
Date:
Fri Nov 08 14:38:09 2019 -0300
Revision:
0:04ac6be8229a
Initial commit, generated based on a clean melodic-desktop-full

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gary Servin 0:04ac6be8229a 1 #ifndef _ROS_sensor_msgs_BatteryState_h
Gary Servin 0:04ac6be8229a 2 #define _ROS_sensor_msgs_BatteryState_h
Gary Servin 0:04ac6be8229a 3
Gary Servin 0:04ac6be8229a 4 #include <stdint.h>
Gary Servin 0:04ac6be8229a 5 #include <string.h>
Gary Servin 0:04ac6be8229a 6 #include <stdlib.h>
Gary Servin 0:04ac6be8229a 7 #include "ros/msg.h"
Gary Servin 0:04ac6be8229a 8 #include "std_msgs/Header.h"
Gary Servin 0:04ac6be8229a 9
Gary Servin 0:04ac6be8229a 10 namespace sensor_msgs
Gary Servin 0:04ac6be8229a 11 {
Gary Servin 0:04ac6be8229a 12
Gary Servin 0:04ac6be8229a 13 class BatteryState : public ros::Msg
Gary Servin 0:04ac6be8229a 14 {
Gary Servin 0:04ac6be8229a 15 public:
Gary Servin 0:04ac6be8229a 16 typedef std_msgs::Header _header_type;
Gary Servin 0:04ac6be8229a 17 _header_type header;
Gary Servin 0:04ac6be8229a 18 typedef float _voltage_type;
Gary Servin 0:04ac6be8229a 19 _voltage_type voltage;
Gary Servin 0:04ac6be8229a 20 typedef float _current_type;
Gary Servin 0:04ac6be8229a 21 _current_type current;
Gary Servin 0:04ac6be8229a 22 typedef float _charge_type;
Gary Servin 0:04ac6be8229a 23 _charge_type charge;
Gary Servin 0:04ac6be8229a 24 typedef float _capacity_type;
Gary Servin 0:04ac6be8229a 25 _capacity_type capacity;
Gary Servin 0:04ac6be8229a 26 typedef float _design_capacity_type;
Gary Servin 0:04ac6be8229a 27 _design_capacity_type design_capacity;
Gary Servin 0:04ac6be8229a 28 typedef float _percentage_type;
Gary Servin 0:04ac6be8229a 29 _percentage_type percentage;
Gary Servin 0:04ac6be8229a 30 typedef uint8_t _power_supply_status_type;
Gary Servin 0:04ac6be8229a 31 _power_supply_status_type power_supply_status;
Gary Servin 0:04ac6be8229a 32 typedef uint8_t _power_supply_health_type;
Gary Servin 0:04ac6be8229a 33 _power_supply_health_type power_supply_health;
Gary Servin 0:04ac6be8229a 34 typedef uint8_t _power_supply_technology_type;
Gary Servin 0:04ac6be8229a 35 _power_supply_technology_type power_supply_technology;
Gary Servin 0:04ac6be8229a 36 typedef bool _present_type;
Gary Servin 0:04ac6be8229a 37 _present_type present;
Gary Servin 0:04ac6be8229a 38 uint32_t cell_voltage_length;
Gary Servin 0:04ac6be8229a 39 typedef float _cell_voltage_type;
Gary Servin 0:04ac6be8229a 40 _cell_voltage_type st_cell_voltage;
Gary Servin 0:04ac6be8229a 41 _cell_voltage_type * cell_voltage;
Gary Servin 0:04ac6be8229a 42 typedef const char* _location_type;
Gary Servin 0:04ac6be8229a 43 _location_type location;
Gary Servin 0:04ac6be8229a 44 typedef const char* _serial_number_type;
Gary Servin 0:04ac6be8229a 45 _serial_number_type serial_number;
Gary Servin 0:04ac6be8229a 46 enum { POWER_SUPPLY_STATUS_UNKNOWN = 0 };
Gary Servin 0:04ac6be8229a 47 enum { POWER_SUPPLY_STATUS_CHARGING = 1 };
Gary Servin 0:04ac6be8229a 48 enum { POWER_SUPPLY_STATUS_DISCHARGING = 2 };
Gary Servin 0:04ac6be8229a 49 enum { POWER_SUPPLY_STATUS_NOT_CHARGING = 3 };
Gary Servin 0:04ac6be8229a 50 enum { POWER_SUPPLY_STATUS_FULL = 4 };
Gary Servin 0:04ac6be8229a 51 enum { POWER_SUPPLY_HEALTH_UNKNOWN = 0 };
Gary Servin 0:04ac6be8229a 52 enum { POWER_SUPPLY_HEALTH_GOOD = 1 };
Gary Servin 0:04ac6be8229a 53 enum { POWER_SUPPLY_HEALTH_OVERHEAT = 2 };
Gary Servin 0:04ac6be8229a 54 enum { POWER_SUPPLY_HEALTH_DEAD = 3 };
Gary Servin 0:04ac6be8229a 55 enum { POWER_SUPPLY_HEALTH_OVERVOLTAGE = 4 };
Gary Servin 0:04ac6be8229a 56 enum { POWER_SUPPLY_HEALTH_UNSPEC_FAILURE = 5 };
Gary Servin 0:04ac6be8229a 57 enum { POWER_SUPPLY_HEALTH_COLD = 6 };
Gary Servin 0:04ac6be8229a 58 enum { POWER_SUPPLY_HEALTH_WATCHDOG_TIMER_EXPIRE = 7 };
Gary Servin 0:04ac6be8229a 59 enum { POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE = 8 };
Gary Servin 0:04ac6be8229a 60 enum { POWER_SUPPLY_TECHNOLOGY_UNKNOWN = 0 };
Gary Servin 0:04ac6be8229a 61 enum { POWER_SUPPLY_TECHNOLOGY_NIMH = 1 };
Gary Servin 0:04ac6be8229a 62 enum { POWER_SUPPLY_TECHNOLOGY_LION = 2 };
Gary Servin 0:04ac6be8229a 63 enum { POWER_SUPPLY_TECHNOLOGY_LIPO = 3 };
Gary Servin 0:04ac6be8229a 64 enum { POWER_SUPPLY_TECHNOLOGY_LIFE = 4 };
Gary Servin 0:04ac6be8229a 65 enum { POWER_SUPPLY_TECHNOLOGY_NICD = 5 };
Gary Servin 0:04ac6be8229a 66 enum { POWER_SUPPLY_TECHNOLOGY_LIMN = 6 };
Gary Servin 0:04ac6be8229a 67
Gary Servin 0:04ac6be8229a 68 BatteryState():
Gary Servin 0:04ac6be8229a 69 header(),
Gary Servin 0:04ac6be8229a 70 voltage(0),
Gary Servin 0:04ac6be8229a 71 current(0),
Gary Servin 0:04ac6be8229a 72 charge(0),
Gary Servin 0:04ac6be8229a 73 capacity(0),
Gary Servin 0:04ac6be8229a 74 design_capacity(0),
Gary Servin 0:04ac6be8229a 75 percentage(0),
Gary Servin 0:04ac6be8229a 76 power_supply_status(0),
Gary Servin 0:04ac6be8229a 77 power_supply_health(0),
Gary Servin 0:04ac6be8229a 78 power_supply_technology(0),
Gary Servin 0:04ac6be8229a 79 present(0),
Gary Servin 0:04ac6be8229a 80 cell_voltage_length(0), cell_voltage(NULL),
Gary Servin 0:04ac6be8229a 81 location(""),
Gary Servin 0:04ac6be8229a 82 serial_number("")
Gary Servin 0:04ac6be8229a 83 {
Gary Servin 0:04ac6be8229a 84 }
Gary Servin 0:04ac6be8229a 85
Gary Servin 0:04ac6be8229a 86 virtual int serialize(unsigned char *outbuffer) const
Gary Servin 0:04ac6be8229a 87 {
Gary Servin 0:04ac6be8229a 88 int offset = 0;
Gary Servin 0:04ac6be8229a 89 offset += this->header.serialize(outbuffer + offset);
Gary Servin 0:04ac6be8229a 90 union {
Gary Servin 0:04ac6be8229a 91 float real;
Gary Servin 0:04ac6be8229a 92 uint32_t base;
Gary Servin 0:04ac6be8229a 93 } u_voltage;
Gary Servin 0:04ac6be8229a 94 u_voltage.real = this->voltage;
Gary Servin 0:04ac6be8229a 95 *(outbuffer + offset + 0) = (u_voltage.base >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 96 *(outbuffer + offset + 1) = (u_voltage.base >> (8 * 1)) & 0xFF;
Gary Servin 0:04ac6be8229a 97 *(outbuffer + offset + 2) = (u_voltage.base >> (8 * 2)) & 0xFF;
Gary Servin 0:04ac6be8229a 98 *(outbuffer + offset + 3) = (u_voltage.base >> (8 * 3)) & 0xFF;
Gary Servin 0:04ac6be8229a 99 offset += sizeof(this->voltage);
Gary Servin 0:04ac6be8229a 100 union {
Gary Servin 0:04ac6be8229a 101 float real;
Gary Servin 0:04ac6be8229a 102 uint32_t base;
Gary Servin 0:04ac6be8229a 103 } u_current;
Gary Servin 0:04ac6be8229a 104 u_current.real = this->current;
Gary Servin 0:04ac6be8229a 105 *(outbuffer + offset + 0) = (u_current.base >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 106 *(outbuffer + offset + 1) = (u_current.base >> (8 * 1)) & 0xFF;
Gary Servin 0:04ac6be8229a 107 *(outbuffer + offset + 2) = (u_current.base >> (8 * 2)) & 0xFF;
Gary Servin 0:04ac6be8229a 108 *(outbuffer + offset + 3) = (u_current.base >> (8 * 3)) & 0xFF;
Gary Servin 0:04ac6be8229a 109 offset += sizeof(this->current);
Gary Servin 0:04ac6be8229a 110 union {
Gary Servin 0:04ac6be8229a 111 float real;
Gary Servin 0:04ac6be8229a 112 uint32_t base;
Gary Servin 0:04ac6be8229a 113 } u_charge;
Gary Servin 0:04ac6be8229a 114 u_charge.real = this->charge;
Gary Servin 0:04ac6be8229a 115 *(outbuffer + offset + 0) = (u_charge.base >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 116 *(outbuffer + offset + 1) = (u_charge.base >> (8 * 1)) & 0xFF;
Gary Servin 0:04ac6be8229a 117 *(outbuffer + offset + 2) = (u_charge.base >> (8 * 2)) & 0xFF;
Gary Servin 0:04ac6be8229a 118 *(outbuffer + offset + 3) = (u_charge.base >> (8 * 3)) & 0xFF;
Gary Servin 0:04ac6be8229a 119 offset += sizeof(this->charge);
Gary Servin 0:04ac6be8229a 120 union {
Gary Servin 0:04ac6be8229a 121 float real;
Gary Servin 0:04ac6be8229a 122 uint32_t base;
Gary Servin 0:04ac6be8229a 123 } u_capacity;
Gary Servin 0:04ac6be8229a 124 u_capacity.real = this->capacity;
Gary Servin 0:04ac6be8229a 125 *(outbuffer + offset + 0) = (u_capacity.base >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 126 *(outbuffer + offset + 1) = (u_capacity.base >> (8 * 1)) & 0xFF;
Gary Servin 0:04ac6be8229a 127 *(outbuffer + offset + 2) = (u_capacity.base >> (8 * 2)) & 0xFF;
Gary Servin 0:04ac6be8229a 128 *(outbuffer + offset + 3) = (u_capacity.base >> (8 * 3)) & 0xFF;
Gary Servin 0:04ac6be8229a 129 offset += sizeof(this->capacity);
Gary Servin 0:04ac6be8229a 130 union {
Gary Servin 0:04ac6be8229a 131 float real;
Gary Servin 0:04ac6be8229a 132 uint32_t base;
Gary Servin 0:04ac6be8229a 133 } u_design_capacity;
Gary Servin 0:04ac6be8229a 134 u_design_capacity.real = this->design_capacity;
Gary Servin 0:04ac6be8229a 135 *(outbuffer + offset + 0) = (u_design_capacity.base >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 136 *(outbuffer + offset + 1) = (u_design_capacity.base >> (8 * 1)) & 0xFF;
Gary Servin 0:04ac6be8229a 137 *(outbuffer + offset + 2) = (u_design_capacity.base >> (8 * 2)) & 0xFF;
Gary Servin 0:04ac6be8229a 138 *(outbuffer + offset + 3) = (u_design_capacity.base >> (8 * 3)) & 0xFF;
Gary Servin 0:04ac6be8229a 139 offset += sizeof(this->design_capacity);
Gary Servin 0:04ac6be8229a 140 union {
Gary Servin 0:04ac6be8229a 141 float real;
Gary Servin 0:04ac6be8229a 142 uint32_t base;
Gary Servin 0:04ac6be8229a 143 } u_percentage;
Gary Servin 0:04ac6be8229a 144 u_percentage.real = this->percentage;
Gary Servin 0:04ac6be8229a 145 *(outbuffer + offset + 0) = (u_percentage.base >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 146 *(outbuffer + offset + 1) = (u_percentage.base >> (8 * 1)) & 0xFF;
Gary Servin 0:04ac6be8229a 147 *(outbuffer + offset + 2) = (u_percentage.base >> (8 * 2)) & 0xFF;
Gary Servin 0:04ac6be8229a 148 *(outbuffer + offset + 3) = (u_percentage.base >> (8 * 3)) & 0xFF;
Gary Servin 0:04ac6be8229a 149 offset += sizeof(this->percentage);
Gary Servin 0:04ac6be8229a 150 *(outbuffer + offset + 0) = (this->power_supply_status >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 151 offset += sizeof(this->power_supply_status);
Gary Servin 0:04ac6be8229a 152 *(outbuffer + offset + 0) = (this->power_supply_health >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 153 offset += sizeof(this->power_supply_health);
Gary Servin 0:04ac6be8229a 154 *(outbuffer + offset + 0) = (this->power_supply_technology >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 155 offset += sizeof(this->power_supply_technology);
Gary Servin 0:04ac6be8229a 156 union {
Gary Servin 0:04ac6be8229a 157 bool real;
Gary Servin 0:04ac6be8229a 158 uint8_t base;
Gary Servin 0:04ac6be8229a 159 } u_present;
Gary Servin 0:04ac6be8229a 160 u_present.real = this->present;
Gary Servin 0:04ac6be8229a 161 *(outbuffer + offset + 0) = (u_present.base >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 162 offset += sizeof(this->present);
Gary Servin 0:04ac6be8229a 163 *(outbuffer + offset + 0) = (this->cell_voltage_length >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 164 *(outbuffer + offset + 1) = (this->cell_voltage_length >> (8 * 1)) & 0xFF;
Gary Servin 0:04ac6be8229a 165 *(outbuffer + offset + 2) = (this->cell_voltage_length >> (8 * 2)) & 0xFF;
Gary Servin 0:04ac6be8229a 166 *(outbuffer + offset + 3) = (this->cell_voltage_length >> (8 * 3)) & 0xFF;
Gary Servin 0:04ac6be8229a 167 offset += sizeof(this->cell_voltage_length);
Gary Servin 0:04ac6be8229a 168 for( uint32_t i = 0; i < cell_voltage_length; i++){
Gary Servin 0:04ac6be8229a 169 union {
Gary Servin 0:04ac6be8229a 170 float real;
Gary Servin 0:04ac6be8229a 171 uint32_t base;
Gary Servin 0:04ac6be8229a 172 } u_cell_voltagei;
Gary Servin 0:04ac6be8229a 173 u_cell_voltagei.real = this->cell_voltage[i];
Gary Servin 0:04ac6be8229a 174 *(outbuffer + offset + 0) = (u_cell_voltagei.base >> (8 * 0)) & 0xFF;
Gary Servin 0:04ac6be8229a 175 *(outbuffer + offset + 1) = (u_cell_voltagei.base >> (8 * 1)) & 0xFF;
Gary Servin 0:04ac6be8229a 176 *(outbuffer + offset + 2) = (u_cell_voltagei.base >> (8 * 2)) & 0xFF;
Gary Servin 0:04ac6be8229a 177 *(outbuffer + offset + 3) = (u_cell_voltagei.base >> (8 * 3)) & 0xFF;
Gary Servin 0:04ac6be8229a 178 offset += sizeof(this->cell_voltage[i]);
Gary Servin 0:04ac6be8229a 179 }
Gary Servin 0:04ac6be8229a 180 uint32_t length_location = strlen(this->location);
Gary Servin 0:04ac6be8229a 181 varToArr(outbuffer + offset, length_location);
Gary Servin 0:04ac6be8229a 182 offset += 4;
Gary Servin 0:04ac6be8229a 183 memcpy(outbuffer + offset, this->location, length_location);
Gary Servin 0:04ac6be8229a 184 offset += length_location;
Gary Servin 0:04ac6be8229a 185 uint32_t length_serial_number = strlen(this->serial_number);
Gary Servin 0:04ac6be8229a 186 varToArr(outbuffer + offset, length_serial_number);
Gary Servin 0:04ac6be8229a 187 offset += 4;
Gary Servin 0:04ac6be8229a 188 memcpy(outbuffer + offset, this->serial_number, length_serial_number);
Gary Servin 0:04ac6be8229a 189 offset += length_serial_number;
Gary Servin 0:04ac6be8229a 190 return offset;
Gary Servin 0:04ac6be8229a 191 }
Gary Servin 0:04ac6be8229a 192
Gary Servin 0:04ac6be8229a 193 virtual int deserialize(unsigned char *inbuffer)
Gary Servin 0:04ac6be8229a 194 {
Gary Servin 0:04ac6be8229a 195 int offset = 0;
Gary Servin 0:04ac6be8229a 196 offset += this->header.deserialize(inbuffer + offset);
Gary Servin 0:04ac6be8229a 197 union {
Gary Servin 0:04ac6be8229a 198 float real;
Gary Servin 0:04ac6be8229a 199 uint32_t base;
Gary Servin 0:04ac6be8229a 200 } u_voltage;
Gary Servin 0:04ac6be8229a 201 u_voltage.base = 0;
Gary Servin 0:04ac6be8229a 202 u_voltage.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Gary Servin 0:04ac6be8229a 203 u_voltage.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Gary Servin 0:04ac6be8229a 204 u_voltage.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Gary Servin 0:04ac6be8229a 205 u_voltage.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Gary Servin 0:04ac6be8229a 206 this->voltage = u_voltage.real;
Gary Servin 0:04ac6be8229a 207 offset += sizeof(this->voltage);
Gary Servin 0:04ac6be8229a 208 union {
Gary Servin 0:04ac6be8229a 209 float real;
Gary Servin 0:04ac6be8229a 210 uint32_t base;
Gary Servin 0:04ac6be8229a 211 } u_current;
Gary Servin 0:04ac6be8229a 212 u_current.base = 0;
Gary Servin 0:04ac6be8229a 213 u_current.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Gary Servin 0:04ac6be8229a 214 u_current.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Gary Servin 0:04ac6be8229a 215 u_current.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Gary Servin 0:04ac6be8229a 216 u_current.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Gary Servin 0:04ac6be8229a 217 this->current = u_current.real;
Gary Servin 0:04ac6be8229a 218 offset += sizeof(this->current);
Gary Servin 0:04ac6be8229a 219 union {
Gary Servin 0:04ac6be8229a 220 float real;
Gary Servin 0:04ac6be8229a 221 uint32_t base;
Gary Servin 0:04ac6be8229a 222 } u_charge;
Gary Servin 0:04ac6be8229a 223 u_charge.base = 0;
Gary Servin 0:04ac6be8229a 224 u_charge.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Gary Servin 0:04ac6be8229a 225 u_charge.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Gary Servin 0:04ac6be8229a 226 u_charge.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Gary Servin 0:04ac6be8229a 227 u_charge.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Gary Servin 0:04ac6be8229a 228 this->charge = u_charge.real;
Gary Servin 0:04ac6be8229a 229 offset += sizeof(this->charge);
Gary Servin 0:04ac6be8229a 230 union {
Gary Servin 0:04ac6be8229a 231 float real;
Gary Servin 0:04ac6be8229a 232 uint32_t base;
Gary Servin 0:04ac6be8229a 233 } u_capacity;
Gary Servin 0:04ac6be8229a 234 u_capacity.base = 0;
Gary Servin 0:04ac6be8229a 235 u_capacity.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Gary Servin 0:04ac6be8229a 236 u_capacity.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Gary Servin 0:04ac6be8229a 237 u_capacity.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Gary Servin 0:04ac6be8229a 238 u_capacity.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Gary Servin 0:04ac6be8229a 239 this->capacity = u_capacity.real;
Gary Servin 0:04ac6be8229a 240 offset += sizeof(this->capacity);
Gary Servin 0:04ac6be8229a 241 union {
Gary Servin 0:04ac6be8229a 242 float real;
Gary Servin 0:04ac6be8229a 243 uint32_t base;
Gary Servin 0:04ac6be8229a 244 } u_design_capacity;
Gary Servin 0:04ac6be8229a 245 u_design_capacity.base = 0;
Gary Servin 0:04ac6be8229a 246 u_design_capacity.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Gary Servin 0:04ac6be8229a 247 u_design_capacity.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Gary Servin 0:04ac6be8229a 248 u_design_capacity.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Gary Servin 0:04ac6be8229a 249 u_design_capacity.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Gary Servin 0:04ac6be8229a 250 this->design_capacity = u_design_capacity.real;
Gary Servin 0:04ac6be8229a 251 offset += sizeof(this->design_capacity);
Gary Servin 0:04ac6be8229a 252 union {
Gary Servin 0:04ac6be8229a 253 float real;
Gary Servin 0:04ac6be8229a 254 uint32_t base;
Gary Servin 0:04ac6be8229a 255 } u_percentage;
Gary Servin 0:04ac6be8229a 256 u_percentage.base = 0;
Gary Servin 0:04ac6be8229a 257 u_percentage.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Gary Servin 0:04ac6be8229a 258 u_percentage.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Gary Servin 0:04ac6be8229a 259 u_percentage.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Gary Servin 0:04ac6be8229a 260 u_percentage.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Gary Servin 0:04ac6be8229a 261 this->percentage = u_percentage.real;
Gary Servin 0:04ac6be8229a 262 offset += sizeof(this->percentage);
Gary Servin 0:04ac6be8229a 263 this->power_supply_status = ((uint8_t) (*(inbuffer + offset)));
Gary Servin 0:04ac6be8229a 264 offset += sizeof(this->power_supply_status);
Gary Servin 0:04ac6be8229a 265 this->power_supply_health = ((uint8_t) (*(inbuffer + offset)));
Gary Servin 0:04ac6be8229a 266 offset += sizeof(this->power_supply_health);
Gary Servin 0:04ac6be8229a 267 this->power_supply_technology = ((uint8_t) (*(inbuffer + offset)));
Gary Servin 0:04ac6be8229a 268 offset += sizeof(this->power_supply_technology);
Gary Servin 0:04ac6be8229a 269 union {
Gary Servin 0:04ac6be8229a 270 bool real;
Gary Servin 0:04ac6be8229a 271 uint8_t base;
Gary Servin 0:04ac6be8229a 272 } u_present;
Gary Servin 0:04ac6be8229a 273 u_present.base = 0;
Gary Servin 0:04ac6be8229a 274 u_present.base |= ((uint8_t) (*(inbuffer + offset + 0))) << (8 * 0);
Gary Servin 0:04ac6be8229a 275 this->present = u_present.real;
Gary Servin 0:04ac6be8229a 276 offset += sizeof(this->present);
Gary Servin 0:04ac6be8229a 277 uint32_t cell_voltage_lengthT = ((uint32_t) (*(inbuffer + offset)));
Gary Servin 0:04ac6be8229a 278 cell_voltage_lengthT |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Gary Servin 0:04ac6be8229a 279 cell_voltage_lengthT |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Gary Servin 0:04ac6be8229a 280 cell_voltage_lengthT |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Gary Servin 0:04ac6be8229a 281 offset += sizeof(this->cell_voltage_length);
Gary Servin 0:04ac6be8229a 282 if(cell_voltage_lengthT > cell_voltage_length)
Gary Servin 0:04ac6be8229a 283 this->cell_voltage = (float*)realloc(this->cell_voltage, cell_voltage_lengthT * sizeof(float));
Gary Servin 0:04ac6be8229a 284 cell_voltage_length = cell_voltage_lengthT;
Gary Servin 0:04ac6be8229a 285 for( uint32_t i = 0; i < cell_voltage_length; i++){
Gary Servin 0:04ac6be8229a 286 union {
Gary Servin 0:04ac6be8229a 287 float real;
Gary Servin 0:04ac6be8229a 288 uint32_t base;
Gary Servin 0:04ac6be8229a 289 } u_st_cell_voltage;
Gary Servin 0:04ac6be8229a 290 u_st_cell_voltage.base = 0;
Gary Servin 0:04ac6be8229a 291 u_st_cell_voltage.base |= ((uint32_t) (*(inbuffer + offset + 0))) << (8 * 0);
Gary Servin 0:04ac6be8229a 292 u_st_cell_voltage.base |= ((uint32_t) (*(inbuffer + offset + 1))) << (8 * 1);
Gary Servin 0:04ac6be8229a 293 u_st_cell_voltage.base |= ((uint32_t) (*(inbuffer + offset + 2))) << (8 * 2);
Gary Servin 0:04ac6be8229a 294 u_st_cell_voltage.base |= ((uint32_t) (*(inbuffer + offset + 3))) << (8 * 3);
Gary Servin 0:04ac6be8229a 295 this->st_cell_voltage = u_st_cell_voltage.real;
Gary Servin 0:04ac6be8229a 296 offset += sizeof(this->st_cell_voltage);
Gary Servin 0:04ac6be8229a 297 memcpy( &(this->cell_voltage[i]), &(this->st_cell_voltage), sizeof(float));
Gary Servin 0:04ac6be8229a 298 }
Gary Servin 0:04ac6be8229a 299 uint32_t length_location;
Gary Servin 0:04ac6be8229a 300 arrToVar(length_location, (inbuffer + offset));
Gary Servin 0:04ac6be8229a 301 offset += 4;
Gary Servin 0:04ac6be8229a 302 for(unsigned int k= offset; k< offset+length_location; ++k){
Gary Servin 0:04ac6be8229a 303 inbuffer[k-1]=inbuffer[k];
Gary Servin 0:04ac6be8229a 304 }
Gary Servin 0:04ac6be8229a 305 inbuffer[offset+length_location-1]=0;
Gary Servin 0:04ac6be8229a 306 this->location = (char *)(inbuffer + offset-1);
Gary Servin 0:04ac6be8229a 307 offset += length_location;
Gary Servin 0:04ac6be8229a 308 uint32_t length_serial_number;
Gary Servin 0:04ac6be8229a 309 arrToVar(length_serial_number, (inbuffer + offset));
Gary Servin 0:04ac6be8229a 310 offset += 4;
Gary Servin 0:04ac6be8229a 311 for(unsigned int k= offset; k< offset+length_serial_number; ++k){
Gary Servin 0:04ac6be8229a 312 inbuffer[k-1]=inbuffer[k];
Gary Servin 0:04ac6be8229a 313 }
Gary Servin 0:04ac6be8229a 314 inbuffer[offset+length_serial_number-1]=0;
Gary Servin 0:04ac6be8229a 315 this->serial_number = (char *)(inbuffer + offset-1);
Gary Servin 0:04ac6be8229a 316 offset += length_serial_number;
Gary Servin 0:04ac6be8229a 317 return offset;
Gary Servin 0:04ac6be8229a 318 }
Gary Servin 0:04ac6be8229a 319
Gary Servin 0:04ac6be8229a 320 const char * getType(){ return "sensor_msgs/BatteryState"; };
Gary Servin 0:04ac6be8229a 321 const char * getMD5(){ return "476f837fa6771f6e16e3bf4ef96f8770"; };
Gary Servin 0:04ac6be8229a 322
Gary Servin 0:04ac6be8229a 323 };
Gary Servin 0:04ac6be8229a 324
Gary Servin 0:04ac6be8229a 325 }
Gary Servin 0:04ac6be8229a 326 #endif