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
/
uri.beacon.sb
152 lines (138 loc) · 5.64 KB
/
uri.beacon.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
// Copyright (c) 2015, 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 ++
// +++++ ++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
// This creates a URIBeacon advertising a link to the Laird Tech website
// Complies with the URIBeacon advertising specification:
// https://github.com/google/uribeacon/blob/master/specification/AdvertisingMode.md
//
//******************************************************************************
//******************************************************************************
// Definitions
//******************************************************************************
#define ADVERT_INTERVAL 200 //Advertising interval (ms)
#define ADVERT_TIMEOUT 60000 //Advertising timeout (s)
#define RESTART_ADVERTISING 1 //If set to 1, will restart advertising when it times out, otherwise sits idle
#define TXPOWER -4 //Desired transmit power level (dBm)
#define FLAGS 0 //Set to 1 to advertise with a hidden hint, otherwise leave as 0
//******************************************************************************
// Library Import
//******************************************************************************
//******************************************************************************
// Global Variable Declarations
//******************************************************************************
// Prefix of URL:
// 0x00 : http://www.
// 0x01 : https://www.
// 0x02 : http://
// 0x03 : https://
dim UrlType : UrlType = 0x00
// Domain URL:
// Will replace \XX with;
// \00 : .com/
// \01 : .org/
// \02 : .edu/
// \03 : .net/
// \04 : .info/
// \05 : .biz/
// \06 : .gov/
// \07 : .com
// \08 : .org
// \09 : .edu
// \0a : .net
// \0b : .info
// \0c : .biz
// \0d : .gov
dim Url$ : Url$ = "lairdtech\00"
//Result code and service ID
dim rc, svcID
//******************************************************************************
// Function and Subroutine definitions
//******************************************************************************
SUB AssertRC(rc, tag)
if (rc != 0) then
print "Error, rc = ";integer.h'rc;" at tag ";tag;"\n"
endif
ENDSUB
FUNCTION SetupAdverts()
//Sets up adverts
dim Dat$, advRpt$, scanRpt$
advRpt$ = ""
scanRpt$ = ""
Dat$ = ""
rc = BleEncode16(Dat$, 0xFED8, 0) //Service ID
AssertRC(rc, 1)
rc = BleEncode8(Dat$, FLAGS, 2) //Flags
AssertRC(rc, 2)
rc = BleEncode8(Dat$, SYSINFO(2008), 3) //TX Power
AssertRC(rc, 3)
rc = BleEncode8(Dat$, UrlType, 4) //URL prefix
AssertRC(rc, 4)
rc = BleEncodeString(Dat$, 5, Url$, 0, strlen(Url$)) //URL
AssertRC(rc, 5)
rc = BLEADVRPTINIT(advRpt$, 0, 0, 0) //Not connectable
AssertRC(rc, 6)
rc = BLESCANRPTINIT(scanRpt$)
AssertRC(rc, 7)
rc = BLEADVRPTADDUUID16(advRpt$, 0xFED8, -1, -1, -1, -1, -1) //Add service to advert report
AssertRC(rc, 8)
rc = BLEADVRPTAPPENDAD(advRpt$, 0x16, Dat$) //Add URIBeacon data to advert report
AssertRC(rc, 9)
rc = BLEADVRPTSCOMMIT(advRpt$, scanRpt$) //Save advert data
AssertRC(rc, 10)
ENDFUNC 1
FUNCTION StartAdverts()
//Starts advertising
dim addr$ : addr$ = ""
rc = BleAdvertStart(0, addr$, ADVERT_INTERVAL, ADVERT_TIMEOUT, 0)
AssertRC(rc, 11)
ENDFUNC 1
FUNCTION HndlrAdvTimeout()
//Runs when adverts time out
IF (RESTART_ADVERTISING == 1) THEN
//Mode set to restart advertising
rc = StartAdverts()
ENDIF
ENDFUNC 1
//******************************************************************************
// Handler definitions
//******************************************************************************
ONEVENT EVBLE_ADV_TIMEOUT CALL HndlrAdvTimeout
//******************************************************************************
// Equivalent to main() in C
//******************************************************************************
//Create service
rc = BleServiceNew(1, BleHandleUuid16(0xFED8), svcID)
AssertRC(rc, 12)
rc = BleServiceCommit(svcID)
AssertRC(rc, 13)
//Set TX power
rc = BLETXPOWERSET(TXPOWER)
AssertRC(rc, 14)
//Setup and start advertising
rc = SetupAdverts()
rc = StartAdverts()
//------------------------------------------------------------------------------
// Wait for a synchronous event.
// An application can have multiple <WaitEvent> statements
//------------------------------------------------------------------------------
WAITEVENT