This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
prx.proximity.custom.sb
2740 lines (2253 loc) · 101 KB
/
prx.proximity.custom.sb
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
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2013, Laird
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// SPDX-License-Identifier:ISC
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++ ++
// +++++ When UwTerminal downloads the app it will store it as a filenname ++
// +++++ which consists of all characters up to the first . and excluding it ++
// +++++ ++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Proximity Profile
//
// ####################################
// # #
// # Search for TODO to make changes #
// # #
// ####################################
//
//******************************************************************************
//******************************************************************************
// Definitions
//******************************************************************************
//This defines how the application startsup and is a bit mask.
//Bit 0 == 1 then OnStartup() is called just before waitevent
//Bit 1 == 1 then StartAds() is called just before waitevent
#define AUTO_STARTUP 3
//Set this to 0 to disable all debugging messages
#define ENABLE_DEBUG_PRINTS 1
//Initial alert level for Link Loss Service (Proximity Profile)
#define INIT_ALERT_LEVEL BLE_ALERT_LEVEL_NO_ALERT
//Tx Power for the TX Service (Proximity Profile)
#define TX_POWER_LEVEL 4
#define DEVICENAME "LAIRD_PRX"
#define DEVICENAME_WRITABLE 1
#define APPEARANCE BLE_APPEARANCE_GENERIC_KEYRING
#define MANF_NAME "Laird Technologies"
#define MODELSTR "BL600"
#define SERIALNUM "12345"
#define HWREV "HwRev1.0"
#define SWREV "SwRev1.0"
//-------------------------------------------
//TODO - Uncomment one of the following three lines
//TODO #define SYSID "\01\02\03\04\05\06\07\08"
//#define SYSID "@"
#define SYSID ""
//-------------------------------------------
//-------------------------------------------
//TODO - Uncomment one of the following two lines
//#define REGLIST "\DE\AD\C0\DE"
#define REGLIST ""
//-------------------------------------------
//-------------------------------------------
//TODO - Uncomment one of the following two lines
//#define PNPID "\01\04\BF\03\20\00\01"
#define PNPID ""
//-------------------------------------------
#define CHAR_CR 13
//Minimum acceptable connection interval (0.5 seconds)
#define MIN_CONN_INTERVAL 80000
//Maximum acceptable connection interval (1 second).
#define MAX_CONN_INTERVAL 100000
//Slave latency -- number of conn events that can be missed
//Effective Conn interval will be (SLAVE_LATENCY+1)*ACTUAL_CONN_INTERVAL
#define SLAVE_LATENCY 2
//Connection supervisory timeout (4 seconds) - max 32 seconds
#define CONN_SUP_TIMEOUT 4000000
//DiscoverableMode, set to BLE_DISCOVERABILITY_xxx
#define DISCOVERY_MODE BLE_DISCOVERABILITY_LIMITED
#define MAX_DEVNAME_CHRS 10
//Set Appearance advertise 0 to suppress
#define ADV_APPEARANCE 1
//Advertise interval
#define ADV_INTERVAL_MS 100
#define ADV_INTERVAL_SLOW_MS 2000
//Advertise timeout
#define ADV_TIMEOUT_MS 30000
#define ADV_TIMEOUT_SLOW_MS 30000
//Whitelist Policy in Adverts
#define ADV_WHITELIST_FILTER_POLICY ADV_FILTERPOLICY_ANY
//Minimum long term key size in octets
#define MIN_LTK_SIZE 8
//Maximum long term key size in octets
#define MAX_LTK_SIZE 16
//Set this to non-zero to enable notiy on batt service
#define BATT_NOTIFY 0
#define BATT_INIT_LEVEL_PERC 100
//This sets the pairing i/p capability using bonding
#define PAIRING_IOCAPABILITY BLE_IOCAPABILITY_NONE
//Connection Update Negotiation paramters
#define FIRST_CONN_PARAMS_UPDATE_DELAY 5000
#define NEXT_CONN_PARAMS_UPDATE_DELAY 5000
#define MAX_CONN_PARAMS_UPDATE_DELAY 15000
//Whether to require bonding or not
#define REQUIRE_BONDING 1
//******************************************************************************
// Debugging resource as early as possible
//******************************************************************************
//******************************************************************************
// Library Import
//******************************************************************************
// -- lib\cli.proximity.custom.sblib -- START
// Copyright (c) 2013, Laird
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// SPDX-License-Identifier:ISC
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++ ++
// +++++ When UwTerminal downloads the app it will store it as a filenname ++
// +++++ which consists of all characters up to the first . and excluding it ++
// +++++ ++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Proximity Profile
//
// ####################################
// # #
// # Search for TODO to make changes #
// # #
// ####################################
//
//
// When you run the app you will get a > command prompt to allow you to submit
// commands as follows:-
//
// initapp - Initialise/start the app
//
// fg n - Set advertising discoverability mode - n is 0 to 3 (see BLE_DISCOVERABILITY_xxx )
// ai nnnn - Set advertising interval in milliseconds - FAST
// aj nnnn - Set advertising interval in milliseconds - FAST
// at nnnn - Set advertising timeout in milliseconds - FAST
// as nnnn - Set advertising timeout in milliseconds - FAST
// af n - Set advertising filter policy 0..3 (see ADV_FILTERPOLICY_xx)
// scinit - Initiliase the scan report to empty
// sd ttaa..aa - Set scan AD tag && data -- MUST be a hex string
// scadd - Append the AD element from sd command to scan report
// sccmt - Commit the scan report to the stack for reports
// ma nnnnn..nnn - Set mac address - 12 hex digits
// ad n - If n=0 then stop adverts otherwise start adverts if
// n=1 then ADV_IND
// n=2 then ADV_DIRECT_IND
// n=3 then ADV_SCAN_IND
// n=4 then ADV_NONCONN_IND
//
// bl nn - Set battery level to nn %
//
// discon - Disconnect
// stop - Exit app to command mode and can resume using RESUME command
// quit - Quit app to command mode
// in nnnn - Set min conn interval (us)
// ix nnnn - Set max conn interval (us)
// st nnnn - Set supervision timeout (us)
// sl nnnn - Set slave latency
// negp - Negotiate connection parameters
//
// io n - If n=0 then BLE_IOCAPABILITY_NONE
// n=1 then BLE_IOCAPABILITY_DISPLAY_YESNO
// n=2 then BLE_IOCAPABILITY_KEYBOARD_ONLY
// n=3 then BLE_IOCAPABILITY_DISPLAY_ONLY
// n=4 then BLE_IOCAPABILITY_KEYBOARD_DISPLAY
// ky nnnn - Set pairing passcode (decimal)
// kn nn - Minimum size of ltk
// kx nn - Maximum size of ltk
// setkey - Commit min and max ltk key size
//
// db nn - Display debug info associated with nn
//
// dr aaaaaa - GAP - set device name with read only
// dw aaaaaa - GAP - set device name with read/write capability only
//
//
//******************************************************************************
//******************************************************************************
// Definitions
//******************************************************************************
//******************************************************************************
// Register Error Handler as early as possible
//******************************************************************************
sub HandlerOnErr()
if (ENABLE_DEBUG_PRINTS!=0) then
print "\n OnErr - ";GetLastError();"\n"
endif
endsub
onerror next HandlerOnErr
//******************************************************************************
// Library Import
//******************************************************************************
// -- lib\debugging.routines.sblib -- START
// Copyright (c) 2013, Laird
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// SPDX-License-Identifier:ISC
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++ ++
// +++++ When UwTerminal downloads the app it will store it as a filenname ++
// +++++ which consists of all characters up to the first . and excluding it ++
// +++++ ++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// Debugging and Tracing Routines - BEFORE includes
//
// Have either the following
//
// #define ENABLE_DEBUG_PRINTS 1
//
// or
//
// #define ENABLE_DEBUG_PRINTS 0
//
// in the source file that includes this
//
//******************************************************************************
// "lib\debugging.routines.sblib"
//==============================================================================
//==============================================================================
sub AssertResCode(byval rc as integer,byval tag as integer)
if (ENABLE_DEBUG_PRINTS!=0) && (rc!=0) then
print "Failed with ";integer.h' rc;" at tag ";tag;"\n"
endif
endsub
//==============================================================================
//==============================================================================
sub DbgMsg(byval msg$ as string)
if (ENABLE_DEBUG_PRINTS!=0) then
print msg$;"\n"
endif
endsub
//==============================================================================
//==============================================================================
sub DbgMsgVal(byval msg$ as string, byval vl as integer)
if (ENABLE_DEBUG_PRINTS!=0) then
print msg$;" ";vl;"\n"
endif
endsub
//==============================================================================
//==============================================================================
sub DbgPrnAdvReport(byref rp$ as string)
if (ENABLE_DEBUG_PRINTS!=0) then
print "Rpt=";strhexize$(rp$);"\n"
endif
endsub
// -- lib\debugging.routines.sblib -- END
// -- lib\ble.sblib -- START
// Copyright (c) 2013, Laird
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// SPDX-License-Identifier:ISC
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ###### #######
// ###### Library File meant to be d in files #######
// ###### #######
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// This library contains all the BLE related #defines that will make your app
// more readable
//
//******************************************************************************
//******************************************************************************
// Library Import
//******************************************************************************
//******************************************************************************
// Definitions
//******************************************************************************
#define BLE_CONN_HANDLE_INVALID 0xFFFF
#define BLE_INVALID_UUID_HANDLE 0
#define BLE_INVALID_CHAR_HANDLE 0
#define BLE_INVALID_SERVICE_HANDLE 0
#define CIRCBUFFER_INVALID_HANDLE -1
//Set BLE_DISCOVERABILITY_NONE if whitelist is enabled in BleAdvertStart()
//as the 4.0 spec says if whitelist is enabled then discoverability is not allowed
#define BLE_DISCOVERABILITY_NONE 0
#define BLE_DISCOVERABILITY_LIMITED 1
#define BLE_DISCOVERABILITY_GENERAL 2
#define BLE_DISCOVERABILITY_BOTH 3
#define BLE_APPEARANCE_UNKNOWN 0
#define BLE_APPEARANCE_GENERIC_PHONE 64
#define BLE_APPEARANCE_GENERIC_COMPUTER 128
#define BLE_APPEARANCE_GENERIC_WATCH 192
#define BLE_APPEARANCE_WATCH_SPORTS_WATCH 193
#define BLE_APPEARANCE_GENERIC_CLOCK 256
#define BLE_APPEARANCE_GENERIC_DISPLAY 320
#define BLE_APPEARANCE_GENERIC_REMOTE_CONTROL 384
#define BLE_APPEARANCE_GENERIC_EYE_GLASSES 448
#define BLE_APPEARANCE_GENERIC_TAG 512
#define BLE_APPEARANCE_GENERIC_KEYRING 576
#define BLE_APPEARANCE_GENERIC_MEDIA_PLAYER 640
#define BLE_APPEARANCE_GENERIC_BARCODE_SCANNER 704
#define BLE_APPEARANCE_GENERIC_THERMOMETER 768
#define BLE_APPEARANCE_THERMOMETER_EAR 769
#define BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR 832
#define BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT 833
#define BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE 896
#define BLE_APPEARANCE_BLOOD_PRESSURE_ARM 897
#define BLE_APPEARANCE_BLOOD_PRESSURE_WRIST 898
#define BLE_APPEARANCE_HUMAN_INTERFACE_DEVICE_HID_GENERIC 960
#define BLE_APPEARANCE_KEYBOARD_HID_SUBTYPE 961
#define BLE_APPEARANCE_MOUSE_HID_SUBTYPE 962
#define BLE_APPEARANCE_JOYSTICK_HID_SUBTYPE 963
#define BLE_APPEARANCE_GAMEPAD_HID_SUBTYPE 964
#define BLE_APPEARANCE_DIGITIZER_TABLET_HID_SUBTYPE 965
#define BLE_APPEARANCE_CARD_READER_HID_SUBTYPE 966
#define BLE_APPEARANCE_DIGITAL_PEN_HID_SUBTYPE 967
#define BLE_APPEARANCE_BARCODE_SCANNER_HID_SUBTYPE 968
#define BLE_APPEARANCE_GENERIC_GLUCOSE_METER 1024
#define UUID_ALERT_NOTIFICATION_SERVICE 0x1811
#define UUID_BATTERY_SERVICE 0x180F
#define UUID_BLOOD_PRESSURE_SERVICE 0x1810
#define UUID_CURRENT_TIME_SERVICE 0x1805
#define UUID_DEVICE_INFORMATION_SERVICE 0x180A
#define UUID_GLUCOSE_SERVICE 0x1808
#define UUID_HEALTH_THERMOMETER_SERVICE 0x1809
#define UUID_HEART_RATE_SERVICE 0x180D
#define UUID_HUMAN_INTERFACE_DEVICE_SERVICE 0x1812
#define UUID_IMMEDIATE_ALERT_SERVICE 0x1802
#define UUID_LINK_LOSS_SERVICE 0x1803
#define UUID_NEXT_DST_CHANGE_SERVICE 0x1807
#define UUID_PHONE_ALERT_STATUS_SERVICE 0x180E
#define UUID_REFERENCE_TIME_UPDATE_SERVICE 0x1806
#define UUID_SCAN_PARAMETERS_SERVICE 0x1813
#define UUID_TX_POWER_SERVICE 0x1804
#define BLE_SERVICE_SECONDARY 0
#define BLE_SERVICE_PRIMARY 1
#define BLE_CHAR_METADATA_ATTR_NOT_PRESENT 0
#define BLE_ATTR_ACCESS_NONE 0
#define BLE_ATTR_ACCESS_OPEN 1
#define BLE_ATTR_ACCESS_ENC_NO_MITM 2
#define BLE_ATTR_ACCESS_ENC_WITH_MITM 3
#define BLE_ATTR_ACCESS_SIGNED_NO_MITM 4
#define BLE_ATTR_ACCESS_SIGNED_WITH_MITM 5
#define BLE_CHAR_PROPERTIES_BROADCAST 0x01
#define BLE_CHAR_PROPERTIES_READ 0x02
#define BLE_CHAR_PROPERTIES_WRITE_WO_RESPONSE 0x04
#define BLE_CHAR_PROPERTIES_WRITE 0x08
#define BLE_CHAR_PROPERTIES_NOTIFY 0x10
#define BLE_CHAR_PROPERTIES_INDICATE 0x20
#define BLE_CHAR_PROPERTIES_AUTH_SIGNED_WR 0x40
#define BLE_CHAR_PROPERTIES_RELIABLE_WRITE 0x80
//Body Sensor Location values
#define BLE_HRS_BODY_SENSOR_LOCATION_OTHER 0
#define BLE_HRS_BODY_SENSOR_LOCATION_CHEST 1
#define BLE_HRS_BODY_SENSOR_LOCATION_WRIST 2
#define BLE_HRS_BODY_SENSOR_LOCATION_FINGER 3
#define BLE_HRS_BODY_SENSOR_LOCATION_HAND 4
#define BLE_HRS_BODY_SENSOR_LOCATION_EAR_LOBE 5
#define BLE_HRS_BODY_SENSOR_LOCATION_FOOT 6
//Types of advert packets
#define ADV_IND 0
#define ADV_DIRECT_IND 1
#define ADV_SCAN_IND 2
#define ADV_NONCONN_IND 3
//Types of filter policy
#define ADV_FILTERPOLICY_ANY 0
#define ADV_FILTERPOLICY_SCANREQ 1
#define ADV_FILTERPOLICY_CONNREQ 2
#define ADV_FILTERPOLICY_BOTH 3
//BLE EVENT MSG IDs
#define BLE_EVBLEMSGID_CONNECT 0 //msgCtx = connection handle
#define BLE_EVBLEMSGID_DISCONNECT 1 //msgCtx = connection handle
#define BLE_EVBLEMSGID_IMMEDIATE_ALERT_SERVICE_ALERT 2 //msgCtx = alert level
#define BLE_EVBLEMSGID_LINKLOSS_SERVICE_ALERT 3 //msgCtx = alert level
#define BLE_EVBLEMSGID_SERVICE_ERROR 4 //msgCtx = resultcode
#define BLE_EVBLEMSGID_HTS_INDICATION_STATE 5 //msgCtx = new indication state 0=off, 1=on
#define BLE_EVBLEMSGID_HTS_INDICATION_CNF 6 //msgCtx = not used
#define BLE_EVBLEMSGID_BPS_INDICATION_STATE 7 //msgCtx = new indication state 0=off, 1=on
#define BLE_EVBLEMSGID_BPS_INDICATION_CNF 8 //msgCtx = not used
#define BLE_EVBLEMSGID_DISPLAY_PASSKEY 9 //msgCtx = passcode to display
#define BLE_EVBLEMSGID_NEW_BOND 10 //msgCtx = connection handle
#define BLE_EVBLEMSGID_AUTH_KEY_REQUEST 11 //msgCtx = 1 for passkey, 2 for 16 byte OOB data
#define BLE_EVBLEMSGID_HRS_NOTIFICATION_STATE 12 //msgCtx = new notification state 0=off, 1=on
//#define FUTURE_USE 13
#define BLE_EVBLEMSGID_CONN_PARMS_UPDATE 14 //msgCtx = connection handle
#define BLE_EVBLEMSGID_CONN_PARMS_UPDATE_FAIL 15 //msgCtx = connection handle
#define BLE_EVBLEMSGID_CONN_TO_BONDED_MASTER 16 //msgCtx = connection handle
#define BLE_EVBLEMSGID_UPDATED_BOND 17 //msgCtx = connection handle
#define BLE_EVBLEMSGID_ENCRYPTED 18 //msgCtx = connection handle
#define BLE_EVBLEMSGID_POWER_FAILURE_WARNING 19 //msgCtx = current supply voltage
#define BLE_EVBLEMSGID_UNENCRYPTED 20 //msgCtx = connection handle
#define BLE_EVBLEMSGID_DEVICENAME_WRITE 21 //msgCtx = connection handle
//BLE Alert Levels
#define BLE_ALERT_LEVEL_NO_ALERT 0
#define BLE_ALERT_LEVEL_MILD_ALERT 1
#define BLE_ALERT_LEVEL_HIGH_ALERT 2
//Blood Pressure Feature Bits
#define BLE_BPS_FEATURE_BODY_MOVEMENT_BIT 1
#define BLE_BPS_FEATURE_CUFF_FIT_BIT 2
#define BLE_BPS_FEATURE_IRREGULAR_PULSE_BIT 4
#define BLE_BPS_FEATURE_PULSE_RATE_RANGE_BIT 8
#define BLE_BPS_FEATURE_MEASUREMENT_POSITION_BIT 16
#define BLE_BPS_FEATURE_MULTIPLE_BOND_BIT 32
//Blood Pressure Measurement Status flags
#define BLE_BPS_MEAS_STAT_BODY_MOVEMENT 1
#define BLE_BPS_MEAS_STAT_CUFF_FIT 2
#define BLE_BPS_MEAS_STAT_IRREGULAR_PULSE 4
#define BLE_BPS_MEAS_STAT_PULSE_RATE_RANGE 8
#define BLE_BPS_MEAS_STAT_MEASUREMENT_POSITION 16
//Pairing i/o capability
#define BLE_IOCAPABILITY_NONE 0
#define BLE_IOCAPABILITY_DISPLAY_YESNO 1
#define BLE_IOCAPABILITY_KEYBOARD_ONLY 2
#define BLE_IOCAPABILITY_DISPLAY_ONLY 3
#define BLE_IOCAPABILITY_KEYBOARD_DISPLAY 4
#define BLE_IOCAPABILITY_ILLEGAL 5
//Health thermometer sensor location
#define BLE_HTS_TEMP_TYPE_ARMPIT 1
#define BLE_HTS_TEMP_TYPE_BODY 2
#define BLE_HTS_TEMP_TYPE_EAR 3
#define BLE_HTS_TEMP_TYPE_FINGER 4
#define BLE_HTS_TEMP_TYPE_GI_TRACT 5
#define BLE_HTS_TEMP_TYPE_MOUTH 6
#define BLE_HTS_TEMP_TYPE_RECTUM 7
#define BLE_HTS_TEMP_TYPE_TOE 8
#define BLE_HTS_TEMP_TYPE_EAR_DRUM 9
//HCI Status Codes
#define BLE_HCI_AUTHENTICATION_FAILURE 0x05
#define BLE_HCI_CONNECTION_TIMEOUT 0x08
//Some Useful Result Codes to help with documentation
#define RESCODE_BLE_SVC_REGISTERED 0x6018
//******************************************************************************
// Global Variable Declarations
//******************************************************************************
//******************************************************************************
// Function and Subroutine definitions
//******************************************************************************
//******************************************************************************
// Handler definitions
//******************************************************************************
//******************************************************************************
// Equivalent to main() in C
//******************************************************************************
// -- lib\ble.sblib -- END
// -- lib\fast.slow.advert.mngr.sblib -- START
// Copyright (c) 2013, Laird
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// SPDX-License-Identifier:ISC
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ###### #######
// ###### Library File meant to be d in files #######
// ###### #######
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// This library contains contains a fast/slow advert manager and should be
// d in your app
//
// Usage: (also see sample hrs.heart.rate.sb for more details)
//
// (*) Call StartAdverts(...) from your code
//
//
//******************************************************************************
//******************************************************************************
// Definitions
//******************************************************************************
//******************************************************************************
// Library Import
//******************************************************************************
//******************************************************************************
// Global Variable Declarations
//******************************************************************************
dim advPhase //Will be 0 if not advertising, 1 for fast adverts, 2 for slow adverts
dim advState //Will be 0 if not advertising, 1,2,3,4 for the four advert types
dim advType //As per ADV_ in ble.sblib
dim addr$ //Peer address for Directed Adverts (MSB first) and exactly 6 bytes long
dim advInt //Adv interval in milliseconds in fast mode
dim advIntS //Adv interval in milliseconds in slow mode
dim advTmout //Adv timeout in milliseconds in fast mode
dim advTmoutS //Adv timeout in milliseconds in slow mode
dim advFilPol //Adv filter policy - see ADV_FILTERPOLICY_xxx in blelib.sblib
// 0 = Any
// 1 = Filter Scan Request
// 2 = Filter Connection Request
// 3 = Both
//******************************************************************************
// Initialisse Global Variable
//******************************************************************************
advState = 0
advPhase = 0
advType = ADV_IND
addr$ = ""
advInt = ADV_INTERVAL_MS
advIntS = ADV_INTERVAL_SLOW_MS
advTmout = ADV_TIMEOUT_MS
advTmoutS = ADV_TIMEOUT_SLOW_MS
advFilPol = ADV_WHITELIST_FILTER_POLICY
//******************************************************************************
// Function and Subroutine definitions
//******************************************************************************
//==============================================================================
// returns 0 if parameters are acceptable
//==============================================================================
function SetAdvertType(byval adType as integer,byref ad$ as string) as integer
if (adType>=ADV_IND)&&(adType<=ADV_NONCONN_IND) then
if (adType==ADV_DIRECT_IND) then
if (strlen(ad$)!=6) then
exitfunc 0
endif
addr$=ad$
endif
advType = adType
exitfunc 1
endif
endfunc 0
//==============================================================================
//==============================================================================
function GetAdvertState() as integer
endfunc advState
//==============================================================================
//==============================================================================
function SetAdvertInt(intvl as integer) as integer
if intvl < 20 then
exitfunc 0
endif
if advType >= ADV_SCAN_IND then
if intvl < 100 then
exitfunc 0
endif
endif
advInt = intvl
endfunc 1
//==============================================================================
//==============================================================================
function SetAdvertIntS(intvl as integer) as integer
if intvl < 20 then
exitfunc 0
endif
if advType >= ADV_SCAN_IND then
if intvl < 100 then
exitfunc 0
endif
endif
advIntS = intvl
endfunc 1
//==============================================================================
//==============================================================================
function SetAdvertTout(inttm as integer) as integer
if inttm < (advInt+20) then
exitfunc 0
endif
advTmout = inttm
endfunc 1
//==============================================================================
//==============================================================================
function SetAdvertToutS(inttm as integer) as integer
if inttm < (advIntS+20) then
exitfunc 0
endif
advTmoutS = inttm
endfunc 1
//==============================================================================
//==============================================================================
function SetAdvertFPol(fpol as integer) as integer
if (fpol >= ADV_FILTERPOLICY_ANY)&&(fpol <= ADV_FILTERPOLICY_BOTH)then
advFilPol = fpol
exitfunc 1
endif
endfunc 0
//==============================================================================
// Returns 0 if successful, otherwise appropriate error code
//==============================================================================
function StopAdverts() as integer
dim rc
rc=0
if advState != 0 then
//Currently advertising
rc = BleAdvertStop()
AssertResCode(rc,3000)
if rc==0 then
//Adverts stopped successfully
advState=0
endif
endif
endfunc rc
//==============================================================================
// -1 for the last valid type of advert that was sent
// 0 ADV_IND
// 1 ADV_DIRECT_IND
// 2 ADV_SCAN_IND
// 3 ADV_NONCONN_IND
//
// Returns 0 if successful, otherwise appropriate error code
//==============================================================================
function StartAdverts(adv as integer) as integer
dim rc
if advState == 0 then
//Currently not advertising
if adv == -1 then
adv = advType
elseif (adv<0)||(adv>3) then
//Invalid advertising type
rc=0xEF01
AssertResCode(rc,3120)
exitfunc rc
endif
rc = BleAdvertStart(adv,addr$,advInt,advTmout,advFilPol)
AssertResCode(rc,3100)
if rc==0 then
//Adverts started successfully
advType = adv
advState = advType + 1
advPhase = 1
endif
else
//Currently advertising
rc=0xEF00
AssertResCode(rc,3110)
endif
endfunc rc
//==============================================================================
// MUST be called from the BLE message handler
//==============================================================================
sub AdvMngrOnBleMsg(BYVAL nMsgId AS INTEGER, BYVAL nCtx AS INTEGER)
dim rc
select nMsgId
case BLE_EVBLEMSGID_CONNECT
advState=0
advPhase=0
case BLE_EVBLEMSGID_DISCONNECT
// restart advertising
rc=StartAdverts(-1)
AssertResCode(rc,3200)
case else
//Do nothing
endselect
endsub
//==============================================================================
// Will return 0 if no longer advertising
//==============================================================================
function AdvMngrOnAdvTimeOut() as integer
dim rc
advState = 0
if advPhase == 1 then
//start slow adverts
rc = BleAdvertStart(advType,addr$,advIntS,advTmoutS,advFilPol)
AssertResCode(rc,3300)
if rc==0 then
//adverts started successfully
advState = advType + 1
advPhase = 2
endif
else
advPhase = 0
endif
endfunc advState
//******************************************************************************
// Handler definitions
//******************************************************************************
//******************************************************************************
// Other initialisations
//******************************************************************************
// -- lib\fast.slow.advert.mngr.sblib -- END
// -- lib\advert.report.manager.sblib -- START
// Copyright (c) 2013, Laird
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// SPDX-License-Identifier:ISC
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ###### #######
// ###### Library File meant to be d in files #######
// ###### #######
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// This library contains contains the advert & scan report manager and should be
// d in your app
//
//
//******************************************************************************
//******************************************************************************
// Definitions
//******************************************************************************
//******************************************************************************
// Library Import
//******************************************************************************
//******************************************************************************
// Global Variable Declarations
//******************************************************************************
dim adRpt$ as string //Contains the most recent Advertise report
dim scRpt$ as string //Contains the most recent scan report
dim advUuid[6] //These are the uuid's that are exposed
dim advUuidCnt //Uuid Counts for advert report
//******************************************************************************
// Initialise Global Variable
//******************************************************************************
adRpt$=""
scRpt$=""
//Initialise the uuid array list with -1 which will be taken as item not to
//to be included in the advert report for the uuid AD element.
for advUuidCnt=0 to 5
advUuid[advUuidCnt]=-1
next
advUuidCnt = 0
//******************************************************************************
// Function and Subroutine definitions
//******************************************************************************
//==============================================================================
// Will add to array if there is space
//==============================================================================
sub AddUuid(nUuid as integer)
if advUuidCnt < 5 then
advUuid[advUuidCnt]=nUuid
advUuidCnt = advUuidCnt + 1
endif
endsub
//==============================================================================
// advFlags = Flags for Advert Report
//==============================================================================
sub InitAdvReports(advFlags as integer)
dim rc
adRpt$=""
scRpt$=""
//If whitelist filter policy is enabled and there is at least one master
//in the bonding manager, then need to reset the advFlags so that
//discoverability is disabled
if advFilPol != ADV_FILTERPOLICY_ANY then
//Filter policy has been enabled
if sysinfo(2009) != 0 then
//There is at least one master in the trusted device database
advFlags = advFlags & 0xFFFFFFFC
endif
endif
//Create a minimal advertise report
rc = BleAdvRptInit(adRpt$,advFlags,ADV_APPEARANCE,MAX_DEVNAME_CHRS)
AssertResCode(rc,2030)
//Append the uuid list to the advert report
rc = BleAdvRptAddUuid16(adRpt$,advUuid[0],advUuid[1],advUuid[2],advUuid[3],advUuid[4],advUuid[5])
AssertResCode(rc,2040)
//Initialise an empty scan report
rc = BleScanRptInit(scRpt$)
AssertResCode(rc,2045)
//Commit the advert and scan report to the scan
rc = BleAdvRptsCommit(adRpt$,scRpt$)
AssertResCode(rc,2050)
endsub
//==============================================================================
//==============================================================================
function ScanReportInit()
dim rc
rc = BleScanRptInit(scRpt$)
AssertResCode(rc,2060)
endfunc rc
//==============================================================================
//==============================================================================
function ScanReportAppend(nTag as integer, byref adData$ as string)
dim rc
rc = BleAdvRptAppendAD(scRpt$,nTag,adData$)
AssertResCode(rc,2070)
endfunc rc
//==============================================================================
//==============================================================================
function ScanReportCommit()
dim rc,rpt$
rpt$=""
rc = BleAdvRptsCommit(rpt$,scRpt$)
AssertResCode(rc,2080)
endfunc rc
//******************************************************************************
// Handler definitions
//******************************************************************************
//******************************************************************************
// Other initialisations
//******************************************************************************
// -- lib\advert.report.manager.sblib -- END
// -- lib\connection.manager.sblib -- START
// Copyright (c) 2013, Laird
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
// IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// SPDX-License-Identifier:ISC
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ###### #######
// ###### Library File meant to be d in files #######
// ###### #######
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// This library contains contains the connection manager and should be
// d in your app
//
//******************************************************************************
//******************************************************************************
// Definitions
//******************************************************************************
//******************************************************************************
// Library Import
//******************************************************************************
//******************************************************************************
// Global Variable Declarations
//******************************************************************************