summaryrefslogtreecommitdiffstats
path: root/src/knx/qknxdevicemanagementframefactory.cpp
blob: 174b0a6063e031ef27682a040307b1dd5687d480 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
/******************************************************************************
**
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtKnx module.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
******************************************************************************/

#include "qknxdevicemanagementframefactory.h"

QT_BEGIN_NAMESPACE

/*!
    \class QKnxDeviceManagementFrame::Builder

    \inmodule QtKnx
    \inheaderfile QKnxDeviceManagementFrameBuilder
    \ingroup qtknx-device-management

    \brief The QKnxDeviceManagementFrame::Builder class provides the means to
    create valid device management service frames.

    The typical arguments needed to build a \l QKnxDeviceManagementFrame are:
    \list
        \li The code describing the service to use,
            \l QKnxDeviceManagementFrame::MessageCode.
        \li The type of the interface object holding the property one wants to
            access, \l QKnxInterfaceObjectType.
        \li The instance of this interface object (because it is possible to
            have more than one realization of an interface object in a given
            device).
        \li The property of the interface object one wants to access,
            \l QKnxInterfaceObjectProperty.
        \li The \l {setData}{data} part which might consist of the number of
            elements one wants to read in this property and start index from
            where to read.
    \endlist

    More specialized versions of the builder are also provided and it is
    recommended to prefer them over the generic version:

    \list
        \li \l QKnxDeviceManagementFrame::PropertyReadBuilder
        \li \l QKnxDeviceManagementFrame::PropertyWriteBuilder
        \li \l QKnxDeviceManagementFrame::PropertyInfoBuilder
        \li \l QKnxDeviceManagementFrame::FunctionPropertyCommandBuilder
        \li \l QKnxDeviceManagementFrame::FunctionPropertyStateReadBuilder
        \li \l QKnxDeviceManagementFrame::ResetBuilder
    \endlist

    \sa QKnxDeviceManagementFrame::MessageCode, QKnxDeviceManagementFrame,
        {Qt KNX Device Management Classes}
*/

/*!
    Sets the message code of this builder to \a code and returns a reference to
    the builder.
*/
QKnxDeviceManagementFrame::Builder &
    QKnxDeviceManagementFrame::Builder::setMessageCode(QKnxDeviceManagementFrame::MessageCode code)
{
    m_code = code;
    return *this;
}

/*!
    Sets the interface object type of this builder to \a type and returns a
    reference to the builder.
*/
QKnxDeviceManagementFrame::Builder &
    QKnxDeviceManagementFrame::Builder::setObjectType(QKnxInterfaceObjectType type)
{
    m_type = type;
    return *this;
}

/*!
    Sets the object instance of this builder to \a instance and returns
    a reference to the builder.
*/
QKnxDeviceManagementFrame::Builder &
    QKnxDeviceManagementFrame::Builder::setObjectInstance(quint8 instance)
{
    m_instance = instance;
    return *this;
}

/*!
    Sets the interface object property of this builder to \a pid and returns
    a reference to the builder.
*/
QKnxDeviceManagementFrame::Builder &
    QKnxDeviceManagementFrame::Builder::setProperty(QKnxInterfaceObjectProperty pid)
{
    m_pid = pid;
    return *this;
}

/*!
    Sets the data of this builder to \a data and returns a reference to the
    builder.
*/
QKnxDeviceManagementFrame::Builder &
    QKnxDeviceManagementFrame::Builder::setData(const QKnxByteArray &data)
{
    m_data = data;
    return *this;
}

