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 <knx/bits.h>
 | 
			
		||||
#include "knx/bits.h"
 | 
			
		||||
 | 
			
		||||
#include <Arduino.h>
 | 
			
		||||
#include <SPI.h>
 | 
			
		||||
 | 
			
		||||
@ -2,6 +2,7 @@
 | 
			
		||||
#include "bits.h"
 | 
			
		||||
#include "data_property.h"
 | 
			
		||||
#include "callback_property.h"
 | 
			
		||||
#include "dptconvert.h"
 | 
			
		||||
#include <cstring>
 | 
			
		||||
 | 
			
		||||
ApplicationProgramObject::ApplicationProgramObject(Memory& memory)
 | 
			
		||||
@ -47,3 +48,23 @@ uint32_t ApplicationProgramObject::getInt(uint32_t 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
 | 
			
		||||
 | 
			
		||||
#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
 | 
			
		||||
{
 | 
			
		||||
  public:
 | 
			
		||||
@ -10,4 +17,5 @@ class ApplicationProgramObject : public TableObject
 | 
			
		||||
    uint8_t getByte(uint32_t addr);
 | 
			
		||||
    uint16_t getWord(uint32_t addr);
 | 
			
		||||
    uint32_t getInt(uint32_t addr);
 | 
			
		||||
    double getFloat(uint32_t addr, ParameterFloatEncodings encoding);
 | 
			
		||||
};
 | 
			
		||||
@ -62,6 +62,6 @@
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1713,6 +1713,17 @@ int32_t signed32FromPayload(const uint8_t* payload, int 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)
 | 
			
		||||
{
 | 
			
		||||
    uint16_t mantissa = unsigned16FromPayload(payload, index) & 0x87FF;
 | 
			
		||||
@ -1727,6 +1738,12 @@ float float32FromPayload(const uint8_t* payload, int 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;
 | 
			
		||||
}
 | 
			
		||||
int64_t signed64FromPayload(const uint8_t* payload, int index)
 | 
			
		||||
{
 | 
			
		||||
    return ((((uint64_t)payload[index]) << 56) & UINT64_C(0xFF00000000000000)) |
 | 
			
		||||
 | 
			
		||||
@ -127,8 +127,10 @@ uint16_t unsigned16FromPayload(const uint8_t* payload, int index);
 | 
			
		||||
int16_t signed16FromPayload(const uint8_t* payload, int index);
 | 
			
		||||
uint32_t unsigned32FromPayload(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);
 | 
			
		||||
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);
 | 
			
		||||
uint8_t bcdFromPayload(const uint8_t* payload, int index);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,7 @@
 | 
			
		||||
        #error Mask version not supported on ARDUINO_ARCH_SAMD
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
#elif ARDUINO_ARCH_ESP8266
 | 
			
		||||
#elif defined(ARDUINO_ARCH_ESP8266)
 | 
			
		||||
    // predefined global instance for IP only
 | 
			
		||||
    #if MASK_VERSION == 0x57B0
 | 
			
		||||
        KnxFacade<EspPlatform, Bau57B0> knx;
 | 
			
		||||
@ -22,7 +22,7 @@
 | 
			
		||||
        #error Mask version not supported on ARDUINO_ARCH_ESP8266
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
#elif ARDUINO_ARCH_ESP32
 | 
			
		||||
#elif defined(ARDUINO_ARCH_ESP32)
 | 
			
		||||
    // predefined global instance for TP or IP or TP/IP coupler
 | 
			
		||||
    #if MASK_VERSION == 0x07B0
 | 
			
		||||
        KnxFacade<Esp32Platform, Bau07B0> knx;
 | 
			
		||||
@ -34,7 +34,7 @@
 | 
			
		||||
        #error Mask version not supported on ARDUINO_ARCH_ESP8266
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
#elif ARDUINO_ARCH_STM32
 | 
			
		||||
#elif defined(ARDUINO_ARCH_STM32)
 | 
			
		||||
    #if MASK_VERSION == 0x07B0
 | 
			
		||||
        KnxFacade<Stm32Platform, Bau07B0> knx;
 | 
			
		||||
    #else
 | 
			
		||||
 | 
			
		||||
@ -9,18 +9,18 @@
 | 
			
		||||
    #include "knx/bau27B0.h"
 | 
			
		||||
    #include "knx/bau2920.h"
 | 
			
		||||
    void buttonUp();
 | 
			
		||||
#elif ARDUINO_ARCH_ESP8266
 | 
			
		||||
#elif defined(ARDUINO_ARCH_ESP8266)
 | 
			
		||||
   #include "esp_platform.h"
 | 
			
		||||
   #include "knx/bau57B0.h"
 | 
			
		||||
   void buttonUp();
 | 
			
		||||
#elif ARDUINO_ARCH_ESP32
 | 
			
		||||
#elif defined(ARDUINO_ARCH_ESP32)
 | 
			
		||||
   #define LED_BUILTIN 13
 | 
			
		||||
   #include "esp32_platform.h"
 | 
			
		||||
   #include "knx/bau07B0.h"
 | 
			
		||||
   #include "knx/bau57B0.h"
 | 
			
		||||
   #include "knx/bau091A.h"
 | 
			
		||||
   void buttonUp();
 | 
			
		||||
#elif ARDUINO_ARCH_STM32
 | 
			
		||||
#elif defined(ARDUINO_ARCH_STM32)
 | 
			
		||||
   #include "stm32_platform.h"
 | 
			
		||||
   #include "knx/bau07B0.h"
 | 
			
		||||
   void buttonUp();
 | 
			
		||||
@ -279,6 +279,14 @@ template <class P, class B> class KnxFacade : private SaveRestore
 | 
			
		||||
        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)
 | 
			
		||||
    GroupObject& getGroupObject(uint16_t goNr)
 | 
			
		||||
    {
 | 
			
		||||
@ -343,14 +351,14 @@ template <class P, class B> class KnxFacade : private SaveRestore
 | 
			
		||||
    #else
 | 
			
		||||
        #error "Mask version not supported on ARDUINO_ARCH_SAMD"
 | 
			
		||||
    #endif
 | 
			
		||||
#elif ARDUINO_ARCH_ESP8266
 | 
			
		||||
#elif defined(ARDUINO_ARCH_ESP8266)
 | 
			
		||||
    // predefined global instance for IP only
 | 
			
		||||
    #if MASK_VERSION == 0x57B0
 | 
			
		||||
        extern KnxFacade<EspPlatform, Bau57B0> knx;
 | 
			
		||||
    #else
 | 
			
		||||
        #error "Mask version not supported on ARDUINO_ARCH_ESP8266"
 | 
			
		||||
    #endif
 | 
			
		||||
#elif ARDUINO_ARCH_ESP32
 | 
			
		||||
#elif defined(ARDUINO_ARCH_ESP32)
 | 
			
		||||
    // predefined global instance for TP or IP or TP/IP coupler
 | 
			
		||||
    #if MASK_VERSION == 0x07B0
 | 
			
		||||
        extern KnxFacade<Esp32Platform, Bau07B0> knx;
 | 
			
		||||
@ -361,7 +369,7 @@ template <class P, class B> class KnxFacade : private SaveRestore
 | 
			
		||||
    #else
 | 
			
		||||
        #error "Mask version not supported on ARDUINO_ARCH_ESP32"
 | 
			
		||||
    #endif
 | 
			
		||||
#elif ARDUINO_ARCH_STM32
 | 
			
		||||
#elif defined(ARDUINO_ARCH_STM32)
 | 
			
		||||
    // predefined global instance for TP only
 | 
			
		||||
    #if MASK_VERSION == 0x07B0
 | 
			
		||||
        extern KnxFacade<Stm32Platform, Bau07B0> knx;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user