-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-new-one-shot-p25.js
56 lines (52 loc) · 1.17 KB
/
start-new-one-shot-p25.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import fetch from 'node-fetch'
import WebSocket from 'ws'
import argv from './args.js'
const args = argv.parse()
const startSurvey = () => {
fetch(`http://${args.remote}/sklt/survey/`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(p25Survey)
})
.then(resp => {
if (resp.ok) {
return resp.json()
}
return Promise.reject(resp)
})
.then(
result => {
console.log('SURVEY Started', result)
},
err => {
console.error('ERROR:', err)
conn.close()
}
)
}
const conn = new WebSocket(`ws://${args.remote}/events/`, ['sklt'])
conn.on('open', () => {
console.log('CONNECTED to WS')
startSurvey()
})
conn.on('close', () => {
console.error('DISCONNECTED from WS')
})
conn.on('message', msg => {
console.log('MSG: %s', msg)
const parsed = JSON.parse(msg)
if (parsed.data.type === 'end_of_scan') {
conn.close()
}
})
const p25Survey = {
one_shot: true,
rx_port: args['rx-port'],
survey_parameters: [
{
tech: 'p25',
type: 'frequency-list',
frequencies_hz: [769806250, 770793750, 773206250, 773718750, 774706250]
}
]
}