/*!
    Creates and returns a device management frame.

    The service used depends on the frame's \l {setMessageCode}{message code}.
    All other fields, such as \l {setObjectType}{object type},
    \l {setObjectInstance}{object instance},
    \l {setProperty}{interface object property}, and depending on the service
    \l {setData}{data}, need to be set as well.

    The common way to create a negative confirmation frame is:
    \code
        auto negativeConfirmation = QKnxDeviceManagementFrame::builder()
            .setMessageCode(QKnxDeviceManagementFrame::MessageCode::FunctionPropertyStateReadConfirmation)
            .setObjectType(...)
            .setObjectInstance(...)
            .setProperty(...)
            .createFrame()
        deviceManagement.sendFrame(negativeConfirmation);
    \endcode

    The above code is equivalent to calling the
    \l FunctionPropertyStateReadBuilder::createNegativeConfirmation function.

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame QKnxDeviceManagementFrame::Builder::createFrame() const
{
    return { m_code, m_type, m_instance, m_pid, m_data };
}


/*!
    \class QKnxDeviceManagementFrame::PropertyReadBuilder

    \inmodule QtKnx
    \inheaderfile QKnxDeviceManagementFrameBuilder
    \ingroup qtknx-device-management

    \brief The QKnxDeviceManagementFrame::PropertyReadBuilder class provides
    the means to create valid device management property read service frames.

    The property read service is used by a common external message interface
    (cEMI) client to send a property read request frame, \c {M_PropRead.req}.
    It must be followed by a property read confirmation frame,
    \c {M_PropRead.con}, sent by a cEMI server. The confirmation indicates
    whether the request was successful.

    \sa QKnxDeviceManagementFrame::MessageCode, QKnxDeviceManagementFrame,
        {Qt KNX Device Management Classes}
*/
using PFRB = QKnxDeviceManagementFrame::PropertyReadBuilder;

/*!
    Sets the interface object type of this builder to \a type and returns a
    reference to the builder.
*/
PFRB &QKnxDeviceManagementFrame::PropertyReadBuilder::setObjectType(QKnxInterfaceObjectType type)
{
    m_builder.setObjectType(type);
    return *this;
}

/*!
    Sets the object instance of this builder to \a instance and returns
    a reference to the builder.
*/
PFRB &QKnxDeviceManagementFrame::PropertyReadBuilder::setObjectInstance(quint8 instance)
{
    m_builder.setObjectInstance(instance);
    return *this;
}

/*!
    Sets the interface object property of this builder to \a pid and returns
    a reference to the builder.
*/
PFRB &QKnxDeviceManagementFrame::PropertyReadBuilder::setProperty(QKnxInterfaceObjectProperty pid)
{
    m_builder.setProperty(pid);
    return *this;
}

/*!
    Sets the number of elements of this builder to \a noe and returns a
    reference to the builder.
*/
PFRB &QKnxDeviceManagementFrame::PropertyReadBuilder::setNumberOfElements(quint8 noe)
{
    m_numberOfElements = noe;
    return *this;
}

/*!
    Sets the start index of this builder to \a startIndex and returns a
    reference to the builder.
*/
PFRB &QKnxDeviceManagementFrame::PropertyReadBuilder::setStartIndex(quint16 startIndex)
{
    m_startIndex= startIndex;
    return *this;
}

