-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib_aci.cpp
executable file
·761 lines (580 loc) · 21.3 KB
/
lib_aci.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
/* Copyright (c) 2014, Nordic Semiconductor ASA
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/** @file
@brief Implementation of the ACI library.
*/
#include "hal_platform.h"
#include "aci.h"
#include "aci_cmds.h"
#include "aci_evts.h"
#include "aci_protocol_defines.h"
#include "acilib_defs.h"
#include "acilib_if.h"
#include "hal_aci_tl.h"
#include "aci_queue.h"
#include "lib_aci.h"
#include <SPI.h>
#define LIB_ACI_DEFAULT_CREDIT_NUMBER 1
/*
Global additionally used used in aci_setup
*/
hal_aci_data_t msg_to_send;
static services_pipe_type_mapping_t * p_services_pipe_type_map;
static hal_aci_data_t * p_setup_msgs;
static bool is_request_operation_pending;
static bool is_indicate_operation_pending;
static bool is_open_remote_pipe_pending;
static bool is_close_remote_pipe_pending;
static uint8_t request_operation_pipe = 0;
static uint8_t indicate_operation_pipe = 0;
// The following structure (aci_cmd_params_open_adv_pipe) will be used to store the complete command
// including the pipes to be opened.
static aci_cmd_params_open_adv_pipe_t aci_cmd_params_open_adv_pipe;
extern aci_queue_t aci_rx_q;
extern aci_queue_t aci_tx_q;
bool lib_aci_is_pipe_available(aci_state_t *aci_stat, uint8_t pipe)
{
uint8_t byte_idx;
byte_idx = pipe / 8;
if (aci_stat->pipes_open_bitmap[byte_idx] & (0x01 << (pipe % 8)))
{
return(true);
}
return(false);
}
bool lib_aci_is_pipe_closed(aci_state_t *aci_stat, uint8_t pipe)
{
uint8_t byte_idx;
byte_idx = pipe / 8;
if (aci_stat->pipes_closed_bitmap[byte_idx] & (0x01 << (pipe % 8)))
{
return(true);
}
return(false);
}
bool lib_aci_is_discovery_finished(aci_state_t *aci_stat)
{
return(aci_stat->pipes_open_bitmap[0]&0x01);
}
void lib_aci_board_init(aci_state_t *aci_stat)
{
hal_aci_evt_t *aci_data = NULL;
aci_data = (hal_aci_evt_t *)&msg_to_send;
if (REDBEARLAB_SHIELD_V1_1 == aci_stat->aci_pins.board_name)
{
/*
The Bluetooth low energy Arduino shield v1.1 requires about 100ms to reset.
This is not required for the nRF2740, nRF2741 modules
*/
delay(100);
/*
Send the soft reset command to the nRF8001 to get the nRF8001 to a known state.
*/
lib_aci_radio_reset();
while (1)
{
/*Wait for the command response of the radio reset command.
as the nRF8001 will be in either SETUP or STANDBY after the ACI Reset Radio is processed
*/
if (true == lib_aci_event_get(aci_stat, aci_data))
{
aci_evt_t * aci_evt;
aci_evt = &(aci_data->evt);
if (ACI_EVT_CMD_RSP == aci_evt->evt_opcode)
{
if (ACI_STATUS_ERROR_DEVICE_STATE_INVALID == aci_evt->params.cmd_rsp.cmd_status) //in SETUP
{
//Inject a Device Started Event Setup to the ACI Event Queue
msg_to_send.buffer[0] = 4; //Length
msg_to_send.buffer[1] = 0x81; //Device Started Event
msg_to_send.buffer[2] = 0x02; //Setup
msg_to_send.buffer[3] = 0; //Hardware Error -> None
msg_to_send.buffer[4] = 2; //Data Credit Available
aci_queue_enqueue(&aci_rx_q, &msg_to_send);
}
else if (ACI_STATUS_SUCCESS == aci_evt->params.cmd_rsp.cmd_status) //We are now in STANDBY
{
//Inject a Device Started Event Standby to the ACI Event Queue
msg_to_send.buffer[0] = 4; //Length
msg_to_send.buffer[1] = 0x81; //Device Started Event
msg_to_send.buffer[2] = 0x03; //Standby
msg_to_send.buffer[3] = 0; //Hardware Error -> None
msg_to_send.buffer[4] = 2; //Data Credit Available
aci_queue_enqueue(&aci_rx_q, &msg_to_send);
}
else if (ACI_STATUS_ERROR_CMD_UNKNOWN == aci_evt->params.cmd_rsp.cmd_status) //We are now in TEST
{
//Inject a Device Started Event Test to the ACI Event Queue
msg_to_send.buffer[0] = 4; //Length
msg_to_send.buffer[1] = 0x81; //Device Started Event
msg_to_send.buffer[2] = 0x01; //Test
msg_to_send.buffer[3] = 0; //Hardware Error -> None
msg_to_send.buffer[4] = 0; //Data Credit Available
aci_queue_enqueue(&aci_rx_q, &msg_to_send);
}
//Break out of the while loop
break;
}
else
{
//Serial.println(F("Discard any other ACI Events"));
}
}
}
}
}
void lib_aci_init(aci_state_t *aci_stat, bool debug)
{
uint8_t i;
for (i = 0; i < PIPES_ARRAY_SIZE; i++)
{
aci_stat->pipes_open_bitmap[i] = 0;
aci_stat->pipes_closed_bitmap[i] = 0;
aci_cmd_params_open_adv_pipe.pipes[i] = 0;
}
is_request_operation_pending = false;
is_indicate_operation_pending = false;
is_open_remote_pipe_pending = false;
is_close_remote_pipe_pending = false;
request_operation_pipe = 0;
indicate_operation_pipe = 0;
p_services_pipe_type_map = aci_stat->aci_setup_info.services_pipe_type_mapping;
p_setup_msgs = aci_stat->aci_setup_info.setup_msgs;
hal_aci_tl_init(&aci_stat->aci_pins, debug);
lib_aci_board_init(aci_stat);
}
uint8_t lib_aci_get_nb_available_credits(aci_state_t *aci_stat)
{
return aci_stat->data_credit_available;
}
uint16_t lib_aci_get_cx_interval_ms(aci_state_t *aci_stat)
{
uint32_t cx_rf_interval_ms_32bits;
uint16_t cx_rf_interval_ms;
cx_rf_interval_ms_32bits = aci_stat->connection_interval;
cx_rf_interval_ms_32bits *= 125; // the connection interval is given in multiples of 0.125 milliseconds
cx_rf_interval_ms = cx_rf_interval_ms_32bits / 100;
return cx_rf_interval_ms;
}
uint16_t lib_aci_get_cx_interval(aci_state_t *aci_stat)
{
return aci_stat->connection_interval;
}
uint16_t lib_aci_get_slave_latency(aci_state_t *aci_stat)
{
return aci_stat->slave_latency;
}
bool lib_aci_set_app_latency(uint16_t latency, aci_app_latency_mode_t latency_mode)
{
aci_cmd_params_set_app_latency_t aci_set_app_latency;
aci_set_app_latency.mode = latency_mode;
aci_set_app_latency.latency = latency;
acil_encode_cmd_set_app_latency(&(msg_to_send.buffer[0]), &aci_set_app_latency);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_test(aci_test_mode_change_t enter_exit_test_mode)
{
aci_cmd_params_test_t aci_cmd_params_test;
aci_cmd_params_test.test_mode_change = enter_exit_test_mode;
acil_encode_cmd_set_test_mode(&(msg_to_send.buffer[0]), &aci_cmd_params_test);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_sleep()
{
acil_encode_cmd_sleep(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_radio_reset()
{
acil_encode_baseband_reset(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_direct_connect()
{
acil_encode_direct_connect(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_device_version()
{
acil_encode_cmd_get_device_version(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_set_local_data(aci_state_t *aci_stat, uint8_t pipe, uint8_t *p_value, uint8_t size)
{
aci_cmd_params_set_local_data_t aci_cmd_params_set_local_data;
if ((p_services_pipe_type_map[pipe-1].location != ACI_STORE_LOCAL)
||
(size > ACI_PIPE_TX_DATA_MAX_LEN))
{
return false;
}
aci_cmd_params_set_local_data.tx_data.pipe_number = pipe;
memcpy(&(aci_cmd_params_set_local_data.tx_data.aci_data[0]), p_value, size);
acil_encode_cmd_set_local_data(&(msg_to_send.buffer[0]), &aci_cmd_params_set_local_data, size);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_connect(uint16_t run_timeout, uint16_t adv_interval)
{
aci_cmd_params_connect_t aci_cmd_params_connect;
aci_cmd_params_connect.timeout = run_timeout;
aci_cmd_params_connect.adv_interval = adv_interval;
acil_encode_cmd_connect(&(msg_to_send.buffer[0]), &aci_cmd_params_connect);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_disconnect(aci_state_t *aci_stat, aci_disconnect_reason_t reason)
{
bool ret_val;
uint8_t i;
aci_cmd_params_disconnect_t aci_cmd_params_disconnect;
aci_cmd_params_disconnect.reason = reason;
acil_encode_cmd_disconnect(&(msg_to_send.buffer[0]), &aci_cmd_params_disconnect);
ret_val = hal_aci_tl_send(&msg_to_send);
// If we have actually sent the disconnect
if (ret_val)
{
// Update pipes immediately so that while the disconnect is happening,
// the application can't attempt sending another message
// If the application sends another message before we updated this
// a ACI Pipe Error Event will be received from nRF8001
for (i=0; i < PIPES_ARRAY_SIZE; i++)
{
aci_stat->pipes_open_bitmap[i] = 0;
aci_stat->pipes_closed_bitmap[i] = 0;
}
}
return ret_val;
}
bool lib_aci_bond(uint16_t run_timeout, uint16_t adv_interval)
{
aci_cmd_params_bond_t aci_cmd_params_bond;
aci_cmd_params_bond.timeout = run_timeout;
aci_cmd_params_bond.adv_interval = adv_interval;
acil_encode_cmd_bond(&(msg_to_send.buffer[0]), &aci_cmd_params_bond);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_wakeup()
{
acil_encode_cmd_wakeup(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_set_tx_power(aci_device_output_power_t tx_power)
{
aci_cmd_params_set_tx_power_t aci_cmd_params_set_tx_power;
aci_cmd_params_set_tx_power.device_power = tx_power;
acil_encode_cmd_set_radio_tx_power(&(msg_to_send.buffer[0]), &aci_cmd_params_set_tx_power);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_get_address()
{
acil_encode_cmd_get_address(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_get_temperature()
{
acil_encode_cmd_temparature(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_get_battery_level()
{
acil_encode_cmd_battery_level(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_send_data(uint8_t pipe, uint8_t *p_value, uint8_t size)
{
bool ret_val = false;
aci_cmd_params_send_data_t aci_cmd_params_send_data;
if(!((p_services_pipe_type_map[pipe-1].pipe_type == ACI_TX) ||
(p_services_pipe_type_map[pipe-1].pipe_type == ACI_TX_ACK)))
{
return false;
}
if (size > ACI_PIPE_TX_DATA_MAX_LEN)
{
return false;
}
{
aci_cmd_params_send_data.tx_data.pipe_number = pipe;
memcpy(&(aci_cmd_params_send_data.tx_data.aci_data[0]), p_value, size);
acil_encode_cmd_send_data(&(msg_to_send.buffer[0]), &aci_cmd_params_send_data, size);
ret_val = hal_aci_tl_send(&msg_to_send);
}
return ret_val;
}
bool lib_aci_request_data(aci_state_t *aci_stat, uint8_t pipe)
{
bool ret_val = false;
aci_cmd_params_request_data_t aci_cmd_params_request_data;
if(!((p_services_pipe_type_map[pipe-1].location == ACI_STORE_REMOTE)&&(p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_REQ)))
{
return false;
}
{
{
aci_cmd_params_request_data.pipe_number = pipe;
acil_encode_cmd_request_data(&(msg_to_send.buffer[0]), &aci_cmd_params_request_data);
ret_val = hal_aci_tl_send(&msg_to_send);
}
}
return ret_val;
}
bool lib_aci_change_timing(uint16_t minimun_cx_interval, uint16_t maximum_cx_interval, uint16_t slave_latency, uint16_t timeout)
{
aci_cmd_params_change_timing_t aci_cmd_params_change_timing;
aci_cmd_params_change_timing.conn_params.min_conn_interval = minimun_cx_interval;
aci_cmd_params_change_timing.conn_params.max_conn_interval = maximum_cx_interval;
aci_cmd_params_change_timing.conn_params.slave_latency = slave_latency;
aci_cmd_params_change_timing.conn_params.timeout_mult = timeout;
acil_encode_cmd_change_timing_req(&(msg_to_send.buffer[0]), &aci_cmd_params_change_timing);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_change_timing_GAP_PPCP()
{
acil_encode_cmd_change_timing_req_GAP_PPCP(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_open_remote_pipe(aci_state_t *aci_stat, uint8_t pipe)
{
bool ret_val = false;
aci_cmd_params_open_remote_pipe_t aci_cmd_params_open_remote_pipe;
if(!((p_services_pipe_type_map[pipe-1].location == ACI_STORE_REMOTE)&&
((p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX)||
(p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_ACK_AUTO)||
(p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_ACK))))
{
return false;
}
{
is_request_operation_pending = true;
is_open_remote_pipe_pending = true;
request_operation_pipe = pipe;
aci_cmd_params_open_remote_pipe.pipe_number = pipe;
acil_encode_cmd_open_remote_pipe(&(msg_to_send.buffer[0]), &aci_cmd_params_open_remote_pipe);
ret_val = hal_aci_tl_send(&msg_to_send);
}
return ret_val;
}
bool lib_aci_close_remote_pipe(aci_state_t *aci_stat, uint8_t pipe)
{
bool ret_val = false;
aci_cmd_params_close_remote_pipe_t aci_cmd_params_close_remote_pipe;
if(!((p_services_pipe_type_map[pipe-1].location == ACI_STORE_REMOTE)&&
((p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX)||
(p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_ACK_AUTO)||
(p_services_pipe_type_map[pipe-1].pipe_type == ACI_RX_ACK))))
{
return false;
}
{
is_request_operation_pending = true;
is_close_remote_pipe_pending = true;
request_operation_pipe = pipe;
aci_cmd_params_close_remote_pipe.pipe_number = pipe;
acil_encode_cmd_close_remote_pipe(&(msg_to_send.buffer[0]), &aci_cmd_params_close_remote_pipe);
ret_val = hal_aci_tl_send(&msg_to_send);
}
return ret_val;
}
bool lib_aci_set_key(aci_key_type_t key_rsp_type, uint8_t *key, uint8_t len)
{
aci_cmd_params_set_key_t aci_cmd_params_set_key;
aci_cmd_params_set_key.key_type = key_rsp_type;
memcpy((uint8_t*)&(aci_cmd_params_set_key.key), key, len);
acil_encode_cmd_set_key(&(msg_to_send.buffer[0]), &aci_cmd_params_set_key);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_echo_msg(uint8_t msg_size, uint8_t *p_msg_data)
{
aci_cmd_params_echo_t aci_cmd_params_echo;
if(msg_size > (ACI_ECHO_DATA_MAX_LEN))
{
return false;
}
if (msg_size > (ACI_ECHO_DATA_MAX_LEN))
{
msg_size = ACI_ECHO_DATA_MAX_LEN;
}
memcpy(&(aci_cmd_params_echo.echo_data[0]), p_msg_data, msg_size);
acil_encode_cmd_echo_msg(&(msg_to_send.buffer[0]), &aci_cmd_params_echo, msg_size);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_bond_request()
{
acil_encode_cmd_bond_security_request(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_event_peek(hal_aci_evt_t *p_aci_evt_data)
{
return hal_aci_tl_event_peek((hal_aci_data_t *)p_aci_evt_data);
}
bool lib_aci_event_get(aci_state_t *aci_stat, hal_aci_evt_t *p_aci_evt_data)
{
bool status = false;
status = hal_aci_tl_event_get((hal_aci_data_t *)p_aci_evt_data);
/**
Update the state of the ACI with the
ACI Events -> Pipe Status, Disconnected, Connected, Bond Status, Pipe Error
*/
if (true == status)
{
aci_evt_t * aci_evt;
aci_evt = &p_aci_evt_data->evt;
switch(aci_evt->evt_opcode)
{
case ACI_EVT_PIPE_STATUS:
{
uint8_t i=0;
for (i=0; i < PIPES_ARRAY_SIZE; i++)
{
aci_stat->pipes_open_bitmap[i] = aci_evt->params.pipe_status.pipes_open_bitmap[i];
aci_stat->pipes_closed_bitmap[i] = aci_evt->params.pipe_status.pipes_closed_bitmap[i];
}
}
break;
case ACI_EVT_DISCONNECTED:
{
uint8_t i=0;
for (i=0; i < PIPES_ARRAY_SIZE; i++)
{
aci_stat->pipes_open_bitmap[i] = 0;
aci_stat->pipes_closed_bitmap[i] = 0;
}
aci_stat->confirmation_pending = false;
aci_stat->data_credit_available = aci_stat->data_credit_total;
}
break;
case ACI_EVT_TIMING:
aci_stat->connection_interval = aci_evt->params.timing.conn_rf_interval;
aci_stat->slave_latency = aci_evt->params.timing.conn_slave_rf_latency;
aci_stat->supervision_timeout = aci_evt->params.timing.conn_rf_timeout;
break;
case ACI_EVT_CONNECTED:
aci_stat->connection_interval = aci_evt->params.connected.conn_rf_interval;
aci_stat->slave_latency = aci_evt->params.connected.conn_slave_rf_latency;
aci_stat->supervision_timeout = aci_evt->params.connected.conn_rf_timeout;
break;
default:
/* Need default case to avoid compiler warnings about missing enum
* values on some platforms.
*/
break;
}
}
return status;
}
bool lib_aci_send_ack(aci_state_t *aci_stat, const uint8_t pipe)
{
bool ret_val = false;
{
acil_encode_cmd_send_data_ack(&(msg_to_send.buffer[0]), pipe);
ret_val = hal_aci_tl_send(&msg_to_send);
}
return ret_val;
}
bool lib_aci_send_nack(aci_state_t *aci_stat, const uint8_t pipe, const uint8_t error_code)
{
bool ret_val = false;
{
acil_encode_cmd_send_data_nack(&(msg_to_send.buffer[0]), pipe, error_code);
ret_val = hal_aci_tl_send(&msg_to_send);
}
return ret_val;
}
bool lib_aci_broadcast(const uint16_t timeout, const uint16_t adv_interval)
{
aci_cmd_params_broadcast_t aci_cmd_params_broadcast;
if (timeout > 16383)
{
return false;
}
// The adv_interval should be between 160 and 16384 (which translates to the advertisement
// interval values 100 ms and 10.24 s.
if ((160 > adv_interval) || (adv_interval > 16384))
{
return false;
}
aci_cmd_params_broadcast.timeout = timeout;
aci_cmd_params_broadcast.adv_interval = adv_interval;
acil_encode_cmd_broadcast(&(msg_to_send.buffer[0]), &aci_cmd_params_broadcast);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_open_adv_pipes(const uint8_t * const adv_service_data_pipes)
{
uint8_t i;
for (i = 0; i < PIPES_ARRAY_SIZE; i++)
{
aci_cmd_params_open_adv_pipe.pipes[i] = adv_service_data_pipes[i];
}
acil_encode_cmd_open_adv_pipes(&(msg_to_send.buffer[0]), &aci_cmd_params_open_adv_pipe);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_open_adv_pipe(const uint8_t pipe)
{
uint8_t byte_idx = pipe / 8;
aci_cmd_params_open_adv_pipe.pipes[byte_idx] |= (0x01 << (pipe % 8));
acil_encode_cmd_open_adv_pipes(&(msg_to_send.buffer[0]), &aci_cmd_params_open_adv_pipe);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_read_dynamic_data()
{
acil_encode_cmd_read_dynamic_data(&(msg_to_send.buffer[0]));
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_write_dynamic_data(uint8_t sequence_number, uint8_t* dynamic_data, uint8_t length)
{
acil_encode_cmd_write_dynamic_data(&(msg_to_send.buffer[0]), sequence_number, dynamic_data, length);
return hal_aci_tl_send(&msg_to_send);
}
bool lib_aci_dtm_command(uint8_t dtm_command_msbyte, uint8_t dtm_command_lsbyte)
{
aci_cmd_params_dtm_cmd_t aci_cmd_params_dtm_cmd;
aci_cmd_params_dtm_cmd.cmd_msb = dtm_command_msbyte;
aci_cmd_params_dtm_cmd.cmd_lsb = dtm_command_lsbyte;
acil_encode_cmd_dtm_cmd(&(msg_to_send.buffer[0]), &aci_cmd_params_dtm_cmd);
return hal_aci_tl_send(&msg_to_send);
}
void lib_aci_flush(void)
{
hal_aci_tl_q_flush();
}
void lib_aci_debug_print(bool enable)
{
hal_aci_tl_debug_print(enable);
}
void lib_aci_pin_reset(void)
{
hal_aci_tl_pin_reset();
}
bool lib_aci_event_queue_empty(void)
{
return hal_aci_tl_rx_q_empty();
}
bool lib_aci_event_queue_full(void)
{
return hal_aci_tl_rx_q_full();
}
bool lib_aci_command_queue_empty(void)
{
return hal_aci_tl_tx_q_empty();
}
bool lib_aci_command_queue_full(void)
{
return hal_aci_tl_tx_q_full();
}