Program Listing for File group_object.h

Return to documentation for file (src/knx/group_object.h)

#pragma once

#include <stddef.h>
#include <stdint.h>
#include "knx_types.h"
#include "dptconvert.h"

class GroupObjectTableObject;

enum ComFlag : uint8_t
{
    Updated = 0,
    ReadRequest = 1,
    WriteRequest = 2,
    Transmitting = 3,
    Ok = 4,
    Error = 5,
    Uninitialized = 6
};

class GroupObject;

#ifndef HAS_FUNCTIONAL
    #if defined(__linux__) || defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_STM32) || defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_RP2040) || defined(LIBRETINY)
        #define HAS_FUNCTIONAL    1
    #else
        #define HAS_FUNCTIONAL   0
    #endif
#endif

#if HAS_FUNCTIONAL
    #include <functional>
    typedef std::function<void(GroupObject&)> GroupObjectUpdatedHandler;
#else
    typedef void (*GroupObjectUpdatedHandler)(GroupObject& go);
#endif

class GroupObject
{
        friend class GroupObjectTableObject;
        GroupObject(const GroupObject& other) = delete;
    public:
        GroupObject();
        virtual ~GroupObject();
        // config flags from ETS
        bool responseUpdateEnable();
        bool transmitEnable();
        bool valueReadOnInit();
        bool writeEnable();
        bool readEnable();
        bool communicationEnable();

        Priority priority();

        ComFlag commFlag();
        void commFlag(ComFlag value);

        bool initialized();

        void requestObjectRead();
        void objectWritten();

        size_t valueSize();
        size_t sizeInTelegram();
        size_t sizeInMemory() const;
        uint8_t* valueRef();
        uint16_t asap();

#ifndef SMALL_GROUPOBJECT
        void callback(GroupObjectUpdatedHandler handler);
        GroupObjectUpdatedHandler callback();
#endif
        KNXValue value(const Dpt& type);
        bool value(const KNXValue& value, const Dpt& type);

        bool valueCompare(const KNXValue& value, const Dpt& type);

        bool valueNoSend(const KNXValue& value, const Dpt& type);

        bool valueNoSendCompare(const KNXValue& value, const Dpt& type);

        bool tryValue(KNXValue& value, const Dpt& type);

#ifndef SMALL_GROUPOBJECT
        KNXValue value();
        bool value(const KNXValue& value);
        bool valueNoSend(const KNXValue& value);
        bool tryValue(KNXValue& value);

        Dpt dataPointType();
        void dataPointType(Dpt value);
#else
        static GroupObjectUpdatedHandler classCallback();
        static void classCallback(GroupObjectUpdatedHandler handler);
        static void processClassCallback(GroupObject& ko);
#endif

    private:
        // class members
        static GroupObjectTableObject* _table;
#ifdef SMALL_GROUPOBJECT
        static GroupObjectUpdatedHandler _updateHandlerStatic;
#endif

        size_t asapValueSize(uint8_t code) const;
        size_t goSize();
        uint16_t _asap = 0;
        bool _uninitialized : 1;
        ComFlag _commFlag : 7;
        uint8_t* _data = 0;
        uint8_t _dataLength = 0;
#ifndef SMALL_GROUPOBJECT
        GroupObjectUpdatedHandler _updateHandler;
        Dpt _datapointType;
#endif
};