Builder Class

(QKnxLinkLayerFrame::Builder)

The QKnxLinkLayerFrame::Builder class provides the means to create a KNX link layer frame. More...

Header: #include <QKnxLinkLayerFrameBuilder>
qmake: QT += knx

Public Functions

Builder()
QKnxLinkLayerFrame createFrame() const
Builder &setAdditionalInfos(const QVector<QKnxAdditionalInfo> &infos)
Builder &setControlField(const QKnxControlField &ctrl)
Builder &setData(const QKnxByteArray &data, quint16 offset = 0)
Builder &setDestinationAddress(const QKnxAddress &dest)
Builder &setExtendedControlField(const QKnxExtendedControlField &extCtrl)
Builder &setMedium(QKnx::MediumType type)
Builder &setMessageCode(MessageCode code)
Builder &setSourceAddress(const QKnxAddress &source)
Builder &setTpdu(const QKnxTpdu &tpdu)

Detailed Description

The QKnxLinkLayerFrame::Builder class provides the means to create a KNX link layer frame.

A KNX link layer frame contains several fields: message code, additional information, control field, maybe an extended control field, a TPDU, as well as a source address and destination address. The fields must be valid for the builder to be able to create a frame.

The builder is set up with default values to create a common external message interface (cEMI) group value read frame, except for the destination address, which needs to be specified during the creation of the frame.

The following code sample illustrates how to establish a KNXnet/IP tunnel connection, to create group value read and write frames, and to send the frames over the connection:

QKnxNetIpTunnel tunnel(...);
tunnel.connectToHost(...);

auto frame = QKnxLinkLayerFrame::builder()
    .setDestinationAddress({ QKnxAddress::Type::Group, QLatin1String("2/1/4") })
    .create();

tunnel.sendFrame(frame);

frame = QKnxLinkLayerFrame::builder()
    .setDestinationAddress({ QKnxAddress::Type::Group, QLatin1String("2/1/4") })
    .setTpdu({
        QKnxTpdu::TransportControlField::DataGroup,
        QKnxTpdu::ApplicationControlField::GroupValueWrite,
        QKnxSwitch(QKnxSwitch::State::On).bytes()
    }).create();

tunnel.sendFrame(frame);

See also QKnxLinkLayerFrame and Qt KNX Tunneling Classes.

Member Function Documentation

Builder::Builder()

Default constructs an instance of Builder.

QKnxLinkLayerFrame Builder::createFrame() const

Creates a frame from the values set for the link layer frame message code, additional information, control field, extended control field, TPDU, source address, and destination address. Alternatively, uses a byte array with all the fields already encoded into it.

See also QKnxLinkLayerFrame, QKnxLinkLayerFrame::MessageCode, QKnxAdditionalInfo, QKnxControlField, QKnxExtendedControlField, QKnxTpdu, QKnxAddress, and QKnxByteArray.

Builder &Builder::setAdditionalInfos(const QVector<QKnxAdditionalInfo> &infos)

Sets the additional information to be used by the builder to infos and returns a reference to the builder.

See also QKnxAdditionalInfo.

Builder &Builder::setControlField(const QKnxControlField &ctrl)

Sets the control field to be used by the builder to ctrl and returns a reference to the builder.

See also QKnxControlField.

Builder &Builder::setData(const QKnxByteArray &data, quint16 offset = 0)

Sets an array of bytes specified by data with all the fields encoded into a byte array starting from the position offset to avoid having to use each of the field setters separately.

See also createFrame() and QKnxByteArray.

Builder &Builder::setDestinationAddress(const QKnxAddress &dest)

Sets the destination address to be used by the builder to dest and returns a reference to the builder.

See also QKnxAddress.

Builder &Builder::setExtendedControlField(const QKnxExtendedControlField &extCtrl)

Sets the extended control field to be used by the builder to extCtrl and returns a reference to the builder.

See also QKnxExtendedControlField.

Builder &Builder::setMedium(QKnx::MediumType type)

Sets the medium that will determine the format and order of fields to type and returns a reference to the builder.

See also QKnx::MediumType.

Builder &Builder::setMessageCode(MessageCode code)

Sets the link layer frame message code to be used by the builder to code and returns a reference to the builder.

See also QKnxLinkLayerFrame::MessageCode.

Builder &Builder::setSourceAddress(const QKnxAddress &source)

Sets the source address to be used by the builder to source and returns a reference to the builder.

See also QKnxAddress.

Builder &Builder::setTpdu(const QKnxTpdu &tpdu)

Sets the TPDU to be used by the builder to tpdu and returns a reference to the builder.

See also QKnxTpdu.

© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.