Nordic Semiconductor nRF5 AirFuel SDK  version 2.2.0
ptu_conn_man.c
Go to the documentation of this file.
1 /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.
2  *
3  * The information contained herein is property of Nordic Semiconductor ASA.
4  * Terms and conditions of usage are described in detail in NORDIC
5  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
6  *
7  * Licensees are granted free, non-transferable use of the information. NO
8  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
9  * the file.
10  *
11  */
12 
15 #include <stdint.h>
16 #include <string.h>
17 #include <stdlib.h>
18 
19 #include "nrf_assert.h"
20 #include "ble_hci.h"
21 #include "ptu_sensors.h"
22 #include "ptu_conn_man.h"
23 #include "ptu_power_ctl.h"
25 
26 
27 /******************************************************************************/
30 /******************************************************************************/
31 
33 typedef enum
34 {
39 
40 typedef struct
41 {
42  ble_gap_addr_t prev_received_adv_packet_addr;
43  ble_gap_addr_t curr_device_connecting;
44  ble_gap_scan_params_t scan_params;
45  uint32_t time_set_p_tx_in_reference;
46  ptu_cm_time_set_state_t time_set_state;
47  bool scanning_reqested;
48  bool scanning;
49  bool connecting;
50  bool mode_trans_in_progess;
51  uint8_t ignored_adv_from_same_pru_cnt;
52  uint8_t nof_connections;
53  uint32_t ticks_at_mt_end;
54 } ptu_cm_status_t;
55 
56 typedef struct {
57  uint8_t nof_samples_taken;
58  uint8_t variation_duration;
59  bool load_variation;
60 } ptu_cm_timeset_data_t;
61 
62 APP_TIMER_DEF(m_mode_trans_timer_id);
63 APP_TIMER_DEF(m_time_set_check_timer_id);
64 static ptu_cm_status_t m_status;
67  .option_valid_max_res = BLE_WPTS_PTU_STATIC_MAX_LOAD_RESISTANCE_VALID,
68  .ptu_power = BLE_WPTS_PTU_POWER,
69  .ptu_max_source_impedance = BLE_WPTS_PTU_STATIC_MAX_SOURCE_IMPEDANCE_VAL,
70  .ptu_max_load_resistance = BLE_WPTS_PTU_STATIC_MAX_LOAD_RESISTANCE_VAL,
71  .ptu_class = PTU_CLASS,
72  .hardware_rev = PTU_HW_REVISION,
73  .firmware_rev = PTU_FW_REVISION,
74  .protocol_rev = PTU_PROTOCOL_REVISION,
75  .devices_supported_bitval = BLE_WPTS_PTU_STATIC_NUM_DEVICES_BITVAL};
78 
79 static const ble_gap_conn_params_t m_conn_params = {
80  .min_conn_interval = PTU_MIN_CONN_INTERVAL,
81  .max_conn_interval = PTU_MAX_CONN_INTERVAL,
82  .slave_latency = PTU_SLAVE_LATENCY,
83  .conn_sup_timeout = PTU_CONN_SUP_TIMEOUT};
90 static void m_connect(ble_gap_addr_t const * p_addr)
91 {
92  ble_gap_scan_params_t scan_params;
93  uint32_t err_code, diff;
94 
95  if(m_status.connecting || m_status.nof_connections >= PTU_MAX_CONNECTIONS || p_addr == NULL)
96  return;
97 
98  m_status.connecting = true;
99  m_status.scanning = false;
100 
101  memcpy(&m_status.curr_device_connecting, p_addr, sizeof(ble_gap_addr_t));
102 
103  memcpy(&scan_params, &m_status.scan_params, sizeof(scan_params));
104  scan_params.timeout = 1;
105 
106  if(m_status.mode_trans_in_progess)
107  {
108  // Can safely assume that ticks now is lower than TICKS_AT_MT
109  uint32_t ticks_now;
110 
111  err_code = app_timer_cnt_get(&ticks_now);
112  APP_ERROR_CHECK(err_code);
113 
114  diff = ticks_diff(m_status.ticks_at_mt_end, ticks_now) / 32000 ;
115  scan_params.timeout += diff;
116  }
117 
118  do
119  {
120  err_code = sd_ble_gap_connect(p_addr, &scan_params, &m_conn_params);
121  }while(err_code == NRF_ERROR_BUSY);
122 
123  APP_ERROR_CHECK(err_code);
124 }
125 
126 
132 static void m_disconnect(uint16_t conn_handle)
133 {
134  uint32_t err_code = sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
135 
136  if((err_code != NRF_ERROR_INVALID_STATE) && (err_code != BLE_ERROR_INVALID_CONN_HANDLE))
137  APP_ERROR_CHECK(err_code);
138 }
139 
140 
141 static void m_on_fully_accepted_adv_packet(ptu_reg_item_t * reg_item_p, ble_gap_evt_adv_report_t * p_adv_report);
142 
148 static void m_connection_init(ptu_reg_item_t * reg_item)
149 {
150  uint32_t err_code;
151 
152  ASSERT(reg_item != NULL);
154 
155  err_code = app_timer_stop(reg_item->timer_id);
156  APP_ERROR_CHECK(err_code);
157 
158  // Start registrartion timer for this registry item
159  err_code = app_timer_start(reg_item->timer_id, APP_TIMER_TICKS(PTU_REG_TIMEOUT_MS, APP_TIMER_PRESCALER), reg_item);
160  APP_ERROR_CHECK(err_code);
161 }
162 
163 
164 // On registration timeout
165 static void m_on_reg_timeout(ptu_reg_item_t * reg_item_p)
166 {
167  uint32_t err_code;
168 
169  ptu_cm_remove_device(reg_item_p);
170 
171  if(m_status.connecting)
172  {
173  err_code = sd_ble_gap_connect_cancel();
174  APP_ERROR_CHECK(err_code);
175 
176  m_status.connecting = false;
177  }
178 
179  m_sm_handler(PTU_SM_SIGNAL_REGISTRATION_TIMEOUT);
180 
181  // This is needed to get PTU from Power Transfer to Power Save fast when a reconnection times out.
182  if(m_status.nof_connections == 0)
183  {
184  m_sm_handler(PTU_SM_SIGNAL_ALL_DEVICES_DISCONNECTED);
185  }
186 }
187 
188 static void m_mode_trans_timer_handle(void * p_context)
189 {
190  if(m_status.nof_connections == 0)
191  {
192  m_sm_handler(PTU_SM_SIGNAL_ALL_DEVICES_DISCONNECTED);
193  }
194 
195  m_status.ticks_at_mt_end = 0;
196  m_status.mode_trans_in_progess = false;
197 }
198 
199 static void m_set_reg_item_fully_accepted(ptu_reg_item_t * reg_item_p)
200 {
201  #if PTU_REVOKE_ACCEPTED_STATE
202  uint32_t err_code;
203  uint32_t ptu_revoke_accepted_state_timeout_ms = PTU_REVOKE_ACCEPTED_STATE_NON_POWER_SAVE_MS;
204 
205  if(PTU_SM_CURRENT_STATE() == PTU_SM_STATE_POWER_SAVE)
206  {
207  ptu_revoke_accepted_state_timeout_ms = PTU_REVOKE_ACCEPTED_STATE_POWER_SAVE_MS;
208  }
209 
210  err_code = TIMER_START( reg_item_p->timer_id, ptu_revoke_accepted_state_timeout_ms, reg_item_p);
211  APP_ERROR_CHECK(err_code);
212  #endif // PTU_REVOKE_ACCEPTED_STATE == true
213 
214  reg_item_p->state = REG_ITEM_STATE_FULLY_ACCEPTED;
215 }
216 
217 static void m_reg_timer_handle(void * p_context)
218 {
219  ptu_reg_item_t * reg_item_p;
220  reg_item_p = p_context;
221 
222  if(reg_item_p->state == REG_ITEM_STATE_PRE_CONNECT) // 1700 ms Timeout, accept advertisement.
223  {
224  m_set_reg_item_fully_accepted(reg_item_p);
225  }
226 
227  else // Registration timeout
228  {
229  m_on_reg_timeout(p_context);
230  }
231 }
232 
233 static void m_send_ctrl_denied_due_to_cc(ptu_reg_item_t * reg_item_p)
234 {
235  // Send control packet stating that PRU will not be allowed to charge due to cross connection
236  memset(&reg_item_p->prev_ctl, 0, sizeof(pru_control_t));
238  reg_item_p->pending_ctl_write = true;
239  reg_item_p->pending_charge_disable = true;
240 
241  while(ble_wpts_c_send_pru_control(&reg_item_p->ble_wpts_c, &reg_item_p->prev_ctl) == BLE_ERROR_NO_TX_PACKETS)
242  {
243  ;
244  }
245  // Device will now be removed from registry and disconnected once control write response arrives.
246 }
247 
248 static void m_stop_time_set_procedure(ptu_cm_timeset_data_t * p_ts)
249 {
250  uint32_t err_code;
251 
252  err_code = app_timer_stop(m_time_set_check_timer_id);
253  APP_ERROR_CHECK(err_code);
254 
255  ptu_power_ctrl_set_disable_power_amplifier_adjustments(false); // Re-enable adjustments of I_TX_COIL
256 
257  p_ts->nof_samples_taken = 0;
258  p_ts->variation_duration = 0;
259  p_ts->load_variation = false;
260 }
261 
270 static void m_ptu_time_set_check_timer_handler(void * p_context)
271 {
272  static ptu_cm_timeset_data_t ts;
273  uint32_t err_code;
274  const ptu_sensor_data_t * sensor_data;
275  ptu_reg_item_t * reg_item_p = p_context;
276 
277  err_code = ptu_sensors_read();
278  APP_ERROR_CHECK(err_code);
279 
280  err_code = ptu_sensors_data_get(&sensor_data);
281  APP_ERROR_CHECK(err_code);
282 
283  if(abs(sensor_data->p_tx_in - m_status.time_set_p_tx_in_reference) >= PTU_P_TX_IN_LOAD_DETECT)
284  {
285  ts.variation_duration+= 2;
286  ts.load_variation = true;
287  }
288  // load variation has stopped, check length
289  else if(ts.load_variation)
290  {
291  if(ts.variation_duration >= PTU_TIME_SET_LOWER_LIMIT_MS &&
292  ts.variation_duration <= PTU_TIME_SET_UPPER_LIMIT_MS)
293  {
294  m_stop_time_set_procedure(&ts);
295  }
296  // reset time set data in case valid variation is found later
297  ts.variation_duration = 0;
298  ts.load_variation = false;
299  }
300 
301  // > 500 ms has passed with no valid time set load found.
302  if(ts.nof_samples_taken++ >= PTU_TIME_SET_500_MS_OF_SAMPLES)
303  {
304  m_stop_time_set_procedure(&ts);
305  m_send_ctrl_denied_due_to_cc(reg_item_p);
306  }
307 }
308 
314 static void m_scan_maintain(void)
315 {
316  uint32_t err_code;
317 
318  // Shall we start scanning?
319  if(m_status.scanning_reqested && !m_status.scanning && !m_status.connecting)
320  {
321  if(ptu_reg_n_entries_get() == 0)
322  {
323  m_status.scan_params.window = PTU_POWER_SAVE_STATE_SCAN_WINDOW;
324  m_status.scan_params.interval = PTU_POWER_SAVE_STATE_SCAN_INTERVAL;
325  }
326  else
327  {
328  m_status.scan_params.window = PTU_NORMAL_SCAN_WINDOW;
329  m_status.scan_params.interval = PTU_NORMAL_SCAN_INTERVAL;
330  }
331 
332  do{
333  err_code = sd_ble_gap_scan_start(&m_status.scan_params);
334  }while(err_code != NRF_SUCCESS);
335 
336  //m_reconnect_enable = true;
337  m_status.scanning = true;
338  }
339 
340  // Shall we stop scanning?
341  if(!m_status.scanning_reqested && m_status.scanning)
342  {
343  if(m_status.scanning)
344  {
345  do{
346  err_code = sd_ble_gap_scan_stop();
347  }while(err_code != NRF_SUCCESS);
348  m_status.scanning = false;
349  }
350  }
351 }
352 
353 static bool m_imp_shift_required(uint8_t adv_flags)
354 {
355  uint8_t pru_category;
357  return !(pru_category == BLE_WPTS_PRU_CATEGORY_NO_IMP_SHIFT);
358 }
359 
360 static void m_update_pre_connect_adv_cnt_for_reg_item(ptu_reg_item_t * reg_item_p)
361 {
362  uint32_t err_code;
363 
364  // If this is the first adv packet from this PRU
365  if(reg_item_p->pre_connect_cnt == 0)
366  {
367  err_code = app_timer_start(reg_item_p->timer_id, APP_TIMER_TICKS(PTU_ADV_IGNORE_TIMEOUT_MS, APP_TIMER_PRESCALER), reg_item_p);
368  APP_ERROR_CHECK(err_code);
369  }
370 
372  {
373  reg_item_p->pre_connect_cnt++;
374  }
375 
376  // If PTU has received enough advertisements from PRU connect to it
377  if(reg_item_p->pre_connect_cnt >= (PTU_ADV_PRE_CONNECT_ALLOW - 1)) // Do "-1" so that the 11th packet is actually accepted.
378  {
379  m_set_reg_item_fully_accepted(reg_item_p);
380  }
381 }
382 
383 static void m_ensure_device_is_in_registry(ptu_reg_item_t ** reg_item_p, ble_gap_evt_adv_report_t * p_adv_report, ptu_reg_item_state_t init_state)
384 {
385  if (*reg_item_p == NULL)
386  *reg_item_p = ptu_reg_item_add(p_adv_report, init_state);
387 
388  // If PRU not added to registry so far
389  if(*reg_item_p == NULL)
390  {
391  // Delete oldest PRU with REG_ITEM_STATE_PRE_CONNECT from registry to make room.
393  if(*reg_item_p != NULL)
394  {
395  ptu_reg_item_delete(*reg_item_p);
396  }
397  else // No registry item with state PRE_CONNECT, look for FULLY ACCEPTED.
398  {
400  if(*reg_item_p != NULL)
401  ptu_reg_item_delete(*reg_item_p);
402  else
403  return;
404  }
405  // Attempt again adding the PRU to the registry
406  *reg_item_p = ptu_reg_item_add(p_adv_report, init_state);
407  }
408 }
409 
410 static bool m_load_var_detected(void)
411 {
412  uint32_t err_code;
413  const ptu_sensor_data_t * sensor_data;
414  err_code = ptu_sensors_data_get(&sensor_data);
415  APP_ERROR_CHECK(err_code);
416  return sensor_data->load_var_detected;
417 }
418 
419 static void m_on_partially_accepted_adv_packet(ptu_reg_item_t * reg_item_p, ble_gap_evt_adv_report_t * p_adv_report)
420 {
421  m_ensure_device_is_in_registry(&reg_item_p, p_adv_report, REG_ITEM_STATE_PRE_CONNECT);
422 
423  // If PRU has been added to registry
424  if(reg_item_p != NULL && reg_item_p->state == REG_ITEM_STATE_PRE_CONNECT)
425  {
426  m_update_pre_connect_adv_cnt_for_reg_item(reg_item_p);
427  }
428 }
429 
430 static void m_on_fully_accepted_adv_packet(ptu_reg_item_t * reg_item_p, ble_gap_evt_adv_report_t * p_adv_report)
431 {
432  if(p_adv_report != NULL)
433  m_ensure_device_is_in_registry(&reg_item_p, p_adv_report, REG_ITEM_STATE_WAITING_TO_CONNECT);
434 
435  if(reg_item_p != NULL)
436  {
437  m_connection_init(reg_item_p);
438  m_sm_handler(PTU_SM_SIGNAL_PRU_ADV_RCVD);
439  }
440 }
441 
447 static void m_on_wpt_adv_report(ble_evt_t * p_ble_evt, uint8_t adv_flags)
448 {
449  ptu_reg_item_t * reg_item_p;
450  bool imp_shift_ok, rssi_ok, fully_accepted, state_ok;
451 
452 #ifndef PTU_DISABLE_DISTANT_LIST
453  ptu_dlh_on_wpt_adv_report(&p_ble_evt->evt.gap_evt.params.adv_report.peer_addr, adv_flags);
454 #endif //PTU_DISABLE_DISTANT_LIST
455 
456  if( !ptu_dlh_device_is_in_distant_list(&p_ble_evt->evt.gap_evt.params.adv_report.peer_addr) &&
457  (ptu_sm_execute(PTU_SM_SIGNAL_NULL, NULL) != PTU_SM_STATE_LOW_POWER || ptu_reg_n_entries_get() == 0))
458  {
459  reg_item_p = ptu_reg_item_get_from_address(&p_ble_evt->evt.gap_evt.params.adv_report.peer_addr);
460 
461  if(reg_item_p != NULL && reg_item_p->reconnect)
462  {
463  reg_item_p->reconnect = false;
464  m_connect(&reg_item_p->address);
465  }
466 
467  else
468  {
469  state_ok = (reg_item_p == NULL || reg_item_p->state == REG_ITEM_STATE_PRE_CONNECT || reg_item_p->state == REG_ITEM_STATE_FULLY_ACCEPTED);
470  rssi_ok = ((p_ble_evt->evt.gap_evt.params.adv_report.rssi > PTU_ADV_PWR_MIN) || !PTU_CCA_RSSI_ENABLE);
471  imp_shift_ok = ((m_imp_shift_required(adv_flags) && m_load_var_detected()) || (!m_imp_shift_required(adv_flags) || !PTU_CCA_ADV_IMP_SHIFT_ENABLE));
472  fully_accepted = (rssi_ok && imp_shift_ok) || reg_item_p->state == REG_ITEM_STATE_FULLY_ACCEPTED;
473 
474  // If all connection conditions are fulfilled
475  if(fully_accepted && state_ok)
476  {
477  m_on_fully_accepted_adv_packet(reg_item_p, &p_ble_evt->evt.gap_evt.params.adv_report);
478  }
479  // If one of the connection conditions are fulfilled
480  else if(rssi_ok || imp_shift_ok)
481  {
482  m_on_partially_accepted_adv_packet(reg_item_p, &p_ble_evt->evt.gap_evt.params.adv_report);
483  }
484  }
485  }
486 }
487 
492 static void m_on_scan_response(ble_evt_t * p_ble_evt)
493 {
494  ptu_reg_item_t * reg_item_p;
495 
496  reg_item_p = ptu_reg_item_get_from_address(&p_ble_evt->evt.gap_evt.params.adv_report.peer_addr);
497 
498  // Only care about scan response from devices added to registry
499  if( reg_item_p != NULL &&
501  {
502  m_connect(&reg_item_p->address);
503 
504  reg_item_p->state = REG_ITEM_STATE_CONNECTING;
505  }
506 }
507 
508 static void m_device_registration_complete(ptu_reg_item_t * reg_item_p)
509 {
510  uint32_t err_code;
511 
512  err_code = app_timer_stop(reg_item_p->timer_id);
513  APP_ERROR_CHECK(err_code);
514 
515  // Mode transition handling
516  m_status.mode_trans_in_progess = false;
517  err_code = app_timer_stop(m_mode_trans_timer_id);
518  APP_ERROR_CHECK(err_code);
519 
520  reg_item_p->state = REG_ITEM_STATE_REGISTERED;
521 }
522 
528 static void m_on_evt_connected(ble_evt_t * p_ble_evt)
529 {
530  ptu_reg_item_t * reg_item_p;
531  uint32_t err_code;
532  reg_item_p = ptu_reg_item_get_from_address(&p_ble_evt->evt.gap_evt.params.connected.peer_addr);
533 
534  ASSERT(m_status.connecting);
535  m_status.connecting = false;
536  m_status.nof_connections++;
537 
538  if(reg_item_p != NULL)
539  {
540  // State is 'REGISTERED' if it is a reconnection, otherwise it is 'CONNECTING'
541  ASSERT(reg_item_p->state == REG_ITEM_STATE_CONNECTING || reg_item_p->state == REG_ITEM_STATE_REGISTERED);
542  reg_item_p->ble_wpts_c.conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
543 
544  memset(&m_status.curr_device_connecting, 0, sizeof(ble_gap_addr_t));
545 
546  // Connection is of a new device, perform registration
547  if(reg_item_p->state == REG_ITEM_STATE_CONNECTING)
548  {
550  err_code = ble_wpts_c_read_pru_static(&(reg_item_p -> ble_wpts_c));
552  }
553 
554  // Connection is a reconnection
555  else if(reg_item_p->state == REG_ITEM_STATE_REGISTERED)
556  {
557  // Stop reconnection timeout timer
558  err_code = app_timer_stop(reg_item_p->timer_id);
559  APP_ERROR_CHECK(err_code);
560 
561  // Re-send PRU control packet to ensure it is set to same state as before reconnection
562  err_code = ble_wpts_c_send_pru_control(&reg_item_p->ble_wpts_c, &reg_item_p->prev_ctl);
563  APP_ERROR_CHECK(err_code);
564  }
565 
566  }
567  else
568  {
569  m_disconnect(p_ble_evt->evt.common_evt.conn_handle);
570  }
571 }
572 
577 static void m_on_evt_timeout(ble_evt_t * p_ble_evt)
578 {
579  ptu_reg_item_t * reg_item_p;
580 
581  // If connection timeout
582  if(p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_CONN)
583  {
584  ASSERT(m_status.connecting);
585 
586  m_status.connecting = false;
587 
588  reg_item_p = ptu_reg_item_get_from_address(&m_status.curr_device_connecting);
589 
590  if(reg_item_p == NULL)
591  return;
592 
593  ptu_reg_item_delete(reg_item_p);
594 
595  if(m_status.nof_connections == 0)
596  {
597  m_sm_handler(PTU_SM_SIGNAL_ALL_DEVICES_DISCONNECTED);
598  }
599  }
600  else if(p_ble_evt->evt.gap_evt.params.timeout.src == BLE_GAP_TIMEOUT_SRC_SECURITY_REQUEST)
601  {
602  // We will not perform any handling if security request times out. This is done to be compatible with wrongly implemented devices.
603  }
604 }
605 
610 static void m_on_evt_disconnected(ble_evt_t * p_ble_evt)
611 {
612  const ptu_sensor_data_t * p_sensor_data;
613  ptu_reg_item_t * reg_item_p;
614  uint32_t err_code;
615  uint8_t zero_address[BLE_GAP_ADDR_LEN];
616 
617  memset(zero_address, 0, BLE_GAP_ADDR_LEN);
618 
619  m_status.nof_connections--;
620 
621  reg_item_p = ptu_reg_item_get_from_conn_handle(p_ble_evt->evt.gap_evt.conn_handle);
622 
623  if(memcmp(reg_item_p->address.addr, zero_address, BLE_GAP_ADDR_LEN) == 0)
624  {
625  ptu_reg_item_delete(reg_item_p); // Mode transition with Zero-address, delete device to ensure that registration performed.
626  }
627 
628  else if(reg_item_p != NULL)
629  {
630  reg_item_p->pending_dyn_read = false;
631 
632  err_code = ptu_sensors_data_get(&p_sensor_data);
633  APP_ERROR_CHECK(err_code);
634 
635  if( !p_sensor_data->load_var_detected && reg_item_p->state == REG_ITEM_STATE_REGISTERED)
636  {
637  if(!m_status.mode_trans_in_progess)
638  {
639  reg_item_p->reconnect = true;
640 
641  err_code = app_timer_start(reg_item_p->timer_id, APP_TIMER_TICKS(PTU_RECONNECT_TIMEOUT_MS, APP_TIMER_PRESCALER), reg_item_p);
642  APP_ERROR_CHECK(err_code);
643  }
644 
645  else // Mode transition with non-zero address
646  {
647  m_connect(&reg_item_p->address);
648  }
649 
650  }
651 
652  else
653  {
654  ptu_reg_item_delete(reg_item_p);
655 
656  if(m_status.nof_connections == 0)
657  {
658  m_sm_handler(PTU_SM_SIGNAL_ALL_DEVICES_DISCONNECTED);
659  }
660  }
661 
662  }
663 }
664 
669 static void m_pairing_start(uint16_t conn_handle)
670 {
671  uint32_t err_code;
672 
673  ble_gap_sec_params_t sec_params;
674  memset(&sec_params, 0, sizeof(ble_gap_sec_params_t));
675  sec_params.io_caps = BLE_GAP_IO_CAPS_NONE;
676  sec_params.min_key_size = PTU_SEC_MIN_KEYSIZE;
677  sec_params.max_key_size = PTU_SEC_MAX_KEYSIZE;
678 
679  err_code = sd_ble_gap_authenticate(conn_handle, &sec_params);
680  APP_ERROR_CHECK(err_code);
681 }
682 
687 static void m_on_evt_rw_response(ble_evt_t * p_ble_evt)
688 {
689  if(p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION)
690  {
691  m_pairing_start(p_ble_evt->evt.gattc_evt.conn_handle);
692  }
693 }
694 
699 static void m_on_evt_seq_request(ble_evt_t * p_ble_evt)
700 {
701  m_pairing_start(p_ble_evt->evt.gattc_evt.conn_handle);
702 }
703 
708 static void m_on_evt_sec_params_request(ble_evt_t * p_ble_evt)
709 {
710  uint32_t err_code;
711  err_code = sd_ble_gap_sec_params_reply(p_ble_evt->evt.gap_evt.conn_handle, BLE_GAP_SEC_STATUS_SUCCESS, NULL, NULL);
712  APP_ERROR_CHECK(err_code);
713 }
714 
719 static void m_on_evt_conn_sec_update(ble_evt_t * p_ble_evt)
720 {
721  uint32_t err_code;
722  ptu_reg_item_t * reg_item_p = ptu_reg_item_get_from_conn_handle(p_ble_evt->evt.gap_evt.conn_handle);
723 
724  if(reg_item_p != NULL)
725  {
726  // If we were in the middle of registration process -> continue registration.
727  switch(reg_item_p->state)
728  {
730  err_code = ble_wpts_c_enable_pru_alert_notification(&(reg_item_p -> ble_wpts_c));
732  break;
733 
735  err_code = ble_wpts_c_read_pru_static(&(reg_item_p -> ble_wpts_c));
737  break;
738 
740  err_code = ble_wpts_c_write_ptu_static(&(reg_item_p -> ble_wpts_c), &m_ptu_static);
742  break;
743 
745  err_code = ble_wpts_c_read_pru_dynamic(&(reg_item_p -> ble_wpts_c));
747  break;
748 
750  // ptu_power_ctl.c module will send control packet complpeting registration.
751  break;
752 
753  default:
754  break;
755  }
756 
757  // Security mode 1 level 2 is expected when IO capabilities = BLE_GAP_IO_CAPS_NONE
758  ASSERT(p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.sm == 1);
759  ASSERT(p_ble_evt->evt.gap_evt.params.conn_sec_update.conn_sec.sec_mode.lv == 2);
760 
761  reg_item_p->link_encrypted = true;
762  }
763 }
764 
765 static void m_on_wpt_alert(ble_wpts_c_t * p_wpts_c, ble_wpts_c_evt_t * const p_wpts_c_evt)
766 {
767  ptu_reg_item_t *p_reg_item;
768  uint8_t mode_trans_val;
769  uint32_t err_code;
770 
771  err_code = app_timer_cnt_get(&m_status.ticks_at_mt_end);
772  APP_ERROR_CHECK(err_code);
773 
774  ASSERT(p_wpts_c_evt->type == BLE_WPTS_C_EVT_PRU_ALERT);
775 
776  mode_trans_val = p_wpts_c_evt->data.pru_alert.mode_transition;
777 
779  {
780  p_reg_item = ptu_reg_item_get_from_conn_handle(p_wpts_c->conn_handle);
781  ASSERT(p_reg_item != NULL);
782 
783  switch(mode_trans_val)
784  {
786  err_code = app_timer_start(m_mode_trans_timer_id, APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER), NULL);
787  APP_ERROR_CHECK(err_code);
788  m_status.ticks_at_mt_end += APP_TIMER_TICKS(2000, APP_TIMER_PRESCALER);
789  break;
790 
792  err_code = app_timer_start(m_mode_trans_timer_id, APP_TIMER_TICKS(3000, APP_TIMER_PRESCALER), NULL);
793  APP_ERROR_CHECK(err_code);
794  m_status.ticks_at_mt_end += APP_TIMER_TICKS(3000, APP_TIMER_PRESCALER);
795  break;
796 
798  err_code = app_timer_start(m_mode_trans_timer_id, APP_TIMER_TICKS(6000, APP_TIMER_PRESCALER), NULL);
799  APP_ERROR_CHECK(err_code);
800  m_status.ticks_at_mt_end += APP_TIMER_TICKS(6000, APP_TIMER_PRESCALER);
801  break;
802  }
803  m_status.mode_trans_in_progess = true;
804  memcpy(p_reg_item->address.addr, p_wpts_c_evt->data.pru_alert.device_address, BLE_GAP_ADDR_LEN);
805  }
806 }
807 
810 static void ptu_char_pru_dynamic_read(uint16_t conn_handle)
811 {
812  ptu_reg_item_t * reg_entry;
813 
814  reg_entry = ptu_reg_item_get_from_conn_handle(conn_handle);
815 
816  // Ignore return value as device could allready be disconnected
817  if(reg_entry != NULL)
818  {
819  if(!reg_entry->pending_dyn_read)
820  {
821  if(ble_wpts_c_read_pru_dynamic(&(reg_entry -> ble_wpts_c)) == NRF_SUCCESS)
822  {
823  reg_entry->pending_dyn_read = true;
824  }
825  }
826  }
827 }
828 
831 /******************************************************************************/
834 /******************************************************************************/
835 
837 {
838  uint32_t err_code;
839 
840  err_code = app_timer_stop(reg_item_p->timer_id);
841  APP_ERROR_CHECK(err_code);
842 
843  // If a connection exists for this item.
844  if((reg_item_p->state != REG_ITEM_STATE_UNUSED) &&
845  (reg_item_p->state != REG_ITEM_STATE_PRE_CONNECT) &&
846  (reg_item_p->state != REG_ITEM_STATE_WAITING_TO_CONNECT) &&
847  (reg_item_p->state != REG_ITEM_STATE_FULLY_ACCEPTED))
848  {
849  m_disconnect(reg_item_p->ble_wpts_c.conn_handle);
850  }
851 
852  ptu_reg_item_delete(reg_item_p);
853 }
854 
856 {
857  return m_status.mode_trans_in_progess;
858 }
859 
860 
861 uint32_t ptu_cm_init(ptu_sm_handler_t sm_handler)
862 {
863  int i;
864  uint32_t err_code;
865  ptu_reg_item_t *reg_item;
866 
867  if(sm_handler == NULL)
868  return NRF_ERROR_INVALID_PARAM;
869 
870  m_sm_handler = sm_handler;
871  memset(&m_status, 0, sizeof(ptu_cm_status_t));
872  m_status.scan_params.active = 1;
873 
874  // Instantiate registration and connection timers
875  for(i = 0; i < PTU_MAX_CONNECTIONS; i++)
876  {
877  err_code = ptu_reg_item_get_from_index(i, &reg_item);
878  APP_ERROR_CHECK(err_code);
879 
880  err_code = app_timer_create(&(reg_item->timer_id), APP_TIMER_MODE_SINGLE_SHOT, m_reg_timer_handle);
881  APP_ERROR_CHECK(err_code);
882  }
883 
884  // Initiate time set impedance shift detect timer
885  err_code = app_timer_create(&m_time_set_check_timer_id, APP_TIMER_MODE_REPEATED, m_ptu_time_set_check_timer_handler);
886  APP_ERROR_CHECK(err_code);
887 
888  err_code = app_timer_create(&m_mode_trans_timer_id, APP_TIMER_MODE_SINGLE_SHOT, m_mode_trans_timer_handle);
889  APP_ERROR_CHECK(err_code);
890 
891  return NRF_SUCCESS;
892 }
893 
894 void ptu_cm_on_ble_evt(ble_evt_t * p_ble_evt)
895 {
896  ble_wpts_service_data_t curr_service_data;
897 
898  switch (p_ble_evt->header.evt_id)
899  {
900  case BLE_GAP_EVT_ADV_REPORT:
901  // If AD received (not scan response)
902  if( p_ble_evt->evt.gap_evt.params.adv_report.scan_rsp == 0)
903  {
904  // If WPT advertisement
905  if (ble_wpts_service_data_read(&p_ble_evt->evt.gap_evt.params.adv_report, &curr_service_data) == NRF_SUCCESS &&
906  curr_service_data.uuid16 == BLE_WPTS_UUID16)
907  m_on_wpt_adv_report(p_ble_evt, curr_service_data.adv_flags);
908  }
909  else // If scan response received
910  {
911  m_on_scan_response(p_ble_evt);
912  }
913  break;
914 
915  case BLE_GAP_EVT_CONNECTED:
916  m_on_evt_connected(p_ble_evt);
917  break;
918 
919  case BLE_GAP_EVT_TIMEOUT:
920  m_on_evt_timeout(p_ble_evt);
921  break;
922 
923  case BLE_GAP_EVT_DISCONNECTED:
924  m_on_evt_disconnected(p_ble_evt);
925  break;
926 
927  case BLE_GATTC_EVT_READ_RSP:
928  case BLE_GATTC_EVT_WRITE_RSP:
929  m_on_evt_rw_response(p_ble_evt);
930  break;
931 
932  case BLE_GAP_EVT_SEC_REQUEST:
933  m_on_evt_seq_request(p_ble_evt);
934  break;
935 
936  case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
937  m_on_evt_sec_params_request(p_ble_evt);
938  break;
939 
940  case BLE_GAP_EVT_CONN_SEC_UPDATE:
941  m_on_evt_conn_sec_update(p_ble_evt);
942  break;
943 
944  default:
945  break;
946  }
947 
948  m_scan_maintain();
949 }
950 
951 // New device requesting power
952 void ptu_cm_on_wpt_service_evt(ble_wpts_c_t * p_wpts_c, ble_wpts_c_evt_t * const p_wpts_c_evt)
953 {
955  uint32_t err_code;
956 
957  if (reg_item_p != NULL)
958  {
959  switch (p_wpts_c_evt->type)
960  {
963  err_code = ble_wpts_c_write_ptu_static(&(reg_item_p -> ble_wpts_c), &m_ptu_static);
965  // Make a local copy in registry of PRU static parameters
966  reg_item_p->prev_pru_static = p_wpts_c_evt->data.pru_static;
967  break;
968 
971  err_code = ble_wpts_c_read_pru_dynamic(&(reg_item_p -> ble_wpts_c));
973  reg_item_p->pending_dyn_read = true;
974  break;
975 
977  if(reg_item_p->state != REG_ITEM_STATE_REGISTERED)
978  {
979  const ptu_sensor_data_t * sensor_data;
980  err_code = ptu_sensors_data_get(&sensor_data);
981  APP_ERROR_CHECK(err_code);
982  m_status.time_set_p_tx_in_reference = sensor_data->p_tx_in;
983 
984  //ASSERT(reg_item_p != 0);
985  reg_item_p->state = REG_ITEM_STATE_PRU_CTL_SEND;
986 
987  // Info: Now, a control packet will be sent by the "power adjust"
988  // part of the code. So we can always rely on getting a
989  // BLE_WPTS_C_EVT_PRU_CONTROL_WRITE_RESP that will end registration.
990  }
991  break;
992 
994  if(reg_item_p->state != REG_ITEM_STATE_REGISTERED)
995  {
996  m_device_registration_complete(reg_item_p);
997  // Stop registration timer.
998  err_code = app_timer_stop(reg_item_p->timer_id);
999  APP_ERROR_CHECK(err_code);
1000 
1001  // If this PRU has "Time set" support, and we just enabled PRU Charge Output
1003  reg_item_p->prev_ctl.enable_pru_output == 1)
1004  {
1005  err_code = app_timer_start(m_time_set_check_timer_id, APP_TIMER_TICKS(PTU_TIME_SET_CHECK_INTERVAL_MS, APP_TIMER_PRESCALER), reg_item_p);
1006  APP_ERROR_CHECK(err_code);
1007  ptu_power_ctrl_set_disable_power_amplifier_adjustments(true); // Disable adjustments of I_TX_COIL during time set.
1008  }
1009 
1010  err_code = ble_wpts_c_enable_pru_alert_notification(&(reg_item_p -> ble_wpts_c));
1012 
1013  // We need to test permissions, so save the control packet data.
1014  if(reg_item_p->prev_ctl.permissions == CTL_PERMISSION_PERMITTED)
1015  {
1016  m_sm_handler(PTU_SM_SIGNAL_CHARGE_START);
1017  }
1018  }
1019  break;
1020 
1022  m_on_wpt_alert(p_wpts_c, p_wpts_c_evt);
1023  break;
1024 
1025  default:
1026  break;
1027  }
1028  }
1029  m_scan_maintain();
1030 }
1031 
1033 {
1034  m_status.scanning_reqested = false;
1035  m_scan_maintain();
1036 }
1037 
1039 {
1040  m_status.scanning_reqested = true;
1041  m_scan_maintain();
1042 }
1043 
1045 {
1046  int i;
1047  ptu_reg_item_t * reg_item;
1048  uint32_t err_code;
1049 
1050  for(i = 0; i < PTU_MAX_CONNECTIONS; i++)
1051  {
1052  err_code = ptu_reg_item_get_from_index(i, &reg_item);
1053  APP_ERROR_CHECK(err_code);
1054  ptu_cm_remove_device(reg_item);
1055  }
1056 }
1057 
1058 
1060 {
1061  ptu_reg_item_t* registered_devices[PTU_MAX_CONNECTIONS];
1062  uint8_t n_reg_devices = ptu_reg_registered_devices_get(registered_devices);
1063 
1064  for(uint8_t i = 0; i < n_reg_devices; i++)
1065  {
1066  ptu_char_pru_dynamic_read(registered_devices[i]->ble_wpts_c.conn_handle);
1067  }
1068 }
1069 
pru_control_t prev_ctl
Definition: ptu_registry.h:55
PTU Static Parameter structure.
Definition: wpt.h:110
#define PTU_P_TX_IN_LOAD_DETECT
Definition: ptu_config.h:73
void ptu_reg_item_delete(ptu_reg_item_t *item)
Delete item that has previoulsy been added to registry.
Definition: ptu_registry.c:220
Registry item.
Definition: ptu_registry.h:47
uint32_t ble_wpts_service_data_read(ble_gap_evt_adv_report_t *p_adv_report, ble_wpts_service_data_t *p_service_data)
Definition: ble_wpts_c.c:483
static void m_scan_maintain(void)
Definition: ptu_conn_man.c:314
APP_TIMER_DEF(m_mode_trans_timer_id)
union ble_wpts_c_evt_t::@1 data
#define BLE_WPTS_PTU_STATIC_MAX_LOAD_RESISTANCE_VAL
Definition: ptu_config.h:219
ptu_reg_item_t * ptu_reg_item_add(ble_gap_evt_adv_report_t *p_adv_report, ptu_reg_item_state_t init_state)
Initiate registration of new device.
Definition: ptu_registry.c:187
uint16_t conn_handle
Definition: ble_wpts_c.h:66
uint8_t mode_transition
Definition: wpt.h:148
WPT Service Client structure. This contains various status information for the service.
Definition: ble_wpts_c.h:57
void(* ptu_sm_handler_t)(ptu_sm_signal_type_t signal)
Definition: ptu.h:30
#define PTU_ADV_IGNORE_TIMEOUT_MS
Definition: ptu_config.h:105
uint8_t link_encrypted
Definition: ptu_registry.h:68
#define BLE_WPTS_PTU_STATIC_NUM_DEVICES_BITVAL
Definition: ptu_config.h:256
#define BLE_WPTS_PRU_ALERT_MODE_NO_MODE_TRANSITION_VAL
PRU Alert Mode transition.
uint32_t ptu_sensors_read(void)
Read sensors. This function should typically be called regularly by a timer and can generate events b...
Definition: ptu_sensors.c:303
#define BLE_WPTS_UUID16
WPT Service UUIDs.
uint8_t ptu_reg_registered_devices_get(ptu_reg_item_t **registered_devices)
Get handles for all registered devices.
Definition: ptu_registry.c:254
uint32_t ticks_diff(uint32_t ticks_now, uint32_t ticks_old)
Definition: common.c:78
PRU Control structure.
Definition: wpt.h:79
ble_wpts_c_t ble_wpts_c
Definition: ptu_registry.h:52
uint32_t ble_wpts_c_enable_pru_alert_notification(ble_wpts_c_t *p_wpts_c)
Enable alert notifications to be sent from PRU.
Definition: ble_wpts_c.c:465
#define BLE_WPTS_PRU_ALERT_MODE_2S_MODE_TRANSITION_VAL
static void m_connect(ble_gap_addr_t const *p_addr)
Definition: ptu_conn_man.c:90
static void m_connection_init(ptu_reg_item_t *reg_item)
Definition: ptu_conn_man.c:148
#define PTU_TIME_SET_500_MS_OF_SAMPLES
Definition: ptu_config.h:91
#define BLE_WPTS_ADV_FLAG_IMPEDANCE_SHIFT_BITPOS
uint32_t ptu_cm_init(ptu_sm_handler_t sm_handler)
Initialize connection manager.
Definition: ptu_conn_man.c:861
static void m_on_scan_response(ble_evt_t *p_ble_evt)
Definition: ptu_conn_man.c:492
uint32_t ble_wpts_c_read_pru_static(ble_wpts_c_t *p_wpts_c)
Read the PRU Static Parameter characterisic value from the PRU server.
Definition: ble_wpts_c.c:403
uint32_t ble_wpts_c_write_ptu_static(ble_wpts_c_t *p_wpts_c, ptu_static_t *p_wpts_ptu_static)
Write the PTU Static characteristic to the PRU server.
Definition: ble_wpts_c.c:413
ptu_reg_item_t * ptu_reg_item_get_from_address(ble_gap_addr_t *address)
Get registry item from GAP address.
Definition: ptu_registry.c:153
uint32_t ptu_reg_item_get_from_index(uint8_t index, ptu_reg_item_t **item_p)
Get registry item from index in database. Index must be < PTU_MAX_CONNECTIONS.
Definition: ptu_registry.c:126
uint8_t ptu_reg_n_entries_get(void)
Get the number of devices currently in registry. This will include all connected devices, as well as all devices which is currently being registered.
Definition: ptu_registry.c:268
uint8_t enable_pru_output
Definition: wpt.h:81
uint8_t reconnect
Definition: ptu_registry.h:70
#define PTU_FW_REVISION
Definition: ptu_config.h:33
#define PTU_MAX_CONN_INTERVAL
Definition: ptu_config.h:127
#define PTU_TIME_SET_CHECK_INTERVAL_MS
Definition: ptu_config.h:90
void ptu_cm_disconnect_all(void)
Disconnect all PRUs.
uint8_t adv_flags
Definition: ptu_registry.h:50
pru_alert_t pru_alert
Definition: ble_wpts_c.h:52
#define BLE_WPTS_PRU_CATEGORY_NO_IMP_SHIFT
PRU Static characteristic PRU Category field.
#define PTU_REVOKE_ACCEPTED_STATE_POWER_SAVE_MS
Definition: ptu_config.h:160
static void m_ptu_time_set_check_timer_handler(void *p_context)
Timeout handler for the time set functionality.
Definition: ptu_conn_man.c:270
#define PTU_MIN_CONN_INTERVAL
Definition: ptu_config.h:126
#define PTU_TIME_SET_UPPER_LIMIT_MS
Definition: ptu_config.h:97
#define APP_ERROR_CHECK_ALLOW_DISCONNECT(ERR_CODE)
Macro equivalent to APP_ERROR_CHECK, except that error codes returned if connection is lost will be a...
Definition: wpt.h:228
static void m_pairing_start(uint16_t conn_handle)
Definition: ptu_conn_man.c:669
static void m_on_evt_rw_response(ble_evt_t *p_ble_evt)
Definition: ptu_conn_man.c:687
Struct holding contents of "Service data AD type".
ptu_cm_time_set_state_t
Definition: ptu_conn_man.c:33
uint32_t ble_wpts_c_read_pru_dynamic(ble_wpts_c_t *p_wpts_c)
Read the PRU Dynamic characterisic value from the PRU server.
Definition: ble_wpts_c.c:408
static void m_on_evt_timeout(ble_evt_t *p_ble_evt)
Definition: ptu_conn_man.c:577
static void ptu_char_pru_dynamic_read(uint16_t conn_handle)
Set pending dynamic read for PRU.
Definition: ptu_conn_man.c:810
#define PTU_ADV_PWR_MIN
Definition: ptu_hw_config.h:37
#define PTU_PROTOCOL_REVISION
Definition: ptu_config.h:34
#define PTU_NORMAL_SCAN_WINDOW
Definition: ptu_config.h:120
uint8_t pending_ctl_write
Definition: ptu_registry.h:65
#define PTU_REVOKE_ACCEPTED_STATE_NON_POWER_SAVE_MS
Definition: ptu_config.h:154
bool ptu_dlh_device_is_in_distant_list(ble_gap_addr_t const *p_addr)
Check if device with provided address is in the distant list.
#define PTU_SLAVE_LATENCY
Definition: ptu_config.h:128
#define PTU_POWER_SAVE_STATE_SCAN_INTERVAL
Definition: ptu_config.h:113
void ptu_cm_on_ble_evt(ble_evt_t *p_ble_evt)
BLE event handler.
Definition: ptu_conn_man.c:894
#define PTU_SEC_MAX_KEYSIZE
Definition: ptu_config.h:40
#define PTU_CLASS
Definition: ptu_hw_config.h:30
void ptu_power_ctrl_set_disable_power_amplifier_adjustments(bool val)
Enable/Disable adjustments of power amplifier (I_TX_COIL).
static void m_on_evt_seq_request(ble_evt_t *p_ble_evt)
Definition: ptu_conn_man.c:699
void ptu_dlh_on_wpt_adv_report(ble_gap_addr_t const *p_addr, uint8_t adv_flags)
Distance list handler WPT Advertisement report handler.
pru_static_t pru_static
Definition: ble_wpts_c.h:50
#define PTU_RECONNECT_TIMEOUT_MS
Definition: ptu_config.h:44
void ptu_cm_scan_disable(void)
Disable scanning.
ptu_reg_item_state_t
Registry item status.
Definition: ptu_registry.h:31
static void m_on_evt_sec_params_request(ble_evt_t *p_ble_evt)
Definition: ptu_conn_man.c:708
#define BLE_WPTS_PRU_ALERT_MODE_6S_MODE_TRANSITION_VAL
ble_wpts_c_evt_type_t type
Definition: ble_wpts_c.h:46
#define PTU_HW_REVISION
Definition: ptu_config.h:32
static void m_on_evt_disconnected(ble_evt_t *p_ble_evt)
Definition: ptu_conn_man.c:610
ble_gap_addr_t address
Definition: ptu_registry.h:51
ctl_perm_t permissions
Definition: wpt.h:84
uint8_t option_valid_max_imp
Definition: wpt.h:112
#define PTU_TIME_SET_LOWER_LIMIT_MS
Definition: ptu_config.h:93
#define BLE_WPTS_PTU_STATIC_MAX_SOURCE_IMPEDANCE_VAL
Definition: ptu_config.h:217
static void m_disconnect(uint16_t conn_handle)
Definition: ptu_conn_man.c:132
pru_static_t prev_pru_static
Definition: ptu_registry.h:53
static const ble_gap_conn_params_t m_conn_params
Definition: ptu_conn_man.c:79
void ptu_cm_scan_enable(void)
Enable scanning.
uint8_t pre_connect_cnt
Definition: ptu_registry.h:59
#define BLE_WPTS_PRU_ALERT_MODE_3S_MODE_TRANSITION_VAL
WPT Service Client event.
Definition: ble_wpts_c.h:44
static void m_on_evt_connected(ble_evt_t *p_ble_evt)
Definition: ptu_conn_man.c:528
#define APP_TIMER_PRESCALER
Definition: pru.h:33
#define PTU_CCA_RSSI_ENABLE
Definition: ptu_config.h:85
uint8_t pending_charge_disable
Definition: ptu_registry.h:67
ptu_reg_item_t * ptu_reg_item_oldest_get(ptu_reg_item_state_t state)
Get oldest registry item having a specific state.
Definition: ptu_registry.c:169
#define TIMER_START(timer_id, ms, p_ctx)
Definition: wpt.h:32
static void m_on_evt_conn_sec_update(ble_evt_t *p_ble_evt)
Definition: ptu_conn_man.c:719
ptu_reg_item_t * ptu_reg_item_get_from_conn_handle(uint16_t conn_handle)
Get registry item from connection handle.
Definition: ptu_registry.c:137
static ptu_sm_handler_t m_sm_handler
State machine event handler.
Definition: ptu_sensors.c:55
void ptu_cm_dynamic_read_all(void)
Issue read request for the PRU dynamic characteristic to all registerred PRUs.
#define PTU_NORMAL_SCAN_INTERVAL
Definition: ptu_config.h:118
uint8_t device_address[BLE_GAP_ADDR_LEN]
Definition: wpt.h:149
uint32_t ptu_sensors_data_get(const ptu_sensor_data_t **sensors_data)
Get the latest data read from the PTU sensors.
Definition: ptu_sensors.c:404
#define PTU_ADV_PRE_CONNECT_ALLOW
Definition: ptu_config.h:102
app_timer_id_t timer_id
Definition: ptu_registry.h:56
uint8_t pending_dyn_read
Definition: ptu_registry.h:64
void ptu_cm_remove_device(ptu_reg_item_t *reg_item_p)
Disconnect and/or unregister any device.
Definition: ptu_conn_man.c:836
static ptu_cm_status_t m_status
Definition: ptu_conn_man.c:64
static void m_on_wpt_adv_report(ble_evt_t *p_ble_evt, uint8_t adv_flags)
Definition: ptu_conn_man.c:447
#define BLE_WPTS_ADV_FLAG_IMPEDANCE_SHIFT_BITMSK
bool ptu_cm_mode_trans_in_progress(void)
Get mode transition status.
Definition: ptu_conn_man.c:855
#define BLE_WPTS_PTU_POWER
Definition: ptu_config.h:221
#define BLE_WPTS_PTU_STATIC_MAX_SOURCE_IMPEDANCE_VALID
Definition: ptu_config.h:218
#define PTU_SM_CURRENT_STATE()
Definition: ptu.h:36
#define PTU_MAX_CONNECTIONS
Definition: ptu_config.h:29
void ptu_cm_on_wpt_service_evt(ble_wpts_c_t *p_wpts_c, ble_wpts_c_evt_t *const p_wpts_c_evt)
Handle service events.
Definition: ptu_conn_man.c:952
#define PTU_POWER_SAVE_STATE_SCAN_WINDOW
Definition: ptu_config.h:114
#define BLE_WPTS_BITFIELD_READ(bitfield, msk, pos)
Read bitfield.
uint32_t ble_wpts_c_send_pru_control(ble_wpts_c_t *p_wpts_c, pru_control_t *p_wpts_pru_control)
Send a PRU Control message to the PRU server.
Definition: ble_wpts_c.c:366
ptu_reg_item_state_t state
Definition: ptu_registry.h:49
#define PTU_CONN_SUP_TIMEOUT
Definition: ptu_config.h:129
#define PTU_SEC_MIN_KEYSIZE
Definition: ptu_config.h:39
#define PTU_CCA_ADV_IMP_SHIFT_ENABLE
Definition: ptu_hw_config.h:51
#define PTU_REG_TIMEOUT_MS
Definition: ptu_config.h:132
static ptu_static_t m_ptu_static
Definition: ptu_conn_man.c:65
Definition of PTU sensor data.
Definition: ptu_hw_config.h:99
#define BLE_WPTS_ADV_FLAG_TIME_SET_SUPPORT_BITMSK
ptu_sm_state_t ptu_sm_execute(ptu_sm_signal_type_t signal, ptu_sm_state_vars_t *p_state)
State machine input signal handler.
Definition: ptu_sm.c:94
#define BLE_WPTS_ADV_FLAG_TIME_SET_SUPPORT_BITPOS
#define BLE_WPTS_PTU_STATIC_MAX_LOAD_RESISTANCE_VALID
Definition: ptu_config.h:220