-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodel.go
281 lines (222 loc) · 5.02 KB
/
model.go
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
package goble
import (
"github.com/MarinX/serial"
)
// Test with HM-10 - Firmware v540
const (
// Test connection
test = "AT"
// Device MAC Address
getDeviceAddress = "AT+ADDR?"
// Device Advertising Interval
getAdvertisingInt = "AT+ADVI?"
setAdvertisingInt = "AT+ADVI%s"
// Device Advertising Type
getAdvertisingType = "AT+ADTY?"
setAdvertisingType = "AT+ADTY%d"
// Device Battery Information
getBatteryInfo = "AT+BATT?"
// Device Baud Rate
getBaudRate = "AT+BAUD?"
setBaudRate = "AT+BAUD%d"
// Device Characteristic
getChar = "AT+CHAR?"
setChar = "AT+CHAR0x%s" // 1-65534
// Clear last connected device Address
clear = "AT+CLEAR"
// Set iBeacon deploy mode
setDeployMode = "AT+DELO%d"
// iBeacon Mode switch
getBeacon = "AT+IBEA?"
setBeacon = "AT+IBEA%d"
// iBeacon UUID
getUUID = "AT+IBE%d?"
setUUID = "AT+IBE%d%s" //1-4294967294
// iBeacon Major
getMajor = "AT+MARJ?"
setMajor = "AT+MARJ0x%s" // 1-65534
// iBeacon Minor
getMinor = "AT+MINO?"
setMinor = "AT+MINO0x%s" // 1-65534
// iBeacon Measured power
getIPower = "AT+MEA??"
setIPower = "AT+MEA0x%s" //1-255 /!\ DANGER /!\
// Device Work Mode
getMode = "AT+MODE?"
setMode = "AT+MODE%d"
// Device Name
getDeviceName = "AT+NAME?"
setDeviceName = "AT+NAME%s"
// Parity bit
getParity = "AT+PARI?"
setParity = "AT+PARI%d"
// PIO1 output status (System Led)
getStatus = "AT+PIO1?"
setStatus = "AT+PIO1%d"
// PIO pins outputs
getPIO = "AT+PIO%s?"
setPIO = "AT+PIO%s%d"
// Device Pin code (000000-999999)
getPin = "AT+PASS?"
setPin = "AT+PASS%d"
// Device power
getPower = "AT+POWE?"
setPower = "AT+POWE%d"
// Restore factory parameters
factoryReset = "AT+RENEW"
// Restart device
restart = "AT+RESET"
// Device Role
getRole = "AT+ROLE?"
setRole = "AT+ROLE%d"
// Last connected device address
lastDeviceAddress = "AT+RADD?"
// Device Bond Mode
getBondMode = "AT+TYPE?"
setBondMode = "AT+TYPE%d"
// Device UUID
getDeviceUUID = "AT+UUID?"
setDeviceUUID = "AT+UUID%s"
// Firmware version
getSoftwareVersion = "AT+VERS?"
)
// BleAdvertisingInt type
type BleAdvertisingInt string
// BleAdvertisingType type
type BleAdvertisingType int
// BleBaudRate type
type BleBaudRate int
// BleDeployMode type
type BleDeployMode int
// BleBeaconMode type
type BleBeaconMode int
// BleUUID type
type BleUUID int
// BleMode type
type BleMode int
// BleParity type
type BleParity int
// BlePIO type
type BlePIO int
// BlePIOPin type
type BlePIOPin string
// BlePower type
type BlePower int
// BleRole type
type BleRole int
// BleBondMode type
type BleBondMode int
// Ble advertising interval
const (
Ms100 BleAdvertisingInt = "0"
Ms152 BleAdvertisingInt = "1"
Ms211 BleAdvertisingInt = "2"
Ms318 BleAdvertisingInt = "3"
Ms417 BleAdvertisingInt = "4"
Ms546 BleAdvertisingInt = "5"
Ms760 BleAdvertisingInt = "6"
Ms852 BleAdvertisingInt = "7"
Ms1022 BleAdvertisingInt = "8"
Ms1285 BleAdvertisingInt = "9"
Ms2000 BleAdvertisingInt = "A"
Ms3000 BleAdvertisingInt = "B"
Ms4000 BleAdvertisingInt = "C"
Ms5000 BleAdvertisingInt = "D"
Ms6000 BleAdvertisingInt = "E"
Ms7000 BleAdvertisingInt = "F"
)
// Ble advertising type
const (
AllinOne BleAdvertisingType = 0 // Advertising, ScanResponse, Connectable
LastDevice BleAdvertisingType = 1 // Only allow last device connect
AdAndScan BleAdvertisingType = 2 // Only allow Advertising and ScanResponse
OnlyAd BleAdvertisingType = 3 // Only allow advertising
)
// Ble baud rate
const (
B9600 BleBaudRate = 0
B19200 BleBaudRate = 1
B38400 BleBaudRate = 2
B57600 BleBaudRate = 3
B115200 BleBaudRate = 4
B4800 BleBaudRate = 5
B2400 BleBaudRate = 6
B1200 BleBaudRate = 7
B230400 BleBaudRate = 8
)
// Ble iBeacon Deploy Mode
const (
BroadAndScan BleDeployMode = 1
BroadOnly BleDeployMode = 2
)
//Ble beacon mode
const (
IBeaconDisable BleBeaconMode = 0
IBeaconEnable BleBeaconMode = 1
)
// Ble UUIS
const (
Part1 BleUUID = 0
Part2 BleUUID = 1
Part3 BleUUID = 2
Part4 BleUUID = 3
)
//Ble mode
const (
Transmission BleMode = 0 // Transmission mode
PIO BleMode = 1 // PIO collection mode + mode 0
Remote BleMode = 2 // Remote control mode + mode 0
)
// Ble parity mode
const (
None BleParity = 0
Even BleParity = 1
Odd BleParity = 2
)
//Ble pin output
const (
Low BlePIO = 0
High BlePIO = 1
)
//Ble pio pins
const (
Pin2 BlePIOPin = "2"
Pin3 BlePIOPin = "3"
Pin4 BlePIOPin = "4"
Pin5 BlePIOPin = "5"
Pin6 BlePIOPin = "6"
Pin7 BlePIOPin = "7"
Pin8 BlePIOPin = "8"
Pin9 BlePIOPin = "9"
PinA BlePIOPin = "A"
PinB BlePIOPin = "B"
)
// Ble device power
const (
P0 BlePower = 0 // -23 dbm
P1 BlePower = 1 // -6 dbm
P2 BlePower = 2 // 0 dbm (default)
P3 BlePower = 3 // 6 dbm
)
//Ble role
const (
RoleSlaver BleRole = 0
RoleMaster BleRole = 1
)
//Ble bond mode
const (
NotNeedPinCode BleBondMode = 0
AuthNotNeedPin BleBondMode = 1
AuthWithPin BleBondMode = 2
AuthAndBond BleBondMode = 3
)
// Ble struct
type Ble struct {
fd *serial.Port
}
// BleResponse struct
type BleResponse struct {
Error error
Result string
Param interface{}
}