We are trying to implement models inside the mesh. So we've started with a functional example of the generic on off and tried to update it according to our needs.
The custom model
typedef struct __attribute((packed))
{
uint32_t tai_seconds;
} time_set_msg_pkt_t;
/** Mandatory parameters for the Time Set message. */
typedef struct
{
uint64_t tai_seconds;
} time_set_params_t;
Modified generic on off client logic for sending a different type of message:
time_set_msg_pkt_t msg;
msg.tai_seconds = 0x123456789A;
message_create(p_client, 0x5C,
(const uint8_t *) &msg, sizeof(time_set_msg_pkt_t),
&p_client->access_message.message);
On the other side we extract the data using the following snipped.
static inline bool set_params_validate(const access_message_rx_t * p_rx_msg, const time_set_msg_pkt_t * p_params)
{
printf("Validating received message length: %d \n", p_rx_msg->length);
printf("Extracted tai_seconds(hex): %x\n", p_params -> tai_seconds);
printf("Extracted tai_seconds(dec): %d\n", p_params -> tai_seconds);
return true;
}
static void handle_set(access_model_handle_t model_handle, const access_message_rx_t * p_rx_msg, void * p_args)
{
time_setup_server_t * p_server = (time_setup_server_t *) p_args;
time_set_params_t in_data = {0};
time_status_params_t out_data = {0};
const time_set_msg_pkt_t * p_msg_params_packed = (const time_set_msg_pkt_t *) p_rx_msg-> p_data;
printf("Extracting parameters data\n");
printf("Received data pointer: %x\n", p_rx_msg -> p_data);
printf("Received data(hex): %x\n", *p_rx_msg -> p_data);
if (set_params_validate(p_rx_msg, p_msg_params_packed))
{
}
}
Unfortunately this will result in the following output
Extracting parameters data
Received data pointer: 2000eb99
Received data(hex): 9a
Validating received message length: 8
Extracted tai_seconds(hex): 3456789a
Extracted tai_seconds(dec): 878082202
Where should i look for the extra 0x12 at the beginning of the message ( received 0x3456789a vs expected 0x123456789a )?