forked from LairdCP/BL600-Applications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conn.mngr.custom.sb
125 lines (112 loc) · 5.3 KB
/
conn.mngr.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
// 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 ++
// +++++ ++
// +++++ In this case $autorun$ will be the filename ++
// +++++ ++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//
// LT Connection Manager Service example
// This demonstrates a workaround for the disconnect delay associated
// with iOS. Now instead of locally calling a disconnect function, the iOS
// app can write the special magic value D15C (0x5CD1) to a custom value.
//
// "conn.mngr.custom.sb"
//
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// When UwTerminal downloads the app it will store it as conn
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//******************************************************************************
//******************************************************************************
// Definitions
//******************************************************************************
//Laird Technologies 128 bit Base UUID
#define LT_BASE_UUID "\56\9a\00\00\b8\7f\49\0c\92\cb\11\ba\5e\a5\16\7c\"
//Connection Manager Service 16 bit UUID
#define CONNMNGR_SVC_UUID 0x1901
//Disconnect Proxy Characteristic 16 bit UUID
#define DISCON_CHAR_UUID 0x2020
//******************************************************************************
// Global Variable Declarations
//******************************************************************************
dim rc //Result code
dim hConn //Connection handle
dim hChar //Characteristic handle
dim addr$ //Peer address
//******************************************************************************
// Function and Subroutine definitions
//******************************************************************************
Sub OnStartup()
dim bseUuid$ : bseUuid$ = LT_BASE_UUID //LT Base Uuid
dim hBseUuid : hBseUuid = BleHandleUuid128(bseUuid$) //LT Base uuid handle
dim hSvc //Service handle
dim hUuidSvc //Service uuid handle
dim hUuidChar //Characteristic uuid handle
dim attr$ //Empty char value variable
//Commit service to GATT table
hUuidSvc=BleHandleUuidSibling(hBseUuid, CONNMNGR_SVC_UUID)
rc=BleSvcCommit(1,hUuidSvc, hSvc)
//Commit char to GATT table
hUuidChar=BleHandleUuidSibling(hBseUuid, DISCON_CHAR_UUID)
rc=BleCharNew(0x08,hUuidChar,BleAttrMetaData(0,1,2,0,rc),0,0)
attr$="\00\00"
rc=BleCharCommit(hSvc,attr$,hChar)
EndSub
//******************************************************************************
// Handler definitions
//******************************************************************************
Function HndlrBleMsg(msgID, hCon)
hConn = hCon
select msgID
case 0
print "\n --- New connection"
print "\n Write 'D15C' to the Disconnect Proxy characteristic"
case 1
print "\n --- Disconnected"
ExitFunc 0
case else
endselect
EndFunc 1
Function HndlrCharVal(char, offset, len)
dim val$
if char==hCHar then
rc=BleCharValueRead(hChar, val$)
print "\nChar Val: "; StrHexize$(val$)
if StrCmp(val$,"\D1\5C")==0 then
rc=BleDisconnect(hConn)
endif
endif
EndFunc 1
//******************************************************************************
// Equivalent to main() in C
//******************************************************************************
OnStartup()
OnEvent EvBleMsg call HndlrBleMsg
OnEvent EvCharVal call HndlrCharVal
//Start advertising
rc=BleAdvertStart(0,addr$,100,0,0)
print "\nMake a connection to the BL600"
//------------------------------------------------------------------------------
// Wait for a synchronous event.
// An application can have multiple <WaitEvent> statements
//------------------------------------------------------------------------------
waitevent