| 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.1'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 1 | my $class = shift(); | |||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | # Automatically disconnect when the object is destroyed | ||||||||||||||||||||||||||||
| 34 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | $self->disconnect(); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | sub _set_error { | ||||||||||||||||||||||||||
|
Subroutine
_set_error: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||
| 41 | 2 | my ($self, $error) = @_; | |||||||||||||||||||||||||||
| 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 | 2 | ▶ | sub error { | ||||||||||||||||||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | return ($self->{_last_error}); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | ▶ | sub connect { | ||||||||||||||||||||||||||
|
Subroutine
connect: called CC=5 SCAR=17.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 2 | my $self = shift(); | |||||||||||||||||||||||||||
| 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 | 4 | ▶ | sub disconnect { | ||||||||||||||||||||||||||
|
Subroutine
disconnect: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||
| 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 | 7 | ▶ | sub read_line { | ||||||||||||||||||||||||||
|
Subroutine
read_line: called CC=3 SCAR=12.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 97 | 7 | my ($self) = shift(); | |||||||||||||||||||||||||||
| 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 | 8 | ▶ | sub command { | ||||||||||||||||||||||||||
|
Subroutine
command: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | 8 | my $self = shift(); | |||||||||||||||||||||||||||
| 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 | 1 | ▶ | sub set_frequency { | ||||||||||||||||||||||||||
|
Subroutine
set_frequency: called CC=3 SCAR=13.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 139 | 1 | my ($self, $frequency) = @_; | |||||||||||||||||||||||||||
| 140 | 1 | my $response = $self->command("F $frequency"); | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 1 | ▶ | if (! defined($response)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 143 | 0 | return (undef); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | elsif ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||||
| 146 | 0 | $self->_set_error("Set frequency failed. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 147 | 0 | return (undef); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 1 | return (1); | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 2 | ▶ | sub get_frequency { | ||||||||||||||||||||||||||
|
Subroutine
get_frequency: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 155 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 2 | return ($self->command("f")); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 2 | ▶ | sub set_demodulator_mode { | ||||||||||||||||||||||||||
|
Subroutine
set_demodulator_mode: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 162 | 2 | my ($self, $mode) = @_; | |||||||||||||||||||||||||||
| 163 | 2 | my $response = $self->command("M $mode"); | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 2 | ▶ | if (! defined($response)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 166 | 0 | return (undef); | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | elsif ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||||
| 169 | 1 | $self->_set_error("Set demodulator mode failed. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 170 | 1 | return (undef); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 1 | return (1); | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 1 | ▶ | sub get_demodulator_mode { | ||||||||||||||||||||||||||
|
Subroutine
get_demodulator_mode: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 178 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 1 | return ($self->command("m")); | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub get_signal_strength { | ||||||||||||||||||||||||||
|
Subroutine
get_signal_strength: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 185 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | return ($self->command("l STRENGTH")); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 1 | ▶ | sub get_squelch_threshold { | ||||||||||||||||||||||||||
|
Subroutine
get_squelch_threshold: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 192 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 1 | return ($self->command("l SQL")); | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 1 | ▶ | sub set_squelch_threshold { | ||||||||||||||||||||||||||
|
Subroutine
set_squelch_threshold: called CC=3 SCAR=13.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 199 | 1 | my ($self, $level) = @_; | |||||||||||||||||||||||||||
| 200 | 1 | my $response = $self->command("L SQL $level"); | |||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 1 | ▶ | if (! defined($response)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 203 | 0 | return (undef); | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | elsif ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||||
| 206 | 0 | $self->_set_error("Set demodulator mode failed. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 207 | 0 | return (undef); | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 1 | return (1); | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub get_recorder_status { | ||||||||||||||||||||||||||
|
Subroutine
get_recorder_status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 215 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | return ($self->command("u RECORD")); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | sub set_recorder_status { | ||||||||||||||||||||||||||
|
Subroutine
set_recorder_status: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 222 | 0 | my ($self, $status) = @_; | |||||||||||||||||||||||||||
| 223 | 0 | my $response = $self->command("U RECORD $status"); | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if (! defined($response)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 227 | 0 | return (undef); | |||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||
| 229 | elsif ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||||
| 230 | 0 | $self->_set_error("Failed to set recorder state. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 231 | 0 | return (undef); | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | return (1); | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | sub start_recording { | ||||||||||||||||||||||||||
|
Subroutine
start_recording: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 239 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 240 | 0 | my $response = $self->command("AOS"); | |||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if (! defined($response)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 243 | 0 | return (undef); | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | elsif ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||||
| 246 | 0 | $self->_set_error("Failed to start recording. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 247 | 0 | return (undef); | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 0 | return (1); | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub stop_recording { | ||||||||||||||||||||||||||
|
Subroutine
stop_recording: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 255 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 256 | 0 | my $response = $self->command("LOS"); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if (! defined($response)) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 259 | 0 | return (undef); | |||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||
| 261 | elsif ($response ne 'RPRT 0') { | ||||||||||||||||||||||||||||
| 262 | 0 | $self->_set_error("Failed to stop recording. Unexpected response: $response"); | |||||||||||||||||||||||||||
| 263 | 0 | return (undef); | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | return (1); | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | 1 | 1; | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | __END__ | ||||||||||||||||||||||||||||