
It is supposed that GPD is a power-limited device running on MCU. If it is battery-less, it can do only limited set of actions until power shortage.
If it is battery-powered, its battery resource is supposed to be low, so the device should be in a deep sleep state generally, consuming minimal energy and usually not retaining RAM. GPD can be waked from the deep sleep by button press, soft reset etc. Anyway it starts from the very beginning of the function main() each time. It means that GPD application starts multiple times from the very beginning of function main (in GreenBOSS it is declared as MAIN).
GPD shall be commissioned to Zigbee network before it can be used.
The commissioning state is stored in NVM in the flash memory. GreenBOSS commissioning API can be used to check the commissioning state and start/continue commissioning.
Therefore the normal application execution flow is the following:
GPD implementing Bidirectional in Operational mode can be only battery-powered. In contrast to GPD which is Unidirectional in the Operational mode, it first loops until Commissioning completed then loops infinitely to handle incoming packets from GPS.
So the execution flow is:
GreenBOSS is designed to use internal MCU flash to store GPD information. It is supposed that flash is erased to -1 (all ones) while write operation clears some bits. Depending on a HW, the number of writes into the same word can vary from 1 (some bits can be set to 0 only in a single write) to 32 (every bit in a word can be set to 0 independently). That setting is platform-dependent and build-configurable.
There are two types of information:
GreenBOSS uses a single eraseable page to store commissioning info. It consists of a header storing commissioning state, channel, key etc, and a bitmap of channel indexes to implement channel cycling. To do decommissioning GreenBOSS erases the commissioning page. Since page erasing is power-consuming operation, at battery-less device page erasing uses power budget of the entire commissioning step.
Packet numbers are stored as a bitmap using more than one page.
DSR provides number of application samples (samples/ folder in GreenBOSS core git repository). DSR recommends to base real devices development on that samples. In summary, the application structure is as follows:
Any GreenBOSS application shall include header file "gboss_api.h".
Application shall define set of constant data structures describing GPD capabilities, OOB key, TX channels set etc.
See the example:
DSR samples use gboss_test_get_button_mask() to check for buttons pressed on application start time. Customers are free to use another method or do not use buttons at all.
See the example:
When using Network Simulator, each start of GPD is imitated by the next run of the example application process.
When GreenBOSS runs on Network Simulator platform there are no buttons physically present. Buttons press is imitated by the command line (-b N, where N - button number).
When osif_deep_sleep() is called, the application process exits.
DSR provides scripts to run test at Network Simulator named "runng.sh".
The device supporting unidirectional commissioning is supposed to be battery-less. So the device can either do a single commissioning step or a single GPD command TX. GPD enters commissioning mode or performs decommissioning by button press in DSR samples. The real GPD can use another methods. The commissioning step can involve either flash page erasing (in such case GreenBOSS has no power for transmit) or transmitting on number of channels and writing step status into NVM.
See the example of unidirectional commissioning step:
GreenBOSS marks unidirectional commissioning as finished when application GPD command TX run after series of commissioning steps.
When the commissioning step is called after one or more application GPD command TX calls, GreenBOSS starts unidirectional commissioning again.
GreenBOSS supports OOB key defined in the application configuration data.
If receiving a key from GPCB is supported (which is configured by the flag in the application configuration data), GPD can receive a key from GPCB and store it in NVM during commissioning. Receiving a key is supported in bidirectional commissioning mode only.
At battery-powered device GreenBOSS supposes all commissioning steps shall be done in a single run of GPD till completeness. To configure GPD as bidirectional battery-powered device user shall call gboss_bidir_battery_mode(). That call reads NVM, so it shall be placed before gboss_bidir_is_commissionned() call.
gboss_bidir_is_commissionned() can be used to check that GPD is commissioned.
To do bidirectional commissioning GPD shall run gboss_bidir_commissioning_step() in a loop.
See an example:
That type of commissioning is similar to battery-powered bidirectional commissioning, but GPD energy budget is enough only to do a single commissioning step. To configure GPD as bidirectional battery-less device user shall call gboss_bidir_batteryless_mode(). The intermediate commissioning stage is stored in MVM. GPD can check the fact that it is already commissioned. If it is not commissioned, it may run single commissioning step.
See an example:
Once GPD is started and known to be commissioned, it defines which command is to be set (DSR samples check for buttons, the real application can use another methods). GreenBOSS provides API to send commands, like GBOSS_CMD_ON().
See the example:
It is supposed that battery-powered device finally goes to deep sleep by calling osif_deep_sleep(). That call is not mandatory, the implementer of the real GPD may do something else.
In additional to the actions described in GreenBOSS Application Structure following steps are required:
Green Power specification does not define any command to be used as a replacement of MAC Poll (DATA REQUEST) in the classical Zigbee. Still, it can be necessary for GPD to periodically send some GPDF with RxAfterTx flag 1 to be able to receive some data from GPS. GreenBOSS currently sends Attribute Reporting command on Poll Control cluster as a logical "poll". That command is understood by application/zgp_attr/zgp_attr.c sample in ZBOSS which is used to test Bidirectional in Operational.
Since GreenBOSS, unlike ZBOSS, does not provide rich framework for the application writer, the application itself must handle commands received from GPS. GreenBOSS provides helper functions for such handling.
The example of getting received cmd:
The example of Read Attribute handling:
The example of Write Attribute handling:
Call zgpd_sleep_tmo() to go into sleep for predefined amount of time with radio off, RAM retention ON. That call is usually used by GPD which implements Bidirectional communication in Operational mode.