mirror of
				https://github.com/thelsing/knx.git
				synced 2025-10-26 10:26:25 +01:00 
			
		
		
		
	reimplement Dpt17
This commit is contained in:
		
							parent
							
								
									e67369caf1
								
							
						
					
					
						commit
						7280cd0e53
					
				@ -70,6 +70,8 @@ set(SOURCES
 | 
				
			|||||||
./knx/group_object/dpt/dpt15.h
 | 
					./knx/group_object/dpt/dpt15.h
 | 
				
			||||||
./knx/group_object/dpt/dpt16.cpp
 | 
					./knx/group_object/dpt/dpt16.cpp
 | 
				
			||||||
./knx/group_object/dpt/dpt16.h
 | 
					./knx/group_object/dpt/dpt16.h
 | 
				
			||||||
 | 
					./knx/group_object/dpt/dpt17.cpp
 | 
				
			||||||
 | 
					./knx/group_object/dpt/dpt17.h
 | 
				
			||||||
./knx/group_object/dpt/dptconvert.cpp
 | 
					./knx/group_object/dpt/dptconvert.cpp
 | 
				
			||||||
./knx/group_object/dpt/dptconvert.h
 | 
					./knx/group_object/dpt/dptconvert.h
 | 
				
			||||||
./knx/group_object/group_object.cpp
 | 
					./knx/group_object/group_object.cpp
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,6 @@
 | 
				
			|||||||
#include "../group_object.h"
 | 
					#include "../group_object.h"
 | 
				
			||||||
namespace Knx
 | 
					namespace Knx
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
#define DPT_SceneNumber Dpt(17, 1)
 | 
					 | 
				
			||||||
#define DPT_SceneControl Dpt(18, 1)
 | 
					#define DPT_SceneControl Dpt(18, 1)
 | 
				
			||||||
#define DPT_DateTime Dpt(19, 1)
 | 
					#define DPT_DateTime Dpt(19, 1)
 | 
				
			||||||
#define DPT_SCLOMode Dpt(20, 1)
 | 
					#define DPT_SCLOMode Dpt(20, 1)
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										28
									
								
								src/knx/group_object/dpt/dpt17.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								src/knx/group_object/dpt/dpt17.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,28 @@
 | 
				
			|||||||
 | 
					#include "dpt17.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "dptconvert.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Knx::Go_SizeCode Knx::DPT_SceneNumber::size() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    return Go_1_Octet;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Knx::DPT_SceneNumber::encode(uint8_t* data) const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    unsigned8ToPayload(data, 0, _value, 0xFF);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool Knx::DPT_SceneNumber::decode(uint8_t* data)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    _value = unsigned8FromPayload(data, 0) & 0x3F;
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Knx::DPT_SceneNumber::value(uint8_t value)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if ( value > 63)
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    _value = value;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										18
									
								
								src/knx/group_object/dpt/dpt17.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/knx/group_object/dpt/dpt17.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					#pragma once
 | 
				
			||||||
 | 
					#include "dpt.h"
 | 
				
			||||||
 | 
					namespace Knx
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    class DPT_SceneNumber: public ValueDpt<uint8_t>
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					            enum ReadDirectionValue { LeftToRight = 0, RightToLeft = 1};
 | 
				
			||||||
 | 
					        public:
 | 
				
			||||||
 | 
					            DPT_SceneNumber();
 | 
				
			||||||
 | 
					            DPT_SceneNumber(const char* value);
 | 
				
			||||||
 | 
					            Go_SizeCode size() const override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            void encode(uint8_t* data) const override;
 | 
				
			||||||
 | 
					            bool decode(uint8_t* data) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            void value(uint8_t value) override;
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -18,10 +18,6 @@ namespace Knx
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if (payload_length > 0)
 | 
					        if (payload_length > 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // DPT 17.* - Scene Number
 | 
					 | 
				
			||||||
            if (datatype.mainGroup == 17 && datatype.subGroup == 1 && !datatype.index)
 | 
					 | 
				
			||||||
                return busValueToScene(payload, payload_length, datatype, value);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            // DPT 18.* - Scene Control
 | 
					            // DPT 18.* - Scene Control
 | 
				
			||||||
            if (datatype.mainGroup == 18 && datatype.subGroup == 1 && datatype.index <= 1)
 | 
					            if (datatype.mainGroup == 18 && datatype.subGroup == 1 && datatype.index <= 1)
 | 
				
			||||||
                return busValueToSceneControl(payload, payload_length, datatype, value);
 | 
					                return busValueToSceneControl(payload, payload_length, datatype, value);
 | 
				
			||||||
@ -100,10 +96,6 @@ namespace Knx
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
 | 
					    int KNX_Encode_Value(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // DPT 17.* - Scene Number
 | 
					 | 
				
			||||||
        if (datatype.mainGroup == 17 && datatype.subGroup == 1 && !datatype.index)
 | 
					 | 
				
			||||||
            return valueToBusValueScene(value, payload, payload_length, datatype);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        // DPT 18.* - Scene Control
 | 
					        // DPT 18.* - Scene Control
 | 
				
			||||||
        if (datatype.mainGroup == 18 && datatype.subGroup == 1 && datatype.index <= 1)
 | 
					        if (datatype.mainGroup == 18 && datatype.subGroup == 1 && datatype.index <= 1)
 | 
				
			||||||
            return valueToBusValueSceneControl(value, payload, payload_length, datatype);
 | 
					            return valueToBusValueSceneControl(value, payload, payload_length, datatype);
 | 
				
			||||||
@ -186,31 +178,6 @@ namespace Knx
 | 
				
			|||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int busValueToString(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        ASSERT_PAYLOAD(14);
 | 
					 | 
				
			||||||
        char strValue[15];
 | 
					 | 
				
			||||||
        strValue[14] = '\0';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (int n = 0; n < 14; ++n)
 | 
					 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            strValue[n] = signed8FromPayload(payload, n);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (!datatype.subGroup && (strValue[n] & 0x80))
 | 
					 | 
				
			||||||
                return false;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        value = strValue;
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    int busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        ASSERT_PAYLOAD(1);
 | 
					 | 
				
			||||||
        value = (uint8_t)(unsigned8FromPayload(payload, 0) & 0x3F);
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
 | 
					    int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ASSERT_PAYLOAD(1);
 | 
					        ASSERT_PAYLOAD(1);
 | 
				
			||||||
@ -590,15 +557,6 @@ namespace Knx
 | 
				
			|||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        if ((int64_t)value < INT64_C(0) || (int64_t)value > INT64_C(63))
 | 
					 | 
				
			||||||
            return false;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        unsigned8ToPayload(payload, 0, (uint64_t)value, 0xFF);
 | 
					 | 
				
			||||||
        return true;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
 | 
					    int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        switch (datatype.index)
 | 
					        switch (datatype.index)
 | 
				
			||||||
 | 
				
			|||||||
@ -49,7 +49,6 @@ namespace Knx
 | 
				
			|||||||
    //KNX to internal
 | 
					    //KNX to internal
 | 
				
			||||||
    int busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
					    int busValueToUnsigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
				
			||||||
    int busValueToSigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
					    int busValueToSigned32(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
				
			||||||
    int busValueToScene(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
					 | 
				
			||||||
    int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
					    int busValueToSceneControl(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
				
			||||||
    int busValueToSceneInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
					    int busValueToSceneInfo(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
				
			||||||
    int busValueToSceneConfig(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
					    int busValueToSceneConfig(const uint8_t* payload, size_t payload_length, const Dpt& datatype, KNXValue& value);
 | 
				
			||||||
@ -70,7 +69,6 @@ namespace Knx
 | 
				
			|||||||
    //Internal to KNX
 | 
					    //Internal to KNX
 | 
				
			||||||
    int valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
					    int valueToBusValueUnsigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
				
			||||||
    int valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
					    int valueToBusValueSigned32(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
				
			||||||
    int valueToBusValueScene(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
					 | 
				
			||||||
    int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
					    int valueToBusValueSceneControl(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
				
			||||||
    int valueToBusValueSceneInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
					    int valueToBusValueSceneInfo(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
				
			||||||
    int valueToBusValueSceneConfig(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
					    int valueToBusValueSceneConfig(const KNXValue& value, uint8_t* payload, size_t payload_length, const Dpt& datatype);
 | 
				
			||||||
 | 
				
			|||||||
@ -15,4 +15,5 @@
 | 
				
			|||||||
#include "dpt13.h"
 | 
					#include "dpt13.h"
 | 
				
			||||||
#include "dpt14.h"
 | 
					#include "dpt14.h"
 | 
				
			||||||
#include "dpt15.h"
 | 
					#include "dpt15.h"
 | 
				
			||||||
#include "dpt16.h"
 | 
					#include "dpt16.h"
 | 
				
			||||||
 | 
					#include "dpt17.h"
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user