Skip to content

Commit

Permalink
Drop added -k option and search more exhaustively for a device match
Browse files Browse the repository at this point in the history
  • Loading branch information
murrayma committed Sep 22, 2022
1 parent 07f7ec3 commit 68ac9f8
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 26 deletions.
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ For RTL-SDR:

For Airspy R2 / Mini:

`acarsdec [-o lv] [-t time] [-A] [-b filter ] [-e] [-n|N|j ipaddr:port] [-i stationid] [-l logfile [-H|-D]] [-g gain] [-k airspy_serial] -s f1 [f2] [... fN] | -s f1 [f2] [... fN]`
> acarsdec [-o lv] [-t time] [-A] [-b filter ] [-e] [-n|N|j ipaddr:port] [-i stationid] [-l logfile [-H|-D]] [-g gain] -s airspydevicenumber f1 [f2] [... fN] | -s f1 [f2] [... fN]
-o lv : output format : 0 : no log, 1 : one line by msg, 2 : full (default), 3 : monitor mode, 4 : msg JSON, 5 : route JSON

Expand Down Expand Up @@ -61,9 +61,7 @@ for the RTLSDR device
for the AirSpy device
-g gain : set airspy gain (0..21)

-k airspy_serial_number : decode from airspy device with supplied serial number specified in hex, ie 0xA74068C82F591693

-s f1 [f2] ... [fN] : decode from airspy receiving at VHF frequencies "f1" and optionally "f2" to "fN" in Mhz (ie : -s 131.525 131.725 131.825 ). Frequencies must be within the same 2MHz.
-s airspydevice f1 [f2] ... [fN] : decode from airspy device number or S/N "airspydevice" receiving at VHF frequencies "f1" and optionally "f2" to "fN" in Mhz (ie : -s 131.525 131.725 131.825 ). Frequencies must be within the same 2MHz.

for the SDRplay device

Expand Down
12 changes: 3 additions & 9 deletions acarsdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ int rtlMult = 160;

#ifdef WITH_AIR
int gain = 18;
uint64_t airspy_serial = 0;
#endif

