| 1 | package GQRX::Remote; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '1.0.0'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||
| 12 | 1 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 1 | my %options = @_; | |||||||||||||||||||||||||||
| 14 | 1 | my $self = { | |||||||||||||||||||||||||||
| 15 | _connection => undef, # IO::Socket connection to GQRX | ||||||||||||||||||||||||||||
| 16 | _last_error => undef, | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Options definable on init: | ||||||||||||||||||||||||||||
| 19 | exit_on_error => 0 # When true, exit on any error | ||||||||||||||||||||||||||||
| 20 | }; | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | bless ($self, $class); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | foreach (keys %options) { | |||||||||||||||||||||||||||
| 25 | 0 | $self->{$_} = $options{$_}; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | return ($self); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | sub DESTROY { | ||||||||||||||||||||||||||||
| 33 | # Automatically disconnect when the object is destroyed | ||||||||||||||||||||||||||||
| 34 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | $self->disconnect(); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | sub _set_error { | ||||||||||||||||||||||||||||
| 41 | 2 | ▶ | my ($self, $error) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_set_error: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | if ($self->{exit_on_error}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | die "GQRX::Remote: ERROR: $error\n"; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 2 | $self->{_last_error} = $error; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | sub error { | ||||||||||||||||||||||||||||
| 52 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | return ($self->{_last_error}); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub connect { | ||||||||||||||||||||||||||||
| 59 | 2 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
connect: called CC=5 SCAR=17.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 2 | my (%option) = @_; | |||||||||||||||||||||||||||
| 61 | 2 | my $connection; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | ▶ | if ($self->{_connection}) { # Close any existent connection | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 1 | $self->disconnect(); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | $connection = new IO::Socket::INET( | ||||||||||||||||||||||||||||
| 68 | PeerHost => $option{host} || '127.0.0.1', | ||||||||||||||||||||||||||||
| 69 | 2 | ▶ | PeerPort => $option{port} || 7356, | ||||||||||||||||||||||||||
|
Condition50%2/4
$option{'host'} || '127.0.0.1'
$option{'port'} || 7356
MC/DC0%0/1
$option{'host'} || '127.0.0.1'
$option{'host'}
MC/DC0%0/1
$option{'port'} || 7356
$option{'port'}
Truth table50%1/2
A
A= $option{'host'}
Truth table50%1/2
A
A= $option{'port'}
| |||||||||||||||||||||||||||||
| 70 | Proto => 'tcp' | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 2 | ▶ | if (! $connection) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 0 | $self->_set_error("Failed to establish connection to gqrx: $@"); | |||||||||||||||||||||||||||
| 75 | 0 | return (undef); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | $self->{_connection} = $connection; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 2 | return (1); | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | sub disconnect { | ||||||||||||||||||||||||||||
| 85 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 4 | ▶ | if ($self->{_connection} && $self->{_connection}->connected()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"_connection"} and $self->{"_connection"}->connected
MC/DC50%1/2
$self->{"_connection"} and $self->{"_connection"}->connected
$self->{"_connection"}
$self->{"_connection"}->connected
Truth table66%2/3
A and B
A= $self->{"_connection"}B= $self->{"_connection"}->connected
| |||||||||||||||||||||||||||||
| 88 | 2 | $self->{_connection}->send("c\n"); # Send the close command to the server | |||||||||||||||||||||||||||
| 89 | 2 | $self->{_connection}->close(); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 4 | $self->{_connection} = undef; | |||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub read_line { | ||||||||||||||||||||||||||||
| 97 | 7 | ▶ | my ($self) = shift(); | ||||||||||||||||||||||||||
|
Subroutine
read_line: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 98 | 7 | my $buf; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 7 | ▶ | if (! $self->{_connection}->connected()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $self->_set_error("Connection lost"); | |||||||||||||||||||||||||||
| 102 | 0 | return (undef); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 7 | $buf = $self->{_connection}->getline(); | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 7 | ▶ | if (! defined($buf)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | return (undef); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||
| 111 | 7 | chomp($buf); | |||||||||||||||||||||||||||
| 112 | 7 | return ($buf); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | sub command { | ||||||||||||||||||||||||||||
| 118 | 8 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
command: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 8 | my $command = shift(); | |||||||||||||||||||||||||||
| 120 | 8 | my (%opt) = @_; | |||||||||||||||||||||||||||
| 121 | 8 | my $buf; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 8 | ▶ | if (! $self->{_connection}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 124 | 1 | $self->_set_error("Failed to send: Not connected"); | |||||||||||||||||||||||||||
| 125 | 1 | return (undef); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | elsif (! $self->{_connection}->connected()) { | ||||||||||||||||||||||||||||
| 128 | 0 | $self->_set_error("Failed to send: Connection lost"); | |||||||||||||||||||||||||||
| 129 | 0 | return (undef); | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 7 | $self->{_connection}->send($command . "\n"); | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 7 | return ($self->read_line(%opt)); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | sub set_frequency { | ||||||||||||||||||||||||||||
| 139 | 1 | ▶ | my ($self, $frequency) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_frequency: called CC=2 SCAR=7.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 140 | 1 | my $response = $self->command("F $frequency"); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 1 | ▶ | if ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | $self->_set_error("Set frequency failed. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 144 | 0 | return (undef); | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 1 | return (1); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | sub get_frequency { | ||||||||||||||||||||||||||||
| 152 | 2 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_frequency: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 2 | return ($self->command("f")); | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | sub set_demodulator_mode { | ||||||||||||||||||||||||||||
| 159 | 2 | ▶ | my ($self, $mode) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_demodulator_mode: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | 2 | my $response = $self->command("M $mode"); | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 2 | ▶ | if ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 1 | $self->_set_error("Set demodulator mode failed. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 164 | 1 | return (undef); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 1 | return (1); | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | sub get_demodulator_mode { | ||||||||||||||||||||||||||||
| 172 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_demodulator_mode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 1 | return ($self->command("m")); | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | sub get_signal_strength { | ||||||||||||||||||||||||||||
| 179 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_signal_strength: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | return ($self->command("l STRENGTH")); | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | sub get_squelch_threshold { | ||||||||||||||||||||||||||||
| 186 | 1 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_squelch_threshold: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 1 | return ($self->command("l SQL")); | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | sub set_squelch_threshold { | ||||||||||||||||||||||||||||
| 193 | 1 | ▶ | my ($self, $level) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_squelch_threshold: called CC=2 SCAR=7.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 194 | 1 | my $response = $self->command("L SQL $level"); | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 1 | ▶ | if ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | $self->_set_error("Set demodulator mode failed. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 198 | 0 | return (undef); | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 1 | return (1); | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | sub get_recorder_status { | ||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_recorder_status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | return ($self->command("u RECORD")); | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | sub set_recorder_status { | ||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my ($self, $status) = @_; | ||||||||||||||||||||||||||
|
Subroutine
set_recorder_status: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 214 | 0 | my $response = $self->command("U RECORD $status"); | |||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 0 | $self->_set_error("Failed to set recorder state. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 218 | 0 | return (undef); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | return (1); | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | sub start_recording { | ||||||||||||||||||||||||||||
| 226 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
start_recording: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 227 | 0 | my $response = $self->command("AOS"); | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 0 | $self->_set_error("Failed to start recording. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 231 | 0 | return (undef); | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | return (1); | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | sub stop_recording { | ||||||||||||||||||||||||||||
| 239 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
stop_recording: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 240 | 0 | my $response = $self->command("LOS"); | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 243 | 0 | $self->_set_error("Failed to stop recording. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 244 | 0 | return (undef); | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | return (1); | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 1 | 1; | |||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | __END__ | ||||||||||||||||||||||||||||