-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-then-stop-survey.js
89 lines (84 loc) · 1.95 KB
/
start-then-stop-survey.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
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
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(lteSurvey)
})
.then(resp => {
if (resp.ok) {
return resp.json()
}
return Promise.reject(resp)
})
.then(
result => {
console.log('SURVEY Started', result)
const survey_id = result.survey_id
setTimeout(() => {
console.log('Five seconds have passed, stopping survey')
stopSurvey(result.survey_id)
}, 5000)
},
err => {
console.error('ERROR:', err)
conn.close()
}
)
}
const stopSurvey = survey_id => {
fetch(`http://${args.remote}/sklt/survey/${survey_id}/state/`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify('stopped')
})
.then(resp => {
if (resp.ok) {
return resp.json()
}
return Promise.reject(resp)
})
.then(
result => {
console.log('SURVEY Stopped', result)
conn.close()
},
err => {
console.error('ERROR Stopping survey:', survey_id, 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 lteSurvey = {
one_shot: false,
rx_port: args['rx-port'],
survey_parameters: [
{
tech: 'lte',
type: 'band',
bands: [
{ band: '2', channels: [] },
{ band: '4', channels: [] }
]
},
{
tech: 'p25',
type: 'frequency-list',
frequencies_hz: [769806250, 770793750, 773206250, 773718750, 774706250]
}
]
}