KNX Project Parser

A client that displays information about group addresses contained in a KNX project.

Usage

Here are the parameters that the client accepts:

Usage: ./knxproj [options]
KNX Project file parser

Options:
  -h, --help            Displays this help.
  -v, --verbose         Show more details of the project file.
  -p, --project <path>  Path to the project file to parse.

Running the client is done using the following command:

./knxproj -v -p qt.io.knxproj
Opening project file: qt.io.knxproj
Status parsing project: No errors
Project ids found: 1
 # project "qt.io.test"
     found 1 installation(s)
  - Installation ""
     found 95 Group address(es)
      Living room Ceiling light switching: 1/1/0
      Living room Desk light switching: 1/1/1
      Living room Socket switching: 1/1/2
      Kitchen Ceiling light switching: 1/1/8
      Kitchen Working light switching: 1/1/9
      Kitchen Dining corner switching: 1/1/10
      Bedroom Ceiling light switching: 1/1/16
      Bedroom Bed left switching: 1/1/17
      Bedroom Bed right switching: 1/1/18
      Bath room Ceiling light switching: 1/1/24
      Bath room Mirror switching: 1/1/25
      ...

Implementation

In the main function, the class QKnxGroupAddressInfos is instantiated. We pass the path to the KNX project file to the constructor as a parameter. This class will provide access to information about group addresses used inside the project file.

int main(int argc, char *argv[])
{
    ...
    QKnxGroupAddressInfos infos(cliParser.value(projFilePathOption));

The next step is to call the method QKnxGroupAddressInfos::parse(). This signals the QKnxGroupAddressInfos instance to read the project file and to gather the information about the group addresses.

    infos.parse();

Before displaying the information that has been read from the project file, we need to check if any errors were found parsing the file:

    if (infos.status() != QKnxGroupAddressInfos::Status::NoError) {
        qInfo() << "ERROR:" <<  infos;
        return EXIT_FAILURE;
    }

Obtaining the project ids, the project's name, and the group addresses used is done in this code snippet:

    for (const auto &projId: infos.projectIds()) {
        auto installations = infos.installations(projId);
        qInfo()<< " # project"<<infos.projectName(projId);
        qInfo().noquote() << QString::fromLatin1("     found %1 installation(s)")
                             .arg(installations.size());
        for (const QString &installation: installations) {
            auto groupAddresses = infos.addressInfos(projId, installation);
            qInfo().noquote() << QString::fromLatin1("  - Installation \"%1\"")
                                 .arg(installation);
            qInfo().noquote() << QString::fromLatin1("     found %1 Group address(es)")
                       .arg(groupAddresses.size());
            for (const QKnxGroupAddressInfo &addInfo: groupAddresses) {
                if (!addInfo.isValid())
                    return EXIT_FAILURE;
                if (verbose)
                    qInfo().noquote() << QString::fromLatin1("      %1: %2")
                                         .arg(addInfo.name()).arg(addInfo.address().toString());
            }
            qInfo() << Qt::endl;
        }
    }

    return EXIT_SUCCESS;
};

Files:

© 2024 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.