/*!
    Creates a and returns a device management property read request frame.

    The common way to create such a request is:
    \code
        auto request = QKnxDeviceManagementFrame::propertyReadBuilder()
            .setObjectType(...)
            .setObjectInstance(...)
            .setProperty(...)
            .setNumberOfElements(...)
            .setStartIndex(...)
            .createRequest()
        deviceManagement.sendFrame(request);
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame QKnxDeviceManagementFrame::PropertyReadBuilder::createRequest() const
{
    m_builder.setMessageCode(MessageCode::PropertyReadRequest);
    auto frame = m_builder.createFrame();
    frame.setNumberOfElements(m_numberOfElements);
    frame.setStartIndex(m_startIndex);
    return frame;
}

/*!
    Creates a and returns a device management property read confirmation frame
    with the data field set to \a data.

    The available default argument \a request can be used to fill some of the
    returned frame fields instead of using the setter functions provided.

    The common way to create such a request is:
    \code
        void MyCemiServer::slotFrameReceived(const QKnxDeviceManagementFrame &request)
        {
            // do some work
            auto data = ...

            auto confirmation = QKnxDeviceManagementFrame::propertyReadBuilder()
                .createConfirmation(data, request);
            deviceManagement.sendFrame(confirmation);
        }
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame PFRB::createConfirmation(const QKnxByteArray &data,
                                                   const QKnxDeviceManagementFrame &request) const
{
    m_builder.setMessageCode(MessageCode::PropertyReadConfirmation);
    if (!request.isNull()) {
        m_builder.setObjectType(request.objectType());
        m_builder.setObjectInstance(request.objectInstance());
        m_builder.setProperty(request.property());
    }

    auto frame = m_builder.createFrame();
    frame.setNumberOfElements(request.isNull() ? m_numberOfElements : request.numberOfElements());
    frame.setStartIndex(request.isNull() ? m_startIndex : request.startIndex());
    frame.setData(data);
    return frame;
}

/*!
    Creates and returns a negative device management property read confirmation
    frame.

    The available default argument \a request can be used to fill some of the
    returned frame fields instead of using the setter functions provided.

    The number of elements of a negative response is set to zero and the start
    index needs to be set to the value received with the request.

    The \a error field of a negative response contains information about the
    error as a \l QKnx::NetIp::CemiServer::Error value.

    The common way to create such a confirmation is:
    \code
        void MyCemiServer::slotFrameReceived(const QKnxDeviceManagementFrame &request)
        {
            // do some work
            bool nonExistingProperty = ...
            if (nonExistingProperty) {
                auto confirmation = QKnxDeviceManagementFrame::propertyReadBuilder()
                    .createNegativeConfirmation(QKnxNetIpCemiServer::Error::NonExistingProperty,
                                                request);
                deviceManagement.sendFrame(confirmation);
            }
        }
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame PFRB::createNegativeConfirmation(QKnxNetIpCemiServer::Error error,
                                                    const QKnxDeviceManagementFrame &request) const
{
    m_builder.setMessageCode(MessageCode::PropertyReadConfirmation);
    if (!request.isNull()) {
        m_builder.setObjectType(request.objectType());
        m_builder.setObjectInstance(request.objectInstance());
        m_builder.setProperty(request.property());
    }

    auto frame = m_builder.createFrame();
    frame.setNumberOfElements(0);
    frame.setStartIndex(request.isNull() ? m_startIndex : request.startIndex());
    frame.setError(error);
    return frame;
}


/*!
    \class QKnxDeviceManagementFrame::PropertyWriteBuilder

    \inmodule QtKnx
    \inheaderfile QKnxDeviceManagementFrameBuilder
    \ingroup qtknx-device-management

    \brief The QKnxDeviceManagementFrame::PropertyWriteBuilder class provides
    the means to create valid device management property write service frames.

    The property write service is used by a common external message interface
    (cEMI) client to send a property write request frame, \c {M_PropWrite.req}.
    It must be followed by a property write confirmation frame,
    \c {M_PropWrite.con}. The confirmation indicates whether the request was
    successful.

    \sa QKnxDeviceManagementFrame::MessageCode, QKnxDeviceManagementFrame,
        {Qt KNX Device Management Classes}
*/
using PFWB = QKnxDeviceManagementFrame::PropertyWriteBuilder;

/*!
    Sets the interface object type of this builder to \a type and returns a
    reference to the builder.
*/
PFWB &QKnxDeviceManagementFrame::PropertyWriteBuilder::setObjectType(QKnxInterfaceObjectType type)
{
    m_builder.setObjectType(type);
    return *this;
}

/*!
    Sets the object instance of this builder to \a instance and returns
    a reference to the builder.
*/
PFWB &QKnxDeviceManagementFrame::PropertyWriteBuilder::setObjectInstance(quint8 instance)
{
    m_builder.setObjectInstance(instance);
    return *this;
}

/*!
    Sets the interface object property of this builder to \a pid and returns
    a reference to the builder.
*/
PFWB &QKnxDeviceManagementFrame::PropertyWriteBuilder::setProperty(QKnxInterfaceObjectProperty pid)
{
    m_builder.setProperty(pid);
    return *this;
}

/*!
    Sets the number of elements of this builder to \a noe and returns a
    reference to the builder.
*/
PFWB &QKnxDeviceManagementFrame::PropertyWriteBuilder::setNumberOfElements(quint8 noe)
{
    m_numberOfElements = noe;
    return *this;
}

/*!
    Sets the start index of this builder to \a startIndex and returns a
    reference to the builder.
*/
PFWB &QKnxDeviceManagementFrame::PropertyWriteBuilder::setStartIndex(quint16 startIndex)
{
    m_startIndex= startIndex;
    return *this;
}

