mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 22:20:37 +00:00
mesh: enumerate state model ids and update reasons
This commit is contained in:
parent
27c4ce3264
commit
09878d7ad7
@ -43,7 +43,6 @@
|
||||
#include "mesh_access.h"
|
||||
#include "btstack_memory.h"
|
||||
#include "btstack_debug.h"
|
||||
#include "bluetooth_company_id.h"
|
||||
#include "mesh_transport.h"
|
||||
#include "mesh_foundation.h"
|
||||
#include "btstack_tlv.h"
|
||||
@ -72,16 +71,17 @@ void mesh_access_init(void){
|
||||
mesh_upper_transport_register_access_message_handler(&mesh_access_message_process_handler);
|
||||
}
|
||||
|
||||
void mesh_access_emit_state_update_bool(btstack_packet_handler_t handler, uint8_t element_index, uint32_t model_identifier, uint32_t state_identifier, uint8_t reason, uint8_t value){
|
||||
void mesh_access_emit_state_update_bool(btstack_packet_handler_t handler, uint8_t element_index, uint32_t model_identifier,
|
||||
model_state_id_t state_identifier, model_state_update_reason_t reason, uint8_t value){
|
||||
if (!handler) return;
|
||||
uint8_t event[14] = {HCI_EVENT_MESH_META, 13, MESH_SUBEVENT_STATE_UPDATE_BOOL};
|
||||
int pos = 3;
|
||||
event[pos++] = element_index;
|
||||
little_endian_store_32(event, 3, model_identifier);
|
||||
pos += 4;
|
||||
little_endian_store_32(event, 3, state_identifier);
|
||||
little_endian_store_32(event, 3, (uint32_t)state_identifier);
|
||||
pos += 4;
|
||||
event[pos++] = reason;
|
||||
event[pos++] = (uint8_t)reason;
|
||||
event[pos++] = value;
|
||||
handler(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
}
|
||||
@ -98,6 +98,10 @@ uint16_t mesh_access_get_primary_element_address(void){
|
||||
return primary_element.unicast_address;
|
||||
}
|
||||
|
||||
uint8_t mesh_access_get_element_index(mesh_model_t * mesh_model){
|
||||
return mesh_model->element->unicast_address - mesh_access_get_primary_element_address();
|
||||
}
|
||||
|
||||
void mesh_access_set_primary_element_location(uint16_t location){
|
||||
primary_element.loc = location;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "btstack_linked_list.h"
|
||||
#include "ble/mesh/mesh_lower_transport.h"
|
||||
#include "mesh_keys.h"
|
||||
#include "bluetooth_company_id.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -56,6 +57,19 @@ extern "C"
|
||||
struct mesh_model;
|
||||
struct mesh_element;
|
||||
|
||||
typedef enum {
|
||||
MODEL_STATE_UPDATE_REASON_SET = 0x00u,
|
||||
// MODEL_STATE_UPDATE_REASON_TRANSITION_START,
|
||||
// MODEL_STATE_UPDATE_REASON_TRANSITION_ACTIVE,
|
||||
// MODEL_STATE_UPDATE_REASON_TRANSITION_END,
|
||||
// MODEL_STATE_UPDATE_REASON_BOUND_STATE,
|
||||
MODEL_STATE_UPDATE_REASON_APPLICATION_CHANGE
|
||||
} model_state_update_reason_t;
|
||||
|
||||
typedef enum {
|
||||
MODEL_STATE_ID_GENERIC_ON_OFF = (BLUETOOTH_COMPANY_ID_BLUETOOTH_SIG_INC << 16) | 0u,
|
||||
} model_state_id_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t address;
|
||||
uint16_t appkey_index;
|
||||
@ -155,6 +169,8 @@ void mesh_access_set_primary_element_location(uint16_t location);
|
||||
|
||||
void mesh_element_add(mesh_element_t * element);
|
||||
|
||||
uint8_t mesh_access_get_element_index(mesh_model_t * mesh_model);
|
||||
|
||||
mesh_element_t * mesh_element_for_unicast_address(uint16_t unicast_address);
|
||||
|
||||
void mesh_element_add_model(mesh_element_t * element, mesh_model_t * mesh_model);
|
||||
@ -191,7 +207,8 @@ mesh_model_t * mesh_model_get_configuration_server(void);
|
||||
|
||||
mesh_model_t * mesh_access_model_for_address_and_model_identifier(uint16_t element_address, uint32_t model_identifier, uint8_t * status);
|
||||
|
||||
void mesh_access_emit_state_update_bool(btstack_packet_handler_t handler, uint8_t element_index, uint32_t model_identifier, uint32_t state_identifier, uint8_t reason, uint8_t value);
|
||||
void mesh_access_emit_state_update_bool(btstack_packet_handler_t handler, uint8_t element_index, uint32_t model_identifier,
|
||||
model_state_id_t state_identifier, model_state_update_reason_t reason, uint8_t value);
|
||||
|
||||
// Mesh PDU Getter
|
||||
uint16_t mesh_pdu_src(mesh_pdu_t * pdu);
|
||||
|
@ -176,12 +176,13 @@ static void generic_on_off_set_handler(mesh_model_t *generic_on_off_server_model
|
||||
generic_on_off_server_state->delay_ms = 0;
|
||||
mesh_generic_on_off_status_message(generic_on_off_server_model, mesh_pdu_netkey_index(pdu), mesh_pdu_src(pdu), mesh_pdu_appkey_index(pdu));
|
||||
mesh_access_message_processed(pdu);
|
||||
// TODO
|
||||
uint8_t reason = 0;
|
||||
uint8_t value = on_off_value;
|
||||
uint8_t element_index = 0; // TODO generic_on_off_server_model->element_index?
|
||||
uint32_t state_identifier = 0; // TODO
|
||||
mesh_access_emit_state_update_bool(mesh_packet_handler, element_index, generic_on_off_server_model->model_identifier, state_identifier, reason, value);
|
||||
|
||||
mesh_access_emit_state_update_bool(mesh_packet_handler,
|
||||
mesh_access_get_element_index(generic_on_off_server_model),
|
||||
generic_on_off_server_model->model_identifier,
|
||||
MODEL_STATE_ID_GENERIC_ON_OFF,
|
||||
MODEL_STATE_UPDATE_REASON_SET,
|
||||
generic_on_off_server_state->current_on_off_value);
|
||||
}
|
||||
|
||||
// static void generic_on_off_set_unacknowledged_handler(mesh_model_t *mesh_model, mesh_pdu_t * pdu){
|
||||
|
Loading…
x
Reference in New Issue
Block a user