kopia lustrzana https://github.com/Guenael/rtlsdr-wsprd
chore(rtlsdr_wsprd.*): code reformat, google style
rodzic
843629c294
commit
175e846ee6
343
rtlsdr_wsprd.c
343
rtlsdr_wsprd.c
|
|
@ -37,22 +37,16 @@
|
|||
#include <signal.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h> // #include <sys/time.h>
|
||||
#include <pthread.h>
|
||||
#include <curl/curl.h>
|
||||
#include <pthread.h>
|
||||
#include <rtl-sdr.h>
|
||||
|
||||
#include "rtlsdr_wsprd.h"
|
||||
#include "wsprd.h"
|
||||
|
||||
/* TODO
|
||||
- multispot report in one post
|
||||
- post zero spot if nothing found
|
||||
- fft & snr sort fix
|
||||
*/
|
||||
#include "./rtlsdr_wsprd.h"
|
||||
#include "./wsprd.h"
|
||||
|
||||
|
||||
/* Sampling definition for RTL devices */
|
||||
#define SIGNAL_LENGHT 116
|
||||
#define SIGNAL_SAMPLE_RATE 375
|
||||
#define SAMPLING_RATE 2400000
|
||||
|
|
@ -89,20 +83,9 @@ struct dongle_state dongle;
|
|||
|
||||
|
||||
/* Callback for each buffer received */
|
||||
static void rtlsdr_callback(unsigned char *samples, uint32_t samples_count, void *ctx) {
|
||||
int8_t *sigIn = (int8_t*) samples;
|
||||
uint32_t sigLenght = samples_count;
|
||||
|
||||
static uint32_t decimationIndex=0;
|
||||
|
||||
/* CIC buffers */
|
||||
static int32_t Ix1,Ix2,Qx1,Qx2;
|
||||
static int32_t Iy1,It1y,It1z,Qy1,Qt1y,Qt1z;
|
||||
static int32_t Iy2,It2y,It2z,Qy2,Qt2y,Qt2z;
|
||||
|
||||
/* FIR compensation filter buffers */
|
||||
static float firI[32], firQ[32];
|
||||
|
||||
static void rtlsdr_callback(unsigned char *samples,
|
||||
uint32_t samples_count,
|
||||
void *ctx) {
|
||||
/* FIR compensation filter coefs
|
||||
Using : Octave/MATLAB code for generating compensation FIR coefficients
|
||||
URL : https://github.com/WestCoastDSP/CIC_Octave_Matlab
|
||||
|
|
@ -110,20 +93,33 @@ static void rtlsdr_callback(unsigned char *samples, uint32_t samples_count, void
|
|||
const static float zCoef[33] = {
|
||||
-0.0027772683, -0.0005058826, 0.0049745750, -0.0034059318,
|
||||
-0.0077557814, 0.0139375423, 0.0039896935, -0.0299394142,
|
||||
0.0162250643, 0.0405130860, -0.0580746013, -0.0272104968,
|
||||
0.1183705475, -0.0306029022, -0.2011241667, 0.1615898423,
|
||||
0.5000000000,
|
||||
0.1615898423, -0.2011241667, -0.0306029022, 0.1183705475,
|
||||
0.0162250643, 0.0405130860, -0.0580746013, -0.0272104968,
|
||||
0.1183705475, -0.0306029022, -0.2011241667, 0.1615898423,
|
||||
0.5000000000,
|
||||
0.1615898423, -0.2011241667, -0.0306029022, 0.1183705475,
|
||||
-0.0272104968, -0.0580746013, 0.0405130860, 0.0162250643,
|
||||
-0.0299394142, 0.0039896935, 0.0139375423, -0.0077557814,
|
||||
-0.0034059318, 0.0049745750, -0.0005058826, -0.0027772683
|
||||
};
|
||||
float Isum,Qsum;
|
||||
|
||||
int8_t *sigIn = (int8_t*)samples;
|
||||
uint32_t sigLenght = samples_count;
|
||||
static uint32_t decimationIndex = 0;
|
||||
|
||||
/* CIC buffers */
|
||||
static int32_t Ix1, Ix2, Qx1, Qx2;
|
||||
static int32_t Iy1, It1y, It1z, Qy1, Qt1y, Qt1z;
|
||||
static int32_t Iy2, It2y, It2z, Qy2, Qt2y, Qt2z;
|
||||
|
||||
/* FIR compensation filter buffers */
|
||||
static float firI[32], firQ[32];
|
||||
|
||||
float Isum, Qsum;
|
||||
|
||||
/* Convert unsigned to signed */
|
||||
for(uint32_t i=0; i<sigLenght; i++)
|
||||
sigIn[i] ^= 0x80; // XOR with a binary mask to flip the first bit (sign)
|
||||
//sigIn[i] = (int8_t)((int32_t)samples[i] - 127);
|
||||
for (uint32_t i = 0; i < sigLenght; i++)
|
||||
// XOR with a binary mask to flip the first bit (sign)
|
||||
sigIn[i] ^= 0x80;
|
||||
|
||||
/* Economic mixer @ fs/4 (upper band)
|
||||
At fs/4, sin and cosin calculation are no longer necessary.
|
||||
|
|
@ -137,7 +133,7 @@ static void rtlsdr_callback(unsigned char *samples, uint32_t samples_count, void
|
|||
(Weaver technique, keep the upper band, IQ inverted on RTL devices)
|
||||
*/
|
||||
int8_t tmp;
|
||||
for (uint32_t i=0; i<sigLenght; i+=8) {
|
||||
for (uint32_t i = 0; i < sigLenght; i+=8) {
|
||||
tmp = -sigIn[i+3];
|
||||
sigIn[i+3] = sigIn[i+2];
|
||||
sigIn[i+2] = tmp;
|
||||
|
|
@ -156,7 +152,7 @@ static void rtlsdr_callback(unsigned char *samples, uint32_t samples_count, void
|
|||
* Understanding cascaded integrator-comb filters
|
||||
http://www.embedded.com/design/configurable-systems/4006446/Understanding-cascaded-integrator-comb-filters
|
||||
*/
|
||||
for(int32_t i=0; i<sigLenght/2; i++) {
|
||||
for (int32_t i = 0; i < sigLenght/2; i++) {
|
||||
/* Integrator stages (N=2) */
|
||||
Ix1 += (int32_t)sigIn[i*2];
|
||||
Qx1 += (int32_t)sigIn[i*2+1];
|
||||
|
|
@ -188,11 +184,11 @@ static void rtlsdr_callback(unsigned char *samples, uint32_t samples_count, void
|
|||
|
||||
// FIXME/TODO : could be made with int32_t (8 bits, 20 bits)
|
||||
/* FIR compensation filter */
|
||||
Isum=0.0, Qsum=0.0;
|
||||
for (uint32_t j=0; j<32; j++) {
|
||||
Isum += firI[j]*zCoef[j];
|
||||
Qsum += firQ[j]*zCoef[j];
|
||||
if (j<31) {
|
||||
Isum = 0.0, Qsum = 0.0;
|
||||
for (uint32_t j = 0; j < 32; j++) {
|
||||
Isum += firI[j] * zCoef[j];
|
||||
Qsum += firQ[j] * zCoef[j];
|
||||
if (j < 31) {
|
||||
firI[j] = firI[j+1];
|
||||
firQ[j] = firQ[j+1];
|
||||
}
|
||||
|
|
@ -204,7 +200,7 @@ static void rtlsdr_callback(unsigned char *samples, uint32_t samples_count, void
|
|||
|
||||
/* Save the result in the buffer */
|
||||
if (rx_state.iqIndex < (SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE)) {
|
||||
/* Lock the buffer during writing */ // Overkill ?!
|
||||
/* Lock the buffer during writing */
|
||||
pthread_rwlock_wrlock(&dec.rw);
|
||||
rx_state.iSamples[rx_state.iqIndex] = Isum;
|
||||
rx_state.qSamples[rx_state.iqIndex] = Qsum;
|
||||
|
|
@ -217,7 +213,6 @@ static void rtlsdr_callback(unsigned char *samples, uint32_t samples_count, void
|
|||
pthread_cond_signal(&dec.ready_cond);
|
||||
pthread_mutex_unlock(&dec.ready_mutex);
|
||||
rx_state.decode_flag = true;
|
||||
//printf("RX done! [Buffer size: %d]\n", rx_state.iqIndex);
|
||||
}
|
||||
}
|
||||
decimationIndex = 0;
|
||||
|
|
@ -237,63 +232,83 @@ static void *rtlsdr_rx(void *arg) {
|
|||
void postSpots(uint32_t n_results) {
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
char url[256]; // FIXME, possible buffer overflow
|
||||
char url[256];
|
||||
|
||||
for (uint32_t i=0; i<n_results; i++) {
|
||||
sprintf(url,"http://wsprnet.org/post?function=wspr&rcall=%s&rgrid=%s&rqrg=%.6f&date=%s&time=%s&sig=%.0f&dt=%.1f&tqrg=%.6f&tcall=%s&tgrid=%s&dbm=%s&version=0.2r_wsprd&mode=2",
|
||||
dec_options.rcall, dec_options.rloc, dec_results[i].freq, dec_options.date, dec_options.uttime,
|
||||
dec_results[i].snr, dec_results[i].dt, dec_results[i].freq,
|
||||
dec_results[i].call, dec_results[i].loc, dec_results[i].pwr);
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
struct tm *gtm = gmtime(&rawtime);
|
||||
|
||||
time_t rawtime;
|
||||
time ( &rawtime );
|
||||
struct tm *gtm = gmtime(&rawtime);
|
||||
for (uint32_t i=0; i < n_results; i++) {
|
||||
snprintf(url, sizeof(url)-1, "http://wsprnet.org/post?function=wspr&rcall=%s&rgrid=%s&rqrg=%.6f&date=%s&time=%s&sig=%.0f&dt=%.1f&tqrg=%.6f&tcall=%s&tgrid=%s&dbm=%s&version=0.2r_wsprd&mode=2",
|
||||
dec_options.rcall,
|
||||
dec_options.rloc,
|
||||
dec_results[i].freq,
|
||||
dec_options.date,
|
||||
dec_options.uttime,
|
||||
dec_results[i].snr,
|
||||
dec_results[i].dt,
|
||||
dec_results[i].freq,
|
||||
dec_results[i].call,
|
||||
dec_results[i].loc,
|
||||
dec_results[i].pwr);
|
||||
|
||||
printf("Spot : %04d-%02d-%02d %02d:%02d:%02d %6.2f %6.2f %10.6f %2d %7s %6s %2s\n",
|
||||
gtm->tm_year + 1900, gtm->tm_mon + 1, gtm->tm_mday, gtm->tm_hour, gtm->tm_min, gtm->tm_sec,
|
||||
dec_results[i].snr, dec_results[i].dt, dec_results[i].freq,
|
||||
(int)dec_results[i].drift, dec_results[i].call, dec_results[i].loc, dec_results[i].pwr);
|
||||
gtm->tm_year + 1900,
|
||||
gtm->tm_mon + 1,
|
||||
gtm->tm_mday,
|
||||
gtm->tm_hour,
|
||||
gtm->tm_min,
|
||||
gtm->tm_sec,
|
||||
dec_results[i].snr,
|
||||
dec_results[i].dt,
|
||||
dec_results[i].freq,
|
||||
(int)dec_results[i].drift,
|
||||
dec_results[i].call,
|
||||
dec_results[i].loc,
|
||||
dec_results[i].pwr);
|
||||
|
||||
curl = curl_easy_init();
|
||||
if(curl) {
|
||||
if (curl) {
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url);
|
||||
curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if(res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
|
||||
if (n_results == 0) {
|
||||
|
||||
time_t rawtime;
|
||||
time ( &rawtime );
|
||||
struct tm *gtm = gmtime(&rawtime);
|
||||
|
||||
printf("No spot %04d-%02d-%02d %02d:%02dz\n",
|
||||
gtm->tm_year + 1900, gtm->tm_mon + 1, gtm->tm_mday, gtm->tm_hour, gtm->tm_min);
|
||||
}
|
||||
printf("No spot %04d-%02d-%02d %02d:%02dz\n",
|
||||
gtm->tm_year + 1900,
|
||||
gtm->tm_mon + 1,
|
||||
gtm->tm_mday,
|
||||
gtm->tm_hour,
|
||||
gtm->tm_min);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void *wsprDecoder(void *arg) {
|
||||
/* WSPR decoder use buffers of 45000 samples (hardcoded)
|
||||
(120 sec max @ 375sps = 45000 samples)
|
||||
Real = 375 * 116 = 43500
|
||||
FIXME with SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE ??
|
||||
*/
|
||||
static float iSamples[45000]= {0};
|
||||
static float qSamples[45000]= {0};
|
||||
static uint32_t samples_len;
|
||||
int32_t n_results=0;
|
||||
int32_t n_results = 0;
|
||||
|
||||
while (!rx_state.exit_flag) {
|
||||
pthread_mutex_lock(&dec.ready_mutex);
|
||||
pthread_cond_wait(&dec.ready_cond, &dec.ready_mutex);
|
||||
pthread_mutex_unlock(&dec.ready_mutex);
|
||||
|
||||
if(rx_state.exit_flag) // Abord case, final sig
|
||||
if (rx_state.exit_flag)
|
||||
/* Abord case, final sig */
|
||||
break;
|
||||
|
||||
/* Lock the buffer access and make a local copy */
|
||||
|
|
@ -309,12 +324,11 @@ static void *wsprDecoder(void *arg) {
|
|||
memcpy(dec_options.date, rx_options.date, sizeof(rx_options.date));
|
||||
memcpy(dec_options.uttime, rx_options.uttime, sizeof(rx_options.uttime));
|
||||
|
||||
/* DEBUG -- Save samples */
|
||||
/* DEBUG -- Save samples HERE */
|
||||
|
||||
/* Search & decode the signal */
|
||||
wspr_decode(iSamples, qSamples, samples_len, dec_options, dec_results, &n_results);
|
||||
postSpots(n_results);
|
||||
|
||||
}
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
|
@ -328,19 +342,20 @@ double atofs(char *s) {
|
|||
len = strlen(s);
|
||||
last = s[len-1];
|
||||
s[len-1] = '\0';
|
||||
|
||||
switch (last) {
|
||||
case 'g':
|
||||
case 'G':
|
||||
suff *= 1e3;
|
||||
case 'm':
|
||||
case 'M':
|
||||
suff *= 1e3;
|
||||
case 'k':
|
||||
case 'K':
|
||||
suff *= 1e3;
|
||||
suff *= atof(s);
|
||||
s[len-1] = last;
|
||||
return suff;
|
||||
case 'g':
|
||||
case 'G':
|
||||
suff *= 1e3;
|
||||
case 'm':
|
||||
case 'M':
|
||||
suff *= 1e3;
|
||||
case 'k':
|
||||
case 'K':
|
||||
suff *= 1e3;
|
||||
suff *= atof(s);
|
||||
s[len-1] = last;
|
||||
return suff;
|
||||
}
|
||||
s[len-1] = last;
|
||||
return atof(s);
|
||||
|
|
@ -352,12 +367,12 @@ int32_t parse_u64(char* s, uint64_t* const value) {
|
|||
char* s_end;
|
||||
uint64_t u64_value;
|
||||
|
||||
if( strlen(s) > 2 ) {
|
||||
if( s[0] == '0' ) {
|
||||
if( (s[1] == 'x') || (s[1] == 'X') ) {
|
||||
if (strlen(s) > 2) {
|
||||
if (s[0] == '0') {
|
||||
if ( (s[1] == 'x') || (s[1] == 'X') ) {
|
||||
base = 16;
|
||||
s += 2;
|
||||
} else if( (s[1] == 'b') || (s[1] == 'B') ) {
|
||||
} else if ( (s[1] == 'b') || (s[1] == 'B') ) {
|
||||
base = 2;
|
||||
s += 2;
|
||||
}
|
||||
|
|
@ -366,7 +381,7 @@ int32_t parse_u64(char* s, uint64_t* const value) {
|
|||
|
||||
s_end = s;
|
||||
u64_value = strtoull(s, &s_end, base);
|
||||
if( (s != s_end) && (*s_end == 0) ) {
|
||||
if ( (s != s_end) && (*s_end == 0) ) {
|
||||
*value = u64_value;
|
||||
return 1;
|
||||
} else {
|
||||
|
|
@ -378,7 +393,7 @@ int32_t parse_u64(char* s, uint64_t* const value) {
|
|||
/* Reset flow control variable & decimation variables */
|
||||
void initSampleStorage() {
|
||||
rx_state.decode_flag = false;
|
||||
rx_state.iqIndex=0;
|
||||
rx_state.iqIndex = 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -431,7 +446,7 @@ int32_t readfile(float *iSamples, float *qSamples, char *filename) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
for(int32_t i=0; i<SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE; i++) {
|
||||
for (int32_t i=0; i < SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE; i++) {
|
||||
iSamples[i] = filebuffer[2*i];
|
||||
qSamples[i] = -filebuffer[2*i+1];
|
||||
}
|
||||
|
|
@ -442,14 +457,12 @@ int32_t readfile(float *iSamples, float *qSamples, char *filename) {
|
|||
}
|
||||
|
||||
|
||||
int32_t writefile(float *iSamples, float *qSamples, char *filename,
|
||||
uint32_t type, double freq) {
|
||||
|
||||
int32_t writefile(float *iSamples, float *qSamples, char *filename, uint32_t type, double freq) {
|
||||
FILE* fd = NULL;
|
||||
char info[15] = {}; // Info descriptor, not used for now
|
||||
|
||||
float filebuffer[2*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE];
|
||||
for(int32_t i=0; i<SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE; i++) {
|
||||
for (int32_t i=0; i < SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE; i++) {
|
||||
filebuffer[2*i] = iSamples[i];
|
||||
filebuffer[2*i+1] = -qSamples[i];
|
||||
}
|
||||
|
|
@ -482,9 +495,9 @@ void usage(void) {
|
|||
"rtlsdr_wsprd, a simple WSPR daemon for RTL receivers\n\n"
|
||||
"Use:\trtlsdr_wsprd -f frequency -c callsign -l locator [options]\n"
|
||||
"\t-f dial frequency [(,k,M) Hz] or band string\n"
|
||||
"\t If band string is used, the transmission will happen in the middle of the WSPR region of the selected band.\n"
|
||||
"\t Bands: LF LF-15 MF MF-15 160m 160m-15 80m 60m 40m 30m 20m 17m 15m 12m 10m 6m 4m 2m\n"
|
||||
"\t '-15' suffix indicates the WSPR-15 region of band.\n"
|
||||
"\t If band string is used, the default dial frequency will used.\n"
|
||||
"\t Bands: LF LF-15 MF MF-15 160m 160m-15 80m 60m 40m 30m 20m 17m 15m 12m 10m 6m 4m 2m 1m25 70cm 23cm\n"
|
||||
"\t ('-15' suffix indicates the WSPR-15 region of band.)\n"
|
||||
"\t-c your callsign (12 chars max)\n"
|
||||
"\t-l your locator grid (6 chars max)\n"
|
||||
"Receiver extra options:\n"
|
||||
|
|
@ -517,104 +530,109 @@ int main(int argc, char** argv) {
|
|||
initDecoder_options();
|
||||
|
||||
/* RX buffer allocation */
|
||||
rx_state.iSamples=malloc(sizeof(float)*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE);
|
||||
rx_state.qSamples=malloc(sizeof(float)*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE);
|
||||
rx_state.iSamples = malloc(sizeof(float)*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE);
|
||||
rx_state.qSamples = malloc(sizeof(float)*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE);
|
||||
|
||||
/* Stop condition setup */
|
||||
rx_state.exit_flag = false;
|
||||
rx_state.decode_flag = false;
|
||||
uint32_t nLoop = 0;
|
||||
|
||||
|
||||
if (argc <= 1)
|
||||
usage();
|
||||
|
||||
while ((opt = getopt(argc, argv, "f:c:l:g:a:o:p:u:d:n:i:H:Q:S")) != -1) {
|
||||
switch (opt) {
|
||||
case 'f': // Frequency
|
||||
if (!strcasecmp(optarg,"LF")) {
|
||||
rx_options.dialfreq=136000.0;
|
||||
} else if (!strcasecmp(optarg,"LF-15")) {
|
||||
rx_options.dialfreq=136112.5;
|
||||
} else if (!strcasecmp(optarg,"MF")) {
|
||||
rx_options.dialfreq=474200.0;
|
||||
} else if (!strcasecmp(optarg,"MF-15")) {
|
||||
rx_options.dialfreq=474312.5;
|
||||
} else if (!strcasecmp(optarg,"160m")) {
|
||||
rx_options.dialfreq=1836600.0;
|
||||
} else if (!strcasecmp(optarg,"160m-15")) {
|
||||
rx_options.dialfreq=1838212.5;
|
||||
} else if (!strcasecmp(optarg,"80m")) {
|
||||
rx_options.dialfreq=3592600.0;
|
||||
} else if (!strcasecmp(optarg,"60m")) {
|
||||
rx_options.dialfreq=5287200.0;
|
||||
} else if (!strcasecmp(optarg,"40m")) {
|
||||
rx_options.dialfreq=7038600.0;
|
||||
} else if (!strcasecmp(optarg,"30m")) {
|
||||
rx_options.dialfreq=10138700.0;
|
||||
} else if (!strcasecmp(optarg,"20m")) {
|
||||
rx_options.dialfreq=14095600.0;
|
||||
} else if (!strcasecmp(optarg,"17m")) {
|
||||
rx_options.dialfreq=18104600.0;
|
||||
} else if (!strcasecmp(optarg,"15m")) {
|
||||
rx_options.dialfreq=21094600.0;
|
||||
} else if (!strcasecmp(optarg,"12m")) {
|
||||
rx_options.dialfreq=24924600.0;
|
||||
} else if (!strcasecmp(optarg,"10m")) {
|
||||
rx_options.dialfreq=28124600.0;
|
||||
} else if (!strcasecmp(optarg,"6m")) {
|
||||
rx_options.dialfreq=50293000.0;
|
||||
} else if (!strcasecmp(optarg,"4m")) {
|
||||
rx_options.dialfreq=70091000.0;
|
||||
} else if (!strcasecmp(optarg,"2m")) {
|
||||
rx_options.dialfreq=144489000.0;
|
||||
} else {
|
||||
// Not a string. Parse it as a double.
|
||||
rx_options.dialfreq=(uint32_t)atofs(optarg);
|
||||
}
|
||||
case 'f': // Frequency
|
||||
if (!strcasecmp(optarg, "LF")) {
|
||||
rx_options.dialfreq = 136000.0;
|
||||
} else if (!strcasecmp(optarg, "LF-15")) {
|
||||
rx_options.dialfreq = 136112.5;
|
||||
} else if (!strcasecmp(optarg, "MF")) {
|
||||
rx_options.dialfreq = 474200.0;
|
||||
} else if (!strcasecmp(optarg, "MF-15")) {
|
||||
rx_options.dialfreq = 474312.5;
|
||||
} else if (!strcasecmp(optarg, "160m")) {
|
||||
rx_options.dialfreq = 1836600.0;
|
||||
} else if (!strcasecmp(optarg, "160m-15")) {
|
||||
rx_options.dialfreq = 1838212.5;
|
||||
} else if (!strcasecmp(optarg, "80m")) {
|
||||
rx_options.dialfreq = 3592600.0;
|
||||
} else if (!strcasecmp(optarg, "60m")) {
|
||||
rx_options.dialfreq = 5287200.0;
|
||||
} else if (!strcasecmp(optarg, "40m")) {
|
||||
rx_options.dialfreq = 7038600.0;
|
||||
} else if (!strcasecmp(optarg, "30m")) {
|
||||
rx_options.dialfreq = 10138700.0;
|
||||
} else if (!strcasecmp(optarg, "20m")) {
|
||||
rx_options.dialfreq = 14095600.0;
|
||||
} else if (!strcasecmp(optarg, "17m")) {
|
||||
rx_options.dialfreq = 18104600.0;
|
||||
} else if (!strcasecmp(optarg, "15m")) {
|
||||
rx_options.dialfreq = 21094600.0;
|
||||
} else if (!strcasecmp(optarg, "12m")) {
|
||||
rx_options.dialfreq = 24924600.0;
|
||||
} else if (!strcasecmp(optarg, "10m")) {
|
||||
rx_options.dialfreq = 28124600.0;
|
||||
} else if (!strcasecmp(optarg, "6m")) {
|
||||
rx_options.dialfreq = 50293000.0;
|
||||
} else if (!strcasecmp(optarg, "4m")) {
|
||||
rx_options.dialfreq = 70091000.0;
|
||||
} else if (!strcasecmp(optarg, "2m")) {
|
||||
rx_options.dialfreq = 144489000.0;
|
||||
} else if (!strcasecmp(optarg, "1m25")) {
|
||||
rx_options.dialfreq = 222280000.0;
|
||||
} else if (!strcasecmp(optarg, "70cm")) {
|
||||
rx_options.dialfreq = 432300000.0;
|
||||
} else if (!strcasecmp(optarg, "23cm")) {
|
||||
rx_options.dialfreq = 1296500000.0;
|
||||
} else {
|
||||
// Not a string. Parse it as a double.
|
||||
rx_options.dialfreq = (uint32_t)atofs(optarg);
|
||||
}
|
||||
break;
|
||||
case 'c': // Callsign
|
||||
sprintf(dec_options.rcall, "%.12s", optarg);
|
||||
case 'c': // Callsign
|
||||
snprintf(dec_options.rcall, sizeof(dec_options.rcall), "%.12s", optarg);
|
||||
break;
|
||||
case 'l': // Locator / Grid
|
||||
sprintf(dec_options.rloc, "%.6s", optarg);
|
||||
case 'l': // Locator / Grid
|
||||
snprintf(dec_options.rloc, sizeof(dec_options.rloc), "%.6s", optarg);
|
||||
break;
|
||||
case 'g': // Small signal amplifier gain
|
||||
case 'g': // Small signal amplifier gain
|
||||
rx_options.gain = atoi(optarg);
|
||||
if (rx_options.gain < 0) rx_options.gain = 0;
|
||||
if (rx_options.gain > 49) rx_options.gain = 49;
|
||||
rx_options.gain *= 10;
|
||||
break;
|
||||
case 'a': // Auto gain
|
||||
case 'a': // Auto gain
|
||||
rx_options.autogain = atoi(optarg);
|
||||
if (rx_options.autogain < 0) rx_options.autogain = 0;
|
||||
if (rx_options.autogain > 1) rx_options.autogain = 1;
|
||||
break;
|
||||
case 'o': // Fine frequency correction
|
||||
case 'o': // Fine frequency correction
|
||||
rx_options.shift = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
rx_options.ppm = atoi(optarg);
|
||||
break;
|
||||
case 'u': // Upconverter frequency
|
||||
case 'u': // Upconverter frequency
|
||||
rx_options.upconverter = (uint32_t)atofs(optarg);
|
||||
break;
|
||||
case 'd': // Direct Sampling
|
||||
case 'd': // Direct Sampling
|
||||
rx_options.directsampling = (uint32_t)atofs(optarg);
|
||||
break;
|
||||
case 'n': // Stop after n iterations
|
||||
case 'n': // Stop after n iterations
|
||||
rx_options.maxloop = (uint32_t)atofs(optarg);
|
||||
break;
|
||||
case 'i': // Select the device to use
|
||||
case 'i': // Select the device to use
|
||||
rx_options.device = (uint32_t)atofs(optarg);
|
||||
break;
|
||||
case 'H': // Decoder option, use a hastable
|
||||
case 'H': // Decoder option, use a hastable
|
||||
dec_options.usehashtable = 1;
|
||||
break;
|
||||
case 'Q': // Decoder option, faster
|
||||
case 'Q': // Decoder option, faster
|
||||
dec_options.quickmode = 1;
|
||||
break;
|
||||
case 'S': // Decoder option, single pass mode (same as original wsprd)
|
||||
case 'S': // Decoder option, single pass mode (same as original wsprd)
|
||||
dec_options.subtraction = 0;
|
||||
dec_options.npasses = 1;
|
||||
break;
|
||||
|
|
@ -665,7 +683,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
|
||||
fprintf(stderr, "Found %d device(s):\n", rtl_count);
|
||||
for (uint32_t i=0; i<rtl_count; i++) {
|
||||
for (uint32_t i=0; i < rtl_count; i++) {
|
||||
rtlsdr_get_device_usb_strings(i, rtl_vendor, rtl_product, rtl_serial);
|
||||
fprintf(stderr, " %d: %s, %s, SN: %s\n", i, rtl_vendor, rtl_product, rtl_serial);
|
||||
}
|
||||
|
|
@ -745,18 +763,20 @@ int main(int argc, char** argv) {
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
/* Print used parameter */
|
||||
time_t rawtime;
|
||||
time ( &rawtime );
|
||||
time(&rawtime);
|
||||
struct tm *gtm = gmtime(&rawtime);
|
||||
printf("\nStarting rtlsdr-wsprd (%04d-%02d-%02d, %02d:%02dz) -- Version 0.2\n",
|
||||
|
||||
printf("\nStarting rtlsdr-wsprd (%04d-%02d-%02d, %02d:%02dz) -- Version 0.3\n",
|
||||
gtm->tm_year + 1900, gtm->tm_mon + 1, gtm->tm_mday, gtm->tm_hour, gtm->tm_min);
|
||||
printf(" Callsign : %s\n", dec_options.rcall);
|
||||
printf(" Locator : %s\n", dec_options.rloc);
|
||||
printf(" Dial freq. : %d Hz\n", rx_options.dialfreq);
|
||||
printf(" Real freq. : %d Hz\n", rx_options.realfreq);
|
||||
printf(" PPM factor : %d\n", rx_options.ppm);
|
||||
if(rx_options.autogain)
|
||||
if (rx_options.autogain)
|
||||
printf(" Auto gain : enable\n");
|
||||
else
|
||||
printf(" Gain : %d dB\n", rx_options.gain/10);
|
||||
|
|
@ -770,7 +790,6 @@ int main(int argc, char** argv) {
|
|||
uint32_t uwait = 120000000 - usec;
|
||||
printf("Wait for time sync (start in %d sec)\n\n", uwait/1000000);
|
||||
printf(" Date Time(z) SNR DT Freq Dr Call Loc Pwr\n");
|
||||
/* Spot : 2021-03-03 10:00:00 -10.96 0.09 7.040130 0 DL4TOM JN59 33 */
|
||||
|
||||
/* Prepare a low priority param for the decoder thread */
|
||||
struct sched_param param;
|
||||
|
|
@ -798,18 +817,18 @@ int main(int argc, char** argv) {
|
|||
usec = sec * 1000000 + lTime.tv_usec;
|
||||
uwait = 120000000 - usec + 10000; // Adding 10ms, to be sure to reach this next minute
|
||||
usleep(uwait);
|
||||
//printf("SYNC! RX started\n");
|
||||
|
||||
/* Use the Store the date at the begin of the frame */
|
||||
time ( &rawtime );
|
||||
time(&rawtime);
|
||||
gtm = gmtime(&rawtime);
|
||||
sprintf(rx_options.date,"%02d%02d%02d", gtm->tm_year - 100, gtm->tm_mon + 1, gtm->tm_mday);
|
||||
sprintf(rx_options.uttime,"%02d%02d", gtm->tm_hour, gtm->tm_min);
|
||||
// FIXME: Complier warning about mixing int & date
|
||||
snprintf(rx_options.date, sizeof(rx_options.date), "%02d%02d%02d", gtm->tm_year - 100, gtm->tm_mon + 1, gtm->tm_mday);
|
||||
snprintf(rx_options.uttime, sizeof(rx_options.uttime), "%02d%02d", gtm->tm_hour, gtm->tm_min);
|
||||
|
||||
/* Start to store the samples */
|
||||
initSampleStorage();
|
||||
|
||||
while( (rx_state.exit_flag == false) &&
|
||||
while ( (rx_state.exit_flag == false) &&
|
||||
(rx_state.iqIndex < (SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE) ) ) {
|
||||
usleep(250000);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@
|
|||
|
||||
|
||||
#ifndef bool
|
||||
typedef uint32_t bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
typedef uint32_t bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -81,5 +81,4 @@ void initrx_options();
|
|||
void sigint_callback_handler(int signum);
|
||||
void usage(void);
|
||||
int32_t readfile(float *iSamples, float *qSamples, char *filename);
|
||||
int32_t writefile(float *iSamples, float *qSamples, char *filename,
|
||||
uint32_t type, double freq);
|
||||
int32_t writefile(float *iSamples, float *qSamples, char *filename, uint32_t type, double freq);
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue