rr2op25.plΒΆ

#!/usr/bin/env perl

$USER=`whoami`;
chomp $USER;

$bin_folder = "/home/${USER}/.local/bin";
$dl_folder = "/mnt/chromeos/MyFiles/Downloads";
$sites_folder = "/home/${USER}/.local/pisdr/sites";
$talkgroups_folder = "/home/${USER}/.local/pisdr/talkgroups";

# print "Bin folder = $bin_folder\n";
# print "DL folder = $dl_folder\n";
# print "Sites folder = $sites_folder\n";
# print "Talkgroups folder = $talkgroups_folder\n";

if ($#ARGV ne 0) {
	print "Usage rr2op25.pl [system-id]\n";
	exit;
}

$system = $ARGV[0];
#$name = $ARGV[1];

# Open source files
open (SITE, "${dl_folder}/trs_site_${system}.csv") || die "Cannot open ${dl_folder}/trs_site_${system}.csv\n";
open (TG, "${dl_folder}/trs_tg_${system}.csv") || die "Cannot open ${dl_folder}/trs_tg_${system}.csv\n";

@site = <SITE>;
if ($site[0] =~ /^RFSS/) {
	$type = 1;
} else {
	$type = 2;
}

shift @site;

@tg = <TG>;
shift @tg;

close (TG);
close (SITE);

unlink "${dl_folder}/trs_site_${system}.csv";
unlink "${dl_folder}/trs_tg_${system}.csv";

# Open destination files
open (TG, ">", "${talkgroups_folder}/trs_tg_${system}.tsv");
open (BL, ">>", "${talkgroups_folder}/trs_tg_${system}_bl.tsv");

foreach (@site) {
	chomp;
	next if (/^#/);
	if ($type eq 1) { ($rfss,$site_dec,$site_hex,$site_nac,$description,$county_name,$latitude,$longitude,$range,@frequencies) = split /,/; }
	if ($type eq 2) { ($sysid,$rfss,$site_dec,$site_hex,$site_nac,$description,$county_name,$latitude,$longitude,$range,@frequencies) = split /,/; }
#	next if ("${site_nac}" eq "");
	open (SITE, ">", "${sites_folder}/trs_site_${system}_${rfss}_${site_dec}.tsv");
	print SITE "\"Sysname\"\t\"Control Channel List\"\t\"Offset\"\t\"NAC\"\t\"Modulation\"\t\"TGID Tags File\"\t\"Whitelist\"\t\"Blacklist\"\t\"Center Frequency\"\n";
	print SITE "\"${description}\"\t\"";
	$freqs = "";
	foreach $freq (@frequencies) {
		$freqs = $freqs . "," . $freq;
	}
	$freqs =~ s/^,//g;
	print SITE "${freqs}\"\t\"0\"\t\"0x${site_nac}\"\t\"CQPSK\"\t\"${talkgroups_folder}/trs_tg_${system}.tsv\"\t\"\"\t\"${talkgroups_folder}/trs_tg_${system}_bl.tsv\"\n";
	close (SITE);
}

foreach (@tg) {
	chomp;
	next if (/^#/);
	($decimal,$hex,$alpha_tag,$mode,$description,$tag,$category) = split /,/;
	print TG "${decimal}\t${alpha_tag}\n";
}

close (TG);