21
21
#include "health_cli.h"
22
22
#include "esp_ble_mesh_health_model_api.h"
23
23
24
- extern s32_t health_msg_timeout ;
25
-
26
24
/* Health Client Model related functions */
27
25
28
26
static inline void btc_ble_mesh_health_client_cb_to_app (esp_ble_mesh_health_client_cb_event_t event ,
@@ -251,7 +249,6 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
251
249
{
252
250
esp_ble_mesh_health_client_cb_param_t cb_params = {0 };
253
251
esp_ble_mesh_client_common_param_t params = {0 };
254
- size_t length = 0U ;
255
252
uint8_t act = 0U ;
256
253
257
254
if (!model || !ctx ) {
@@ -292,8 +289,7 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
292
289
cb_params .params = & params ;
293
290
294
291
if (val && len ) {
295
- length = (len <= sizeof (cb_params .status_cb )) ? len : sizeof (cb_params .status_cb );
296
- memcpy (& cb_params .status_cb , val , length );
292
+ memcpy (& cb_params .status_cb , val , MIN (len , sizeof (cb_params .status_cb )));
297
293
}
298
294
299
295
btc_ble_mesh_health_client_callback (& cb_params , act );
@@ -317,7 +313,7 @@ void btc_ble_mesh_health_publish_callback(u32_t opcode, struct bt_mesh_model *mo
317
313
static int btc_ble_mesh_health_client_get_state (esp_ble_mesh_client_common_param_t * params ,
318
314
esp_ble_mesh_health_client_get_state_t * get )
319
315
{
320
- struct bt_mesh_msg_ctx ctx = {0 };
316
+ bt_mesh_client_common_param_t param = {0 };
321
317
322
318
if (params == NULL ) {
323
319
BT_ERR ("%s, Invalid parameter" , __func__ );
@@ -329,23 +325,25 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param
329
325
return - EINVAL ;
330
326
}
331
327
332
- ctx .net_idx = params -> ctx .net_idx ;
333
- ctx .app_idx = params -> ctx .app_idx ;
334
- ctx .addr = params -> ctx .addr ;
335
- ctx .send_rel = params -> ctx .send_rel ;
336
- ctx .send_ttl = params -> ctx .send_ttl ;
337
-
338
- health_msg_timeout = params -> msg_timeout ;
328
+ param .opcode = params -> opcode ;
329
+ param .model = (struct bt_mesh_model * )params -> model ;
330
+ param .ctx .net_idx = params -> ctx .net_idx ;
331
+ param .ctx .app_idx = params -> ctx .app_idx ;
332
+ param .ctx .addr = params -> ctx .addr ;
333
+ param .ctx .send_rel = params -> ctx .send_rel ;
334
+ param .ctx .send_ttl = params -> ctx .send_ttl ;
335
+ param .msg_timeout = params -> msg_timeout ;
336
+ param .msg_role = params -> msg_role ;
339
337
340
- switch (params -> opcode ) {
338
+ switch (param . opcode ) {
341
339
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET :
342
- return bt_mesh_health_attention_get (& ctx );
340
+ return bt_mesh_health_attention_get (& param );
343
341
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET :
344
- return bt_mesh_health_period_get (& ctx );
342
+ return bt_mesh_health_period_get (& param );
345
343
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET :
346
- return bt_mesh_health_fault_get (& ctx , get -> fault_get .company_id );
344
+ return bt_mesh_health_fault_get (& param , get -> fault_get .company_id );
347
345
default :
348
- BT_ERR ("Invalid Health Get opcode 0x%04x" , params -> opcode );
346
+ BT_ERR ("Invalid Health Get opcode 0x%04x" , param . opcode );
349
347
return - EINVAL ;
350
348
}
351
349
@@ -355,40 +353,42 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param
355
353
static int btc_ble_mesh_health_client_set_state (esp_ble_mesh_client_common_param_t * params ,
356
354
esp_ble_mesh_health_client_set_state_t * set )
357
355
{
358
- struct bt_mesh_msg_ctx ctx = {0 };
356
+ bt_mesh_client_common_param_t param = {0 };
359
357
360
358
if (params == NULL || set == NULL ) {
361
359
BT_ERR ("%s, Invalid parameter" , __func__ );
362
360
return - EINVAL ;
363
361
}
364
362
365
- ctx .net_idx = params -> ctx .net_idx ;
366
- ctx .app_idx = params -> ctx .app_idx ;
367
- ctx .addr = params -> ctx .addr ;
368
- ctx .send_rel = params -> ctx .send_rel ;
369
- ctx .send_ttl = params -> ctx .send_ttl ;
363
+ param .opcode = params -> opcode ;
364
+ param .model = (struct bt_mesh_model * )params -> model ;
365
+ param .ctx .net_idx = params -> ctx .net_idx ;
366
+ param .ctx .app_idx = params -> ctx .app_idx ;
367
+ param .ctx .addr = params -> ctx .addr ;
368
+ param .ctx .send_rel = params -> ctx .send_rel ;
369
+ param .ctx .send_ttl = params -> ctx .send_ttl ;
370
+ param .msg_timeout = params -> msg_timeout ;
371
+ param .msg_role = params -> msg_role ;
370
372
371
- health_msg_timeout = params -> msg_timeout ;
372
-
373
- switch (params -> opcode ) {
373
+ switch (param .opcode ) {
374
374
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET :
375
- return bt_mesh_health_attention_set (& ctx , set -> attention_set .attention , true);
375
+ return bt_mesh_health_attention_set (& param , set -> attention_set .attention , true);
376
376
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK :
377
- return bt_mesh_health_attention_set (& ctx , set -> attention_set .attention , false);
377
+ return bt_mesh_health_attention_set (& param , set -> attention_set .attention , false);
378
378
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET :
379
- return bt_mesh_health_period_set (& ctx , set -> period_set .fast_period_divisor , true);
379
+ return bt_mesh_health_period_set (& param , set -> period_set .fast_period_divisor , true);
380
380
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK :
381
- return bt_mesh_health_period_set (& ctx , set -> period_set .fast_period_divisor , false);
381
+ return bt_mesh_health_period_set (& param , set -> period_set .fast_period_divisor , false);
382
382
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST :
383
- return bt_mesh_health_fault_test (& ctx , set -> fault_test .company_id , set -> fault_test .test_id , true);
383
+ return bt_mesh_health_fault_test (& param , set -> fault_test .company_id , set -> fault_test .test_id , true);
384
384
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK :
385
- return bt_mesh_health_fault_test (& ctx , set -> fault_test .company_id , set -> fault_test .test_id , false);
385
+ return bt_mesh_health_fault_test (& param , set -> fault_test .company_id , set -> fault_test .test_id , false);
386
386
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR :
387
- return bt_mesh_health_fault_clear (& ctx , set -> fault_clear .company_id , true);
387
+ return bt_mesh_health_fault_clear (& param , set -> fault_clear .company_id , true);
388
388
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK :
389
- return bt_mesh_health_fault_clear (& ctx , set -> fault_clear .company_id , false);
389
+ return bt_mesh_health_fault_clear (& param , set -> fault_clear .company_id , false);
390
390
default :
391
- BT_ERR ("Invalid Health Set opcode 0x%04x" , params -> opcode );
391
+ BT_ERR ("Invalid Health Set opcode 0x%04x" , param . opcode );
392
392
return - EINVAL ;
393
393
}
394
394
@@ -399,7 +399,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
399
399
{
400
400
btc_ble_mesh_health_client_args_t * arg = NULL ;
401
401
esp_ble_mesh_health_client_cb_param_t cb = {0 };
402
- bt_mesh_role_param_t role_param = {0 };
403
402
404
403
if (!msg || !msg -> arg ) {
405
404
BT_ERR ("%s, Invalid parameter" , __func__ );
@@ -411,12 +410,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
411
410
switch (msg -> act ) {
412
411
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE : {
413
412
cb .params = arg -> health_client_get_state .params ;
414
- role_param .model = (struct bt_mesh_model * )cb .params -> model ;
415
- role_param .role = cb .params -> msg_role ;
416
- if (bt_mesh_set_client_model_role (& role_param )) {
417
- BT_ERR ("Failed to set model role" );
418
- break ;
419
- }
420
413
cb .error_code = btc_ble_mesh_health_client_get_state (arg -> health_client_get_state .params ,
421
414
arg -> health_client_get_state .get_state );
422
415
if (cb .error_code ) {
@@ -427,12 +420,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
427
420
}
428
421
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE : {
429
422
cb .params = arg -> health_client_set_state .params ;
430
- role_param .model = (struct bt_mesh_model * )cb .params -> model ;
431
- role_param .role = cb .params -> msg_role ;
432
- if (bt_mesh_set_client_model_role (& role_param )) {
433
- BT_ERR ("Failed to set model role" );
434
- break ;
435
- }
436
423
cb .error_code = btc_ble_mesh_health_client_set_state (arg -> health_client_set_state .params ,
437
424
arg -> health_client_set_state .set_state );
438
425
if (cb .error_code ) {
0 commit comments