/*!
    Creates a and returns a device management property write request frame with
    the data field set to \a data.

    The common way to create such a request is:
    \code
        auto data = ...
        auto request = QKnxDeviceManagementFrame::propertyWriteBuilder()
            .setObjectType(...)
            .setObjectInstance(...)
            .setProperty(...)
            .setNumberOfElements(...)
            .setStartIndex(...)
            .createRequest(data)
        deviceManagement.sendFrame(request);
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame PFWB::createRequest(const QKnxByteArray &data) const
{
    m_builder.setMessageCode(MessageCode::PropertyWriteRequest);
    auto frame = m_builder.createFrame();
    frame.setNumberOfElements(m_numberOfElements);
    frame.setStartIndex(m_startIndex);
    frame.setData(data);
    return frame;
}

/*!
    Creates a and returns a device management property write confirmation frame.

    The available default argument \a request can be used to fill some of the
    returned frame fields instead of using the setter functions provided.

    The common way to create such a request is:
    \code
        void MyCemiServer::slotFrameReceived(const QKnxDeviceManagementFrame &request)
        {
            if (request.messageCode() != QKnxDeviceManagementFrame::MessageCode::PropertyWriteRequest)
                return;

            // execute the write operation

            auto confirmation = QKnxDeviceManagementFrame::propertyWriteBuilder()
                .createConfirmation(request);
            deviceManagement.sendFrame(confirmation);
        }
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame PFWB::createConfirmation(const QKnxDeviceManagementFrame &request) const
{
    m_builder.setMessageCode(MessageCode::PropertyWriteConfirmation);
    if (!request.isNull()) {
        m_builder.setObjectType(request.objectType());
        m_builder.setObjectInstance(request.objectInstance());
        m_builder.setProperty(request.property());
    }

    auto frame = m_builder.createFrame();
    frame.setNumberOfElements(request.isNull() ? m_numberOfElements : request.numberOfElements());
    frame.setStartIndex(request.isNull() ? m_startIndex : request.startIndex());
    return frame;
}

/*!
    Creates and returns a negative device management property write confirmation
    frame.

    The available default argument \a request can be used to fill some of the
    returned frame fields instead of using the setter functions provided.

    The number of elements of a negative response is set to zero and the start
    index needs to be set to the value received with the request.

    The \a error field of a negative response contains information about the
    error as a \l QKnx::NetIp::CemiServer::Error value.

    The common way to create such a confirmation is:
    \code
        void MyCemiServer::slotFrameReceived(const QKnxDeviceManagementFrame &request)
        {
            if (request.messageCode() != QKnxDeviceManagementFrame::MessageCode::PropertyWriteRequest)
                return;

            bool readOnly = ... // check if the property is read only
            if (readOnly) {
                auto confirmation = QKnxDeviceManagementFrame::propertyWriteBuilder()
                    .createNegativeConfirmation(QKnxNetIpCemiServer::Error::ReadOnly, request);
                deviceManagement.sendFrame(confirmation);
            }
        }
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame PFWB::createNegativeConfirmation(QKnxNetIpCemiServer::Error error,
                                                    const QKnxDeviceManagementFrame &request) const
{
    m_builder.setMessageCode(MessageCode::PropertyWriteConfirmation);
    if (!request.isNull()) {
        m_builder.setObjectType(request.objectType());
        m_builder.setObjectInstance(request.objectInstance());
        m_builder.setProperty(request.property());
    }

    auto frame = m_builder.createFrame();
    frame.setNumberOfElements(0);
    frame.setStartIndex(request.isNull() ? m_startIndex : request.startIndex());
    frame.setError(error);
    return frame;
}


/*!
    \class QKnxDeviceManagementFrame::PropertyInfoBuilder

    \inmodule QtKnx
    \inheaderfile QKnxDeviceManagementFrameBuilder
    \ingroup qtknx-device-management

    \brief The QKnxDeviceManagementFrame::PropertyInfoBuilder class provides
    the means to create a valid device management property info indication frame.

    The property info service is used for local device management. It is an
    \e unconfirmed service, that is used by a common external message interface
    (cEMI) cEMI server to send notifications upon events, for example.

    \sa QKnxDeviceManagementFrame::MessageCode, QKnxDeviceManagementFrame,
        {Qt KNX Device Management Classes}
*/
using PFIB = QKnxDeviceManagementFrame::PropertyInfoBuilder;

/*!
    Creates a device management property info builder object.
*/
QKnxDeviceManagementFrame::PropertyInfoBuilder::PropertyInfoBuilder()
{
    m_builder.setMessageCode(MessageCode::PropertyInfoIndication);
}

/*!
    Sets the interface object type of this builder to \a type and returns a
    reference to the builder.
*/
PFIB &QKnxDeviceManagementFrame::PropertyInfoBuilder::setObjectType(QKnxInterfaceObjectType type)
{
    m_builder.setObjectType(type);
    return *this;
}

/*!
    Sets the object instance of this builder to \a instance and returns
    a reference to the builder.
*/
PFIB &QKnxDeviceManagementFrame::PropertyInfoBuilder::setObjectInstance(quint8 instance)
{
    m_builder.setObjectInstance(instance);
    return *this;
}

/*!
    Sets the interface object property of this builder to \a pid and returns
    a reference to the builder.
*/
PFIB &QKnxDeviceManagementFrame::PropertyInfoBuilder::setProperty(QKnxInterfaceObjectProperty pid)
{
    m_builder.setProperty(pid);
    return *this;
}

/*!
    Sets the number of elements of this builder to \a noe and returns a
    reference to the builder.
*/
PFIB &QKnxDeviceManagementFrame::PropertyInfoBuilder::setNumberOfElements(quint8 noe)
{
    m_numberOfElements = noe;
    return *this;
}

/*!
    Sets the start index of this builder to \a startIndex and returns a
    reference to the builder.
*/
PFIB &QKnxDeviceManagementFrame::PropertyInfoBuilder::setStartIndex(quint16 startIndex)
{
    m_startIndex= startIndex;
    return *this;
}

/*!
    Creates and returns a device management property info indication frame with
    the data field set to \a data.

    The common way to create such an indication is:
    \code
        auto indication = QKnxDeviceManagementFrame::propertyInfoBuilder()
            .setObjectType(...)
            .setObjectInstance(...)
            .setProperty(...)
            .setNumberOfElements(...)
            .setStartIndex(...)
            .createIndication(...)
        deviceManagement.sendFrame(indication);
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame PFIB::createIndication(const QKnxByteArray &data) const
{
    auto frame = m_builder.createFrame();
    frame.setNumberOfElements(m_numberOfElements);
    frame.setStartIndex(m_startIndex);
    frame.setData(data);
    return frame;
}


/*!
    \class QKnxDeviceManagementFrame::FunctionPropertyCommandBuilder

    \inmodule QtKnx
    \inheaderfile QKnxDeviceManagementFrameBuilder
    \ingroup qtknx-device-management

    \brief The QKnxDeviceManagementFrame::FunctionPropertyCommandBuilder class
    provides the means to create valid device management function property
    command service frames.

    The function property command service is used by a common external message
    interface (cEMI) client to send a function property command request frame,
    \c {M_FuncPropCommand.req}. It must be followed by a function property
    command confirmation frame, \c {M_FuncPropCommand.con}, sent by a cEMI
    server. The confirmation indicates whether the request was successful.

    \sa QKnxDeviceManagementFrame::MessageCode, QKnxDeviceManagementFrame,
        {Qt KNX Device Management Classes}
*/
using FPCB = QKnxDeviceManagementFrame::FunctionPropertyCommandBuilder;

/*!
    Sets the interface object type of this builder to \a type and returns a
    reference to the builder.
*/
FPCB &FPCB::setObjectType(QKnxInterfaceObjectType type)
{
    m_builder.setObjectType(type);
    return *this;
}

/*!
    Sets the object instance of this builder to \a instance and returns
    a reference to the builder.
*/
FPCB &FPCB::setObjectInstance(quint8 instance)
{
    m_builder.setObjectInstance(instance);
    return *this;
}

/*!
    Sets the interface object property of this builder to \a pid and returns
    a reference to the builder.
*/
FPCB &FPCB::setProperty(QKnxInterfaceObjectProperty pid)
{
    m_builder.setProperty(pid);
    return *this;
}

