-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbcs.js
36 lines (33 loc) · 1.02 KB
/
bcs.js
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
const genmega = require('./build/Release/genmega.node')
const return_codes = require('./return_codes')
const return_messages = require('./return_messages')
exports.scan = (serialPortName, mobilePhoneMode) => {
return new Promise(resolve => {
/* There's a timeout at ~30s, but we never learn of it... */
let timeout = setTimeout(() => {
timeout = null
const decoded = null
const return_int = -9
resolve({ decoded, return_int })
exports.cancelScan()
}, 31000)
genmega._BCSScan(
serialPortName,
mobilePhoneMode,
(return_int, decoded) => {
if (timeout) {
clearTimeout(timeout)
console.log("BCSScan resolving with return_int", return_int, "and decoded", decoded)
resolve({ decoded, return_int })
}
}
)
})
.then(({ decoded, return_int }) => ({
decoded,
return_int,
return_code: return_codes[return_int],
return_message: return_messages[return_int],
}))
}
exports.cancelScan = () => genmega._BCSCancelScan()