This repository has been archived by the owner on Jan 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwt.js
85 lines (68 loc) · 2.7 KB
/
wt.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
// *******************************************************************************************
// ** wt.js
// **
// ** This libaray handles the parsing and creating of Win-Test (rotator) messages for ARSCTL.
// **
// **
// ** (c) Tobias Wellnitz (DH1TW), 2015
// ********************************************************************************************
exports.decodeMsg = function (msg){
var bandMappingRev = {1: "160m", 2:"80m", 3:"40m", 4:"30m", 5:"20m", 6:"17m", 7:"15m", 8:"12m", 9:"10m"}
var wtMsg = {};
var originalMsg = msg;
var frameType;
var fromStation;
var toStation;
var data;
var selector;
var antenna;
var band;
var rotator;
var heading;
try{
var frameType = msg.match("[A-Z]+:")[0];
msg = msg.replace(frameType, "");
frameType = frameType.replace(":", "");
wtMsg["frameType"] = frameType;
var fromStation = msg.match(/["][\w\d\s]{0,}["]/i)[0];
msg = msg.replace(fromStation, "");
fromStation = fromStation.replace(/["]/g, '');
wtMsg["fromStation"] = fromStation;
var toStation = msg.match(/["][\w\d\s]{0,}["]/i)[0];
msg = msg.replace(toStation, "");
toStation = toStation.replace(/["]/g, '');
wtMsg["toStation"] = toStation;
var data = msg.substring(0, msg.length-1); //chop off checksum
if (frameType == "SETAZIMUTH"){
var selector = data.match(/["][\w\d\s]{0,}["]/i)[0];
data = data.replace(selector, "");
selector = selector.replace(/["]/g, '');
wtMsg["selector"] = selector;
if (selector == "ANTENNA"){
var antenna = data.match(/["][\w\d\s\W]{0,}["]/i)[0];
data = data.replace(antenna, "");
antenna = antenna.replace(/["]/g, '');
wtMsg["antenna"] = antenna;
}
else if(selector == "AUTO"){
var band = data.match(/[ ][0-9][ ]/)[0];
data = data.replace(band, "");
band = band.replace(/[^0-9]/g, '');
wtMsg["band"] = bandMappingRev[band];
}
else if(selector == "ROTATOR"){
var rotator = data.match(/["][\w\d\s\W]{0,}["]/i)[0];
data = data.replace(rotator, "");
rotator = rotator.replace(/["]/g, '');
wtMsg["rotator"] = rotator;
}
var heading = data.match(/[0-9]{1,3}/)[0];
wtMsg["heading"] = heading;
}
}
catch(err){
// console.log("Can't decode Win-Test Message -> " + originalMsg + " throwing -> " + err);
wtMsg = null;
}
return wtMsg;
}