You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.2 KiB
C
59 lines
1.2 KiB
C
4 weeks ago
|
/*
|
||
|
* ModbusRTUVariant.h
|
||
|
*
|
||
|
* Author: Aleksey Gerasimenko
|
||
|
* gerasimenko.aleksey.n@gmail.com
|
||
|
*/
|
||
|
|
||
|
#include <math.h>
|
||
|
#include <stdint.h>
|
||
|
|
||
|
#include "RUDRIVEFRAMEWORK/DataTypesDefinitions.h"
|
||
|
|
||
|
|
||
|
#ifndef MODBUSRTU_MODBUSRTUVARIANT_H_
|
||
|
#define MODBUSRTU_MODBUSRTUVARIANT_H_
|
||
|
|
||
|
namespace MODBUSRTU
|
||
|
{
|
||
|
|
||
|
|
||
|
enum modbus_variant_type_t {VARIANT_FLOAT, VARIANT_INT16, VARIANT_INT32, VARIANT_UINT16, VARIANT_UINT32, VARIANT_BOOL};
|
||
|
|
||
|
class ModbusRTUVariant
|
||
|
{
|
||
|
private:
|
||
|
union
|
||
|
{
|
||
|
float f;
|
||
|
int16_t i16;
|
||
|
int32_t i32;
|
||
|
uint16_t u16;
|
||
|
uint32_t u32;
|
||
|
bool b;
|
||
|
};
|
||
|
modbus_variant_type_t t;
|
||
|
public:
|
||
|
ModbusRTUVariant();
|
||
|
modbus_variant_type_t get_type() const;
|
||
|
//setters
|
||
|
void set_float (float v);
|
||
|
void set_int16 (int16_t v);
|
||
|
void set_int32 (int32_t v);
|
||
|
void set_uint16 (uint16_t v);
|
||
|
void set_uint32 (uint32_t v);
|
||
|
void set_bool (bool v);
|
||
|
//getters
|
||
|
float get_float() const;
|
||
|
int16_t get_int16() const;
|
||
|
int32_t get_int32() const;
|
||
|
uint16_t get_uint16() const;
|
||
|
uint32_t get_uint32() const;
|
||
|
bool get_bool() const;
|
||
|
//
|
||
|
};
|
||
|
|
||
|
} /* namespace MODBUSRTU */
|
||
|
|
||
|
#endif /* MODBUSRTU_MODBUSRTUVARIANT_H_ */
|