From e6349372a8c94d905e405e8ca6313e827532425c Mon Sep 17 00:00:00 2001 From: Stéphane Raimbault Date: Sun, 27 Feb 2011 22:10:12 +0100 Subject: [PATCH] Minor changes in float functions --- src/modbus-data.c | 12 +++++++----- src/modbus.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/modbus-data.c b/src/modbus-data.c index 0f1453f..9bc959a 100644 --- a/src/modbus-data.c +++ b/src/modbus-data.c @@ -19,6 +19,7 @@ #include #include #include +#include /* Sets many bits from a single byte value (all 8 bits of the byte value are set) */ @@ -71,20 +72,21 @@ uint8_t modbus_get_byte_from_bits(const uint8_t *src, int address, /* Get a float from 4 bytes in Modbus format */ float modbus_get_float(const uint16_t *src) { - float r = 0.0f; + float f = 0.0f; uint32_t i; i = (((uint32_t)src[1]) << 16) + src[0]; - memcpy(&r, &i, sizeof (r)); - return r; + memcpy(&f, &i, sizeof(float)); + + return f; } /* Set a float to 4 bytes in Modbus format */ -void modbus_set_float(float real, uint16_t *dest) +void modbus_set_float(float f, uint16_t *dest) { uint32_t i = 0; - memcpy(&i, &real, sizeof (i)); + memcpy(&i, &f, sizeof(uint32_t)); dest[0] = (uint16_t)i; dest[1] = (uint16_t)(i >> 16); } diff --git a/src/modbus.h b/src/modbus.h index 8c87f4e..dfd550a 100644 --- a/src/modbus.h +++ b/src/modbus.h @@ -193,7 +193,7 @@ void modbus_set_bits_from_bytes(uint8_t *dest, int address, unsigned int nb_bits const uint8_t *tab_byte); uint8_t modbus_get_byte_from_bits(const uint8_t *src, int address, unsigned int nb_bits); float modbus_get_float(const uint16_t *src); -void modbus_set_float(float real, uint16_t *dest); +void modbus_set_float(float f, uint16_t *dest); #include "modbus-tcp.h" #include "modbus-rtu.h" -- libgit2 0.21.4