/*!
    Creates and returns a device management function property command request
    frame with the data field set to \a data.

    The common way to create such a request is:
    \code
        auto request = QKnxDeviceManagementFrame::functionPropertyCommandBuilder()
            .setObjectType(...)
            .setObjectInstance(...)
            .setProperty(...)
            .createRequest(...);
        deviceManagement.sendFrame(request);
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame FPCB::createRequest(const QKnxByteArray &data) const
{
    m_builder.setMessageCode(MessageCode::FunctionPropertyCommandRequest);
    m_builder.setData(data);
    return m_builder.createFrame();
}

/*!
    Creates and returns a device management function property command
    confirmation frame with the return code set to \a code and the data field
    to \a data.

    The available default argument \a request can be used to fill some of the
    returned frame fields instead of using the setter functions provided.

    The common way to create such a confirmation is:
    \code
        void MyCemiServer::slotFrameReceived(const QKnxDeviceManagementFrame &request)
        {
            // do some work
            auto data = ...

            auto confirmation = QKnxDeviceManagementFrame::functionPropertyCommandBuilder()
                .createConfirmation(QKnxNetIpCemiServer::ReturnCode::NoError, data, request);
            deviceManagement.sendFrame(confirmation);
        }
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame FPCB::createConfirmation(QKnxNetIpCemiServer::ReturnCode code,
        const QKnxByteArray &data, const QKnxDeviceManagementFrame &request) const
{
    m_builder.setMessageCode(MessageCode::FunctionPropertyCommandConfirmation);
    if (!request.isNull()) {
        m_builder.setObjectType(request.objectType());
        m_builder.setObjectInstance(request.objectInstance());
        m_builder.setProperty(request.property());
    }

    auto frame = m_builder.createFrame();
    frame.setReturnCode(code);
    frame.setData(data);
    return frame;
}

/*!
    Creates and returns a negative device management function property command
    confirmation frame.

    The available default argument \a request can be used to fill some of the
    returned frame fields instead of using the setter functions provided.

    The common way to create such a confirmation is:
    \code
        void MyCemiServer::slotFrameReceived(const QKnxDeviceManagementFrame &request)
        {
            // do some work
            bool error = ...
            if (error) {
                auto confirmation = QKnxDeviceManagementFrame::functionPropertyCommandBuilder()
                    .createNegativeConfirmation(request);
                deviceManagement.sendFrame(confirmation);
            }
        }
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame
    FPCB::createNegativeConfirmation(const QKnxDeviceManagementFrame &request) const
{
    m_builder.setMessageCode(MessageCode::FunctionPropertyCommandConfirmation);
    if (!request.isNull()) {
        m_builder.setObjectType(request.objectType());
        m_builder.setObjectInstance(request.objectInstance());
        m_builder.setProperty(request.property());
    }
    return m_builder.createFrame();
}


/*!
    \class QKnxDeviceManagementFrame::FunctionPropertyStateReadBuilder

    \inmodule QtKnx
    \inheaderfile QKnxDeviceManagementFrameBuilder
    \ingroup qtknx-device-management

    \brief The QKnxDeviceManagementFrame::FunctionPropertyStateReadBuilder
    class provides the means to create valid device management function
    property state read service.

    The function property state read service is used by a common external
    message interface (cEMI) client to send a function property state read
    request frame, \c {M_FuncPropStateRead.req}.

    It must be followed by a function property state read confirmation frame,
    \c {M_FuncPropStateRead.con}, sent by a cEMI server. The confirmation
    indicates whether the request was successful.

    \sa QKnxDeviceManagementFrame::MessageCode, QKnxDeviceManagementFrame,
        {Qt KNX Device Management Classes}
*/
using FPSRB = QKnxDeviceManagementFrame::FunctionPropertyStateReadBuilder;

/*!
    Sets the interface object type of this builder to \a type and returns a
    reference to the builder.
*/
FPSRB &FPSRB::setObjectType(QKnxInterfaceObjectType type)
{
    m_builder.setObjectType(type);
    return *this;
}

/*!
    Sets the object instance of this builder to \a instance and returns
    a reference to the builder.
*/
FPSRB &FPSRB::setObjectInstance(quint8 instance)
{
    m_builder.setObjectInstance(instance);
    return *this;
}

/*!
    Sets the interface object property of this builder to \a pid and returns
    a reference to the builder.
*/
FPSRB &FPSRB::setProperty(QKnxInterfaceObjectProperty pid)
{
    m_builder.setProperty(pid);
    return *this;
}

