mirror of
				https://github.com/thelsing/knx.git
				synced 2025-10-26 10:26:25 +01:00 
			
		
		
		
	Add float type for parameters & a few fixes (#95)
* Fix not-relative include throws if a include directory is not set. * add forgotten defined() in environment checking '#elif's * fix mis-spelled "config.j" * Add float type support to Parameters All 3 encodings supported. * Using dptconvert functions to handle parameters handling
This commit is contained in:
		
							parent
							
								
									c167305a87
								
							
						
					
					
						commit
						083d83f777
					
				@ -1,5 +1,5 @@
 | 
				
			|||||||
#include "arduino_platform.h"
 | 
					#include "arduino_platform.h"
 | 
				
			||||||
#include <knx/bits.h>
 | 
					#include "knx/bits.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <Arduino.h>
 | 
					#include <Arduino.h>
 | 
				
			||||||
#include <SPI.h>
 | 
					#include <SPI.h>
 | 
				
			||||||
 | 
				
			|||||||
@ -2,6 +2,7 @@
 | 
				
			|||||||
#include "bits.h"
 | 
					#include "bits.h"
 | 
				
			||||||
#include "data_property.h"
 | 
					#include "data_property.h"
 | 
				
			||||||
#include "callback_property.h"
 | 
					#include "callback_property.h"
 | 
				
			||||||
 | 
					#include "dptconvert.h"
 | 
				
			||||||
#include <cstring>
 | 
					#include <cstring>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ApplicationProgramObject::ApplicationProgramObject(Memory& memory)
 | 
					ApplicationProgramObject::ApplicationProgramObject(Memory& memory)
 | 
				
			||||||
@ -47,3 +48,23 @@ uint32_t ApplicationProgramObject::getInt(uint32_t addr)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    return ::getInt(TableObject::data() + addr);
 | 
					    return ::getInt(TableObject::data() + addr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					double ApplicationProgramObject::getFloat(uint32_t addr, ParameterFloatEncodings encoding)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    uint8_t buffer[8];
 | 
				
			||||||
 | 
					    switch (encoding)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        case Float_Enc_DPT9:
 | 
				
			||||||
 | 
					            return float16FromPayload(TableObject::data() + addr, 0);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        case Float_Enc_IEEE754Single:
 | 
				
			||||||
 | 
					            return float32FromPayload(TableObject::data() + addr, 0);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        case Float_Enc_IEEE754Double:
 | 
				
			||||||
 | 
					            return float64FromPayload(TableObject::data() + addr, 0);
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        default:
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,14 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "table_object.h"
 | 
					#include "table_object.h"
 | 
				
			||||||
 | 
					#include "bits.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					enum ParameterFloatEncodings
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    Float_Enc_DPT9 = 0,          // 2 Byte. See Chapter 3.7.2 section 3.10 (Datapoint Types 2-Octet Float Value)
 | 
				
			||||||
 | 
					    Float_Enc_IEEE754Single = 1, // 4 Byte. C++ float
 | 
				
			||||||
 | 
					    Float_Enc_IEEE754Double = 2, // 8 Byte. C++ double
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
class ApplicationProgramObject : public TableObject
 | 
					class ApplicationProgramObject : public TableObject
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  public:
 | 
					  public:
 | 
				
			||||||
@ -10,4 +17,5 @@ class ApplicationProgramObject : public TableObject
 | 
				
			|||||||
    uint8_t getByte(uint32_t addr);
 | 
					    uint8_t getByte(uint32_t addr);
 | 
				
			||||||
    uint16_t getWord(uint32_t addr);
 | 
					    uint16_t getWord(uint32_t addr);
 | 
				
			||||||
    uint32_t getInt(uint32_t addr);
 | 
					    uint32_t getInt(uint32_t addr);
 | 
				
			||||||
};
 | 
					    double getFloat(uint32_t addr, ParameterFloatEncodings encoding);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -62,6 +62,6 @@
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if !defined(MASK_VERSION)
 | 
					#if !defined(MASK_VERSION)
 | 
				
			||||||
#error MASK_VERSION must be defined! See config.j for possible values!
 | 
					#error MASK_VERSION must be defined! See config.h for possible values!
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1713,6 +1713,17 @@ int32_t signed32FromPayload(const uint8_t* payload, int index)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    return (int32_t)unsigned32FromPayload(payload, index);
 | 
					    return (int32_t)unsigned32FromPayload(payload, index);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					uint64_t unsigned64FromPayload(const uint8_t* payload, int index)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return ((((uint64_t)payload[index]) << 56) & 0xFF00000000000000) |
 | 
				
			||||||
 | 
							((((uint64_t)payload[index + 1]) << 48) & 0x00FF000000000000) |
 | 
				
			||||||
 | 
							((((uint64_t)payload[index + 2]) << 40) & 0x0000FF0000000000) |
 | 
				
			||||||
 | 
							((((uint64_t)payload[index + 3]) << 32) & 0x000000FF00000000) |
 | 
				
			||||||
 | 
							((((uint64_t)payload[index + 4]) << 24) & 0x00000000FF000000) |
 | 
				
			||||||
 | 
							((((uint64_t)payload[index + 5]) << 16) & 0x0000000000FF0000) |
 | 
				
			||||||
 | 
							((((uint64_t)payload[index + 6]) << 8) & 0x000000000000FF00) |
 | 
				
			||||||
 | 
							(((uint64_t)payload[index + 7]) & 0x00000000000000FF);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
double float16FromPayload(const uint8_t* payload, int index)
 | 
					double float16FromPayload(const uint8_t* payload, int index)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint16_t mantissa = unsigned16FromPayload(payload, index) & 0x87FF;
 | 
					    uint16_t mantissa = unsigned16FromPayload(payload, index) & 0x87FF;
 | 
				
			||||||
@ -1725,6 +1736,12 @@ float float32FromPayload(const uint8_t* payload, int index)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    union { float f; uint32_t i; } area;
 | 
					    union { float f; uint32_t i; } area;
 | 
				
			||||||
    area.i = unsigned32FromPayload(payload, index);
 | 
					    area.i = unsigned32FromPayload(payload, index);
 | 
				
			||||||
 | 
						return area.f;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					double float64FromPayload(const uint8_t* payload, int index)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						union { double f; uint64_t i; } area;
 | 
				
			||||||
 | 
						area.i = unsigned64FromPayload(payload, index);
 | 
				
			||||||
    return area.f;
 | 
					    return area.f;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
int64_t signed64FromPayload(const uint8_t* payload, int index)
 | 
					int64_t signed64FromPayload(const uint8_t* payload, int index)
 | 
				
			||||||
 | 
				
			|||||||
@ -127,8 +127,10 @@ uint16_t unsigned16FromPayload(const uint8_t* payload, int index);
 | 
				
			|||||||
int16_t signed16FromPayload(const uint8_t* payload, int index);
 | 
					int16_t signed16FromPayload(const uint8_t* payload, int index);
 | 
				
			||||||
uint32_t unsigned32FromPayload(const uint8_t* payload, int index);
 | 
					uint32_t unsigned32FromPayload(const uint8_t* payload, int index);
 | 
				
			||||||
int32_t signed32FromPayload(const uint8_t* payload, int index);
 | 
					int32_t signed32FromPayload(const uint8_t* payload, int index);
 | 
				
			||||||
 | 
					uint64_t unsigned64FromPayload(const uint8_t* payload, int index);
 | 
				
			||||||
double float16FromPayload(const uint8_t* payload, int index);
 | 
					double float16FromPayload(const uint8_t* payload, int index);
 | 
				
			||||||
float float32FromPayload(const uint8_t* payload, int index);
 | 
					float float32FromPayload(const uint8_t* payload, int index);
 | 
				
			||||||
 | 
					double float64FromPayload(const uint8_t* payload, int index);
 | 
				
			||||||
int64_t signed64FromPayload(const uint8_t* payload, int index);
 | 
					int64_t signed64FromPayload(const uint8_t* payload, int index);
 | 
				
			||||||
uint8_t bcdFromPayload(const uint8_t* payload, int index);
 | 
					uint8_t bcdFromPayload(const uint8_t* payload, int index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -142,4 +144,4 @@ void signed32ToPayload(uint8_t* payload, size_t payload_length, int index, int32
 | 
				
			|||||||
void float16ToPayload(uint8_t* payload, size_t payload_length, int index, double value, uint16_t mask);      //mask = 0xFFFF
 | 
					void float16ToPayload(uint8_t* payload, size_t payload_length, int index, double value, uint16_t mask);      //mask = 0xFFFF
 | 
				
			||||||
void float32ToPayload(uint8_t* payload, size_t payload_length, int index, double value, uint32_t mask);      //mask  = 0xFFFFFFFF
 | 
					void float32ToPayload(uint8_t* payload, size_t payload_length, int index, double value, uint32_t mask);      //mask  = 0xFFFFFFFF
 | 
				
			||||||
void signed64ToPayload(uint8_t* payload, size_t payload_length, int index, int64_t value, uint64_t mask);    //mask = UINT64_C(0xFFFFFFFFFFFFFFFF)
 | 
					void signed64ToPayload(uint8_t* payload, size_t payload_length, int index, int64_t value, uint64_t mask);    //mask = UINT64_C(0xFFFFFFFFFFFFFFFF)
 | 
				
			||||||
void bcdToPayload(uint8_t* payload, size_t payload_length, int index, uint8_t value);
 | 
					void bcdToPayload(uint8_t* payload, size_t payload_length, int index, uint8_t value);
 | 
				
			||||||
 | 
				
			|||||||
@ -14,7 +14,7 @@
 | 
				
			|||||||
        #error Mask version not supported on ARDUINO_ARCH_SAMD
 | 
					        #error Mask version not supported on ARDUINO_ARCH_SAMD
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#elif ARDUINO_ARCH_ESP8266
 | 
					#elif defined(ARDUINO_ARCH_ESP8266)
 | 
				
			||||||
    // predefined global instance for IP only
 | 
					    // predefined global instance for IP only
 | 
				
			||||||
    #if MASK_VERSION == 0x57B0
 | 
					    #if MASK_VERSION == 0x57B0
 | 
				
			||||||
        KnxFacade<EspPlatform, Bau57B0> knx;
 | 
					        KnxFacade<EspPlatform, Bau57B0> knx;
 | 
				
			||||||
@ -22,7 +22,7 @@
 | 
				
			|||||||
        #error Mask version not supported on ARDUINO_ARCH_ESP8266
 | 
					        #error Mask version not supported on ARDUINO_ARCH_ESP8266
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#elif ARDUINO_ARCH_ESP32
 | 
					#elif defined(ARDUINO_ARCH_ESP32)
 | 
				
			||||||
    // predefined global instance for TP or IP or TP/IP coupler
 | 
					    // predefined global instance for TP or IP or TP/IP coupler
 | 
				
			||||||
    #if MASK_VERSION == 0x07B0
 | 
					    #if MASK_VERSION == 0x07B0
 | 
				
			||||||
        KnxFacade<Esp32Platform, Bau07B0> knx;
 | 
					        KnxFacade<Esp32Platform, Bau07B0> knx;
 | 
				
			||||||
@ -34,7 +34,7 @@
 | 
				
			|||||||
        #error Mask version not supported on ARDUINO_ARCH_ESP8266
 | 
					        #error Mask version not supported on ARDUINO_ARCH_ESP8266
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#elif ARDUINO_ARCH_STM32
 | 
					#elif defined(ARDUINO_ARCH_STM32)
 | 
				
			||||||
    #if MASK_VERSION == 0x07B0
 | 
					    #if MASK_VERSION == 0x07B0
 | 
				
			||||||
        KnxFacade<Stm32Platform, Bau07B0> knx;
 | 
					        KnxFacade<Stm32Platform, Bau07B0> knx;
 | 
				
			||||||
    #else
 | 
					    #else
 | 
				
			||||||
 | 
				
			|||||||
@ -9,18 +9,18 @@
 | 
				
			|||||||
    #include "knx/bau27B0.h"
 | 
					    #include "knx/bau27B0.h"
 | 
				
			||||||
    #include "knx/bau2920.h"
 | 
					    #include "knx/bau2920.h"
 | 
				
			||||||
    void buttonUp();
 | 
					    void buttonUp();
 | 
				
			||||||
#elif ARDUINO_ARCH_ESP8266
 | 
					#elif defined(ARDUINO_ARCH_ESP8266)
 | 
				
			||||||
   #include "esp_platform.h"
 | 
					   #include "esp_platform.h"
 | 
				
			||||||
   #include "knx/bau57B0.h"
 | 
					   #include "knx/bau57B0.h"
 | 
				
			||||||
   void buttonUp();
 | 
					   void buttonUp();
 | 
				
			||||||
#elif ARDUINO_ARCH_ESP32
 | 
					#elif defined(ARDUINO_ARCH_ESP32)
 | 
				
			||||||
   #define LED_BUILTIN 13
 | 
					   #define LED_BUILTIN 13
 | 
				
			||||||
   #include "esp32_platform.h"
 | 
					   #include "esp32_platform.h"
 | 
				
			||||||
   #include "knx/bau07B0.h"
 | 
					   #include "knx/bau07B0.h"
 | 
				
			||||||
   #include "knx/bau57B0.h"
 | 
					   #include "knx/bau57B0.h"
 | 
				
			||||||
   #include "knx/bau091A.h"
 | 
					   #include "knx/bau091A.h"
 | 
				
			||||||
   void buttonUp();
 | 
					   void buttonUp();
 | 
				
			||||||
#elif ARDUINO_ARCH_STM32
 | 
					#elif defined(ARDUINO_ARCH_STM32)
 | 
				
			||||||
   #include "stm32_platform.h"
 | 
					   #include "stm32_platform.h"
 | 
				
			||||||
   #include "knx/bau07B0.h"
 | 
					   #include "knx/bau07B0.h"
 | 
				
			||||||
   void buttonUp();
 | 
					   void buttonUp();
 | 
				
			||||||
@ -279,6 +279,14 @@ template <class P, class B> class KnxFacade : private SaveRestore
 | 
				
			|||||||
        return _bau.parameters().getInt(addr);
 | 
					        return _bau.parameters().getInt(addr);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    double paramFloat(uint32_t addr, ParameterFloatEncodings enc)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if (!_bau.configured())
 | 
				
			||||||
 | 
					            return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return _bau.parameters().getFloat(addr, enc);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
#if (MASK_VERSION == 0x07B0) || (MASK_VERSION == 0x27B0) || (MASK_VERSION == 0x57B0)
 | 
					#if (MASK_VERSION == 0x07B0) || (MASK_VERSION == 0x27B0) || (MASK_VERSION == 0x57B0)
 | 
				
			||||||
    GroupObject& getGroupObject(uint16_t goNr)
 | 
					    GroupObject& getGroupObject(uint16_t goNr)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -343,14 +351,14 @@ template <class P, class B> class KnxFacade : private SaveRestore
 | 
				
			|||||||
    #else
 | 
					    #else
 | 
				
			||||||
        #error "Mask version not supported on ARDUINO_ARCH_SAMD"
 | 
					        #error "Mask version not supported on ARDUINO_ARCH_SAMD"
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
#elif ARDUINO_ARCH_ESP8266
 | 
					#elif defined(ARDUINO_ARCH_ESP8266)
 | 
				
			||||||
    // predefined global instance for IP only
 | 
					    // predefined global instance for IP only
 | 
				
			||||||
    #if MASK_VERSION == 0x57B0
 | 
					    #if MASK_VERSION == 0x57B0
 | 
				
			||||||
        extern KnxFacade<EspPlatform, Bau57B0> knx;
 | 
					        extern KnxFacade<EspPlatform, Bau57B0> knx;
 | 
				
			||||||
    #else
 | 
					    #else
 | 
				
			||||||
        #error "Mask version not supported on ARDUINO_ARCH_ESP8266"
 | 
					        #error "Mask version not supported on ARDUINO_ARCH_ESP8266"
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
#elif ARDUINO_ARCH_ESP32
 | 
					#elif defined(ARDUINO_ARCH_ESP32)
 | 
				
			||||||
    // predefined global instance for TP or IP or TP/IP coupler
 | 
					    // predefined global instance for TP or IP or TP/IP coupler
 | 
				
			||||||
    #if MASK_VERSION == 0x07B0
 | 
					    #if MASK_VERSION == 0x07B0
 | 
				
			||||||
        extern KnxFacade<Esp32Platform, Bau07B0> knx;
 | 
					        extern KnxFacade<Esp32Platform, Bau07B0> knx;
 | 
				
			||||||
@ -361,7 +369,7 @@ template <class P, class B> class KnxFacade : private SaveRestore
 | 
				
			|||||||
    #else
 | 
					    #else
 | 
				
			||||||
        #error "Mask version not supported on ARDUINO_ARCH_ESP32"
 | 
					        #error "Mask version not supported on ARDUINO_ARCH_ESP32"
 | 
				
			||||||
    #endif
 | 
					    #endif
 | 
				
			||||||
#elif ARDUINO_ARCH_STM32
 | 
					#elif defined(ARDUINO_ARCH_STM32)
 | 
				
			||||||
    // predefined global instance for TP only
 | 
					    // predefined global instance for TP only
 | 
				
			||||||
    #if MASK_VERSION == 0x07B0
 | 
					    #if MASK_VERSION == 0x07B0
 | 
				
			||||||
        extern KnxFacade<Stm32Platform, Bau07B0> knx;
 | 
					        extern KnxFacade<Stm32Platform, Bau07B0> knx;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user