This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Setting ACCESS_MODEL_COUNT and ACCESS_ELEMENT_COUNT dynamically druing run-time

Dear DevZone community,

I'm developing a Mesh application using nRF52840 Segger Embedded Studio (SES) onLinux. I'm using version 5.0.0 of the Mesh SDK. As desccribed in the Subject, i am trying to figure out how to set the #defines #define ACCESS_ELEMENT_COUNT and #define ACCESS_MODEL_COUNT  in file nrf_mesh_config_app.h druing run-time and not compile time.

The point is, that depending on the room the model amount as well as the element amount will differ and since the room is set during run-time, i have to set those two defines during run-time.

When i set this to #defines in that way:

#define ACCESS_MODEL_COUNT_LIVING_ROOM  (30)
#define ACCESS_MODEL_COUNT_KITCHEN      (5)
#define ACCESS_MODEL_COUNT_BED_ROOM     (8)

#define ACCESS_ELEMENT_COUNT_LIVING_ROOM  (30)
#define ACCESS_ELEMENT_COUNT_KITCHEN      (5)
#define ACCESS_ELEMENT_COUNT_BED_ROOM     (8)

#define ACCESS_MODEL_COUNT      ((room == LIVING_ROOM) ? (ACCESS_MODEL_COUNT_LIVING_ROOM) : \
                                  ((room == KITCHEN) ? (ACCESS_MODEL_COUNT_KITCHEN) : (ACCESS_MODEL_COUNT_BED_ROOM)))
                                  
#define ACCESS_ELEMENT_COUNT    ((room == LIVING_ROOM) ? (ACCESS_ELEMENT_COUNT_LIVING_ROOM) : \
                                  ((room == KITCHEN) ? (ACCESS_ELEMENT_COUNT_KITCHEN) : (ACCESS_ELEMENT_COUNT_BED_ROOM)))     

I get always follwoing error message as soon as i compile it:

expression in static assertion is not constant

in following static_assert:

/** The composition data must fit within the Composition Data Status packet. If this assert fails,
 * there are too many models or too many elements defined. Note that the macro assumes all models to be vendor models. */
NRF_MESH_STATIC_ASSERT(CONFIG_COMPOSITION_DATA_SIZE <=
    (ACCESS_MESSAGE_LENGTH_MAX - ACCESS_UTILS_SIG_OPCODE_SIZE(CONFIG_OPCODE_COMPOSITION_DATA_STATUS) - sizeof(config_msg_composition_data_status_t)));

So my question is, is it possible to set it druing run-time? Is there a workoaround to overcome this problem?

Thanks in advance.

Rgerads,

MKarl

  • Hi,

    I am afraid those settings must be provided compile time, as they control the size of various static buffers.

    One potential workaround is to set it to the highest value out of the options, as that way it would be high enough for any of the configurations. Then use the number of elements/models needed for a particular use case.

    Regards,
    Terje

  • Hi Terje,

    thanks for your quick response. That means that as long as the actual numbers of models and elements does not exceed the maximum set values, it does not cause any problems?

    Regards,

    MKarl

     
  • Hi,

    You may have to do some other workarounds as well, such as exposing more elements and/or models on the node than what is actually used. I have not tested this locally, but brief code inspection shows that the stack uses ACCESS_ELEMENT_COUNT elements and ACCESS_MODEL_COUNT models several places, not only for buffer sizes. Worst case you may have to expose the full number of elements/models for provisioning, configuration, etc. to work.

    You also must handle the fact that the number of elements for a node is fixed once it is provisioned (this is per the Bluetooth mesh specification.) Changing the number of elements means you have to remove the node from the network, change the configuration of the device (while not part of the network), then provision it into the network as a new node.

    A full solution of runtime-configurable number of elements and models, as seen from other devices in the network, may require some rewriting of our Bluetooth mesh stack. Modification of the stack voids the Bluetooth SIG qualification, which means you need to qualify the (modified) stack on your own.

    Regards,
    Terje

Related