/*!
    Creates and returns a device management function property state request
    frame with the data field set to \a data.

    The common way to create such a request is:
    \code
        auto request = QKnxDeviceManagementFrame::functionPropertyStateReadBuilder()
            .setObjectType(...)
            .setObjectInstance(...)
            .setProperty(...)
            .createRequest(...);
        deviceManagement.sendFrame(request);
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame FPSRB::createRequest(const QKnxByteArray &data) const
{
    m_builder.setMessageCode(MessageCode::FunctionPropertyStateReadRequest);
    m_builder.setData(data);
    return m_builder.createFrame();
}

/*!
    Creates and returns a device management function property state confirmation
    frame with the return code set to \a code and the data field to \a data.

    The available default argument \a request can be used to fill some of the
    returned frame fields instead of using the setter functions provided.

    The common way to create such a confirmation is:
    \code
        void MyCemiServer::slotFrameReceived(const QKnxDeviceManagementFrame &request)
        {
            // do some work
            auto data = ...

            auto confirmation = QKnxDeviceManagementFrame::functionPropertyStateReadBuilder()
                .createConfirmation(QKnxNetIpCemiServer::ReturnCode::NoError, data, request);
            deviceManagement.sendFrame(confirmation);
        }
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame FPSRB::createConfirmation(QKnxNetIpCemiServer::ReturnCode code,
        const QKnxByteArray &data, const QKnxDeviceManagementFrame &request) const
{
    m_builder.setMessageCode(MessageCode::FunctionPropertyStateReadConfirmation);
    if (!request.isNull()) {
        m_builder.setObjectType(request.objectType());
        m_builder.setObjectInstance(request.objectInstance());
        m_builder.setProperty(request.property());
    }

    auto frame = m_builder.createFrame();
    frame.setReturnCode(code);
    frame.setData(data);
    return frame;
}

/*!
    Creates and returns a negative device management function property state
    confirmation frame.

    The available default argument \a request can be used to fill some of the
    returned frame fields instead of using the setter functions provided.

    The common way to create such a confirmation is:
    \code
        void MyCemiServer::slotFrameReceived(const QKnxDeviceManagementFrame &request)
        {
            // do some work
            bool error = ...
            if (error) {
                auto confirmation = QKnxDeviceManagementFrame::functionPropertyStateReadBuilder()
                    .createNegativeConfirmation(request);
                deviceManagement.sendFrame(confirmation);
            }
        }
    \endcode

    \note The returned frame may be invalid depending on the values used
    during setup.

    \sa QKnxDeviceManagementFrame, QKnxDeviceManagementFrame::isValid()
*/
QKnxDeviceManagementFrame
    FPSRB::createNegativeConfirmation(const QKnxDeviceManagementFrame &request) const
{
    m_builder.setMessageCode(MessageCode::FunctionPropertyStateReadConfirmation);
    if (!request.isNull()) {
        m_builder.setObjectType(request.objectType());
        m_builder.setObjectInstance(request.objectInstance());
        m_builder.setProperty(request.property());
    }
    return m_builder.createFrame();
}


/*!
    \class QKnxDeviceManagementFrame::ResetBuilder

    \inmodule QtKnx
    \inheaderfile QKnxDeviceManagementFrameBuilder
    \ingroup qtknx-device-management

    \brief The QKnxDeviceManagementFrame::ResetBuilder class provides the means
    to build valid device management reset service frames.

    The reset service is used by a common external message interface (cEMI)
    client to send a reset request frame, \c {M_Reset.req}. It may be followed
    by a reset indication frame, \c {M_Reset.ind}.

    \sa QKnxDeviceManagementFrame::MessageCode, QKnxDeviceManagementFrame,
        {Qt KNX Device Management Classes}
*/

/*!
    Creates a reset request frame.
*/
QKnxDeviceManagementFrame QKnxDeviceManagementFrame::ResetBuilder::createRequest()
{
    return QKnxDeviceManagementFrame { QKnxDeviceManagementFrame::MessageCode::ResetRequest };
}

/*!
    Creates a reset indication frame.
*/
QKnxDeviceManagementFrame QKnxDeviceManagementFrame::ResetBuilder::createIndication()
{
    return QKnxDeviceManagementFrame { QKnxDeviceManagementFrame::MessageCode::ResetIndication };
}

QT_END_NAMESPACE