-
Notifications
You must be signed in to change notification settings - Fork 0
/
soarBT.c
191 lines (177 loc) · 5.03 KB
/
soarBT.c
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
#include <PalmOS.h>
#include "soarBT.h"
/**
* \file soarBT.c
* \brief SoarPilot Bluetooth code
*/
/**************/
/* BT Globals */
/**************/
//static UInt16 unPortId;
static UInt16 btLibRefNum=0;
UInt8 BTAddress[6];
static Err err;
//static SrmOpenConfigType config;
//static BtVdOpenParams btParams;
//static BtLibSdpUuidType sppUuid;
/***********************/
/* Load the BT library */
/***********************/
static void BT_LoadLibrary()
{
btLibRefNum=0;
// BT library already in memory?
err=SysLibFind("Bluetooth Library",&btLibRefNum);
if(err) {
// nope, then load it
err=SysLibLoad(sysFileTLibrary,sysFileCBtLib,&btLibRefNum);
}
}
/****************************************/
/* Find a BT device on air */
/* On success return 0, else error code */
/* BTAddress array is filled with user */
/* selected address. */
/****************************************/
Err BT_FindDevice()
{
if (!btLibRefNum) {
BT_LoadLibrary();
}
if(btLibRefNum && !err)
{
err=BtLibOpen(btLibRefNum,false);
if(!err) {
/*
Discover all available devices, present them
in the user interface, and allow the user to select one
of these devices.
Parameters
- btLibRefNum
Reference number for the Bluetooth library.
- instructionTxt
Text displayed at the top of the selection box.
Pass NULL to display the default text.
The default text is "Select a device:"
- deviceFilterList
Array of BtLibClassOfDeviceTypes. This function
displays only the remote devices whose class matches
a class in this list. If deviceFilterList is NULL,
this function displays all discovered devices.
- deviceFilterListLen
Number of elements in deviceFilterList.
- selectedDeviceP
Pointer to a BtLibDeviceAddressType where this function
stores the address of the device the user selects.
You need to allocate this space before calling this function.
- addressAsName
If true, display the Bluetooth addresses of the remote
devices instead of their names. This option is available
for debugging purposes.
- showLastList
If true, causes all other parameters to be ignored and
displays the same list as the previous call to
BtLibDiscoverSingleDevice.
*/
err=BtLibDiscoverSingleDevice(btLibRefNum,
NULL,
NULL,
0,
(BtLibDeviceAddressType *)BTAddress,
false,
false);
}
BtLibClose(btLibRefNum);
}
return err;
}
/************************************/
/* Pause n milliseconds */
/************************************/
/*
static void Uti_WaitMilliSec(UInt32 ulMilliSec)
{
UInt16 unTickPerSec;
unTickPerSec=SysTicksPerSecond();
if(unTickPerSec)
SysTaskDelay(ulMilliSec*unTickPerSec/1000);
else
SysTaskDelay(ulMilliSec/10);
}
*/
/**************************************/
/* Close a Bluetooth serial connetion */
/**************************************/
/* not used for now, rely on SrmExtOpen instead
static void BT_Close()
{
if(unPortId)
{
SrmClose(unPortId);
unPortId=0;
Uti_WaitMilliSec(500);
SrmClose(unPortId); // Retry, on some system it's hard to die
}
}
*/
/**************************************/
/* Open a Bluetooth serial connection */
/**************************************/
/* not used for now, rely on SrmExtOpen instead
static void BT_Open()
{
BT_Close();
MemSet(&sppUuid, sizeof(sppUuid), 0);
sppUuid.size = btLibUuidSize16;
sppUuid.UUID[0] = 0x11;
sppUuid.UUID[1] = 0x01;
MemSet(&btParams, sizeof(btParams), 0);
btParams.u.client.remoteDevAddr.address[0]=cAddress[0];
btParams.u.client.remoteDevAddr.address[1]=cAddress[1];
btParams.u.client.remoteDevAddr.address[2]=cAddress[2];
btParams.u.client.remoteDevAddr.address[3]=cAddress[3];
btParams.u.client.remoteDevAddr.address[4]=cAddress[4];
btParams.u.client.remoteDevAddr.address[5]=cAddress[5];
btParams.role = btVdClient;
btParams.u.client.method = btVdUseUuidList;
btParams.u.client.u.uuidList.tab = &sppUuid;
btParams.u.client.u.uuidList.len = 1;
MemSet(&config, sizeof(config), 0);
config.function = serFncUndefined;
config.drvrDataP = (MemPtr)&btParams;
config.drvrDataSize = sizeof(btParams);
err=SrmExtOpen(sysFileCVirtRfComm,&config,sizeof(config),&unPortId);
}
*/
/****************/
/* Flush BT ser */
/****************/
/*
static void BT_Flush(UInt16 unTimeout)
{
if(unPortId)
err=SrmReceiveFlush(unPortId,unTimeout);
}
*/
/****************/
/* Send BT data */
/****************/
/*
static void BT_Send(char * pData,UInt16 unLen)
{
if(unPortId)
SrmSend(unPortId,pData,unLen,&err);
}
*/
/*******************/
/* Receive BT data */
/*******************/
/*
static UInt16 BT_Receive(char * pData,UInt16 unLen,UInt16 unTimeout)
{
UInt16 unLenRead;
if(unPortId)
unLenRead=SrmReceive(unPortId,pData,unLen,unTimeout,&err);
return(unLenRead);
}
*/