Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug logging some CC messages, adding unit logging #181

Merged
merged 22 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Trunk Recorder has been tested on Ubuntu (14.04, 16.04, 16.10, 17.04, 17.10, 18.
### Install Required Prequisites
* [Docker](https://github.com/robotastic/trunk-recorder/wiki/Docker-Install)
* [Ubuntu](https://github.com/robotastic/trunk-recorder/wiki/Ubuntu)
* [Ubuntu minimal](https://github.com/robotastic/trunk-recorder/wiki/MinimalInstall)
* [Arch Linux](https://github.com/robotastic/trunk-recorder/wiki/Arch-Linux)
* [macOS](https://github.com/robotastic/trunk-recorder/wiki/macOS)
* [Raspberry Pi Buster Install](https://github.com/robotastic/trunk-recorder/wiki/Raspberry-Pi-Buster-Install) (Also works for the ASUS Tinker Board [S])
Expand Down Expand Up @@ -121,6 +122,7 @@ Here are the different arguments:
- **recordUnknown** - record talkgroups if they are not listed in the Talkgroups File. The options are *true* and *false* (without quotes). The default is *true*.
- **shortName** - this is a nickname for the system. It is used to help name and organize the recordings from this system. It should be 4-6 letters with no spaces.
- **uploadScript** - this script is called after each recording has finished. Checkout *encode-upload.sh.sample* as an example. The script should be located in the same directory as the trunk-recorder executable.
- **unitScript** - this script is called when radio join or leave a system. Checkout *unit-script.sh* in the example direcotry. The script should be located in the same directory as the trunk-recorder executable. The script will be passed 4 parameters: System ShortName, Radio ID, Action, and Talkgroup.
- **apiKey** - *(Optional, only if uploadServer set)* System-specific API key for uploading calls to OpenMHz.com. See the Config tab for your system in OpenMHz to find what the value should be.
- **broadcastifyApiKey** - *(Optional)* System-specific API key for Broadcastify Calls
- **broadcastifySystemId** - *(Optional)* System ID for Broadcastify Calls (this is an integer, and different from the RadioReference system ID)
Expand All @@ -139,6 +141,7 @@ Here are the different arguments:
- **decodeFSync** - *(Optional, For conventional systems)* enable the Fleet Sync signaling decoder. The options are *true* or *false*, without quotes. The default is *false*.
- **decodeStar** - *(Optional, For conventional systems)* enable the Star signaling decoder. The options are *true* or *false*, without quotes. The default is *false*.
- **decodeTPS** - *(Optional, For conventional systems)* enable the Motorola Tactical Public Safety (aka FDNY Fireground) signaling decoder. The options are *true* or *false*, without quotes. The default is *false*.
- **onUnitChange** *(Optional)* run a script when a unit radio registers (is turned on), affiliates (joins a talk group), deregisters (is turned off), sends an acknowledgment response or transmits. Passed as parameters: `shortName` `radio ID` `on|join|off|ackresp|call`. On joins and transmissions, `<talk group>` is passed as a fourth parameter.
- **defaultMode** - Default mode to use when a talkgroups is not listed in the **talkgroupsFile**. The options are *digital* or *analog*. The default is *digital*. This argument is global and not system-specific, and only affects Type II `smartnet` trunking systems which can have both analog and digital talkpaths whereas `p25` trunking systems don't have analog talkpaths.
- **captureDir** - the complete path to the directory where recordings should be saved.
- **callTimeout** - a Call will stop recording and save if it has not received anything on the control channel, after this many seconds. The default is 3.
Expand Down
13 changes: 13 additions & 0 deletions examples/unit-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
printf -v TRDATE '%(%Y/%-m/%-d)T'
printf -v NOWTIME '%(%s)T'
SHORTNAME=$1
RADIOID=$2
ACTION=$3
TALKGROUP=$4
if $3 != "ackresp"
sed <capture_dir>/$1/radiolist.csv 's/^$RADIOID,(.*)/$RADIOID,$NOWTIME,$ACTION,$TALKGROUP,/'
elif
sed <capture_dir>/$1/radiolist.csv 's/$RADIOID,(\d+),([on|join|off|call]),(\d+),(\d+)/$RADIOID,$1,$2,$3,$NOWTIME'
done
echo "$2,$3,$4" >> <capture_dir>/$1/$TRDATE/radiolog.csv
68 changes: 55 additions & 13 deletions trunk-recorder/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ bool load_config(string config_file) {
BOOST_LOG_TRIVIAL(info) << "Decode Star: " << system->get_star_enabled();
system->set_tps_enabled(node.second.get<bool>("decodeTPS", false));
BOOST_LOG_TRIVIAL(info) << "Decode TPS: " << system->get_tps_enabled();
system->set_unit_script(node.second.get<std::string>("unitScript", ""));
BOOST_LOG_TRIVIAL(info) << "Unit Script: " << system->get_unit_script();
std::string talkgroup_display_format_string = node.second.get<std::string>("talkgroupDisplayFormat", "Id");
if (boost::iequals(talkgroup_display_format_string, "id_tag")) {
system->set_talkgroup_display_format(System::talkGroupDisplayFormat_id_tag);
Expand Down Expand Up @@ -855,20 +857,48 @@ void current_system_status(TrunkMessage message, System *sys) {
}
}

void unit_registration(long unit) {}
void unit_registration(string unit_script, long unit) {
unit_affiliations[unit] = 0;

void unit_deregistration(long unit) {
std::map<long, long>::iterator it;
if (unit_script.length() != 0) {
char shell_command[200];
sprintf(shell_command, "%s %li on &", unit_script.c_str(), unit);
int rc = system(shell_command);
}
}

it = unit_affiliations.find(unit);
void unit_deregistration(string unit_script, long unit) {
/* std::map<long, long>::iterator it;

it = unit_affiliations.find(unit);
if (it != unit_affiliations.end()) {
unit_affiliations.erase(it);
unit_affiliations.erase(it); */

unit_affiliations[unit] = -1;

if (unit_script.length() != 0) {
char shell_command[200];
sprintf(shell_command, "%s %li off &", unit_script.c_str(), unit);
int rc = system(shell_command);
}
}

void group_affiliation(long unit, long talkgroup) {
void unit_ack(string unit_script, long unit) {
if (unit_script.length() != 0) {
char shell_command[200];
sprintf(shell_command, "%s %li ackresp &", unit_script.c_str(), unit);
int rc = system(shell_command);
}
}

void group_affiliation(string unit_script, long unit, long talkgroup) {
unit_affiliations[unit] = talkgroup;

if (unit_script.length() != 0) {
char shell_command[200];
sprintf(shell_command, "%s %li join %li &", unit_script.c_str(), unit, talkgroup);
int rc = system(shell_command);
}
}

void handle_call(TrunkMessage message, System *sys) {
Expand All @@ -882,6 +912,14 @@ void handle_call(TrunkMessage message, System *sys) {
recorder is start on a source that can cover that freq. This makes sure any of the remaining transmission that it is in the buffer
of the original recorder gets flushed. */

unit_affiliations[message.source] = message.talkgroup;

if (sys->get_unit_script().length() != 0) {
char shell_command[200];
sprintf(shell_command, "%s %s %li call %li &", sys->get_unit_script().c_str(), sys->get_short_name().c_str(), message.source, message.talkgroup);
int rc = system(shell_command);
}

for (vector<Call *>::iterator it = calls.begin(); it != calls.end();) {
Call *call = *it;

Expand Down Expand Up @@ -958,7 +996,7 @@ void unit_check() {
talkgroup_totals[it->second]++;
}

sprintf(unit_filename, "%s/%ld-unit_check.json", path_stream.str().c_str(), starttime);
sprintf(unit_filename, "%s/radiolist.json", path_stream.str().c_str());

ofstream myfile(unit_filename);

Expand All @@ -970,12 +1008,11 @@ void unit_check() {
if (it != talkgroup_totals.begin()) {
myfile << ",\n";
}
myfile << "\"" << it->first << "\": " << it->second;
myfile << "\"" << it->first << "\":" << it->second;
}
myfile << "\n}\n}\n";
sprintf(shell_command, "./unit_check.sh %s > /dev/null 2>&1 &", unit_filename);
system(shell_command);
//sprintf(shell_command, "./unit_check.sh %s > /dev/null 2>&1 &", unit_filename);
//int rc = system(shell_command);
myfile << "}";
myfile.close();
}
}
Expand All @@ -995,14 +1032,15 @@ void handle_message(std::vector<TrunkMessage> messages, System *sys) {
break;

case REGISTRATION:
unit_registration(sys->get_unit_script(), message.source);
break;

case DEREGISTRATION:
unit_deregistration(message.source);
unit_deregistration(sys->get_unit_script(), message.source);
break;

case AFFILIATION:
group_affiliation(message.source, message.talkgroup);
group_affiliation(sys->get_unit_script(), message.source, message.talkgroup);
break;

case SYSID:
Expand All @@ -1012,6 +1050,10 @@ void handle_message(std::vector<TrunkMessage> messages, System *sys) {
current_system_status(message, sys);
break;

case ACKRESP:
unit_ack(sys->get_unit_script(), message.source);
break;

case UNKNOWN:
break;
}
Expand Down
Loading