#ifdef WITH_SDRPLAY
Expand Down Expand Up @@ -109,7 +108,7 @@ static void usage(void)
#endif
#ifdef WITH_AIR
fprintf(stderr,
"[-g linearity_gain] [-k airspy_serial_number] -s f1 [f2] ... [fN]");
"[-g linearity_gain] -s airspydevicenumber f1 [f2] ... [fN]");
#endif
#ifdef WITH_SDRPLAY
fprintf (stderr, " [-L lnaState] [-G GRdB] [-p ppm] -s f1 [f2] .. [fN]");
Expand Down Expand Up @@ -171,9 +170,7 @@ static void usage(void)
fprintf(stderr,
" -g linearity_gain\t: set linearity gain [0-21] default : 18\n");
fprintf(stderr,
" -k airspy_serial\t: airspy serial number to bind to i9n hex, (ie : 0xA74068C82F591693)\n");
fprintf(stderr,
" -s f1 [f2]...[f%d]\t: decode from airspy receiving at VHF frequencies f1 and optionally f2 to f%d in Mhz (ie : -s 131.525 131.725 131.825 )\n", MAXNBCHANNELS, MAXNBCHANNELS);
" -s airspydevice f1 [f2]...[f%d]\t: decode from airspy dongle number or hex serial number receiving at VHF frequencies f1 and optionally f2 to f%d in Mhz (ie : -s 131.525 131.725 131.825 )\n", MAXNBCHANNELS, MAXNBCHANNELS);
#endif
#ifdef WITH_SDRPLAY
fprintf (stderr,
Expand Down Expand Up @@ -219,7 +216,7 @@ int main(int argc, char **argv)
idstation = strdup(sys_hostname);

res = 0;
while ((c = getopt_long(argc, argv, "HDvarfsRo:t:g:k:m:Aep:n:N:j:l:c:i:L:G:b:M:P:U:T:", long_opts, NULL)) != EOF) {
while ((c = getopt_long(argc, argv, "HDvarfsRo:t:g:m:Aep:n:N:j:l:c:i:L:G:b:M:P:U:T:", long_opts, NULL)) != EOF) {

switch (c) {
case 'v':
Expand Down Expand Up @@ -286,9 +283,6 @@ int main(int argc, char **argv)
res = initAirspy(argv, optind);
inmode = 4;
break;
case 'k':
airspy_serial = strtoull(optarg, NULL, 16);
break;
case 'g':
gain = atoi(optarg);
break;
Expand Down
3 changes: 0 additions & 3 deletions acarsdec.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ extern int mdly;
extern int hourly, daily;

extern int gain;
#if defined(WITH_AIR)
extern uint64_t airspy_serial;
#endif
extern int ppm;
extern int lnaState;
extern int GRdB;
Expand Down
98 changes: 88 additions & 10 deletions air.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#define _GNU_SOURCE
#include <stdlib.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
Expand Down Expand Up @@ -71,8 +72,94 @@ int initAirspy(char **argv, int optind)
int result;
uint32_t i,count;
uint32_t * supported_samplerates;
uint64_t airspy_serial = 0;
int airspy_device_count = 0;
uint64_t *airspy_device_list = NULL;


// Request the total number of libairspy devices connected, allocate space, then request the list.
result = airspy_device_count = airspy_list_devices(NULL, 0);
if(result < 1) {
if(result == 0) {
fprintf(stderr, "No airspy devices found.\n");
} else {
fprintf(stderr, "airspy_list_devices() failed: %s (%d).\n", airspy_error_name(result), result);
}
airspy_exit();
return -1;
}

airspy_device_list = (uint64_t *)malloc(sizeof(uint64_t)*airspy_device_count);
if (airspy_device_list == NULL) return -1;
result = airspy_list_devices(airspy_device_list, airspy_device_count);
if (result != airspy_device_count) {
fprintf(stderr, "airspy_list_devices() failed.\n");
free(airspy_device_list);
airspy_exit();
return -1;
}


// clear errno to catch invalid input.
errno = 0;
// Attempt to interpret first argument as a specific device serial.
airspy_serial = strtoull(argv[optind], &argF, 16);

// If strtoull result is an integer from 0 to airspy_device_count:
// 1. Attempt to open airspy serial indicated.
// 2. If successful, consume argument and continue.
// If still no device and strtoull successfully finds a 16bit hex value, then:
// 1. Attempt to open a specific airspy device using value as a serialnumber.
// 2. If succesful, consume argument and continue.
// If still no device and strtoull result fails
// 1. Iterate over list of airspy devices and attempt to open each one.
// 2. If opened succesfully, do not consume argument and continue.
// Else:
// 1. Give up.

if ( (argv[optind] != argF) && (errno == 0)) {
if ( (airspy_serial < airspy_device_count) ) {
if(verbose) {
fprintf(stderr, "Attempting to open airspy device slot #%lu with serial %016lx.\n", airspy_serial, airspy_device_list[airspy_serial]);
}
result = airspy_open_sn(&device, airspy_device_list[airspy_serial]);
if (result == AIRSPY_SUCCESS) {
optind++; // consume parameter
}
} else {
if (verbose) {
fprintf(stderr, "Attempting to open airspy serial 0x%016lx\n", airspy_serial);
}
result = airspy_open_sn(&device, airspy_serial);
if (result == AIRSPY_SUCCESS) {
optind++; // consume parameter
}
}
}

if (device == NULL) {
for(n = 0; n < airspy_device_count; n++) {
if (verbose) {
fprintf(stderr, "Attempting to open airspy device #%d.\n", n);
}
result = airspy_open_sn(&device, airspy_device_list[n]);
if (result == AIRSPY_SUCCESS)
break;
}
}
memset(airspy_device_list, 0, sizeof(uint64_t)*airspy_device_count);
free(airspy_device_list);
airspy_device_list = NULL;

if (device == NULL) {
result = airspy_open(&device);
if (result != AIRSPY_SUCCESS) {
fprintf(stderr, "Failed to open any airspy device.\n");
airspy_exit();
return -1;
}
}

/* parse args */
nbch = 0;
while ((argF = argv[optind]) && nbch < MAXNBCHANNELS) {
Expand Down Expand Up @@ -103,16 +190,7 @@ int initAirspy(char **argv, int optind)

/* init airspy */

if (airspy_serial > 0) {
if (verbose) {
fprintf(stderr, "attempting to open airspy serial 0x%016lx\n", airspy_serial);
}
result = airspy_open_sn(&device, airspy_serial);
} else {
result = airspy_open(&device);
}

if( result != AIRSPY_SUCCESS ) {
if( result != AIRSPY_SUCCESS ) {
fprintf(stderr,"airspy_open() failed: %s (%d)\n", airspy_error_name(result), result);
airspy_exit();
return -1;
Expand Down

0 comments on commit 68ac9f8

Please sign in to comment.