-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrecord.js
More file actions
105 lines (81 loc) · 2.31 KB
/
record.js
File metadata and controls
105 lines (81 loc) · 2.31 KB
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
/*
record.js - records packets from JS8Call for later playback.
This uses lib-js8Call.
It saves the data in a filename that has the UTC date and time in it.
An example is: js8data20210112165111.json
The packets are saved when the connection to JS8Call is closed
and the date and time of the filename are set then.
*/
let connected = false;
let packets = [];
const fs = require('fs')
const storeData = (data, path) => {
try {
console.log('Saving data to: ' + path);
fs.writeFileSync(path, JSON.stringify(data))
} catch (err) {
console.error(err)
}
}
const loadData = (path) => {
try {
return fs.readFileSync(path, 'utf8')
} catch (err) {
console.error(err)
return false
}
}
const js8 = require('@trippnology/lib-js8call')({
tcp: { enabled: true, port: 2442 },
udp: { disabled: false, port: 2242, },
});
function timeoutCheck()
{
if(!connected)
{
js8.tcp.connect();
}
}
setInterval(timeoutCheck, 5000);
js8.on('tcp.connected', (connection) => {
console.log(
'Server listening %s:%s Mode: %s',
connection.address,
connection.port,
connection.mode
);
connected = true;
});
function getUTCDateTimeString()
{
const date = new Date();
const year = date.getUTCFullYear();
const month = `${date.getUTCMonth() + 1}`.padStart(2, '0');
const day =`${date.getUTCDate()}`.padStart(2, '0');
const hours =`${date.getUTCHours()}`.padStart(2, '0');
const minutes =`${date.getUTCMinutes()}`.padStart(2, '0');
const seconds =`${date.getUTCSeconds()}`.padStart(2, '0');
return `${year}${month}${day}${hours}${minutes}${seconds}`
}
js8.on('tcp.disconnected', (s) => {
// Lost the tcp connection
console.log(s);
let utcDateTime = getUTCDateTimeString();
storeData(packets, "./testdata/js8data" + utcDateTime + ".json");
connected = false;
process.exit(1);
});
js8.on('tcp-error', (e) => {
// tcp error
console.log();
});
js8.on('packet', (packet) => {
// Do your custom stuff
//console.log(packet);
packets.push(packet);
console.log(packets.length);
});
// Need to request the text that is sent (not worrying about typeahead here although JS8Assistant will)
js8.on('rig.ptt', (packet) => {
js8.tx.getText();
});