| 262 | */ |
| 263 | class Bonded { |
| 264 | static get(usageID) { |
| 265 | const buffer = Preference.get(Bonded.PREFERENCE_DOMAIN, Bonded.key(usageID)); |
| 266 | if (buffer) { |
| 267 | let index = 1; |
| 268 | const entry = new Uint8Array(buffer); |
| 269 | const address = entry.slice(index, index + 6).buffer; |
| 270 | index += 6; |
| 271 | const addressType = entry[index++]; |
| 272 | const serviceStartHandle = entry[index++] | (entry[index++] << 8); |
| 273 | const serviceEndHandle = entry[index++] | (entry[index++] << 8); |
| 274 | const reportCount = entry[index++]; |
| 275 | const reports = new Array(reportCount); |
| 276 | const services = [new Service({ start:serviceStartHandle, end:serviceEndHandle })]; |
| 277 | for (let i = 0; i < reportCount; ++i) { |
| 278 | const reportType = entry[index++]; |
| 279 | const handle = entry[index++] | (entry[index++] << 8); |
| 280 | const characteristic = new Characteristic({ handle, type:"Uint8Array" }); |
| 281 | services[0].characteristics.push(characteristic); |
| 282 | reports[i] = { reportType, characteristic }; |
| 283 | } |
| 284 | const bonded = { |
| 285 | device: { address, addressType, services }, |
| 286 | reports |
| 287 | }; |
| 288 | return bonded; |
| 289 | } |
| 290 | } |
| 291 | static set(usageID, device, reports) { |
| 292 | const length = 13 + ((1 + 2) * reports.length); |
| 293 | let entry = new Uint8Array(length); |