forked from robotastic/trunk-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smartnet_parser.cc
105 lines (92 loc) · 2.76 KB
/
smartnet_parser.cc
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
#include "smartnet_parser.h"
using namespace std;
SmartnetParser::SmartnetParser() {
lastaddress = 0;
lastcmd = 0;
}
double SmartnetParser::getfreq(int cmd) {
/* Different Systems will have different band plans. Below is the one for WMATA which is a bit werid:*/
/* if (cmd < 0x12e) {
freq = float((cmd) * 0.025 + 489.0875);
} else if (cmd < 0x2b0) {
freq = float((cmd-380) * 0.025 + 489.0875);
} else {
freq = 0;
}
cout << "CMD: 0x" << hex << cmd << " Freq: " << freq << " Multi: " << (cmd - 308) * 0.025 << " CMD: " << dec << cmd << endl;
*/
float freq;
if (cmd < 0x1b8) {
freq = float(cmd * 0.025 + 851.0125);
} else if (cmd < 0x230) {
freq = float(cmd * 0.025 + 851.0125 - 10.9875);
} else {
freq = 0;
}
return freq*1000000;
}
std::vector<TrunkMessage> SmartnetParser::parse_message(std::string s) {
std::vector<TrunkMessage> messages;
TrunkMessage message;
message.message_type = UNKNOWN;
message.encrypted = false;
message.tdma = false;
message.source = 0;
message.sysid = 0;
message.emergency = false;
std::vector<std::string> x;
boost::split(x, s, boost::is_any_of(","), boost::token_compress_on);
int full_address = atoi( x[0].c_str() );
int status = full_address & 0x000F;
long address = full_address & 0xFFF0;
//int groupflag = atoi( x[1].c_str() );
int command = atoi( x[2].c_str() );
x.clear();
vector<string>().swap(x);
if ((address & 0xfc00) == 0x2800) {
message.sysid = lastaddress;
message.message_type = SYSID;
} else if (command < 0x2d0) {
message.talkgroup = address;
message.freq = getfreq(command);
if ( lastcmd == 0x308 || lastcmd == 0x321 ) { // Include digital
// Channel Grant
message.message_type = GRANT;
message.source = lastaddress;
// Check Status
/* Status Message in TalkGroup ID
* 0 Normal Talkgroup
* 1 All Talkgroup
* 2 Emergency
* 3 Talkgroup patch to another
* 4 Emergency Patch
* 5 Emergency multi - group
* 6 Not assigned
* 7 Multi - select (initiated by dispatcher)
* 8 DES Encryption talkgroup
* 9 DES All Talkgroup
* 10 DES Emergency
* 11 DES Talkgroup patch
* 12 DES Emergency Patch
* 13 DES Emergency multi - group
* 14 Not assigned
* 15 Multi - select DES TG
*/
if(status == 2 && status == 4 && status == 5) {
message.emergency = true;
} else if ( status >= 8 ) { // Ignore DES Encryption
message.message_type = UNKNOWN;
}
} else {
// Call continuation
message.message_type = UPDATE;
}
} else if (command == 0x03c0) {
message.message_type = STATUS;
//parse_status(command, address,groupflag);
}
lastaddress = full_address;
lastcmd = command;
messages.push_back(message);
return messages;
}