clear project
							parent
							
								
									7ab4153cca
								
							
						
					
					
						commit
						3abcb43b33
					
				@ -1,109 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ModbusRTUCRC.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUCRC.h"
 | 
			
		||||
 | 
			
		||||
namespace MODBUSRTU
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
const uint16_t ModbusRTUCRC::m_table[256] = {0x0000, 0xC1C0, 0x81C1, 0x4001, 0x01C3, 0xC003, 0x8002, 0x41C2,
 | 
			
		||||
                                      0x01C6, 0xC006, 0x8007, 0x41C7, 0x0005, 0xC1C5, 0x81C4, 0x4004,
 | 
			
		||||
                                      0x01CC, 0xC00C, 0x800D, 0x41CD, 0x000F, 0xC1CF, 0x81CE, 0x400E,
 | 
			
		||||
                                      0x000A, 0xC1CA, 0x81CB, 0x400B, 0x01C9, 0xC009, 0x8008, 0x41C8,
 | 
			
		||||
                                      0x01D8, 0xC018, 0x8019, 0x41D9, 0x001B, 0xC1DB, 0x81DA, 0x401A,
 | 
			
		||||
                                      0x001E, 0xC1DE, 0x81DF, 0x401F, 0x01DD, 0xC01D, 0x801C, 0x41DC,
 | 
			
		||||
                                      0x0014, 0xC1D4, 0x81D5, 0x4015, 0x01D7, 0xC017, 0x8016, 0x41D6,
 | 
			
		||||
                                      0x01D2, 0xC012, 0x8013, 0x41D3, 0x0011, 0xC1D1, 0x81D0, 0x4010,
 | 
			
		||||
                                      0x01F0, 0xC030, 0x8031, 0x41F1, 0x0033, 0xC1F3, 0x81F2, 0x4032,
 | 
			
		||||
                                      0x0036, 0xC1F6, 0x81F7, 0x4037, 0x01F5, 0xC035, 0x8034, 0x41F4,
 | 
			
		||||
                                      0x003C, 0xC1FC, 0x81FD, 0x403D, 0x01FF, 0xC03F, 0x803E, 0x41FE,
 | 
			
		||||
                                      0x01FA, 0xC03A, 0x803B, 0x41FB, 0x0039, 0xC1F9, 0x81F8, 0x4038,
 | 
			
		||||
                                      0x0028, 0xC1E8, 0x81E9, 0x4029, 0x01EB, 0xC02B, 0x802A, 0x41EA,
 | 
			
		||||
                                      0x01EE, 0xC02E, 0x802F, 0x41EF, 0x002D, 0xC1ED, 0x81EC, 0x402C,
 | 
			
		||||
                                      0x01E4, 0xC024, 0x8025, 0x41E5, 0x0027, 0xC1E7, 0x81E6, 0x4026,
 | 
			
		||||
                                      0x0022, 0xC1E2, 0x81E3, 0x4023, 0x01E1, 0xC021, 0x8020, 0x41E0,
 | 
			
		||||
                                      0x01A0, 0xC060, 0x8061, 0x41A1, 0x0063, 0xC1A3, 0x81A2, 0x4062,
 | 
			
		||||
                                      0x0066, 0xC1A6, 0x81A7, 0x4067, 0x01A5, 0xC065, 0x8064, 0x41A4,
 | 
			
		||||
                                      0x006C, 0xC1AC, 0x81AD, 0x406D, 0x01AF, 0xC06F, 0x806E, 0x41AE,
 | 
			
		||||
                                      0x01AA, 0xC06A, 0x806B, 0x41AB, 0x0069, 0xC1A9, 0x81A8, 0x4068,
 | 
			
		||||
                                      0x0078, 0xC1B8, 0x81B9, 0x4079, 0x01BB, 0xC07B, 0x807A, 0x41BA,
 | 
			
		||||
                                      0x01BE, 0xC07E, 0x807F, 0x41BF, 0x007D, 0xC1BD, 0x81BC, 0x407C,
 | 
			
		||||
                                      0x01B4, 0xC074, 0x8075, 0x41B5, 0x0077, 0xC1B7, 0x81B6, 0x4076,
 | 
			
		||||
                                      0x0072, 0xC1B2, 0x81B3, 0x4073, 0x01B1, 0xC071, 0x8070, 0x41B0,
 | 
			
		||||
                                      0x0050, 0xC190, 0x8191, 0x4051, 0x0193, 0xC053, 0x8052, 0x4192,
 | 
			
		||||
                                      0x0196, 0xC056, 0x8057, 0x4197, 0x0055, 0xC195, 0x8194, 0x4054,
 | 
			
		||||
                                      0x019C, 0xC05C, 0x805D, 0x419D, 0x005F, 0xC19F, 0x819E, 0x405E,
 | 
			
		||||
                                      0x005A, 0xC19A, 0x819B, 0x405B, 0x0199, 0xC059, 0x8058, 0x4198,
 | 
			
		||||
                                      0x0188, 0xC048, 0x8049, 0x4189, 0x004B, 0xC18B, 0x818A, 0x404A,
 | 
			
		||||
                                      0x004E, 0xC18E, 0x818F, 0x404F, 0x018D, 0xC04D, 0x804C, 0x418C,
 | 
			
		||||
                                      0x0044, 0xC184, 0x8185, 0x4045, 0x0187, 0xC047, 0x8046, 0x4186,
 | 
			
		||||
                                      0x0182, 0xC042, 0x8043, 0x4183, 0x0041, 0xC181, 0x8180, 0x4040};
 | 
			
		||||
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
ModbusRTUCRC::ModbusRTUCRC():
 | 
			
		||||
        m_crc_calculate(),
 | 
			
		||||
        m_table_crc_index(0),
 | 
			
		||||
        m_table_crc_value(),
 | 
			
		||||
        m_start(0),
 | 
			
		||||
        m_end(0)
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
uint16_t ModbusRTUCRC::calculate(uint16_t *start, uint16_t length)
 | 
			
		||||
{
 | 
			
		||||
    m_crc_calculate.all = 0x0ffFF;
 | 
			
		||||
    m_start = start;
 | 
			
		||||
    m_end = start + length - 1;
 | 
			
		||||
 | 
			
		||||
    _while_cycle();
 | 
			
		||||
 | 
			
		||||
    return m_crc_calculate.all;
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
uint16_t ModbusRTUCRC::calculate(uint16_t *start, uint16_t *end)
 | 
			
		||||
{
 | 
			
		||||
    m_crc_calculate.all = 0x0ffFF;
 | 
			
		||||
    m_start = start;
 | 
			
		||||
    m_end = end;
 | 
			
		||||
 | 
			
		||||
    _while_cycle();
 | 
			
		||||
 | 
			
		||||
    return m_crc_calculate.all;
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
uint16_t ModbusRTUCRC::calculate(uint16_t databyte, uint16_t crc)
 | 
			
		||||
{
 | 
			
		||||
    m_crc_calculate.all = crc;
 | 
			
		||||
 | 
			
		||||
    m_table_crc_index = m_crc_calculate.byte.low ^ databyte;
 | 
			
		||||
    m_table_crc_value.all = m_table[m_table_crc_index];
 | 
			
		||||
    m_crc_calculate.byte.low = m_crc_calculate.byte.high ^ m_table_crc_value.byte.high;
 | 
			
		||||
    m_crc_calculate.byte.high = m_table_crc_value.byte.low;
 | 
			
		||||
 | 
			
		||||
    return m_crc_calculate.all;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
inline void ModbusRTUCRC::_while_cycle()
 | 
			
		||||
{
 | 
			
		||||
    while(m_start <= m_end)
 | 
			
		||||
    {
 | 
			
		||||
        m_table_crc_index = m_crc_calculate.byte.low ^ (*m_start++);
 | 
			
		||||
        m_table_crc_value.all = m_table[m_table_crc_index];
 | 
			
		||||
        m_crc_calculate.byte.low = m_crc_calculate.byte.high ^ m_table_crc_value.byte.high;
 | 
			
		||||
        m_crc_calculate.byte.high = m_table_crc_value.byte.low;
 | 
			
		||||
        //
 | 
			
		||||
    }//while
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
} /* namespace MODBUSRTU */
 | 
			
		||||
@ -1,58 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ModbusRTUCRC.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_MODBUSRTUCRC_H_
 | 
			
		||||
#define MODBUSRTU_MODBUSRTUCRC_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct Uint16ByteField
 | 
			
		||||
{
 | 
			
		||||
    uint16_t low: 8;
 | 
			
		||||
    uint16_t high: 8;
 | 
			
		||||
};//Uint16ByteField
 | 
			
		||||
 | 
			
		||||
union Uint16Register
 | 
			
		||||
{
 | 
			
		||||
    uint16_t all;
 | 
			
		||||
    Uint16ByteField byte;
 | 
			
		||||
    Uint16Register():
 | 
			
		||||
    all(0)
 | 
			
		||||
    {}
 | 
			
		||||
};//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace MODBUSRTU
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class ModbusRTUCRC
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    static const uint16_t m_table[256];
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    Uint16Register  m_crc_calculate;
 | 
			
		||||
    uint16_t        m_table_crc_index;
 | 
			
		||||
    Uint16Register  m_table_crc_value;
 | 
			
		||||
    uint16_t        *m_start;
 | 
			
		||||
    uint16_t        *m_end;
 | 
			
		||||
public:
 | 
			
		||||
    ModbusRTUCRC();
 | 
			
		||||
public:
 | 
			
		||||
    uint16_t calculate(uint16_t *start, uint16_t length);
 | 
			
		||||
    uint16_t calculate(uint16_t *start, uint16_t *end);
 | 
			
		||||
    uint16_t calculate(uint16_t databyte, uint16_t crc);
 | 
			
		||||
private:
 | 
			
		||||
    inline void _while_cycle();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace MODBUSRTU */
 | 
			
		||||
 | 
			
		||||
#endif /* MODBUSRTU_MODBUSRTUCRC_H_ */
 | 
			
		||||
@ -1,65 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ModbusRTUCRCTable.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_MODBUSRTUCRCTABLE_H_
 | 
			
		||||
#define MODBUSRTU_MODBUSRTUCRCTABLE_H_
 | 
			
		||||
 | 
			
		||||
struct Uint16ByteField
 | 
			
		||||
{
 | 
			
		||||
    uint16_t low: 8;
 | 
			
		||||
    uint16_t high: 8;
 | 
			
		||||
};//Uint16ByteField
 | 
			
		||||
 | 
			
		||||
union Uint16Register
 | 
			
		||||
{
 | 
			
		||||
    uint16_t all;
 | 
			
		||||
    Uint16ByteField byte;
 | 
			
		||||
    Uint16Register():
 | 
			
		||||
    all(0)
 | 
			
		||||
    {}
 | 
			
		||||
};//
 | 
			
		||||
 | 
			
		||||
static const  uint16_t TABLE_CRC_16[] =
 | 
			
		||||
    {
 | 
			
		||||
        0x0000, 0xC1C0, 0x81C1, 0x4001, 0x01C3, 0xC003, 0x8002, 0x41C2,
 | 
			
		||||
        0x01C6, 0xC006, 0x8007, 0x41C7, 0x0005, 0xC1C5, 0x81C4, 0x4004,
 | 
			
		||||
        0x01CC, 0xC00C, 0x800D, 0x41CD, 0x000F, 0xC1CF, 0x81CE, 0x400E,
 | 
			
		||||
        0x000A, 0xC1CA, 0x81CB, 0x400B, 0x01C9, 0xC009, 0x8008, 0x41C8,
 | 
			
		||||
        0x01D8, 0xC018, 0x8019, 0x41D9, 0x001B, 0xC1DB, 0x81DA, 0x401A,
 | 
			
		||||
        0x001E, 0xC1DE, 0x81DF, 0x401F, 0x01DD, 0xC01D, 0x801C, 0x41DC,
 | 
			
		||||
        0x0014, 0xC1D4, 0x81D5, 0x4015, 0x01D7, 0xC017, 0x8016, 0x41D6,
 | 
			
		||||
        0x01D2, 0xC012, 0x8013, 0x41D3, 0x0011, 0xC1D1, 0x81D0, 0x4010,
 | 
			
		||||
        0x01F0, 0xC030, 0x8031, 0x41F1, 0x0033, 0xC1F3, 0x81F2, 0x4032,
 | 
			
		||||
        0x0036, 0xC1F6, 0x81F7, 0x4037, 0x01F5, 0xC035, 0x8034, 0x41F4,
 | 
			
		||||
        0x003C, 0xC1FC, 0x81FD, 0x403D, 0x01FF, 0xC03F, 0x803E, 0x41FE,
 | 
			
		||||
        0x01FA, 0xC03A, 0x803B, 0x41FB, 0x0039, 0xC1F9, 0x81F8, 0x4038,
 | 
			
		||||
        0x0028, 0xC1E8, 0x81E9, 0x4029, 0x01EB, 0xC02B, 0x802A, 0x41EA,
 | 
			
		||||
        0x01EE, 0xC02E, 0x802F, 0x41EF, 0x002D, 0xC1ED, 0x81EC, 0x402C,
 | 
			
		||||
        0x01E4, 0xC024, 0x8025, 0x41E5, 0x0027, 0xC1E7, 0x81E6, 0x4026,
 | 
			
		||||
        0x0022, 0xC1E2, 0x81E3, 0x4023, 0x01E1, 0xC021, 0x8020, 0x41E0,
 | 
			
		||||
        0x01A0, 0xC060, 0x8061, 0x41A1, 0x0063, 0xC1A3, 0x81A2, 0x4062,
 | 
			
		||||
        0x0066, 0xC1A6, 0x81A7, 0x4067, 0x01A5, 0xC065, 0x8064, 0x41A4,
 | 
			
		||||
        0x006C, 0xC1AC, 0x81AD, 0x406D, 0x01AF, 0xC06F, 0x806E, 0x41AE,
 | 
			
		||||
        0x01AA, 0xC06A, 0x806B, 0x41AB, 0x0069, 0xC1A9, 0x81A8, 0x4068,
 | 
			
		||||
        0x0078, 0xC1B8, 0x81B9, 0x4079, 0x01BB, 0xC07B, 0x807A, 0x41BA,
 | 
			
		||||
        0x01BE, 0xC07E, 0x807F, 0x41BF, 0x007D, 0xC1BD, 0x81BC, 0x407C,
 | 
			
		||||
        0x01B4, 0xC074, 0x8075, 0x41B5, 0x0077, 0xC1B7, 0x81B6, 0x4076,
 | 
			
		||||
        0x0072, 0xC1B2, 0x81B3, 0x4073, 0x01B1, 0xC071, 0x8070, 0x41B0,
 | 
			
		||||
        0x0050, 0xC190, 0x8191, 0x4051, 0x0193, 0xC053, 0x8052, 0x4192,
 | 
			
		||||
        0x0196, 0xC056, 0x8057, 0x4197, 0x0055, 0xC195, 0x8194, 0x4054,
 | 
			
		||||
        0x019C, 0xC05C, 0x805D, 0x419D, 0x005F, 0xC19F, 0x819E, 0x405E,
 | 
			
		||||
        0x005A, 0xC19A, 0x819B, 0x405B, 0x0199, 0xC059, 0x8058, 0x4198,
 | 
			
		||||
        0x0188, 0xC048, 0x8049, 0x4189, 0x004B, 0xC18B, 0x818A, 0x404A,
 | 
			
		||||
        0x004E, 0xC18E, 0x818F, 0x404F, 0x018D, 0xC04D, 0x804C, 0x418C,
 | 
			
		||||
        0x0044, 0xC184, 0x8185, 0x4045, 0x0187, 0xC047, 0x8046, 0x4186,
 | 
			
		||||
        0x0182, 0xC042, 0x8043, 0x4183, 0x0041, 0xC181, 0x8180, 0x4040
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif /* MODBUSRTU_MODBUSRTUCRCTABLE_H_ */
 | 
			
		||||
@ -1,257 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ModbusRTUDefines.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#include "F28335/DSP28x_Project.h"
 | 
			
		||||
#include "F28335/DSP2833x_Examples.h"
 | 
			
		||||
 | 
			
		||||
#include "DSP28335/GPIO.h"
 | 
			
		||||
#include "DSP28335/SCIBase.h"
 | 
			
		||||
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUVariant.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef SCIRS485_BAUDRATE_DEFAULT
 | 
			
		||||
//#define SCIRS485_BAUDRATE_DEFAULT   (DSP28335::BR2400)
 | 
			
		||||
//#define SCIRS485_BAUDRATE_DEFAULT   (DSP28335::BR4800)
 | 
			
		||||
#define SCIRS485_BAUDRATE_DEFAULT   (DSP28335::BR9600)
 | 
			
		||||
//#define SCIRS485_BAUDRATE_DEFAULT   (DSP28335::BR14400)
 | 
			
		||||
//#define SCIRS485_BAUDRATE_DEFAULT   (DSP28335::BR19200)
 | 
			
		||||
//#define SCIRS485_BAUDRATE_DEFAULT   (DSP28335::BR38400)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef SCIRS485_PARITY_DEFAULT
 | 
			
		||||
#define SCIRS485_PARITY_DEFAULT     (DSP28335::NO)
 | 
			
		||||
//#define SCIRS485_PARITY_DEFAULT     (MODBUSRTU::ODD)
 | 
			
		||||
//#define SCIRS485_PARITY_DEFAULT     (MODBUSRTU::EVEN)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef SCIRS485_STOPBITS_DEFAULT
 | 
			
		||||
#define SCIRS485_STOPBITS_DEFAULT   (DSP28335::ONE)
 | 
			
		||||
//#define SCIRS485_STOPBITS_DEFAULT   (DSP28335::ODD)
 | 
			
		||||
//#define SCIRS485_STOPBITS_DEFAULT   (DSP28335::EVEN)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef SCIRS485_LENGHT_DEFAULT
 | 
			
		||||
#define SCIRS485_LENGHT_DEFAULT     (DSP28335::LEN8)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef SCIRS485_GPIO_SETUP_DEFAULT
 | 
			
		||||
#define SCIRS485_GPIO_SETUP_DEFAULT (&DSP28335::GPIO::gpio_scib_setup)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef SCIRS485_GPIO_DE_DEFAULT
 | 
			
		||||
#define SCIRS485_GPIO_DE_DEFAULT (&DSP28335::GPIO::gpio_scib_re_de_set)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef SCIRS485_GPIO_RE_DEFAULT
 | 
			
		||||
#define SCIRS485_GPIO_RE_DEFAULT (&DSP28335::GPIO::gpio_scib_re_de_clear)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef NOP
 | 
			
		||||
#define  NOP   asm(" NOP")
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_FUNCTION_BROADCAST
 | 
			
		||||
#define MODBUSRTU_FUNCTION_BROADCAST                    (uint16_t) 00
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_FUNCTION_READ_COIL_STATUS
 | 
			
		||||
#define MODBUSRTU_FUNCTION_READ_COIL_STATUS             (uint16_t) 01
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_FUNCTION_READ_INPUT_STATUS
 | 
			
		||||
#define MODBUSRTU_FUNCTION_READ_INPUT_STATUS            (uint16_t) 02
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_FUNCTION_READ_HOLDING_REGISTERS
 | 
			
		||||
#define MODBUSRTU_FUNCTION_READ_HOLDING_REGISTERS       (uint16_t) 03
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_FUNCTION_READ_INPUT_REGISTERS
 | 
			
		||||
#define MODBUSRTU_FUNCTION_READ_INPUT_REGISTERS         (uint16_t) 04
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_FUNCTION_FORCE_SINGLE_COIL
 | 
			
		||||
#define MODBUSRTU_FUNCTION_FORCE_SINGLE_COIL            (uint16_t) 05
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_FUNCTION_PRESET_SINGLE_REGISTER
 | 
			
		||||
#define MODBUSRTU_FUNCTION_PRESET_SINGLE_REGISTER       (uint16_t) 06
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_FUNCTION_FORCE_MULTIPLE_COILS
 | 
			
		||||
#define MODBUSRTU_FUNCTION_FORCE_MULTIPLE_COILS         (uint16_t) 15
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_FUNCTION_PRESET_MULTIPLE_REGISTERS
 | 
			
		||||
#define MODBUSRTU_FUNCTION_PRESET_MULTIPLE_REGISTERS    (uint16_t) 16
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef DEFAULT_MODBUSRTU_INPUT_REGISTERS_SIZE
 | 
			
		||||
#define DEFAULT_MODBUSRTU_INPUT_REGISTERS_SIZE (uint16_t)10
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef DEFAULT_MODBUSRTU_OUTPUT_REGISTERS_SIZE
 | 
			
		||||
#define DEFAULT_MODBUSRTU_OUTPUT_REGISTERS_SIZE (uint16_t)10
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef DEFAULT_MODBUSRTU_INPUT_COILS_SIZE
 | 
			
		||||
#define DEFAULT_MODBUSRTU_INPUT_COILS_SIZE (uint16_t)10
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef DEFAULT_MODBUSRTU_OUTPUT_COILS_SIZE
 | 
			
		||||
#define DEFAULT_MODBUSRTU_OUTPUT_COILS_SIZE (uint16_t)10
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_INPUT_REGISTERS_SIZE
 | 
			
		||||
#define MODBUSRTU_INPUT_REGISTERS_SIZE DEFAULT_MODBUSRTU_INPUT_REGISTERS_SIZE
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_OUTPUT_REGISTERS_SIZE
 | 
			
		||||
#define MODBUSRTU_OUTPUT_REGISTERS_SIZE  DEFAULT_MODBUSRTU_OUTPUT_REGISTERS_SIZE
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_INPUT_COILS_SIZE
 | 
			
		||||
#define MODBUSRTU_INPUT_COILS_SIZE  DEFAULT_MODBUSRTU_INPUT_COILS_SIZE
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_OUTPUT_COILS_SIZE
 | 
			
		||||
#define MODBUSRTU_OUTPUT_COILS_SIZE  DEFAULT_MODBUSRTU_OUTPUT_COILS_SIZE
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_MODBUSRTUDEFINES_H_
 | 
			
		||||
#define MODBUSRTU_MODBUSRTUDEFINES_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace MODBUSRTU
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
enum buffer_type_t  {OUTPUTCOILS, INPUTCOILS, OUTPUTREGISTERS, INPUTREGISTERS};
 | 
			
		||||
enum transceiver_state_machine_t {SCAN, RECEIVE, WAIT_RESPONSE, TRANSMIT, BREAK};
 | 
			
		||||
enum transceiver_event_t {ENTRY, RXREADY, TXREADY, TXWAIT};
 | 
			
		||||
 | 
			
		||||
enum modbusrtu_register_16_bit_t {  REG16_BIT0,
 | 
			
		||||
                                    REG16_BIT1,
 | 
			
		||||
                                    REG16_BIT2,
 | 
			
		||||
                                    REG16_BIT3,
 | 
			
		||||
                                    REG16_BIT4,
 | 
			
		||||
                                    REG16_BIT5,
 | 
			
		||||
                                    REG16_BIT6,
 | 
			
		||||
                                    REG16_BIT7,
 | 
			
		||||
                                    REG16_BIT8,
 | 
			
		||||
                                    REG16_BIT9,
 | 
			
		||||
                                    REG16_BIT10,
 | 
			
		||||
                                    REG16_BIT11,
 | 
			
		||||
                                    REG16_BIT12,
 | 
			
		||||
                                    REG16_BIT13,
 | 
			
		||||
                                    REG16_BIT14,
 | 
			
		||||
                                    REG16_BIT15};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//struct ModbusRTUDataByteField
 | 
			
		||||
//{
 | 
			
		||||
//    uint16_t low :8;
 | 
			
		||||
//    uint16_t high :8;
 | 
			
		||||
//};//ModbusRTUDataByteField
 | 
			
		||||
 | 
			
		||||
//union ModbusRTUDataRegister
 | 
			
		||||
//{
 | 
			
		||||
//    uint16_t all;
 | 
			
		||||
//    ModbusRTUDataByteField byte;
 | 
			
		||||
//    ModbusRTUDataRegister():
 | 
			
		||||
//        all(0)
 | 
			
		||||
//    {}
 | 
			
		||||
//};//ModbusRTUDataRegister
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//enum ModbusRTUEventRS
 | 
			
		||||
//{
 | 
			
		||||
//    ENTRY,                  // state entry event
 | 
			
		||||
//    EXIT,                   // state exit event
 | 
			
		||||
//    TIMEOUT3_5CHAR,         // All datagram have been received
 | 
			
		||||
//    TIMEOUT1_5CHAR,         // Interval time of each byte in datagram. Not used
 | 
			
		||||
//    RX_READY,               // SCIRXST.bit.RXRDY. Serial port received a serial data (one byte)
 | 
			
		||||
//    TX_READY,               // All datagram have been sent
 | 
			
		||||
//    TX_WAIT                 // Wait for the datagram to be sent
 | 
			
		||||
//};//
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
enum ModbusRTUReceiveEvent
 | 
			
		||||
{
 | 
			
		||||
    ENTRY,
 | 
			
		||||
    RECEIVE,
 | 
			
		||||
    EXIT,
 | 
			
		||||
    TIMEOUT355CHAR,
 | 
			
		||||
    TIMEOUT155CHAR,
 | 
			
		||||
    FRAMEREADY,
 | 
			
		||||
    WAIT
 | 
			
		||||
};//
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//struct ModbusRTUTimerStateBitField
 | 
			
		||||
//{
 | 
			
		||||
//    uint16_t time_over_1_5_char :1;
 | 
			
		||||
//    uint16_t time_over_3_5_char :1;
 | 
			
		||||
//};//ModbusRTUTimerStateBitField
 | 
			
		||||
 | 
			
		||||
//union ModbusRTUTimerState
 | 
			
		||||
//{
 | 
			
		||||
//    uint16_t all;
 | 
			
		||||
//    ModbusRTUTimerStateBitField bit;
 | 
			
		||||
//    ModbusRTUTimerState():
 | 
			
		||||
//        all((uint16_t)0)
 | 
			
		||||
//    {}
 | 
			
		||||
//};//ModbusRTUTimerState
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//struct ModbusRTUTimer
 | 
			
		||||
//{
 | 
			
		||||
//    uint32_t counter;
 | 
			
		||||
//    uint32_t start;
 | 
			
		||||
//    uint32_t interval;
 | 
			
		||||
//    uint32_t period_1_5_char;
 | 
			
		||||
//    uint32_t period_3_5_char;
 | 
			
		||||
//    ModbusRTUTimerState flag;
 | 
			
		||||
//    ModbusRTUTimer():
 | 
			
		||||
//        counter((uint32_t)0),
 | 
			
		||||
//        start((uint32_t)0),
 | 
			
		||||
//        interval((uint32_t)0),
 | 
			
		||||
//        period_1_5_char((uint32_t)0),
 | 
			
		||||
//        period_3_5_char((uint32_t)0),
 | 
			
		||||
//        flag()
 | 
			
		||||
//    {}
 | 
			
		||||
//};//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
} /* namespace MODBUSRTU */
 | 
			
		||||
 | 
			
		||||
#endif /* MODBUSRTU_MODBUSRTUDEFINES_H_ */
 | 
			
		||||
@ -1,496 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ModbusRTUTransceiver.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUTransceiver.h"
 | 
			
		||||
 | 
			
		||||
namespace MODBUSRTU
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
//ModbusRTUTransceiver::ModbusRTUTransceiver(DSP28335::SCIBase& sciport, DSP28335::CPUTimers& cputimer, MODBUSRTU::ModbusRTUCRC& crc):
 | 
			
		||||
ModbusRTUTransceiver::ModbusRTUTransceiver(DSP28335::SCIBase& sciport, DSP28335::MeasureTimeInterval& interval_measure, MODBUSRTU::ModbusRTUCRC& crc):
 | 
			
		||||
        m_sci_port(sciport),
 | 
			
		||||
        m_sci_config(),
 | 
			
		||||
        m_node_id(0),
 | 
			
		||||
        //
 | 
			
		||||
        m_state_machine(MODBUSRTU::SCAN),
 | 
			
		||||
        m_event(MODBUSRTU::ENTRY),
 | 
			
		||||
        //
 | 
			
		||||
        //m_interval(cputimer.CPUTimer),
 | 
			
		||||
        m_interval_measure(interval_measure),
 | 
			
		||||
        m_interval_pause((Uint32)0),
 | 
			
		||||
        m_interval_b5((Uint32)0),
 | 
			
		||||
        m_interval_b75((Uint32)0),
 | 
			
		||||
        m_interval_1b((Uint32)0),
 | 
			
		||||
        m_interval_1b25((Uint32)0),
 | 
			
		||||
        m_interval_1b5((Uint32)0),
 | 
			
		||||
        m_interval_1b75((Uint32)0),
 | 
			
		||||
        m_interval_3b5((Uint32)0),
 | 
			
		||||
        m_interval_freeze((Uint32)0),
 | 
			
		||||
        m_interval_current((Uint32)0),
 | 
			
		||||
        //
 | 
			
		||||
        m_rx_buffer(),
 | 
			
		||||
        m_tx_buffer(),
 | 
			
		||||
        m_rx_count(0),
 | 
			
		||||
        m_tx_count(0),
 | 
			
		||||
        m_tx_length(0),
 | 
			
		||||
        //
 | 
			
		||||
        m_aux_rx_buf(0),
 | 
			
		||||
        m_aux_rx_count(0),
 | 
			
		||||
        m_aux_tx_buf(0),
 | 
			
		||||
        m_aux_tx_count(0),
 | 
			
		||||
        //
 | 
			
		||||
        m_crc_status(false),
 | 
			
		||||
        m_crc(crc),
 | 
			
		||||
        m_crc_rx_frame(0),
 | 
			
		||||
        m_crc_tx_frame(0),
 | 
			
		||||
        //
 | 
			
		||||
        m_rx_external_buffer(m_rx_buffer),
 | 
			
		||||
        m_tx_external_buffer(m_tx_buffer),
 | 
			
		||||
        m_rx_messaage_length(&m_rx_count),
 | 
			
		||||
        m_tx_message_length(&m_tx_count),
 | 
			
		||||
        //
 | 
			
		||||
        m_destination(0),
 | 
			
		||||
        m_source_start(0),
 | 
			
		||||
        m_source_end(0),
 | 
			
		||||
        m_copy_length(0),
 | 
			
		||||
        //
 | 
			
		||||
        _execute(&ModbusRTUTransceiver::_execute_transceiver),
 | 
			
		||||
        _frame_transceiver(&ModbusRTUTransceiver::_frame_receive_node_id),
 | 
			
		||||
        //
 | 
			
		||||
        _re_de_setup(&DSP28335::GPIO::gpio_scib_re_de_setup),
 | 
			
		||||
        _driver_enable(&DSP28335::GPIO::gpio_scib_re_de_set),
 | 
			
		||||
        _receiver_enable(&DSP28335::GPIO::gpio_scib_re_de_clear)
 | 
			
		||||
        //
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ModbusRTUTransceiver::setup(ModbusRTUTransceiverSetup& setup)
 | 
			
		||||
{
 | 
			
		||||
    //m_interval.setup();
 | 
			
		||||
    _re_de_setup = setup.gpio_re_de_setup;
 | 
			
		||||
    _driver_enable = setup.gpio_driver_enable;
 | 
			
		||||
    _receiver_enable = setup.gpio_receiver_enable;
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    (*_re_de_setup)();
 | 
			
		||||
    
 | 
			
		||||
    _set_receive_node_id();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void ModbusRTUTransceiver::configure(ModbusRTUTransceiverConfiguration& config)
 | 
			
		||||
{
 | 
			
		||||
    m_sci_config = config.config;
 | 
			
		||||
    m_node_id = config.node_id;
 | 
			
		||||
 | 
			
		||||
    if(!m_sci_port.compare_configuration(m_sci_config))
 | 
			
		||||
    {
 | 
			
		||||
        m_sci_port.set_configuration(m_sci_config);
 | 
			
		||||
        //
 | 
			
		||||
    }//if
 | 
			
		||||
 | 
			
		||||
    switch(m_sci_config.baudrate)
 | 
			
		||||
    {
 | 
			
		||||
    case DSP28335::BR2400:  {m_interval_b5 = (Uint32)250000; m_interval_b75 = (Uint32)375000; m_interval_1b = (Uint32)500000; m_interval_1b25 = (Uint32)625000; m_interval_1b5 = (Uint32)750000; m_interval_1b75 = (Uint32)875000; m_interval_3b5 = (Uint32)1750000; m_interval_freeze = (Uint32)2000000; break;}
 | 
			
		||||
    case DSP28335::BR4800:  {m_interval_b5 = (Uint32)125000; m_interval_b75 = (Uint32)187500; m_interval_1b = (Uint32)250000; m_interval_1b25 = (Uint32)312500; m_interval_1b5 = (Uint32)375000; m_interval_1b75 = (Uint32)250000; m_interval_3b5 = (Uint32) 875000; m_interval_freeze = (Uint32)1000000; break;}
 | 
			
		||||
    case DSP28335::BR9600:  {m_interval_b5 = (Uint32) 62500; m_interval_b75 = (Uint32) 93750; m_interval_1b = (Uint32)125000; m_interval_1b25 = (Uint32)156250; m_interval_1b5 = (Uint32)187500; m_interval_1b75 = (Uint32)218750; m_interval_3b5 = (Uint32) 437500; m_interval_freeze = (Uint32) 500000; break;}
 | 
			
		||||
    case DSP28335::BR19200: {m_interval_b5 = (Uint32) 31250; m_interval_b75 = (Uint32) 46875; m_interval_1b = (Uint32) 62500; m_interval_1b25 = (Uint32)78125;  m_interval_1b5 = (Uint32) 93750; m_interval_1b75 = (Uint32)109375; m_interval_3b5 = (Uint32) 218750; m_interval_freeze = (Uint32) 250000; break;}
 | 
			
		||||
    case DSP28335::BR38400: {m_interval_b5 = (Uint32)15625;  m_interval_b75 = (Uint32)23437;  m_interval_1b = (Uint32) 31250; m_interval_1b25 = (Uint32)39062;  m_interval_1b5 = (Uint32) 46875; m_interval_1b75 = (Uint32) 54687; m_interval_3b5 = (Uint32) 109375; m_interval_freeze = (Uint32) 125000; break;}
 | 
			
		||||
    default: {m_interval_b5 = (Uint32)62500;  m_interval_b75 = (Uint32)93750;  m_interval_1b = (Uint32)125000; m_interval_1b25 = (Uint32)156250; m_interval_1b5 = (Uint32)187500; m_interval_1b75 = (Uint32)218750; m_interval_3b5 = (Uint32) 437500; m_interval_freeze = (Uint32) 500000; break;}
 | 
			
		||||
    }//switch
 | 
			
		||||
 | 
			
		||||
    m_interval_pause = m_interval_1b * 0.1;
 | 
			
		||||
    //m_interval_pause = m_interval_1b * 0.2;
 | 
			
		||||
 | 
			
		||||
    _set_receive_node_id();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
void ModbusRTUTransceiver::port_reset()
 | 
			
		||||
{
 | 
			
		||||
    m_sci_port.set_configuration(m_sci_config);
 | 
			
		||||
    _set_receive_node_id();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
bool ModbusRTUTransceiver::compare_state(MODBUSRTU::transceiver_state_machine_t  state_machine)
 | 
			
		||||
{
 | 
			
		||||
    return m_state_machine == state_machine;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void ModbusRTUTransceiver::execute()
 | 
			
		||||
{
 | 
			
		||||
    (this->*_execute)();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
void ModbusRTUTransceiver::_execute_transceiver()
 | 
			
		||||
{
 | 
			
		||||
    if(m_sci_port.SciRegs.SCIRXST.bit.BRKDT)
 | 
			
		||||
    {
 | 
			
		||||
        _set_break_condition();
 | 
			
		||||
        //
 | 
			
		||||
    }//if
 | 
			
		||||
    //
 | 
			
		||||
    (this->*_frame_transceiver)();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void ModbusRTUTransceiver::_execute_break()
 | 
			
		||||
{
 | 
			
		||||
    //m_interval_current = m_interval.interval();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void ModbusRTUTransceiver::setRXBuffer(uint16_t *bufferStart, uint16_t *messageLen)
 | 
			
		||||
{
 | 
			
		||||
    m_rx_external_buffer = bufferStart;
 | 
			
		||||
    m_rx_messaage_length = messageLen;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void ModbusRTUTransceiver::setTXBuffer(uint16_t *bufferStart, uint16_t *messageLen)
 | 
			
		||||
{
 | 
			
		||||
    m_tx_external_buffer = bufferStart;
 | 
			
		||||
    m_tx_message_length = messageLen;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_set_receive_node_id()
 | 
			
		||||
{
 | 
			
		||||
    m_state_machine = MODBUSRTU::SCAN;
 | 
			
		||||
    _frame_transceiver = &ModbusRTUTransceiver::_frame_receive_node_id;
 | 
			
		||||
    _execute = &ModbusRTUTransceiver::_execute_transceiver;
 | 
			
		||||
    (*_receiver_enable)();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_set_receive_function()
 | 
			
		||||
{
 | 
			
		||||
    m_state_machine = MODBUSRTU::RECEIVE;
 | 
			
		||||
    _frame_transceiver = &ModbusRTUTransceiver::_frame_receive_function;
 | 
			
		||||
    _execute = &ModbusRTUTransceiver::_execute_transceiver;
 | 
			
		||||
    (*_receiver_enable)();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_set_receive_data()
 | 
			
		||||
{
 | 
			
		||||
    m_state_machine = MODBUSRTU::RECEIVE;
 | 
			
		||||
    _frame_transceiver = &ModbusRTUTransceiver::_frame_receive_data;
 | 
			
		||||
    _execute = &ModbusRTUTransceiver::_execute_transceiver;
 | 
			
		||||
    (*_receiver_enable)();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_set_wait_response()
 | 
			
		||||
{
 | 
			
		||||
    m_state_machine = MODBUSRTU::WAIT_RESPONSE;
 | 
			
		||||
    _frame_transceiver = &ModbusRTUTransceiver::_frame_wait_response;
 | 
			
		||||
    _execute = &ModbusRTUTransceiver::_execute_transceiver;
 | 
			
		||||
    (*_receiver_enable)();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_set_transmit_data()
 | 
			
		||||
{
 | 
			
		||||
    m_state_machine = MODBUSRTU::TRANSMIT;
 | 
			
		||||
    _frame_transceiver = &ModbusRTUTransceiver::_frame_transmit_data;
 | 
			
		||||
    _execute = &ModbusRTUTransceiver::_execute_transceiver;
 | 
			
		||||
    (*_driver_enable)();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_set_break_condition()
 | 
			
		||||
{
 | 
			
		||||
    m_state_machine = MODBUSRTU::BREAK;
 | 
			
		||||
    _frame_transceiver = &ModbusRTUTransceiver::_frame_break_condition;
 | 
			
		||||
    _execute = &ModbusRTUTransceiver::_execute_break;
 | 
			
		||||
    (*_receiver_enable)();
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_frame_receive_node_id()
 | 
			
		||||
{
 | 
			
		||||
        if(m_sci_port.SciRegs.SCIRXST.bit.RXRDY)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_rx_buf = m_sci_port.SciRegs.SCIRXBUF.bit.RXDT;
 | 
			
		||||
 | 
			
		||||
            while(m_sci_port.SciRegs.SCIRXST.bit.RXRDY){}
 | 
			
		||||
 | 
			
		||||
            if((m_node_id == m_aux_rx_buf)||(MODBUSRTU_FUNCTION_BROADCAST == m_aux_rx_buf))
 | 
			
		||||
            {
 | 
			
		||||
                m_rx_buffer[0] = m_aux_rx_buf;
 | 
			
		||||
 | 
			
		||||
                m_aux_rx_count = 1;
 | 
			
		||||
                m_interval_measure.start();
 | 
			
		||||
                _set_receive_function();
 | 
			
		||||
                //
 | 
			
		||||
            }//if
 | 
			
		||||
        }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_frame_receive_function()
 | 
			
		||||
{
 | 
			
		||||
    if(m_sci_port.SciRegs.SCIRXST.bit.RXRDY)
 | 
			
		||||
    {
 | 
			
		||||
        m_aux_rx_buf = m_sci_port.SciRegs.SCIRXBUF.bit.RXDT;
 | 
			
		||||
 | 
			
		||||
        while(m_sci_port.SciRegs.SCIRXST.bit.RXRDY){}
 | 
			
		||||
 | 
			
		||||
        if(//(MODBUSRTU_FUNCTION_BROADCAST                        == m_aux_rx_buf)||
 | 
			
		||||
                (MODBUSRTU_FUNCTION_READ_COIL_STATUS            == m_aux_rx_buf)||
 | 
			
		||||
                //(MODBUSRTU_FUNCTION_READ_INPUT_STATUS           == m_aux_rx_buf)||
 | 
			
		||||
                (MODBUSRTU_FUNCTION_READ_HOLDING_REGISTERS      == m_aux_rx_buf)||
 | 
			
		||||
                //(MODBUSRTU_FUNCTION_READ_INPUT_REGISTERS        == m_aux_rx_buf)||
 | 
			
		||||
                (MODBUSRTU_FUNCTION_FORCE_SINGLE_COIL           == m_aux_rx_buf)||
 | 
			
		||||
                (MODBUSRTU_FUNCTION_PRESET_SINGLE_REGISTER      == m_aux_rx_buf)||
 | 
			
		||||
                (MODBUSRTU_FUNCTION_FORCE_MULTIPLE_COILS        == m_aux_rx_buf)||
 | 
			
		||||
                (MODBUSRTU_FUNCTION_PRESET_MULTIPLE_REGISTERS   == m_aux_rx_buf))
 | 
			
		||||
        {
 | 
			
		||||
            m_rx_buffer[1] = m_aux_rx_buf;
 | 
			
		||||
            m_aux_rx_count = 2;
 | 
			
		||||
            m_interval_measure.start();
 | 
			
		||||
            _set_receive_data();
 | 
			
		||||
            //
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            // wrong function, break receive
 | 
			
		||||
            m_interval_measure.stop();
 | 
			
		||||
            _set_receive_node_id();
 | 
			
		||||
            //
 | 
			
		||||
        }//if else
 | 
			
		||||
        //
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        m_interval_current = m_interval_measure.interval();
 | 
			
		||||
        if(m_interval_current > m_interval_1b5)
 | 
			
		||||
        {
 | 
			
		||||
            // exceed time interval, break receive
 | 
			
		||||
            m_interval_measure.stop();
 | 
			
		||||
            _set_receive_node_id();
 | 
			
		||||
            //
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//if else
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_frame_receive_data()
 | 
			
		||||
{
 | 
			
		||||
    if(m_sci_port.SciRegs.SCIRXST.bit.RXRDY)
 | 
			
		||||
    {
 | 
			
		||||
        m_aux_rx_buf = m_sci_port.SciRegs.SCIRXBUF.bit.RXDT;
 | 
			
		||||
 | 
			
		||||
        while(m_sci_port.SciRegs.SCIRXST.bit.RXRDY){}
 | 
			
		||||
 | 
			
		||||
        m_rx_buffer[m_aux_rx_count] = m_aux_rx_buf;
 | 
			
		||||
        m_aux_rx_count++;
 | 
			
		||||
        m_interval_measure.start();
 | 
			
		||||
 | 
			
		||||
        if(m_aux_rx_count >= 256)
 | 
			
		||||
        {
 | 
			
		||||
            // exceed count, break receive
 | 
			
		||||
            m_interval_measure.stop();
 | 
			
		||||
            _set_receive_node_id();
 | 
			
		||||
            //
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        m_interval_current = m_interval_measure.interval();
 | 
			
		||||
        if(m_interval_current >= m_interval_1b5)
 | 
			
		||||
        {
 | 
			
		||||
            //
 | 
			
		||||
            // count must be more then 4
 | 
			
		||||
            if(m_aux_rx_count > 4)
 | 
			
		||||
            {
 | 
			
		||||
                // stop receive, frame is ended
 | 
			
		||||
                // check message
 | 
			
		||||
                m_rx_count = m_aux_rx_count;
 | 
			
		||||
 | 
			
		||||
                m_crc_calculate = m_crc.calculate(m_rx_buffer, m_rx_count - 2);
 | 
			
		||||
 | 
			
		||||
                m_crc_rx_frame = (m_rx_buffer[m_rx_count - 1] << 8) | m_rx_buffer[m_rx_count - 2];
 | 
			
		||||
 | 
			
		||||
                m_crc_status =  m_crc_calculate == m_crc_rx_frame ? true : false;
 | 
			
		||||
 | 
			
		||||
                if(m_crc_status)
 | 
			
		||||
                {
 | 
			
		||||
                    m_destination = m_rx_external_buffer;
 | 
			
		||||
                    m_source_start = m_rx_buffer;
 | 
			
		||||
                    m_source_end = m_rx_buffer + m_rx_count - 1;
 | 
			
		||||
                    m_copy_length = m_rx_count;
 | 
			
		||||
                    *m_rx_messaage_length = m_rx_count;
 | 
			
		||||
                    m_event = MODBUSRTU::RXREADY;
 | 
			
		||||
                    //_frame_copy();
 | 
			
		||||
                    _frame_copy_erase();
 | 
			
		||||
                    _set_wait_response();
 | 
			
		||||
                    //
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    m_interval_measure.stop();
 | 
			
		||||
                    _set_receive_node_id();
 | 
			
		||||
                    //
 | 
			
		||||
                }//if else
 | 
			
		||||
                //
 | 
			
		||||
            }//
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                m_interval_measure.stop();
 | 
			
		||||
                _set_receive_node_id();
 | 
			
		||||
                //
 | 
			
		||||
            }// if else
 | 
			
		||||
            //
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//if else
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_frame_wait_response()
 | 
			
		||||
{
 | 
			
		||||
    if(m_sci_port.SciRegs.SCIRXST.bit.RXRDY)
 | 
			
		||||
    {
 | 
			
		||||
        m_aux_rx_buf = m_sci_port.SciRegs.SCIRXBUF.bit.RXDT;
 | 
			
		||||
 | 
			
		||||
        while(m_sci_port.SciRegs.SCIRXST.bit.RXRDY){}
 | 
			
		||||
 | 
			
		||||
        // error protocol, reset message
 | 
			
		||||
        m_interval_measure.stop();
 | 
			
		||||
        _set_receive_node_id();
 | 
			
		||||
        //
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        m_interval_current = m_interval_measure.interval();
 | 
			
		||||
        if(m_interval_current >= m_interval_3b5)
 | 
			
		||||
        {
 | 
			
		||||
            m_interval_measure.stop();
 | 
			
		||||
            _set_receive_node_id();
 | 
			
		||||
            //
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            if(*m_tx_message_length != 0)
 | 
			
		||||
            {
 | 
			
		||||
                // copy external tx buffer
 | 
			
		||||
                m_tx_length = *m_tx_message_length;
 | 
			
		||||
                m_source_start = m_tx_external_buffer;
 | 
			
		||||
                m_source_end = m_tx_external_buffer + m_tx_length - 1;
 | 
			
		||||
                m_destination = m_tx_buffer;
 | 
			
		||||
                //_frame_copy_erase();
 | 
			
		||||
                _frame_copy();
 | 
			
		||||
                *m_tx_message_length = 0;
 | 
			
		||||
                m_tx_count = 0;
 | 
			
		||||
                _set_transmit_data();
 | 
			
		||||
                _frame_transmit_data();
 | 
			
		||||
                m_interval_measure.stop();
 | 
			
		||||
                //
 | 
			
		||||
            }//if
 | 
			
		||||
            //
 | 
			
		||||
        }//if else
 | 
			
		||||
        //
 | 
			
		||||
    }//if else
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_frame_transmit_data()
 | 
			
		||||
{
 | 
			
		||||
    if(m_sci_port.SciRegs.SCICTL2.bit.TXRDY & m_sci_port.SciRegs.SCICTL2.bit.TXEMPTY)
 | 
			
		||||
    {
 | 
			
		||||
        // data was transmitted
 | 
			
		||||
        if(m_tx_count >= m_tx_length)
 | 
			
		||||
        {
 | 
			
		||||
            // all message was transmitted
 | 
			
		||||
            // break transmit mode, go to the receive mode
 | 
			
		||||
            _set_receive_node_id();
 | 
			
		||||
            //
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            m_sci_port.SciRegs.SCITXBUF = m_tx_buffer[m_tx_count];
 | 
			
		||||
 | 
			
		||||
            while(m_sci_port.SciRegs.SCICTL2.bit.TXEMPTY == 1){}
 | 
			
		||||
 | 
			
		||||
            m_tx_count++;
 | 
			
		||||
            //
 | 
			
		||||
        }//if else
 | 
			
		||||
        //
 | 
			
		||||
    }// if
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_frame_break_condition()
 | 
			
		||||
{
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
inline void ModbusRTUTransceiver::_frame_copy()
 | 
			
		||||
{
 | 
			
		||||
    while(m_source_start <= m_source_end)
 | 
			
		||||
    {
 | 
			
		||||
        *m_destination++ = *m_source_start++;
 | 
			
		||||
        //
 | 
			
		||||
    }//while
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
inline void ModbusRTUTransceiver::_frame_copy_erase()
 | 
			
		||||
{
 | 
			
		||||
    while(m_source_start <= m_source_end)
 | 
			
		||||
    {
 | 
			
		||||
        *m_destination++ = *m_source_start;
 | 
			
		||||
        *m_source_start++ = 0;
 | 
			
		||||
        //
 | 
			
		||||
    }//while
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
// #pragma CODE_SECTION("ramfuncs");
 | 
			
		||||
void ModbusRTUTransceiver::_frame_copy(uint16_t *source, uint16_t length, uint16_t *destination)
 | 
			
		||||
{
 | 
			
		||||
    m_destination = destination;
 | 
			
		||||
    m_source_start = source;
 | 
			
		||||
    m_source_end = destination + length - 1;
 | 
			
		||||
    m_copy_length = length;
 | 
			
		||||
 | 
			
		||||
    while(m_source_start <= m_source_end)
 | 
			
		||||
    {
 | 
			
		||||
        *m_destination++ = *m_source_start++;
 | 
			
		||||
        //
 | 
			
		||||
    }//while
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
} /* namespace MODBUSRTU */
 | 
			
		||||
@ -1,125 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ModbusRTUTransceiver.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <DSP28x_Project.h>
 | 
			
		||||
 | 
			
		||||
#include "DSP28335/GPIO.h"
 | 
			
		||||
#include "DSP28335/CPUTimers.h"
 | 
			
		||||
#include "DSP28335/MeasureTimeInterval.h"
 | 
			
		||||
#include "DSP28335/SCIA.h"
 | 
			
		||||
#include "DSP28335/SCIB.h"
 | 
			
		||||
#include "DSP28335/SCIBase.h"
 | 
			
		||||
#include "DSP28335/SCIC.h"
 | 
			
		||||
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUTransceiverBase.h"
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUCRC.h"
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUDefines.h"
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUVariant.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_MODBUSRTUTRANSCEIVER_H_
 | 
			
		||||
#define MODBUSRTU_MODBUSRTUTRANSCEIVER_H_
 | 
			
		||||
 | 
			
		||||
namespace MODBUSRTU
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ModbusRTUTransceiver
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    DSP28335::SCIBase&          m_sci_port;
 | 
			
		||||
    DSP28335::SCIConfiguration  m_sci_config;
 | 
			
		||||
    uint16_t                    m_node_id;
 | 
			
		||||
private:
 | 
			
		||||
    MODBUSRTU::transceiver_state_machine_t  m_state_machine;
 | 
			
		||||
    MODBUSRTU::transceiver_event_t          m_event;
 | 
			
		||||
private:
 | 
			
		||||
    DSP28335::MeasureTimeInterval&    m_interval_measure;
 | 
			
		||||
    Uint32 m_interval_pause;
 | 
			
		||||
    Uint32 m_interval_b5;
 | 
			
		||||
    Uint32 m_interval_b75;
 | 
			
		||||
    Uint32 m_interval_1b;
 | 
			
		||||
    Uint32 m_interval_1b25;
 | 
			
		||||
    Uint32 m_interval_1b5;
 | 
			
		||||
    Uint32 m_interval_1b75;
 | 
			
		||||
    Uint32 m_interval_3b5;
 | 
			
		||||
    Uint32 m_interval_freeze;
 | 
			
		||||
    Uint32 m_interval_current;
 | 
			
		||||
private:
 | 
			
		||||
    uint16_t m_rx_buffer[256];
 | 
			
		||||
    uint16_t m_tx_buffer[256];
 | 
			
		||||
    uint16_t m_rx_count;
 | 
			
		||||
    uint16_t m_tx_count;
 | 
			
		||||
    uint16_t m_tx_length;
 | 
			
		||||
    //
 | 
			
		||||
private:
 | 
			
		||||
    uint16_t     m_aux_rx_buf;
 | 
			
		||||
    uint16_t     m_aux_rx_count;
 | 
			
		||||
    uint16_t     m_aux_tx_buf;
 | 
			
		||||
    uint16_t     m_aux_tx_count;
 | 
			
		||||
private:
 | 
			
		||||
    bool            m_crc_status;
 | 
			
		||||
    MODBUSRTU::ModbusRTUCRC& m_crc;
 | 
			
		||||
    uint16_t        m_crc_calculate;
 | 
			
		||||
    uint16_t        m_crc_rx_frame;
 | 
			
		||||
    uint16_t        m_crc_tx_frame;
 | 
			
		||||
private:
 | 
			
		||||
    uint16_t *m_rx_external_buffer;
 | 
			
		||||
    uint16_t *m_tx_external_buffer;
 | 
			
		||||
    uint16_t *m_rx_messaage_length;
 | 
			
		||||
    uint16_t *m_tx_message_length;
 | 
			
		||||
private:
 | 
			
		||||
    uint16_t *m_destination;
 | 
			
		||||
    uint16_t *m_source_start;
 | 
			
		||||
    uint16_t *m_source_end;
 | 
			
		||||
    uint16_t m_copy_length;
 | 
			
		||||
public:
 | 
			
		||||
    ModbusRTUTransceiver(DSP28335::SCIBase& sciport, DSP28335::MeasureTimeInterval& interval_measure, MODBUSRTU::ModbusRTUCRC& crc);
 | 
			
		||||
    void setup(ModbusRTUTransceiverSetup& setup);
 | 
			
		||||
    void configure(ModbusRTUTransceiverConfiguration& config);
 | 
			
		||||
    void port_reset();
 | 
			
		||||
    bool compare_state(MODBUSRTU::transceiver_state_machine_t  state_machine);
 | 
			
		||||
public:
 | 
			
		||||
    void execute();
 | 
			
		||||
public:
 | 
			
		||||
    void setRXBuffer(uint16_t *bufferStart, uint16_t *messageLen);
 | 
			
		||||
    void setTXBuffer(uint16_t *bufferStart, uint16_t *messageLen);
 | 
			
		||||
private:
 | 
			
		||||
    void _set_receive_node_id();
 | 
			
		||||
    void _set_receive_function();
 | 
			
		||||
    void _set_receive_data();
 | 
			
		||||
    void _set_wait_response();
 | 
			
		||||
    void _set_transmit_data();
 | 
			
		||||
    void _set_break_condition();
 | 
			
		||||
private:
 | 
			
		||||
    void (ModbusRTUTransceiver::*_execute)();
 | 
			
		||||
    void (ModbusRTUTransceiver::*_frame_transceiver)();
 | 
			
		||||
    void _execute_transceiver();
 | 
			
		||||
    void _execute_break();
 | 
			
		||||
    void _frame_receive_node_id();
 | 
			
		||||
    void _frame_receive_function();
 | 
			
		||||
    void _frame_receive_data();
 | 
			
		||||
    void _frame_wait_response();
 | 
			
		||||
    void _frame_transmit_data();
 | 
			
		||||
    void _frame_break_condition();
 | 
			
		||||
private:
 | 
			
		||||
    inline void _frame_copy();
 | 
			
		||||
    inline void _frame_copy_erase();
 | 
			
		||||
    void _frame_copy(uint16_t *source, uint16_t length, uint16_t *destination);
 | 
			
		||||
private:
 | 
			
		||||
    void (*_re_de_setup)();
 | 
			
		||||
    void (*_driver_enable)();
 | 
			
		||||
    void (*_receiver_enable)();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace MODBUSRTU */
 | 
			
		||||
 | 
			
		||||
#endif /* MODBUSRTU_MODBUSRTUTRANSCEIVER_H_ */
 | 
			
		||||
@ -1,23 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ModbusRTUTransceiverBase.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUTransceiverBase.h"
 | 
			
		||||
 | 
			
		||||
namespace MODBUSRTU
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
ModbusRTUTransceiverBase::ModbusRTUTransceiverBase(DSP28335::SCIBase& sciport, DSP28335::CPUTimers& cputimer, MODBUSRTU::ModbusRTUCRC& crc):
 | 
			
		||||
        m_sci_port(sciport),
 | 
			
		||||
        m_sci_config(),
 | 
			
		||||
        m_node_id(0),
 | 
			
		||||
        //
 | 
			
		||||
        m_state_machine(MODBUSRTU::SCAN),
 | 
			
		||||
        m_event(MODBUSRTU::ENTRY)
 | 
			
		||||
        //
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
} /* namespace MODBUSRTU */
 | 
			
		||||
@ -1,83 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ModbusRTUTransceiverBase.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#include "F28335/DSP28x_Project.h"
 | 
			
		||||
 | 
			
		||||
#include "DSP28335/GPIO.h"
 | 
			
		||||
#include "DSP28335/CPUTimers.h"
 | 
			
		||||
#include "DSP28335/SCIA.h"
 | 
			
		||||
#include "DSP28335/SCIB.h"
 | 
			
		||||
#include "DSP28335/SCIBase.h"
 | 
			
		||||
#include "DSP28335/SCIC.h"
 | 
			
		||||
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUCRC.h"
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUDefines.h"
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUVariant.h"
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUSRTU_MODBUSRTUTRANSCEIVERBASE_H_
 | 
			
		||||
#define MODBUSRTU_MODBUSRTUTRANSCEIVERBASE_H_
 | 
			
		||||
 | 
			
		||||
namespace MODBUSRTU
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct ModbusRTUTransceiverSetup
 | 
			
		||||
{
 | 
			
		||||
    pGPIO_FUNCTION gpio_re_de_setup;
 | 
			
		||||
    pGPIO_FUNCTION gpio_driver_enable;
 | 
			
		||||
    pGPIO_FUNCTION gpio_receiver_enable;
 | 
			
		||||
    ModbusRTUTransceiverSetup():
 | 
			
		||||
        gpio_re_de_setup(0),
 | 
			
		||||
        gpio_driver_enable(0),
 | 
			
		||||
        gpio_receiver_enable(0)
 | 
			
		||||
    {
 | 
			
		||||
        //gpio_re_de_setup = &DSP28335::GPIO::gpio_scib_re_de_setup;
 | 
			
		||||
        //gpio_driver_enable = &DSP28335::GPIO::gpio_scib_re_de_set;
 | 
			
		||||
        //gpio_receiver_enable = &DSP28335::GPIO::gpio_scib_re_de_clear;
 | 
			
		||||
    }
 | 
			
		||||
};//ModbusRTUTransceiverSetup
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct ModbusRTUTransceiverConfiguration
 | 
			
		||||
{
 | 
			
		||||
    uint16_t                        node_id;
 | 
			
		||||
    DSP28335::SCIConfiguration      config;
 | 
			
		||||
    ModbusRTUTransceiverConfiguration():
 | 
			
		||||
        node_id(1234),
 | 
			
		||||
        config()
 | 
			
		||||
    {
 | 
			
		||||
        //config.baudrate = SCIRS485_BAUDRATE_DEFAULT;
 | 
			
		||||
        //config.parity = SCIRS485_PARITY_DEFAULT;
 | 
			
		||||
        //config.stopbits = SCIRS485_STOPBITS_DEFAULT;
 | 
			
		||||
        //config.lenght = SCIRS485_LENGHT_DEFAULT;
 | 
			
		||||
    }
 | 
			
		||||
};//ModbusRTUTransceiverConfiguration
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class ModbusRTUTransceiverBase
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
    DSP28335::SCIBase&          m_sci_port;
 | 
			
		||||
    DSP28335::SCIConfiguration  m_sci_config;
 | 
			
		||||
    uint16_t                    m_node_id;
 | 
			
		||||
protected:
 | 
			
		||||
    MODBUSRTU::transceiver_state_machine_t  m_state_machine;
 | 
			
		||||
    MODBUSRTU::transceiver_event_t          m_event;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    ModbusRTUTransceiverBase(DSP28335::SCIBase& sciport, DSP28335::CPUTimers& cputimer, MODBUSRTU::ModbusRTUCRC& crc);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace MODBUSRTU */
 | 
			
		||||
 | 
			
		||||
#endif /* MODBUSRTU_MODBUSRTUTRANSCEIVERBASE_H_ */
 | 
			
		||||
@ -1,110 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * ModbusRTUVariant.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUVariant.h"
 | 
			
		||||
 | 
			
		||||
namespace MODBUSRTU
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
ModbusRTUVariant::ModbusRTUVariant():
 | 
			
		||||
        t(MODBUSRTU::VARIANT_UINT32),
 | 
			
		||||
        u32((uint32_t)0)
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
MODBUSRTU::modbus_variant_type_t ModbusRTUVariant::get_type() const
 | 
			
		||||
{
 | 
			
		||||
    return t;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
void ModbusRTUVariant::set_float(float value)
 | 
			
		||||
{
 | 
			
		||||
    f = value;
 | 
			
		||||
    t = MODBUSRTU::VARIANT_FLOAT;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
void ModbusRTUVariant::set_int16(int16_t value)
 | 
			
		||||
{
 | 
			
		||||
    i16 = value;
 | 
			
		||||
    t = MODBUSRTU::VARIANT_INT16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void ModbusRTUVariant::set_int32(int32_t value)
 | 
			
		||||
{
 | 
			
		||||
    i32 = value;
 | 
			
		||||
    t = MODBUSRTU::VARIANT_INT32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void ModbusRTUVariant::set_uint16(uint16_t value)
 | 
			
		||||
{
 | 
			
		||||
    u16 = value;
 | 
			
		||||
    t = MODBUSRTU::VARIANT_UINT16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void ModbusRTUVariant::set_uint32(uint32_t value)
 | 
			
		||||
{
 | 
			
		||||
    u32 = value;
 | 
			
		||||
    t = MODBUSRTU::VARIANT_UINT32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void ModbusRTUVariant::set_bool(bool value)
 | 
			
		||||
{
 | 
			
		||||
    b = value;
 | 
			
		||||
    t = MODBUSRTU::VARIANT_BOOL;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
float ModbusRTUVariant::get_float() const
 | 
			
		||||
{
 | 
			
		||||
    return f;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
int16_t ModbusRTUVariant::get_int16() const
 | 
			
		||||
{
 | 
			
		||||
    return i16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
int32_t  ModbusRTUVariant::get_int32() const
 | 
			
		||||
{
 | 
			
		||||
    return i32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
uint16_t ModbusRTUVariant::get_uint16() const
 | 
			
		||||
{
 | 
			
		||||
    return u16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
uint32_t ModbusRTUVariant::get_uint32() const
 | 
			
		||||
{
 | 
			
		||||
    return u32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool ModbusRTUVariant::get_bool() const
 | 
			
		||||
{
 | 
			
		||||
    return b;
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
} /* namespace MODBUSRTU */
 | 
			
		||||
@ -1,58 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * 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_ */
 | 
			
		||||
@ -1,26 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * HeaderWeinbus.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef MODBUS_HEADERWEINBUS_H_
 | 
			
		||||
#define MODBUS_HEADERWEINBUS_H_
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBuffer.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferCoil.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferInputCoil.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferInputRegister.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferOutputCoil.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferOutputRegister.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferRegister.h"
 | 
			
		||||
#include "WEINBUS/WeinbusDefines.h"
 | 
			
		||||
#include "WEINBUS/WeinbusSlave.h"
 | 
			
		||||
#include "WEINBUS/WeinbusTableCoil.h"
 | 
			
		||||
#include "WEINBUS/WeinbusTableRegister.h"
 | 
			
		||||
#include "WEINBUS/WeinbusTableUnit.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#endif /* MODBUS_HEADERWEINBUS_H_ */
 | 
			
		||||
@ -1,41 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBuffer.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBuffer.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusBuffer::WeinbusBuffer():
 | 
			
		||||
        m_type(WEINBUS::OUTPUTCOILS),
 | 
			
		||||
        m_length  (0),
 | 
			
		||||
        m_start_addr(0),
 | 
			
		||||
        m_end_addr(0),
 | 
			
		||||
        m_addr(0),
 | 
			
		||||
        m_counter(0),
 | 
			
		||||
        m_quantity(0),
 | 
			
		||||
        m_size(0)
 | 
			
		||||
        //
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
void WeinbusBuffer::set(WEINBUS::buffer_type_t type, uint16_t startAddr)
 | 
			
		||||
{
 | 
			
		||||
    m_type = type;
 | 
			
		||||
    m_start_addr = startAddr;
 | 
			
		||||
    m_end_addr = startAddr;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
bool WeinbusBuffer::address_range(uint16_t address)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    return ((address >= m_start_addr)&&(address <= m_end_addr) ? true : false);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,39 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBuffer.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusDefines.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSBUFFER_H_
 | 
			
		||||
#define WEINBUS_WEINBUSBUFFER_H_
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusBuffer
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
    WEINBUS::buffer_type_t m_type;
 | 
			
		||||
    uint16_t m_length;
 | 
			
		||||
    uint16_t m_start_addr;
 | 
			
		||||
    uint16_t m_end_addr;
 | 
			
		||||
    uint16_t m_addr;
 | 
			
		||||
protected:
 | 
			
		||||
    uint16_t m_counter;
 | 
			
		||||
    uint16_t m_quantity;
 | 
			
		||||
    uint16_t m_size;
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusBuffer();
 | 
			
		||||
    void set(WEINBUS::buffer_type_t type, uint16_t startAddr);
 | 
			
		||||
    bool address_range(uint16_t address);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSBUFFER_H_ */
 | 
			
		||||
@ -1,17 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferCoil.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBufferCoil.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusBufferCoil::WeinbusBufferCoil():
 | 
			
		||||
        WeinbusBuffer()
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,27 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferCoil.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBuffer.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSBUFFERCOIL_H_
 | 
			
		||||
#define WEINBUS_WEINBUSBUFFERCOIL_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusBufferCoil: public WEINBUS::WeinbusBuffer
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusBufferCoil();
 | 
			
		||||
public:
 | 
			
		||||
    virtual void add(uint16_t offset, WEINBUS::weinbus_coil_t coil, uint16_t* param) = 0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSBUFFERCOIL_H_ */
 | 
			
		||||
@ -1,29 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferInputCoil.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <WEINBUS/WeinbusBufferInputCoil.h>
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusBufferInputCoil::WeinbusBufferInputCoil():
 | 
			
		||||
        WeinbusBufferCoil(),
 | 
			
		||||
        m_coils()
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputCoil::add(uint16_t offset, WEINBUS::weinbus_coil_t coil, uint16_t* param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
        {
 | 
			
		||||
            m_coils[m_counter].add(m_start_addr + offset, coil, param);
 | 
			
		||||
            m_counter++;
 | 
			
		||||
            m_quantity = m_counter;
 | 
			
		||||
        }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,30 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferInputCoil.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBufferCoil.h"
 | 
			
		||||
#include "WEINBUS/WeinbusTableCoil.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSBUFFERINPUTCOIL_H_
 | 
			
		||||
#define WEINBUS_WEINBUSBUFFERINPUTCOIL_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusBufferInputCoil: public WEINBUS::WeinbusBufferCoil
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    WEINBUS::WeinbusTableCoil m_coils[16];
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusBufferInputCoil();
 | 
			
		||||
public:
 | 
			
		||||
    void add(uint16_t offset, WEINBUS::weinbus_coil_t coil, uint16_t* param);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSBUFFERINPUTCOIL_H_ */
 | 
			
		||||
@ -1,246 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferInputRegister.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBufferInputRegister.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusBufferInputRegister::WeinbusBufferInputRegister():
 | 
			
		||||
        WeinbusBufferRegister(),
 | 
			
		||||
        m_registers(),
 | 
			
		||||
        m_aux_register(),
 | 
			
		||||
        m_iterator(0)
 | 
			
		||||
        //
 | 
			
		||||
{
 | 
			
		||||
    m_size = WEINBUS_INPUT_REGISTERS_SIZE;
 | 
			
		||||
}//CONSTRUCTRO
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::add(uint16_t offset, uint16_t   *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (uint16_t*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::add(uint16_t offset, int16_t    *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (int16_t*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::add(uint16_t offset, uint32_t   *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (uint32_t*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::add(uint16_t offset, int32_t    *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (int32_t*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::add(uint16_t offset, float      *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (float*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
WEINBUS::WeinbusTableRegister WeinbusBufferInputRegister::get_register_address(uint16_t address)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    return m_aux_register;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
WEINBUS::WeinbusTableRegister WeinbusBufferInputRegister::get_register_cursor(uint16_t cursor)
 | 
			
		||||
{
 | 
			
		||||
    return m_registers[cursor];
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write(uint16_t address, uint16_t data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.write((uint16_t)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write(uint16_t address, int16_t  data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.write((int16_t)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write(uint16_t address, uint32_t data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.write((uint32_t)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write(uint16_t address, int32_t  data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.write((int32_t)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write(uint16_t address, float    data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.write((float)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint16_t WeinbusBufferInputRegister::get_cursor(uint16_t address)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    return m_iterator;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write_cursor(uint16_t cursor, uint16_t data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].write((uint16_t)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write_cursor(uint16_t cursor, int16_t  data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].write((int16_t)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write_cursor(uint16_t cursor, uint32_t data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].write((uint32_t)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write_cursor(uint16_t cursor, int32_t  data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].write((int32_t)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferInputRegister::write_cursor(uint16_t cursor, float    data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].write((float)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,52 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferInputRegisters.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBufferRegister.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSBUFFERINPUTREGISTER_H_
 | 
			
		||||
#define WEINBUS_WEINBUSBUFFERINPUTREGISTER_H_
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusBufferInputRegister:public WEINBUS::WeinbusBufferRegister
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    WEINBUS::WeinbusTableRegister m_registers[WEINBUS_INPUT_REGISTERS_SIZE];
 | 
			
		||||
private:
 | 
			
		||||
    WEINBUS::WeinbusTableRegister m_aux_register;
 | 
			
		||||
    uint16_t m_iterator;
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusBufferInputRegister();
 | 
			
		||||
public:
 | 
			
		||||
    void add(uint16_t offset, uint16_t   *param);
 | 
			
		||||
    void add(uint16_t offset, int16_t    *param);
 | 
			
		||||
    void add(uint16_t offset, uint32_t   *param);
 | 
			
		||||
    void add(uint16_t offset, int32_t    *param);
 | 
			
		||||
    void add(uint16_t offset, float      *param);
 | 
			
		||||
public:
 | 
			
		||||
    WEINBUS::WeinbusTableRegister get_register_address(uint16_t address);
 | 
			
		||||
    WEINBUS::WeinbusTableRegister get_register_cursor(uint16_t cursor);
 | 
			
		||||
public:
 | 
			
		||||
    void write(uint16_t address, uint16_t data);
 | 
			
		||||
    void write(uint16_t address, int16_t  data);
 | 
			
		||||
    void write(uint16_t address, uint32_t data);
 | 
			
		||||
    void write(uint16_t address, int32_t  data);
 | 
			
		||||
    void write(uint16_t address, float    data);
 | 
			
		||||
public:
 | 
			
		||||
    uint16_t get_cursor(uint16_t address);
 | 
			
		||||
public:
 | 
			
		||||
    void write_cursor(uint16_t cursor, uint16_t data);
 | 
			
		||||
    void write_cursor(uint16_t cursor, int16_t  data);
 | 
			
		||||
    void write_cursor(uint16_t cursor, uint32_t data);
 | 
			
		||||
    void write_cursor(uint16_t cursor, int32_t  data);
 | 
			
		||||
    void write_cursor(uint16_t cursor, float    data);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSBUFFERINPUTREGISTER_H_ */
 | 
			
		||||
@ -1,30 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferOutputCoil.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBufferOutputCoil.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusBufferOutputCoil::WeinbusBufferOutputCoil():
 | 
			
		||||
        WeinbusBufferCoil(),
 | 
			
		||||
        m_coils()
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void WeinbusBufferOutputCoil::add(uint16_t offset, WEINBUS::weinbus_coil_t coil, uint16_t* param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
        {
 | 
			
		||||
            m_coils[m_counter].add(m_start_addr + offset, coil, param);
 | 
			
		||||
            m_counter++;
 | 
			
		||||
            m_quantity = m_counter;
 | 
			
		||||
        }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,30 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferOutputCoil.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBufferCoil.h"
 | 
			
		||||
#include "WEINBUS/WeinbusTableCoil.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSBUFFEROUTPUTCOIL_H_
 | 
			
		||||
#define WEINBUS_WEINBUSBUFFEROUTPUTCOIL_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusBufferOutputCoil: public WeinbusBufferCoil
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    WEINBUS::WeinbusTableCoil m_coils[16];
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusBufferOutputCoil();
 | 
			
		||||
public:
 | 
			
		||||
    void add(uint16_t offset, WEINBUS::weinbus_coil_t coil, uint16_t* param);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSBUFFEROUTPUTCOIL_H_ */
 | 
			
		||||
@ -1,239 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferOutputRegister.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBufferOutputRegister.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusBufferOutputRegister::WeinbusBufferOutputRegister():
 | 
			
		||||
        WeinbusBufferRegister(),
 | 
			
		||||
        m_registers(),
 | 
			
		||||
        m_aux_register(),
 | 
			
		||||
        m_iterator(0)
 | 
			
		||||
        //
 | 
			
		||||
{
 | 
			
		||||
    m_size = WEINBUS_OUTPUT_REGISTERS_SIZE;
 | 
			
		||||
}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
void WeinbusBufferOutputRegister::add(uint16_t offset, uint16_t   *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (uint16_t*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::add(uint16_t offset, int16_t    *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (int16_t*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::add(uint16_t offset, uint32_t   *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (uint32_t*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::add(uint16_t offset, int32_t    *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (int32_t*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::add(uint16_t offset, float      *param)
 | 
			
		||||
{
 | 
			
		||||
    if(m_counter < m_size)
 | 
			
		||||
    {
 | 
			
		||||
        m_addr = m_start_addr + offset;
 | 
			
		||||
        m_end_addr = m_addr > m_end_addr ? m_addr : m_end_addr;
 | 
			
		||||
        m_registers[m_counter].add(m_addr, (float*)param);
 | 
			
		||||
        m_counter++;
 | 
			
		||||
        m_quantity = m_counter;
 | 
			
		||||
    }
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
WEINBUS::WeinbusTableRegister WeinbusBufferOutputRegister::get_register_address(uint16_t address)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    return m_aux_register;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
WEINBUS::WeinbusTableRegister WeinbusBufferOutputRegister::get_register_cursor(uint16_t cursor)
 | 
			
		||||
{
 | 
			
		||||
    return m_registers[cursor];
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read(uint16_t address, uint16_t &data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.read((uint16_t&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read(uint16_t address, int16_t  &data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.read((int16_t&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read(uint16_t address, uint32_t &data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.read((uint32_t&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read(uint16_t address, int32_t  &data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.read((int32_t&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read(uint16_t address, float    &data)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = m_registers[m_iterator];
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    m_aux_register.read((float&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
uint16_t WeinbusBufferOutputRegister::get_cursor(uint16_t address)
 | 
			
		||||
{
 | 
			
		||||
    for(m_iterator = 0; m_iterator < m_quantity; m_iterator++)
 | 
			
		||||
    {
 | 
			
		||||
        if(m_registers[m_iterator].get_address() == address)
 | 
			
		||||
        {
 | 
			
		||||
            break;
 | 
			
		||||
        }//if
 | 
			
		||||
        //
 | 
			
		||||
    }//for
 | 
			
		||||
    //
 | 
			
		||||
    return m_iterator;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read_cursor(uint16_t cursor, uint16_t &data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].read((uint16_t&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read_cursor(uint16_t cursor, int16_t &data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].read((int16_t&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read_cursor(uint16_t cursor, uint32_t &data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].read((uint32_t&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read_cursor(uint16_t cursor, int32_t &data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].read((int32_t&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusBufferOutputRegister::read_cursor(uint16_t cursor, float &data)
 | 
			
		||||
{
 | 
			
		||||
    m_registers[cursor].read((float&)data);
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,54 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferOutputRegister.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBufferRegister.h"
 | 
			
		||||
#include "WEINBUS/WeinbusTableRegister.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSBUFFEROUTPUTREGISTER_H_
 | 
			
		||||
#define WEINBUS_WEINBUSBUFFEROUTPUTREGISTER_H_
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class WeinbusBufferOutputRegister:public WEINBUS:: WeinbusBufferRegister
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    WEINBUS::WeinbusTableRegister m_registers[WEINBUS_OUTPUT_REGISTERS_SIZE];
 | 
			
		||||
private:
 | 
			
		||||
    WEINBUS::WeinbusTableRegister m_aux_register;
 | 
			
		||||
    uint16_t m_iterator;
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusBufferOutputRegister();
 | 
			
		||||
public:
 | 
			
		||||
    void add(uint16_t offset, uint16_t   *param);
 | 
			
		||||
    void add(uint16_t offset, int16_t    *param);
 | 
			
		||||
    void add(uint16_t offset, uint32_t   *param);
 | 
			
		||||
    void add(uint16_t offset, int32_t    *param);
 | 
			
		||||
    void add(uint16_t offset, float      *param);
 | 
			
		||||
public:
 | 
			
		||||
    WEINBUS::WeinbusTableRegister get_register_address(uint16_t address);
 | 
			
		||||
    WEINBUS::WeinbusTableRegister get_register_cursor(uint16_t cursor);
 | 
			
		||||
public:
 | 
			
		||||
    void read(uint16_t address, uint16_t &data);
 | 
			
		||||
    void read(uint16_t address, int16_t  &data);
 | 
			
		||||
    void read(uint16_t address, uint32_t &data);
 | 
			
		||||
    void read(uint16_t address, int32_t  &data);
 | 
			
		||||
    void read(uint16_t address, float    &data);
 | 
			
		||||
public:
 | 
			
		||||
    uint16_t get_cursor(uint16_t address);
 | 
			
		||||
    void read_cursor(uint16_t cursor, uint16_t &data);
 | 
			
		||||
    void read_cursor(uint16_t cursor, int16_t  &data);
 | 
			
		||||
    void read_cursor(uint16_t cursor, uint32_t &data);
 | 
			
		||||
    void read_cursor(uint16_t cursor, int32_t  &data);
 | 
			
		||||
    void read_cursor(uint16_t cursor, float    &data);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSBUFFEROUTPUTREGISTER_H_ */
 | 
			
		||||
@ -1,18 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferRegister.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBufferRegister.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusBufferRegister::WeinbusBufferRegister():
 | 
			
		||||
        WeinbusBuffer()
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,30 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusBufferRegister.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusBuffer.h"
 | 
			
		||||
#include "WEINBUS/WeinbusTableRegister.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSBUFFERREGISTER_H_
 | 
			
		||||
#define WEINBUS_WEINBUSBUFFERREGISTER_H_
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusBufferRegister: public WEINBUS::WeinbusBuffer
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusBufferRegister();
 | 
			
		||||
    virtual void add(uint16_t offset, uint16_t   *param) = 0;
 | 
			
		||||
    virtual void add(uint16_t offset, int16_t    *param) = 0;
 | 
			
		||||
    virtual void add(uint16_t offset, uint32_t   *param) = 0;
 | 
			
		||||
    virtual void add(uint16_t offset, int32_t    *param) = 0;
 | 
			
		||||
    virtual void add(uint16_t offset, float      *param) = 0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSBUFFERREGISTER_H_ */
 | 
			
		||||
@ -1,134 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusDefines.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSDEFINES_H_
 | 
			
		||||
#define WEINBUS_WEINBUSDEFINES_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
typedef unsigned char uint8_t;
 | 
			
		||||
typedef signed   char int8_t;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_INPUT_REGISTERS_SIZE
 | 
			
		||||
#define WEINBUS_INPUT_REGISTERS_SIZE    20
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_OUTPUT_REGISTERS_SIZE
 | 
			
		||||
#define WEINBUS_OUTPUT_REGISTERS_SIZE   20
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
enum data_variant_type_t {DATA_UINT16, DATA_INT16, DATA_UINT32, DATA_INT32, DATA_FLOAT};
 | 
			
		||||
 | 
			
		||||
enum buffer_type_t  {OUTPUTCOILS, INPUTCOILS, OUTPUTREGISTERS, INPUTREGISTERS};
 | 
			
		||||
 | 
			
		||||
enum weinbus_coil_t {    COIL00,
 | 
			
		||||
                        COIL01,
 | 
			
		||||
                        COIL02,
 | 
			
		||||
                        COIL03,
 | 
			
		||||
                        COIL04,
 | 
			
		||||
                        COIL05,
 | 
			
		||||
                        COIL06,
 | 
			
		||||
                        COIL07,
 | 
			
		||||
                        COIL08,
 | 
			
		||||
                        COIL09,
 | 
			
		||||
                        COIL10,
 | 
			
		||||
                        COIL11,
 | 
			
		||||
                        COIL12,
 | 
			
		||||
                        COIL13,
 | 
			
		||||
                        COIL14,
 | 
			
		||||
                        COIL15};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct REGISTER_16_BIT_FIELD
 | 
			
		||||
{
 | 
			
		||||
    uint16_t b00: 1;
 | 
			
		||||
    uint16_t b01: 1;
 | 
			
		||||
    uint16_t b02: 1;
 | 
			
		||||
    uint16_t b03: 1;
 | 
			
		||||
    uint16_t b04: 1;
 | 
			
		||||
    uint16_t b05: 1;
 | 
			
		||||
    uint16_t b06: 1;
 | 
			
		||||
    uint16_t b07: 1;
 | 
			
		||||
    uint16_t b08: 1;
 | 
			
		||||
    uint16_t b09: 1;
 | 
			
		||||
    uint16_t b10: 1;
 | 
			
		||||
    uint16_t b11: 1;
 | 
			
		||||
    uint16_t b12: 1;
 | 
			
		||||
    uint16_t b13: 1;
 | 
			
		||||
    uint16_t b14: 1;
 | 
			
		||||
    uint16_t b15: 1;
 | 
			
		||||
};//REGISTER_16_BIT_FIELD
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct REGISTER_16_BYTE_FIELD
 | 
			
		||||
{
 | 
			
		||||
    uint16_t bt0 :8;
 | 
			
		||||
    uint16_t bt1 :8;
 | 
			
		||||
};//REGISTER_16_BYTE_FIELD
 | 
			
		||||
 | 
			
		||||
union REGISTER_16
 | 
			
		||||
{
 | 
			
		||||
    uint16_t            all;
 | 
			
		||||
    REGISTER_16_BIT_FIELD  bit;
 | 
			
		||||
    REGISTER_16_BYTE_FIELD byte;
 | 
			
		||||
    REGISTER_16():
 | 
			
		||||
        all(0)
 | 
			
		||||
    {}
 | 
			
		||||
    REGISTER_16(uint16_t val):
 | 
			
		||||
        all(val)
 | 
			
		||||
    {}
 | 
			
		||||
};//REGISTER_16
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct REGISTER_32_BYTE_FIELD
 | 
			
		||||
{
 | 
			
		||||
    uint16_t bt0 :8;
 | 
			
		||||
    uint16_t bt1 :8;
 | 
			
		||||
    uint16_t bt2 :8;
 | 
			
		||||
    uint16_t bt3 :8;
 | 
			
		||||
};//REGISTER_32_BYTE_FIELD
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
union REGISTER_32
 | 
			
		||||
{
 | 
			
		||||
    uint32_t    all;
 | 
			
		||||
    bool        b;
 | 
			
		||||
    uint8_t     u8;
 | 
			
		||||
    int8_t      i8;
 | 
			
		||||
    uint16_t    u16;
 | 
			
		||||
    int16_t     i16;
 | 
			
		||||
    uint32_t    u32;
 | 
			
		||||
    int32_t     i32;
 | 
			
		||||
    float       f;
 | 
			
		||||
    REGISTER_32_BYTE_FIELD byte;
 | 
			
		||||
    REGISTER_32():
 | 
			
		||||
        all((uint32_t)0)
 | 
			
		||||
    {};
 | 
			
		||||
    REGISTER_32(uint32_t val):
 | 
			
		||||
        all(val)
 | 
			
		||||
    {}
 | 
			
		||||
};//REGISTER_32
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}//namespace WEINBUS
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSDEFINES_H_ */
 | 
			
		||||
@ -1,90 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinRegisterVariant.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusRegisterVariant.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusRegisterVariant::WeinbusRegisterVariant():
 | 
			
		||||
        t(WEINBUS::DATA_UINT32),
 | 
			
		||||
        u32((uint32_t)0)
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
WEINBUS::data_variant_type_t WeinbusRegisterVariant::get_type() const
 | 
			
		||||
{
 | 
			
		||||
    return t;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusRegisterVariant::set_uint16(uint16_t value)
 | 
			
		||||
{
 | 
			
		||||
    u16 = value;
 | 
			
		||||
    t = WEINBUS::DATA_UINT16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusRegisterVariant::set_int16(int16_t value)
 | 
			
		||||
{
 | 
			
		||||
    i16 = value;
 | 
			
		||||
    t = WEINBUS::DATA_INT16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusRegisterVariant::set_uint32(uint32_t value)
 | 
			
		||||
{
 | 
			
		||||
    u32 = value;
 | 
			
		||||
    t = WEINBUS::DATA_UINT32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusRegisterVariant::set_int32(int32_t value)
 | 
			
		||||
{
 | 
			
		||||
    i32 = value;
 | 
			
		||||
    t = WEINBUS::DATA_INT32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusRegisterVariant::set_float(float value)
 | 
			
		||||
{
 | 
			
		||||
    f = value;
 | 
			
		||||
    t = WEINBUS::DATA_FLOAT;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
uint16_t WeinbusRegisterVariant::get_uint16() const
 | 
			
		||||
{
 | 
			
		||||
    return u16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
int16_t WeinbusRegisterVariant::get_int16() const
 | 
			
		||||
{
 | 
			
		||||
    return i16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
uint32_t WeinbusRegisterVariant::get_uint32() const
 | 
			
		||||
{
 | 
			
		||||
    return u32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
int32_t  WeinbusRegisterVariant::get_int32() const
 | 
			
		||||
{
 | 
			
		||||
    return i32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
float WeinbusRegisterVariant::get_float() const
 | 
			
		||||
{
 | 
			
		||||
    return f;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,52 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinRegisterVariant.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusDefines.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSREGISTERVARIANT_H_
 | 
			
		||||
#define WEINBUS_WEINBUSREGISTERVARIANT_H_
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusRegisterVariant
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    union
 | 
			
		||||
        {
 | 
			
		||||
        uint16_t    u16;
 | 
			
		||||
        int16_t     i16;
 | 
			
		||||
        uint32_t    u32;
 | 
			
		||||
        int32_t     i32;
 | 
			
		||||
        float       f;
 | 
			
		||||
        };
 | 
			
		||||
    data_variant_type_t t;
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusRegisterVariant();
 | 
			
		||||
    data_variant_type_t get_type() const;
 | 
			
		||||
    //setters
 | 
			
		||||
    void set_uint16 (uint16_t value);
 | 
			
		||||
    void set_int16  (int16_t  value);
 | 
			
		||||
    void set_uint32 (uint32_t value);
 | 
			
		||||
    void set_int32  (int32_t  value);
 | 
			
		||||
    void set_float  (float    value);
 | 
			
		||||
    //getters
 | 
			
		||||
    uint16_t get_uint16() const;
 | 
			
		||||
    int16_t  get_int16()  const;
 | 
			
		||||
    uint32_t get_uint32() const;
 | 
			
		||||
    int32_t  get_int32()  const;
 | 
			
		||||
    float    get_float()  const;
 | 
			
		||||
    //
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSREGISTERVARIANT_H_ */
 | 
			
		||||
@ -1,410 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusSlave.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusSlave.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusSlave::WeinbusSlave(MODBUSRTU::ModbusRTUCRC& crc):
 | 
			
		||||
        //outputCoils(),
 | 
			
		||||
        //inputCoils(),
 | 
			
		||||
        outputRegisters(),
 | 
			
		||||
        inputRegisters(),
 | 
			
		||||
        //
 | 
			
		||||
        rxStack(),
 | 
			
		||||
        txStack(),
 | 
			
		||||
        rxLength(0),
 | 
			
		||||
        txLength(0),
 | 
			
		||||
        //
 | 
			
		||||
        m_function(0),
 | 
			
		||||
        m_start_address(0),
 | 
			
		||||
        m_length(0),
 | 
			
		||||
        m_value(0),
 | 
			
		||||
        m_counter(0),
 | 
			
		||||
        m_counter_length(0),
 | 
			
		||||
        m_point(0),
 | 
			
		||||
        m_cursor(0),
 | 
			
		||||
        m_byte_length(0),
 | 
			
		||||
        m_byte_counter(0),
 | 
			
		||||
        m_aux_register(),
 | 
			
		||||
        //
 | 
			
		||||
        m_crc(crc)
 | 
			
		||||
        //
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void WeinbusSlave::execute()
 | 
			
		||||
{
 | 
			
		||||
    if(rxLength != 0)
 | 
			
		||||
    {
 | 
			
		||||
        m_function = rxStack[1];
 | 
			
		||||
 | 
			
		||||
        switch(m_function)
 | 
			
		||||
        {
 | 
			
		||||
        case MODBUSRTU_FUNCTION_BROADCAST:                  { _function_broadcast();                    break;}
 | 
			
		||||
        case MODBUSRTU_FUNCTION_READ_COIL_STATUS:           { _function_read_coil_status();             break;}
 | 
			
		||||
        case MODBUSRTU_FUNCTION_READ_INPUT_STATUS:          { _function_read_input_status();            break;}
 | 
			
		||||
        case MODBUSRTU_FUNCTION_READ_HOLDING_REGISTERS:     { _function_read_holding_registers();       break;}
 | 
			
		||||
        case MODBUSRTU_FUNCTION_READ_INPUT_REGISTERS:       { _function_read_input_registers();         break;}
 | 
			
		||||
        case MODBUSRTU_FUNCTION_FORCE_SINGLE_COIL:          { _function_force_single_coil();            break;}
 | 
			
		||||
        case MODBUSRTU_FUNCTION_PRESET_SINGLE_REGISTER:     { _function_preset_single_register();       break;}
 | 
			
		||||
        case MODBUSRTU_FUNCTION_FORCE_MULTIPLE_COILS:       { _function_force_multiple_coils();         break;}
 | 
			
		||||
        case MODBUSRTU_FUNCTION_PRESET_MULTIPLE_REGISTERS:  { _function_preset_multiple_registers();    break;}
 | 
			
		||||
        default:{ txLength = 0;}
 | 
			
		||||
 | 
			
		||||
        //
 | 
			
		||||
        }//switch
 | 
			
		||||
        //
 | 
			
		||||
    }//if
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusSlave::_function_broadcast()
 | 
			
		||||
{
 | 
			
		||||
    // Function 0x001 broadcast
 | 
			
		||||
    //
 | 
			
		||||
    txLength = 0;
 | 
			
		||||
    rxLength = 0;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusSlave::_function_read_coil_status()
 | 
			
		||||
{
 | 
			
		||||
    // Function 0x01 read coil, table is "outputCoils"
 | 
			
		||||
    //
 | 
			
		||||
    txLength = 0;
 | 
			
		||||
    rxLength = 0;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusSlave::_function_read_input_status()
 | 
			
		||||
{
 | 
			
		||||
    // Function 0x02 read input status
 | 
			
		||||
    //
 | 
			
		||||
    txLength = 0;
 | 
			
		||||
    rxLength = 0;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusSlave::_function_read_holding_registers()
 | 
			
		||||
{
 | 
			
		||||
    // Function 0x03 read register, table is "outputRegisters"
 | 
			
		||||
 | 
			
		||||
    // construct start address
 | 
			
		||||
    m_start_address.byte.bt1 = rxStack[2];
 | 
			
		||||
    m_start_address.byte.bt0 = rxStack[3];
 | 
			
		||||
 | 
			
		||||
    // construct 16-bit register quantity
 | 
			
		||||
    m_length.byte.bt1 = rxStack[4];
 | 
			
		||||
    m_length.byte.bt0 = rxStack[5];
 | 
			
		||||
    m_counter_length = m_length.all;
 | 
			
		||||
    m_counter = 0;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // check address range
 | 
			
		||||
//    if((outputRegisters.address_range(m_start_address.all))&
 | 
			
		||||
//            (outputRegisters.address_range(m_start_address.all + m_length.all - (uint16_t)1)))
 | 
			
		||||
    if(outputRegisters.address_range(m_start_address.all))
 | 
			
		||||
    {
 | 
			
		||||
        // CONSTRUCT ANSWER
 | 
			
		||||
        //1. Node ID
 | 
			
		||||
        txStack[0] = rxStack[0];
 | 
			
		||||
        //2. Function code
 | 
			
		||||
        txStack[1] = rxStack[1];
 | 
			
		||||
        //3. Byte number - should be counted
 | 
			
		||||
        txStack[2] = 0 ;
 | 
			
		||||
        m_byte_counter = 0;
 | 
			
		||||
        //4. Fill fields with values
 | 
			
		||||
        m_point = 3;
 | 
			
		||||
 | 
			
		||||
        m_cursor = outputRegisters.get_cursor(m_start_address.all);
 | 
			
		||||
 | 
			
		||||
        //for(m_counter = 0; m_counter < m_length.all; m_counter++)
 | 
			
		||||
        while(m_counter < m_counter_length)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = outputRegisters.get_register_cursor(m_cursor);
 | 
			
		||||
            switch(m_aux_register.get_type())
 | 
			
		||||
            {
 | 
			
		||||
            case DATA_UINT16:
 | 
			
		||||
            {
 | 
			
		||||
                m_aux_register.read((uint16_t&)m_value.u16);
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt1;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt0;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                m_counter++;
 | 
			
		||||
                m_cursor++;
 | 
			
		||||
                m_byte_counter += 2;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            case DATA_INT16:
 | 
			
		||||
            {
 | 
			
		||||
                m_aux_register.read((int16_t&)m_value.i16);
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt1;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt0;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                m_counter++;
 | 
			
		||||
                m_cursor++;
 | 
			
		||||
                m_byte_counter += 2;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            case DATA_UINT32:
 | 
			
		||||
            {
 | 
			
		||||
                m_aux_register.read((uint32_t&)m_value.u32);
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt1;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt0;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt3;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt2;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                m_counter += 2;
 | 
			
		||||
                m_cursor++;
 | 
			
		||||
                m_byte_counter += 4;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            case DATA_INT32:
 | 
			
		||||
            {
 | 
			
		||||
                m_aux_register.read((int32_t&)m_value.i32);
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt1;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt0;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt3;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt2;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                m_counter += 2;
 | 
			
		||||
                m_cursor++;
 | 
			
		||||
                m_byte_counter += 4;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            case DATA_FLOAT:
 | 
			
		||||
            {
 | 
			
		||||
                m_aux_register.read((float&)m_value.f);
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt1;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt0;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt3;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                txStack[m_point] = m_value.byte.bt2;
 | 
			
		||||
                m_point++;
 | 
			
		||||
                m_counter += 2;
 | 
			
		||||
                m_cursor++;
 | 
			
		||||
                m_byte_counter += 4;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            default:{}
 | 
			
		||||
            }
 | 
			
		||||
            //
 | 
			
		||||
        }//for
 | 
			
		||||
        //
 | 
			
		||||
        //5. Byte number
 | 
			
		||||
        txStack[2] = m_byte_counter;
 | 
			
		||||
        //6. CRC
 | 
			
		||||
        m_value.all = m_crc.calculate(txStack, m_point);
 | 
			
		||||
        txStack[m_point] = m_value.byte.bt0;
 | 
			
		||||
        m_point++;
 | 
			
		||||
        txStack[m_point] = m_value.byte.bt1;
 | 
			
		||||
        m_point++;
 | 
			
		||||
        //
 | 
			
		||||
        //6. Finish
 | 
			
		||||
        txLength = m_point;
 | 
			
		||||
        rxLength = 0;
 | 
			
		||||
        //
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        // address wrong
 | 
			
		||||
        txLength = 0;
 | 
			
		||||
        rxLength = 0;
 | 
			
		||||
        //
 | 
			
		||||
    }//if else
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusSlave::_function_read_input_registers()
 | 
			
		||||
{
 | 
			
		||||
    // Function 0x04 read input register
 | 
			
		||||
    //
 | 
			
		||||
    txLength = 0;
 | 
			
		||||
    rxLength = 0;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusSlave::_function_force_single_coil()
 | 
			
		||||
{
 | 
			
		||||
    // Function 0x05 write single coil, table is "inputCoils"
 | 
			
		||||
    //
 | 
			
		||||
    txLength = 0;
 | 
			
		||||
    rxLength = 0;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusSlave::_function_preset_single_register()
 | 
			
		||||
{
 | 
			
		||||
    // Function 0x06 write single register, table is "inputRegisters"
 | 
			
		||||
    //
 | 
			
		||||
    txLength = 0;
 | 
			
		||||
    rxLength = 0;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusSlave::_function_force_multiple_coils()
 | 
			
		||||
{
 | 
			
		||||
    // Function 0x0F write multiple coil, table is "inputCoils"`
 | 
			
		||||
    //
 | 
			
		||||
    txLength = 0;
 | 
			
		||||
    rxLength = 0;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void WeinbusSlave::_function_preset_multiple_registers()
 | 
			
		||||
{
 | 
			
		||||
    // Function 0x10 write multiple register, table is "inputRegisters"
 | 
			
		||||
 | 
			
		||||
    // construct start address
 | 
			
		||||
    m_start_address.byte.bt1 = rxStack[2];
 | 
			
		||||
    m_start_address.byte.bt0 = rxStack[3];
 | 
			
		||||
 | 
			
		||||
    // construct 16-bit register quantity
 | 
			
		||||
    m_length.byte.bt1 = rxStack[4];
 | 
			
		||||
    m_length.byte.bt0 = rxStack[5];
 | 
			
		||||
    m_counter_length = m_length.all;
 | 
			
		||||
    m_counter = 0;
 | 
			
		||||
 | 
			
		||||
    // construct byte length
 | 
			
		||||
    m_byte_length = rxStack[6];
 | 
			
		||||
    m_byte_counter = 0;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // check address range
 | 
			
		||||
//    if((outputRegisters.address_range(m_start_address.all))&
 | 
			
		||||
//            (outputRegisters.address_range(m_start_address.all + m_length.all - (uint16_t)1)))
 | 
			
		||||
    if(outputRegisters.address_range(m_start_address.all))
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        m_cursor = inputRegisters.get_cursor(m_start_address.all);
 | 
			
		||||
        m_point = 7;
 | 
			
		||||
        while(m_byte_counter < m_byte_length)
 | 
			
		||||
        {
 | 
			
		||||
            m_aux_register = inputRegisters.get_register_cursor(m_cursor);
 | 
			
		||||
            switch(m_aux_register.get_type())
 | 
			
		||||
            {
 | 
			
		||||
                case DATA_UINT16:
 | 
			
		||||
                {
 | 
			
		||||
                    m_value.byte.bt1 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt0 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_byte_counter += 2;
 | 
			
		||||
                    m_aux_register.write((uint16_t)m_value.u16);
 | 
			
		||||
                    m_cursor++;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                case DATA_INT16:
 | 
			
		||||
                {
 | 
			
		||||
                    m_value.byte.bt1 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt0 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_byte_counter += 2;
 | 
			
		||||
                    m_aux_register.write((int16_t)m_value.i16);
 | 
			
		||||
                    m_cursor++;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                case DATA_UINT32:
 | 
			
		||||
                {
 | 
			
		||||
                    m_value.byte.bt1 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt0 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt3 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt2 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_byte_counter += 4;
 | 
			
		||||
                    m_aux_register.write((uint32_t)m_value.u32);
 | 
			
		||||
                    m_cursor++;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                case DATA_INT32:
 | 
			
		||||
                {
 | 
			
		||||
                    m_value.byte.bt1 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt0 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt3 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt2 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_byte_counter += 4;
 | 
			
		||||
                    m_aux_register.write((int32_t)m_value.i32);
 | 
			
		||||
                    m_cursor++;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                case DATA_FLOAT:
 | 
			
		||||
                {
 | 
			
		||||
                    m_value.byte.bt1 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt0 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt3 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_value.byte.bt2 = rxStack[m_point];
 | 
			
		||||
                    m_point++;
 | 
			
		||||
                    m_byte_counter += 4;
 | 
			
		||||
                    m_aux_register.write((float)m_value.f);
 | 
			
		||||
                    m_cursor++;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
                default:{}
 | 
			
		||||
            }//switch
 | 
			
		||||
            //
 | 
			
		||||
        }//while
 | 
			
		||||
 | 
			
		||||
        // CONSTRUCT ANSWER
 | 
			
		||||
        //1. Node ID
 | 
			
		||||
        txStack[0] = rxStack[0];
 | 
			
		||||
        //2. Function code
 | 
			
		||||
        txStack[1] = rxStack[1];
 | 
			
		||||
        //3. Address h-byte
 | 
			
		||||
        txStack[2] = m_start_address.byte.bt1;
 | 
			
		||||
        //4. Address l-byte
 | 
			
		||||
        txStack[3] = m_start_address.byte.bt0;
 | 
			
		||||
        //5. Quantity h-byte
 | 
			
		||||
        txStack[4] = m_length.byte.bt1;
 | 
			
		||||
        //6. Quantity l-byte
 | 
			
		||||
        txStack[5] = m_length.byte.bt0;
 | 
			
		||||
        //7. CRC
 | 
			
		||||
        m_value.all = m_crc.calculate(txStack, 6);
 | 
			
		||||
        txStack[6] = m_value.byte.bt0;
 | 
			
		||||
        txStack[7] = m_value.byte.bt1;
 | 
			
		||||
        //
 | 
			
		||||
        //8. Finish
 | 
			
		||||
        txLength = 8;
 | 
			
		||||
        rxLength = 0;
 | 
			
		||||
        //
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        // address wrong
 | 
			
		||||
        txLength = 0;
 | 
			
		||||
        rxLength = 0;
 | 
			
		||||
        //
 | 
			
		||||
    }//if else
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,82 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusSlave.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusDefines.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBuffer.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferRegister.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferInputRegister.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferOutputRegister.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferCoil.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferInputCoil.h"
 | 
			
		||||
#include "WEINBUS/WeinbusBufferOutputCoil.h"
 | 
			
		||||
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUCRC.h"
 | 
			
		||||
#include "MODBUSRTU/ModbusRTUDefines.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSSLAVE_H_
 | 
			
		||||
#define WEINBUS_WEINBUSSLAVE_H_
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusSlave
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    // Function 0x01 read coil
 | 
			
		||||
    //WEINBUS::WeinbusBufferOutputCoil        outputCoils;
 | 
			
		||||
    // Function 0x05, 0x0F write single/multiple coil
 | 
			
		||||
    //WEINBUS::WeinbusBufferInputCoil         inputCoils;
 | 
			
		||||
    // Function 0x03 read register
 | 
			
		||||
    WEINBUS::WeinbusBufferOutputRegister    outputRegisters;
 | 
			
		||||
    // Function 0x06, 0x10 write single/multiple register
 | 
			
		||||
    WEINBUS::WeinbusBufferInputRegister     inputRegisters;
 | 
			
		||||
public:
 | 
			
		||||
    uint16_t    rxStack[256];
 | 
			
		||||
    uint16_t    txStack[256];
 | 
			
		||||
    uint16_t    rxLength;
 | 
			
		||||
    uint16_t    txLength;
 | 
			
		||||
    //
 | 
			
		||||
private:
 | 
			
		||||
    uint16_t        m_function;
 | 
			
		||||
    REGISTER_16     m_start_address;
 | 
			
		||||
    REGISTER_16     m_length;
 | 
			
		||||
    REGISTER_32     m_value;
 | 
			
		||||
    uint16_t        m_counter;
 | 
			
		||||
    uint16_t        m_counter_length;
 | 
			
		||||
    uint16_t        m_point;
 | 
			
		||||
    uint16_t        m_cursor;
 | 
			
		||||
    uint16_t        m_byte_length;
 | 
			
		||||
    uint16_t        m_byte_counter;
 | 
			
		||||
private:
 | 
			
		||||
    WEINBUS::WeinbusTableRegister m_aux_register;
 | 
			
		||||
private:
 | 
			
		||||
    MODBUSRTU::ModbusRTUCRC& m_crc;
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusSlave(MODBUSRTU::ModbusRTUCRC& crc);
 | 
			
		||||
public:
 | 
			
		||||
    void execute();
 | 
			
		||||
private:
 | 
			
		||||
    inline void _function_broadcast();
 | 
			
		||||
    inline void _function_read_coil_status();
 | 
			
		||||
    inline void _function_read_input_status();
 | 
			
		||||
    inline void _function_read_holding_registers();
 | 
			
		||||
    inline void _function_read_input_registers();
 | 
			
		||||
    inline void _function_force_single_coil();
 | 
			
		||||
    inline void _function_preset_single_register();
 | 
			
		||||
    inline void _function_force_multiple_coils();
 | 
			
		||||
    inline void _function_preset_multiple_registers();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSSLAVE_H_ */
 | 
			
		||||
@ -1,28 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusTableCoil.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusTableCoil.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusTableCoil::WeinbusTableCoil():
 | 
			
		||||
        WeinbusTableUnit(),
 | 
			
		||||
        m_coil(WEINBUS::COIL00)
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void WeinbusTableCoil::add(uint16_t address, WEINBUS::weinbus_coil_t coil, uint16_t* param)
 | 
			
		||||
{
 | 
			
		||||
    m_address = address;
 | 
			
		||||
    m_param = param;
 | 
			
		||||
    m_coil = coil;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,35 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusTableCoil.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusDefines.h"
 | 
			
		||||
#include "WEINBUS/WeinbusTableUnit.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSTABLECOIL_H_
 | 
			
		||||
#define WEINBUS_WEINBUSTABLECOIL_H_
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusTableCoil: public WEINBUS::WeinbusTableUnit
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    WEINBUS::weinbus_coil_t m_coil;
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusTableCoil();
 | 
			
		||||
public:
 | 
			
		||||
    void add(uint16_t address, WEINBUS::weinbus_coil_t coil, uint16_t* param);
 | 
			
		||||
public:
 | 
			
		||||
    void read(uint16_t data);
 | 
			
		||||
    void write(uint16_t data);
 | 
			
		||||
    void write(int16_t  data);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSTABLECOIL_H_ */
 | 
			
		||||
@ -1,125 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusTableRegister.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusTableRegister.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusTableRegister::WeinbusTableRegister():
 | 
			
		||||
        WeinbusTableUnit(),
 | 
			
		||||
        t(WEINBUS::DATA_UINT32)
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
WEINBUS::data_variant_type_t WeinbusTableRegister::get_type()
 | 
			
		||||
{
 | 
			
		||||
    return t;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::add(uint16_t address, uint16_t  *param)
 | 
			
		||||
{
 | 
			
		||||
    m_address = address;
 | 
			
		||||
    m_param = param;
 | 
			
		||||
    t = WEINBUS::DATA_UINT16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::add(uint16_t address, int16_t   *param)
 | 
			
		||||
{
 | 
			
		||||
    m_address = address;
 | 
			
		||||
    m_param = param;
 | 
			
		||||
    t = WEINBUS::DATA_INT16;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::add(uint16_t address, uint32_t  *param)
 | 
			
		||||
{
 | 
			
		||||
    m_address = address;
 | 
			
		||||
    m_param = param;
 | 
			
		||||
    t = WEINBUS::DATA_UINT32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::add(uint16_t address, int32_t   *param)
 | 
			
		||||
{
 | 
			
		||||
    m_address = address;
 | 
			
		||||
    m_param = param;
 | 
			
		||||
    t = WEINBUS::DATA_INT32;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::add(uint16_t address, float     *param)
 | 
			
		||||
{
 | 
			
		||||
    m_address = address;
 | 
			
		||||
    m_param = param;
 | 
			
		||||
    t = WEINBUS::DATA_FLOAT;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::read(uint16_t   &data)
 | 
			
		||||
{
 | 
			
		||||
    data = *(uint16_t*)m_param;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::read(int16_t    &data)
 | 
			
		||||
{
 | 
			
		||||
    data = *(int16_t*)m_param;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::read(uint32_t   &data)
 | 
			
		||||
{
 | 
			
		||||
    data = *(uint32_t*)m_param;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::read(int32_t    &data)
 | 
			
		||||
{
 | 
			
		||||
    data = *(int32_t*)m_param;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::read(float      &data)
 | 
			
		||||
{
 | 
			
		||||
    data = *(float*)m_param;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::write(uint16_t  data)
 | 
			
		||||
{
 | 
			
		||||
    *(uint16_t*)m_param = (uint16_t)data;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::write(int16_t   data)
 | 
			
		||||
{
 | 
			
		||||
    *(int16_t*)m_param = (int16_t)data;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::write(uint32_t  data)
 | 
			
		||||
{
 | 
			
		||||
    *(uint32_t*)m_param = (uint32_t)data;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
//
 | 
			
		||||
void  WeinbusTableRegister::write(int32_t  data)
 | 
			
		||||
{
 | 
			
		||||
    *(int32_t*)m_param = (int32_t)data;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
void  WeinbusTableRegister::write(float  data)
 | 
			
		||||
{
 | 
			
		||||
    *(float*)m_param = (float)data;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,49 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusTableRegister.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusDefines.h"
 | 
			
		||||
#include "WEINBUS/WeinbusTableUnit.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSTABLEREGISTER_H_
 | 
			
		||||
#define WEINBUS_WEINBUSTABLEREGISTER_H_
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusTableRegister: public WEINBUS::WeinbusTableUnit
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
    WEINBUS::data_variant_type_t t;
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusTableRegister();
 | 
			
		||||
public:
 | 
			
		||||
    WEINBUS::data_variant_type_t get_type();
 | 
			
		||||
public:
 | 
			
		||||
    void add(uint16_t address, uint16_t  *param);
 | 
			
		||||
    void add(uint16_t address, int16_t   *param);
 | 
			
		||||
    void add(uint16_t address, uint32_t  *param);
 | 
			
		||||
    void add(uint16_t address, int32_t   *param);
 | 
			
		||||
    void add(uint16_t address, float     *param);
 | 
			
		||||
public:
 | 
			
		||||
    void read(uint16_t   &data);
 | 
			
		||||
    void read(int16_t    &data);
 | 
			
		||||
    void read(uint32_t   &data);
 | 
			
		||||
    void read(int32_t    &data);
 | 
			
		||||
    void read(float      &data);
 | 
			
		||||
public:
 | 
			
		||||
    void write(uint16_t  data);
 | 
			
		||||
    void write(int16_t   data);
 | 
			
		||||
    void write(uint32_t  data);
 | 
			
		||||
    void write(int32_t   data);
 | 
			
		||||
    void write(float     data);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSTABLEREGISTER_H_ */
 | 
			
		||||
@ -1,25 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusTableUnit.cpp
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusTableUnit.h"
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
//CONSTRUCTOR
 | 
			
		||||
WeinbusTableUnit::WeinbusTableUnit():
 | 
			
		||||
        m_address(0),
 | 
			
		||||
        m_param(0)
 | 
			
		||||
{}//CONSTRUCTOR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint16_t WeinbusTableUnit::get_address()
 | 
			
		||||
{
 | 
			
		||||
    return m_address;
 | 
			
		||||
    //
 | 
			
		||||
}//
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
@ -1,32 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * WeinbusTableUnit.h
 | 
			
		||||
 *
 | 
			
		||||
 *      Author: Aleksey Gerasimenko
 | 
			
		||||
 *      gerasimenko.aleksey.n@gmail.com
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <math.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
 | 
			
		||||
#include "WEINBUS/WeinbusDefines.h"
 | 
			
		||||
 | 
			
		||||
#ifndef WEINBUS_WEINBUSTABLEUNIT_H_
 | 
			
		||||
#define WEINBUS_WEINBUSTABLEUNIT_H_
 | 
			
		||||
 | 
			
		||||
namespace WEINBUS
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
class WeinbusTableUnit
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
    uint16_t    m_address;
 | 
			
		||||
    void*       m_param;
 | 
			
		||||
public:
 | 
			
		||||
    WeinbusTableUnit();
 | 
			
		||||
public:
 | 
			
		||||
    uint16_t    get_address();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} /* namespace WEINBUS */
 | 
			
		||||
 | 
			
		||||
#endif /* WEINBUS_WEINBUSTABLEUNIT_H_ */
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue