mesh: add basic support for model publication (mesh_publish_state_t function define)

This commit is contained in:
Matthias Ringwald 2019-06-28 15:59:17 +02:00
parent e2b16cca7d
commit 24678bce17
2 changed files with 42 additions and 1 deletions

View File

@ -1149,3 +1149,28 @@ int mesh_model_contains_appkey(mesh_model_t * mesh_model, uint16_t appkey_index)
return 0;
}
// Mesh Model Publication
static void mesh_access_publish_model(mesh_model_t * mesh_model){
mesh_publication_model_t * publication_model = mesh_model->publication_model;
if (publication_model == NULL) return;
if (publication_model->publish_state_fn == NULL) return;
uint16_t dest = publication_model->address;
if (dest == MESH_ADDRESS_UNSASSIGNED) return;
uint16_t appkey_index = publication_model->appkey_index;
mesh_transport_key_t * app_key = mesh_transport_key_get(appkey_index);
if (app_key == NULL) return;
// compose message
mesh_pdu_t * pdu = (*publication_model->publish_state_fn)(mesh_model);
if (pdu == NULL) return;
mesh_upper_transport_setup_access_pdu_header(pdu, app_key->netkey_index, appkey_index, publication_model->ttl, mesh_access_get_element_address(mesh_model), dest, 0);
mesh_upper_transport_send_access_pdu(pdu);
}
void mesh_access_state_changed(mesh_model_t * mesh_model){
// TODO: schedule publication - for now just send right away
mesh_access_publish_model(mesh_model);
}

View File

@ -57,6 +57,14 @@ extern "C"
struct mesh_model;
struct mesh_element;
// function to handle model operation message
typedef void (*mesh_operation_handler)(struct mesh_model * mesh_model, mesh_pdu_t * pdu);
// function to publish the current state of a model
// @param mesh_model to publish
// @returns mesh_pdu with status message
typedef mesh_pdu_t * (*mesh_publish_state_t)(struct mesh_model * mesh_model);
typedef enum {
MESH_DEFAULT_TRANSITION_STEP_RESOLUTION_100ms = 0x00u,
MESH_DEFAULT_TRANSITION_STEP_RESOLUTION_1s,
@ -91,6 +99,8 @@ typedef enum {
} model_state_id_t;
typedef struct {
mesh_publish_state_t publish_state_fn;
uint16_t address;
uint16_t appkey_index;
uint8_t friendship_credential_flag;
@ -99,7 +109,6 @@ typedef struct {
uint8_t retransmit;
} mesh_publication_model_t;
typedef void (*mesh_operation_handler)(struct mesh_model * mesh_model, mesh_pdu_t * pdu);
typedef struct {
uint32_t opcode;
@ -282,6 +291,13 @@ void mesh_access_transitions_add(mesh_transition_t * transition);
void mesh_access_transitions_remove(mesh_transition_t * transition);
uint8_t mesh_access_transactions_get_next_transaction_id(void);
// Mesh Model Publicaation
/**
* Inform Mesh Access that the state of a model has changed. may trigger state publication
*/
void mesh_access_state_changed(mesh_model_t * mesh_model);
// Mesh PDU Getter
uint16_t mesh_pdu_src(mesh_pdu_t * pdu);
uint16_t mesh_pdu_dst(mesh_pdu_t * pdu);