Skip to content

Commit

Permalink
Managed to pass health_pub from dts
Browse files Browse the repository at this point in the history
I added `vargs` as a string array which can be used to extract arguments
to the certain model. I used DT_STRING_UNQUOTED_BY_IDX instead of
DT_STRING_TOKEN_BY_IDX to allow to pass &health_pub instead of
health_pub to model args. Otherwise I'd have to add & manually.
  • Loading branch information
PavelVPV committed Dec 13, 2024
1 parent 20e1408 commit 5529a6e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions samples/bluetooth/mesh/ngcdp/ble_mesh.overlay
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
model-health-srv {
vname = "health_srv";
cmodel = "bt-mesh-model-health-srv";
vargs = "&health_pub";
compatible = "bt-mesh-model";
};
model-onoff-cli-0 {
Expand Down
5 changes: 5 additions & 0 deletions samples/bluetooth/mesh/ngcdp/dts/bindings/bt_mesh_model.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ properties:
type: string
description: Model variable name
required: true

vargs:
type: string-array
description: Variable args to model macro
required: false
10 changes: 5 additions & 5 deletions samples/bluetooth/mesh/ngcdp/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ BT_MESH_HEALTH_PUB_DEFINE(health_pub, 0);

#define EXPAND(x) x

#define bt_mesh_model_cfg_srv_MACRO(name) EXPAND(BT_MESH_MODEL_CFG_SRV)
#define bt_mesh_model_health_srv_MACRO(name) EXPAND(BT_MESH_MODEL_HEALTH_SRV(&name, &health_pub))
#define bt_mesh_model_onoff_cli_MACRO(name) EXPAND(BT_MESH_MODEL_ONOFF_CLI(&name))
#define bt_mesh_model_ponoff_srv_MACRO(name) EXPAND(BT_MESH_MODEL_PONOFF_SRV(&name))
#define bt_mesh_model_cfg_srv_MACRO(model) EXPAND(BT_MESH_MODEL_CFG_SRV)
#define bt_mesh_model_health_srv_MACRO(model) EXPAND(BT_MESH_MODEL_HEALTH_SRV(&DT_STRING_TOKEN(model, vname), DT_STRING_UNQUOTED_BY_IDX(model, vargs, 0)))
#define bt_mesh_model_onoff_cli_MACRO(model) EXPAND(BT_MESH_MODEL_ONOFF_CLI(&DT_STRING_TOKEN(model, vname)))
#define bt_mesh_model_ponoff_srv_MACRO(model) EXPAND(BT_MESH_MODEL_PONOFF_SRV(&DT_STRING_TOKEN(model, vname)))


//#define MACRO_FROM_COMPAT(compat) compat##_MACRO
Expand All @@ -100,7 +100,7 @@ BT_MESH_HEALTH_PUB_DEFINE(health_pub, 0);
/**
* @param model - dts model
*/
#define DT_BT_MESH_MODEL_INIT(model) EXPAND_AND_CONCAT(DT_STRING_TOKEN(model, cmodel), _MACRO)(DT_STRING_TOKEN(model, vname)),
#define DT_BT_MESH_MODEL_INIT(model) EXPAND_AND_CONCAT(DT_STRING_TOKEN(model, cmodel), _MACRO)(model),

/**
* @param element - dts element
Expand Down

0 comments on commit 5529a6e

Please sign in to comment.