All the software written by me, described in these pages, is available as open source on github.
Regarding the PIC firmware loaded in the KNXgate board, follow the instructions on the author web site.
To run in polling mode: after init, a timed function asks every 250ms to KNXgate to send the content of its buffer, if available, using the "@r" command.
For interrupt mode: in init procedure use command "@l" to enable continuos log of data received.
Let's analyze the application server part of the program.
In initialization section the program loads all the modules, starts the web server and begins listening for websocket connection requests. Then opens the serial port toward KNXgate and initialize it according to the operating mode needed.
When the "data received from serial" event triggers the listener, the packet decoding function starts separating all the information embedded from the telegram ...
...and prepares a json data structure to send to a potential client.
The structure of the telegram according to the KNX standard.
In the opposite direction, a web socket listener waits for a connection event. When the json file sent from the client arrives, it is decoded and the corresponding commands are sent to the KNXgate through the serial line in order to control the desired device on the bus.