mesh: support generic level server move set message

This commit is contained in:
Matthias Ringwald 2019-11-14 15:39:24 +01:00
parent 43e3439045
commit b66ef5c943
3 changed files with 28 additions and 12 deletions

View File

@ -368,7 +368,7 @@ void mesh_access_transitions_setup(mesh_transition_t * transition, mesh_model_t
// Only values of 0x00 through 0x3E shall be used to specify the value of the Transition Number of Steps field
uint8_t num_steps = mesh_access_transitions_num_steps_from_gdtt(transition_time_gdtt);
if (num_steps > 0x3E) return;
if (num_steps >= MESH_TRANSITION_NUM_STEPS_INFINITE) return;
transition->state = MESH_TRANSITION_STATE_IDLE;
transition->phase_start_ms = 0;

View File

@ -90,6 +90,8 @@ typedef enum {
#define MESH_MAX_NUM_FAULTS 5
#define MESH_TRANSITION_NUM_STEPS_INFINITE 0x3f
typedef struct {
// linked list item
btstack_linked_item_t item;

View File

@ -54,7 +54,6 @@
#include "mesh/mesh_network.h"
#include "mesh/mesh_upper_transport.h"
static void generic_server_send_message(uint16_t src, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, mesh_pdu_t *pdu){
uint8_t ttl = mesh_foundation_default_ttl_get();
mesh_upper_transport_setup_access_pdu_header(pdu, netkey_index, appkey_index, ttl, src, dest, 0);
@ -159,7 +158,11 @@ static void mesh_server_transition_step(mesh_transition_t * base_transition, tra
case MESH_TRANSITION_STATE_ACTIVE:
if (event != TRANSITION_UPDATE) break;
time_step_ms = current_timestamp_ms - transition->base_transition.phase_start_ms;
if (transition->base_transition.remaining_transition_time_ms > time_step_ms){
if (transition->base_transition.num_steps == MESH_TRANSITION_NUM_STEPS_INFINITE){
mesh_server_transition_state_update_stepwise_value(transition);
// done when max value reached
if (transition->current_value > - 32768 && transition->current_value < 32767) break;
} else if (transition->base_transition.remaining_transition_time_ms > time_step_ms){
transition->base_transition.remaining_transition_time_ms -= time_step_ms;
transition->base_transition.phase_start_ms += time_step_ms;
mesh_server_transition_state_update_stepwise_value(transition);
@ -215,7 +218,12 @@ static mesh_pdu_t * mesh_generic_level_status_message(mesh_model_t *generic_leve
// setup message
mesh_transport_pdu_t * transport_pdu = NULL;
if (state->transition_data.base_transition.remaining_transition_time_ms != 0) {
uint8_t remaining_time = mesh_access_time_as_gdtt(state->transition_data.base_transition.step_duration_ms, state->transition_data.base_transition.remaining_transition_time_ms);
uint8_t remaining_time;
if (state->transition_data.base_transition.num_steps == MESH_TRANSITION_NUM_STEPS_INFINITE){
remaining_time = MESH_TRANSITION_NUM_STEPS_INFINITE;
} else {
remaining_time = mesh_access_time_as_gdtt(state->transition_data.base_transition.step_duration_ms, state->transition_data.base_transition.remaining_transition_time_ms);
}
transport_pdu = mesh_access_setup_segmented_message(&mesh_generic_level_status_transition, state->transition_data.current_value,
state->transition_data.target_value, remaining_time);
} else {
@ -274,7 +282,7 @@ static void generic_level_handle_set_move_message(mesh_model_t *mesh_model, mesh
mesh_access_parser_state_t parser;
mesh_access_parser_init(&parser, (mesh_pdu_t*) pdu);
int32_t increment_value = mesh_access_parser_get_u16(&parser);
int32_t delta_value = (int32_t) mesh_access_parser_get_u16(&parser);
// The TID field is a transaction identifier indicating whether the message is
// a new message or a retransmission of a previously sent message
@ -286,8 +294,11 @@ static void generic_level_handle_set_move_message(mesh_model_t *mesh_model, mesh
// Generic Default Transition Time format - num_steps (higher 6 bits), step_resolution (lower 2 bits)
transition_time_gdtt = mesh_access_parser_get_u8(&parser);
delay_time_gdtt = mesh_access_parser_get_u8(&parser);
} else {
// transition speed is delta / num steps, without num steps, and without a default transition time, we cannot do this
return;
}
mesh_transition_t * base_transition = generic_level_server_get_base_transition(mesh_model);
switch (mesh_access_transitions_transaction_status(base_transition, tid, mesh_pdu_src(pdu), mesh_pdu_dst(pdu))){
@ -297,18 +308,21 @@ static void generic_level_handle_set_move_message(mesh_model_t *mesh_model, mesh
default:
mesh_access_transitions_setup_transaction(base_transition, tid, mesh_pdu_src(pdu), mesh_pdu_dst(pdu));
int num_steps = mesh_access_transitions_num_steps_from_gdtt(transition_time_gdtt);
generic_level_server_state->transition_data.initial_value = generic_level_server_state->transition_data.current_value;
generic_level_server_state->transition_data.target_value = add_and_clip_int16(generic_level_server_state->transition_data.current_value, increment_value);
generic_level_server_state->transition_data.stepwise_value_increment = increment_value;
generic_level_server_state->transition_data.target_value = add_and_clip_int16(generic_level_server_state->transition_data.current_value, delta_value);
generic_level_server_state->transition_data.stepwise_value_increment = delta_value / num_steps;
generic_level_server_state->transition_data.delta_from_initial_value = 0;
int num_steps = mesh_access_transitions_num_steps_from_gdtt(transition_time_gdtt);
if (num_steps > 0){
// TODO: remove division
generic_level_server_state->transition_data.target_value = add_and_clip_int16(generic_level_server_state->transition_data.current_value, increment_value * num_steps);
if (delta_value > 0){
generic_level_server_state->transition_data.target_value = 32767;
} else {
generic_level_server_state->transition_data.target_value = -32768;
}
mesh_server_transition_setup_transition_or_instantaneous_update_int16(mesh_model, transition_time_gdtt, delay_time_gdtt, MODEL_STATE_UPDATE_REASON_SET);
generic_level_server_state->transition_data.base_transition.num_steps = MESH_TRANSITION_NUM_STEPS_INFINITE;
break;
}
}