kopia lustrzana https://github.com/Guenael/rtlsdr-wsprd
feat(reformat): using Google c++ style everywhere
rodzic
2524ddb6f6
commit
d140fd524f
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
BasedOnStyle: Google
|
||||
ColumnLimit: 0
|
||||
UseTab: Never
|
||||
---
|
||||
Language: Cpp
|
||||
SortIncludes: false
|
||||
IndentWidth: 4
|
||||
---
|
116
rtlsdr_wsprd.c
116
rtlsdr_wsprd.c
|
@ -34,7 +34,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
@ -45,6 +44,7 @@
|
|||
#include <curl/curl.h>
|
||||
#include <rtl-sdr.h>
|
||||
|
||||
|
||||
#include "./rtlsdr_wsprd.h"
|
||||
#include "wsprd/wsprd.h"
|
||||
|
||||
|
@ -110,7 +110,7 @@ static void rtlsdr_callback(unsigned char *samples,
|
|||
-0.0034059318, 0.0049745750, -0.0005058826, -0.0027772683
|
||||
};
|
||||
|
||||
int8_t *sigIn = (int8_t*)samples;
|
||||
int8_t *sigIn = (int8_t *)samples;
|
||||
uint32_t sigLenght = samples_count;
|
||||
static uint32_t decimationIndex = 0;
|
||||
|
||||
|
@ -141,17 +141,17 @@ static void rtlsdr_callback(unsigned char *samples,
|
|||
(Weaver technique, keep the upper band, IQ inverted on RTL devices)
|
||||
*/
|
||||
int8_t tmp;
|
||||
for (uint32_t i = 0; i < sigLenght; i+=8) {
|
||||
tmp = -sigIn[i+3];
|
||||
sigIn[i+3] = sigIn[i+2];
|
||||
sigIn[i+2] = tmp;
|
||||
for (uint32_t i = 0; i < sigLenght; i += 8) {
|
||||
tmp = -sigIn[i + 3];
|
||||
sigIn[i + 3] = sigIn[i + 2];
|
||||
sigIn[i + 2] = tmp;
|
||||
|
||||
sigIn[i+4] = -sigIn[i+4];
|
||||
sigIn[i+5] = -sigIn[i+5];
|
||||
sigIn[i + 4] = -sigIn[i + 4];
|
||||
sigIn[i + 5] = -sigIn[i + 5];
|
||||
|
||||
tmp = -sigIn[i+6];
|
||||
sigIn[i+6] = sigIn[i+7];
|
||||
sigIn[i+7] = tmp;
|
||||
tmp = -sigIn[i + 6];
|
||||
sigIn[i + 6] = sigIn[i + 7];
|
||||
sigIn[i + 7] = tmp;
|
||||
}
|
||||
|
||||
/* CIC decimator (N=2)
|
||||
|
@ -160,10 +160,10 @@ static void rtlsdr_callback(unsigned char *samples,
|
|||
* 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];
|
||||
Ix1 += (int32_t)sigIn[i * 2];
|
||||
Qx1 += (int32_t)sigIn[i * 2 + 1];
|
||||
Ix2 += Ix1;
|
||||
Qx2 += Qx1;
|
||||
|
||||
|
@ -197,14 +197,14 @@ static void rtlsdr_callback(unsigned char *samples,
|
|||
Isum += firI[j] * zCoef[j];
|
||||
Qsum += firQ[j] * zCoef[j];
|
||||
if (j < 31) {
|
||||
firI[j] = firI[j+1];
|
||||
firQ[j] = firQ[j+1];
|
||||
firI[j] = firI[j + 1];
|
||||
firQ[j] = firQ[j + 1];
|
||||
}
|
||||
}
|
||||
firI[31] = (float)Iy2;
|
||||
firQ[31] = (float)Qy2;
|
||||
Isum += firI[31]*zCoef[32];
|
||||
Qsum += firQ[31]*zCoef[32];
|
||||
Isum += firI[31] * zCoef[32];
|
||||
Qsum += firQ[31] * zCoef[32];
|
||||
|
||||
/* Save the result in the buffer */
|
||||
if (rx_state.iqIndex < (SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE)) {
|
||||
|
@ -246,8 +246,8 @@ void postSpots(uint32_t n_results) {
|
|||
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",
|
||||
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,
|
||||
|
@ -305,8 +305,8 @@ static void *wsprDecoder(void *arg) {
|
|||
Real = 375 * 116 = 43500
|
||||
FIXME with SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE ??
|
||||
*/
|
||||
static float iSamples[45000]= {0};
|
||||
static float qSamples[45000]= {0};
|
||||
static float iSamples[45000] = {0};
|
||||
static float qSamples[45000] = {0};
|
||||
static uint32_t samples_len;
|
||||
int32_t n_results = 0;
|
||||
|
||||
|
@ -348,8 +348,8 @@ double atofs(char *s) {
|
|||
uint32_t len;
|
||||
double suff = 1.0;
|
||||
len = strlen(s);
|
||||
last = s[len-1];
|
||||
s[len-1] = '\0';
|
||||
last = s[len - 1];
|
||||
s[len - 1] = '\0';
|
||||
|
||||
switch (last) {
|
||||
case 'g':
|
||||
|
@ -362,25 +362,25 @@ double atofs(char *s) {
|
|||
case 'K':
|
||||
suff *= 1e3;
|
||||
suff *= atof(s);
|
||||
s[len-1] = last;
|
||||
s[len - 1] = last;
|
||||
return suff;
|
||||
}
|
||||
s[len-1] = last;
|
||||
s[len - 1] = last;
|
||||
return atof(s);
|
||||
}
|
||||
|
||||
|
||||
int32_t parse_u64(char* s, uint64_t* const value) {
|
||||
int32_t parse_u64(char *s, uint64_t *const value) {
|
||||
uint_fast8_t base = 10;
|
||||
char* s_end;
|
||||
char *s_end;
|
||||
uint64_t u64_value;
|
||||
|
||||
if (strlen(s) > 2) {
|
||||
if (s[0] == '0') {
|
||||
if ( (s[1] == 'x') || (s[1] == 'X') ) {
|
||||
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;
|
||||
}
|
||||
|
@ -389,7 +389,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 {
|
||||
|
@ -433,8 +433,8 @@ void sigint_callback_handler(int signum) {
|
|||
|
||||
|
||||
int32_t readfile(float *iSamples, float *qSamples, char *filename) {
|
||||
FILE* fd = NULL;
|
||||
float filebuffer[2*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE];
|
||||
FILE *fd = NULL;
|
||||
float filebuffer[2 * SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE];
|
||||
|
||||
fd = fopen(filename, "rb");
|
||||
if (fd == NULL) {
|
||||
|
@ -449,16 +449,16 @@ int32_t readfile(float *iSamples, float *qSamples, char *filename) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int32_t nread = fread(filebuffer, sizeof(float), 2*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE, fd);
|
||||
if (nread != 2*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE) {
|
||||
int32_t nread = fread(filebuffer, sizeof(float), 2 * SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE, fd);
|
||||
if (nread != 2 * SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE) {
|
||||
fprintf(stderr, "Cannot read all the data!\n");
|
||||
fclose(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (int32_t i=0; i < SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE; i++) {
|
||||
iSamples[i] = filebuffer[2*i];
|
||||
qSamples[i] = -filebuffer[2*i+1];
|
||||
for (int32_t i = 0; i < SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE; i++) {
|
||||
iSamples[i] = filebuffer[2 * i];
|
||||
qSamples[i] = -filebuffer[2 * i + 1];
|
||||
}
|
||||
|
||||
fclose(fd);
|
||||
|
@ -468,13 +468,13 @@ int32_t readfile(float *iSamples, float *qSamples, char *filename) {
|
|||
|
||||
|
||||
int32_t writefile(float *iSamples, float *qSamples, char *filename, uint32_t type, double freq) {
|
||||
FILE* fd = NULL;
|
||||
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++) {
|
||||
filebuffer[2*i] = iSamples[i];
|
||||
filebuffer[2*i+1] = -qSamples[i];
|
||||
float filebuffer[2 * SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE];
|
||||
for (int32_t i = 0; i < SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE; i++) {
|
||||
filebuffer[2 * i] = iSamples[i];
|
||||
filebuffer[2 * i + 1] = -qSamples[i];
|
||||
}
|
||||
|
||||
fd = fopen(filename, "wb");
|
||||
|
@ -488,8 +488,8 @@ int32_t writefile(float *iSamples, float *qSamples, char *filename, uint32_t typ
|
|||
fwrite(&type, sizeof(uint32_t), 1, fd);
|
||||
fwrite(&freq, sizeof(double), 1, fd);
|
||||
|
||||
int32_t nwrite = fwrite(filebuffer, sizeof(float), 2*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE, fd);
|
||||
if (nwrite != 2*SIGNAL_LENGHT*SIGNAL_SAMPLE_RATE) {
|
||||
int32_t nwrite = fwrite(filebuffer, sizeof(float), 2 * SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE, fd);
|
||||
if (nwrite != 2 * SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE) {
|
||||
fprintf(stderr, "Cannot write all the data!\n");
|
||||
return 1;
|
||||
}
|
||||
|
@ -529,7 +529,7 @@ void usage(void) {
|
|||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main(int argc, char **argv) {
|
||||
uint32_t opt;
|
||||
|
||||
int32_t rtl_result;
|
||||
|
@ -540,8 +540,8 @@ 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;
|
||||
|
@ -690,15 +690,13 @@ int main(int argc, char** argv) {
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
fprintf(stderr, "\nUsing device %d: %s\n", rx_options.device, rtlsdr_get_device_name(rx_options.device));
|
||||
|
||||
|
||||
rtl_result = rtlsdr_open(&rtl_device, rx_options.device);
|
||||
if (rtl_result < 0) {
|
||||
fprintf(stderr, "ERROR: Failed to open rtlsdr device #%d.\n", rx_options.device);
|
||||
|
@ -721,7 +719,6 @@ int main(int argc, char** argv) {
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
rtl_result = rtlsdr_set_tuner_gain_mode(rtl_device, 1);
|
||||
if (rtl_result < 0) {
|
||||
fprintf(stderr, "ERROR: Failed to enable manual gain\n");
|
||||
|
@ -729,7 +726,6 @@ int main(int argc, char** argv) {
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
if (rx_options.autogain) {
|
||||
rtl_result = rtlsdr_set_tuner_gain_mode(rtl_device, 0);
|
||||
if (rtl_result != 0) {
|
||||
|
@ -746,7 +742,6 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (rx_options.ppm != 0) {
|
||||
rtl_result = rtlsdr_set_freq_correction(rtl_device, rx_options.ppm);
|
||||
if (rtl_result < 0) {
|
||||
|
@ -756,7 +751,6 @@ int main(int argc, char** argv) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
rtl_result = rtlsdr_set_center_freq(rtl_device, rx_options.realfreq + FS4_RATE + 1500);
|
||||
if (rtl_result < 0) {
|
||||
fprintf(stderr, "ERROR: Failed to set frequency\n");
|
||||
|
@ -764,7 +758,6 @@ int main(int argc, char** argv) {
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
rtl_result = rtlsdr_reset_buffer(rtl_device);
|
||||
if (rtl_result < 0) {
|
||||
fprintf(stderr, "ERROR: Failed to reset buffers.\n");
|
||||
|
@ -772,7 +765,6 @@ int main(int argc, char** argv) {
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
/* Print used parameter */
|
||||
time_t rawtime;
|
||||
time(&rawtime);
|
||||
|
@ -788,8 +780,7 @@ int main(int argc, char** argv) {
|
|||
if (rx_options.autogain)
|
||||
printf(" Auto gain : enable\n");
|
||||
else
|
||||
printf(" Gain : %d dB\n", rx_options.gain/10);
|
||||
|
||||
printf(" Gain : %d dB\n", rx_options.gain / 10);
|
||||
|
||||
/* Time alignment stuff */
|
||||
struct timeval lTime;
|
||||
|
@ -797,7 +788,7 @@ int main(int argc, char** argv) {
|
|||
uint32_t sec = lTime.tv_sec % 120;
|
||||
uint32_t usec = sec * 1000000 + lTime.tv_usec;
|
||||
uint32_t uwait = 120000000 - usec;
|
||||
printf("Wait for time sync (start in %d sec)\n\n", uwait/1000000);
|
||||
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");
|
||||
|
||||
/* Prepare a low priority param for the decoder thread */
|
||||
|
@ -817,7 +808,6 @@ int main(int argc, char** argv) {
|
|||
pthread_create(&dongle.thread, NULL, rtlsdr_rx, NULL);
|
||||
pthread_create(&dec.thread, &dec.tattr, wsprDecoder, NULL);
|
||||
|
||||
|
||||
/* Main loop : Wait, read, decode */
|
||||
while (!rx_state.exit_flag && !(rx_options.maxloop && (nLoop >= rx_options.maxloop))) {
|
||||
/* Wait for time Sync on 2 mins */
|
||||
|
@ -837,8 +827,8 @@ int main(int argc, char** argv) {
|
|||
/* Start to store the samples */
|
||||
initSampleStorage();
|
||||
|
||||
while ( (rx_state.exit_flag == false) &&
|
||||
(rx_state.iqIndex < (SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE) ) ) {
|
||||
while ((rx_state.exit_flag == false) &&
|
||||
(rx_state.iqIndex < (SIGNAL_LENGHT * SIGNAL_SAMPLE_RATE))) {
|
||||
usleep(250000);
|
||||
}
|
||||
nLoop++;
|
||||
|
|
|
@ -25,13 +25,10 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#ifndef bool
|
||||
typedef uint32_t bool;
|
||||
#define true 1
|
||||
|
@ -69,12 +66,13 @@ struct receiver_options {
|
|||
char uttime[5];
|
||||
};
|
||||
|
||||
|
||||
static void rtlsdr_callback(unsigned char *samples, uint32_t samples_count, void *ctx);
|
||||
static void *rtlsdr_rx(void *arg);
|
||||
void postSpots(uint32_t n_results);
|
||||
static void *wsprDecoder(void *arg);
|
||||
double atofs(char *s);
|
||||
int32_t parse_u64(char* s, uint64_t* const value);
|
||||
int32_t parse_u64(char *s, uint64_t *const value);
|
||||
void initSampleStorage();
|
||||
void initDecoder_options();
|
||||
void initrx_options();
|
||||
|
|
22
wsprd/fano.c
22
wsprd/fano.c
|
@ -70,7 +70,7 @@ int encode(unsigned char *symbols, // Output buffer, 2*8*nbytes
|
|||
|
||||
encstate = 0;
|
||||
while (nbytes-- != 0) {
|
||||
for (i=7; i >= 0; i--) {
|
||||
for (i = 7; i >= 0; i--) {
|
||||
encstate = (encstate << 1) | ((*data >> i) & 1);
|
||||
ENCODE(sym, encstate);
|
||||
*symbols++ = sym >> 1;
|
||||
|
@ -104,18 +104,18 @@ int fano(unsigned int *metric, // Final path metric (returned value)
|
|||
unsigned int lsym;
|
||||
unsigned int i;
|
||||
|
||||
if ((nodes = (struct node *)malloc((nbits+1)*sizeof(struct node))) == NULL) {
|
||||
if ((nodes = (struct node *)malloc((nbits + 1) * sizeof(struct node))) == NULL) {
|
||||
printf("malloc failed\n");
|
||||
return 0;
|
||||
}
|
||||
lastnode = &nodes[nbits-1];
|
||||
tail = &nodes[nbits-31];
|
||||
lastnode = &nodes[nbits - 1];
|
||||
tail = &nodes[nbits - 31];
|
||||
*maxnp = 0;
|
||||
|
||||
/* Compute all possible branch metrics for each symbol pair
|
||||
* This is the only place we actually look at the raw input symbols
|
||||
*/
|
||||
for (np=nodes; np <= lastnode; np++) {
|
||||
for (np = nodes; np <= lastnode; np++) {
|
||||
np->metrics[0] = mettab[0][symbols[0]] + mettab[0][symbols[1]];
|
||||
np->metrics[1] = mettab[0][symbols[0]] + mettab[1][symbols[1]];
|
||||
np->metrics[2] = mettab[1][symbols[0]] + mettab[0][symbols[1]];
|
||||
|
@ -136,7 +136,7 @@ int fano(unsigned int *metric, // Final path metric (returned value)
|
|||
* This code should be modified if a systematic code were used.
|
||||
*/
|
||||
|
||||
m1 = np->metrics[3^lsym];
|
||||
m1 = np->metrics[3 ^ lsym];
|
||||
if (m0 > m1) {
|
||||
np->tm[0] = m0; // 0-branch has better metric
|
||||
np->tm[1] = m1;
|
||||
|
@ -150,8 +150,8 @@ int fano(unsigned int *metric, // Final path metric (returned value)
|
|||
np->gamma = t = 0;
|
||||
|
||||
// Start the Fano decoder
|
||||
for (i=1; i <= maxcycles; i++) {
|
||||
if ((int)(np-nodes) > (int)*maxnp) *maxnp = (int)(np-nodes);
|
||||
for (i = 1; i <= maxcycles; i++) {
|
||||
if ((int)(np - nodes) > (int)*maxnp) *maxnp = (int)(np - nodes);
|
||||
|
||||
// Look forward */
|
||||
ngamma = np->gamma + np->tm[np->i];
|
||||
|
@ -169,7 +169,7 @@ int fano(unsigned int *metric, // Final path metric (returned value)
|
|||
// Move forward
|
||||
np[1].gamma = ngamma;
|
||||
np[1].encstate = np->encstate << 1;
|
||||
if ( ++np == (lastnode+1) ) {
|
||||
if (++np == (lastnode + 1)) {
|
||||
break; // Done!
|
||||
}
|
||||
|
||||
|
@ -184,7 +184,7 @@ int fano(unsigned int *metric, // Final path metric (returned value)
|
|||
np->tm[0] = np->metrics[lsym];
|
||||
} else {
|
||||
m0 = np->metrics[lsym];
|
||||
m1 = np->metrics[3^lsym];
|
||||
m1 = np->metrics[3 ^ lsym];
|
||||
if (m0 > m1) {
|
||||
np->tm[0] = m0; // 0-branch is better
|
||||
np->tm[1] = m1;
|
||||
|
@ -233,7 +233,7 @@ int fano(unsigned int *metric, // Final path metric (returned value)
|
|||
*data++ = np->encstate;
|
||||
np += 8;
|
||||
}
|
||||
*cycles = i+1;
|
||||
*cycles = i + 1;
|
||||
|
||||
free(nodes);
|
||||
if (i >= maxcycles)
|
||||
|
|
19
wsprd/fano.h
19
wsprd/fano.h
|
@ -32,12 +32,13 @@ extern unsigned char Partab[];
|
|||
* POLY1 goes into the 2-bit of sym, and the symbol generated from POLY2
|
||||
* goes into the 1-bit.
|
||||
*/
|
||||
#define ENCODE(sym, encstate) {\
|
||||
unsigned long _tmp;\
|
||||
_tmp = (encstate) & POLY1;\
|
||||
_tmp ^= _tmp >> 16;\
|
||||
(sym) = Partab[(_tmp ^ (_tmp >> 8)) & 0xff] << 1;\
|
||||
_tmp = (encstate) & POLY2;\
|
||||
_tmp ^= _tmp >> 16;\
|
||||
(sym) |= Partab[(_tmp ^ (_tmp >> 8)) & 0xff];\
|
||||
}
|
||||
#define ENCODE(sym, encstate) \
|
||||
{ \
|
||||
unsigned long _tmp; \
|
||||
_tmp = (encstate)&POLY1; \
|
||||
_tmp ^= _tmp >> 16; \
|
||||
(sym) = Partab[(_tmp ^ (_tmp >> 8)) & 0xff] << 1; \
|
||||
_tmp = (encstate)&POLY2; \
|
||||
_tmp ^= _tmp >> 16; \
|
||||
(sym) |= Partab[(_tmp ^ (_tmp >> 8)) & 0xff]; \
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
/*******************************************************************************
|
||||
* 4 metric tables calculated via simulation for 2-FSK with Es/No=0,3,6,9 dB
|
||||
* tables were calculated for constant rms noise level of 50. The symbol vector
|
||||
* should be normalized to have rms amplitude equal to "symbol_scale".
|
||||
********************************************************************************/
|
||||
* 4 metric tables calculated via simulation for 2-FSK with Es/No=0,3,6,9 dB
|
||||
* tables were calculated for constant rms noise level of 50. The symbol vector
|
||||
* should be normalized to have rms amplitude equal to "symbol_scale".
|
||||
********************************************************************************/
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmissing-braces"
|
||||
|
||||
//float symbol_scale[4]={42.6, 53.3, 72.7, 100.2};
|
||||
static const float metric_tables[4][256]= {
|
||||
// float symbol_scale[4]={42.6, 53.3, 72.7, 100.2};
|
||||
static const float metric_tables[4][256] = {
|
||||
0.9782, 0.9695, 0.9689, 0.9669, 0.9666, 0.9653, 0.9638, 0.9618, 0.9599, 0.9601,
|
||||
0.9592, 0.9570, 0.9556, 0.9540, 0.9525, 0.9527, 0.9486, 0.9477, 0.9450, 0.9436,
|
||||
0.9424, 0.9400, 0.9381, 0.9360, 0.9340, 0.9316, 0.9301, 0.9272, 0.9254, 0.9224,
|
||||
|
@ -112,7 +112,6 @@ static const float metric_tables[4][256]= {
|
|||
-13.3265, -13.1667, -13.4274, -13.6064, -13.5515, -13.9501, -13.9926, -14.4049, -14.1653, -14.4348,
|
||||
-14.7983, -14.7807, -15.2349, -15.3536, -15.3026, -15.2739, -15.7170, -16.2161, -15.9185, -15.9490,
|
||||
-16.6258, -16.5568, -16.4318, -16.7999, -16.4101, -17.6393, -17.7643, -17.2644, -17.5973, -17.0403,
|
||||
-17.7039, -18.0073, -18.1840, -18.3848, -18.6286, -20.7063
|
||||
};
|
||||
-17.7039, -18.0073, -18.1840, -18.3848, -18.6286, -20.7063};
|
||||
|
||||
#pragma GCC diagnostic pop
|
286
wsprd/nhash.c
286
wsprd/nhash.c
|
@ -81,9 +81,9 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy.
|
|||
|
||||
#define HASH_LITTLE_ENDIAN 1
|
||||
|
||||
#define hashsize(n) ((uint32_t)1<<(n))
|
||||
#define hashmask(n) (hashsize(n)-1)
|
||||
#define rot(x,k) (((x)<<(k)) | ((x)>>(32-(k))))
|
||||
#define hashsize(n) ((uint32_t)1 << (n))
|
||||
#define hashmask(n) (hashsize(n) - 1)
|
||||
#define rot(x, k) (((x) << (k)) | ((x) >> (32 - (k))))
|
||||
|
||||
/*
|
||||
-------------------------------------------------------------------------------
|
||||
|
@ -129,15 +129,15 @@ on, and rotates are much kinder to the top and bottom bits, so I used
|
|||
rotates.
|
||||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
#define mix(a,b,c) \
|
||||
{ \
|
||||
#define mix(a, b, c) \
|
||||
{ \
|
||||
a -= c; a ^= rot(c, 4); c += b; \
|
||||
b -= a; b ^= rot(a, 6); a += c; \
|
||||
c -= b; c ^= rot(b, 8); b += a; \
|
||||
a -= c; a ^= rot(c,16); c += b; \
|
||||
b -= a; b ^= rot(a,19); a += c; \
|
||||
c -= b; c ^= rot(b, 4); b += a; \
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
-------------------------------------------------------------------------------
|
||||
|
@ -164,8 +164,8 @@ and these came close:
|
|||
11 8 15 26 3 22 24
|
||||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
#define final(a,b,c) \
|
||||
{ \
|
||||
#define final(a, b, c) \
|
||||
{ \
|
||||
c ^= b; c -= rot(b,14); \
|
||||
a ^= c; a -= rot(c,11); \
|
||||
b ^= a; b -= rot(a,25); \
|
||||
|
@ -173,7 +173,7 @@ and these came close:
|
|||
a ^= c; a -= rot(c,4); \
|
||||
b ^= a; b -= rot(a,14); \
|
||||
c ^= b; c -= rot(b,24); \
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
-------------------------------------------------------------------------------
|
||||
|
@ -202,8 +202,8 @@ acceptable. Do NOT use for cryptographic purposes.
|
|||
-------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
uint32_t nhash( const void *key, size_t length, uint32_t initval) {
|
||||
uint32_t a,b,c; /* internal state */
|
||||
uint32_t nhash(const void *key, size_t length, uint32_t initval) {
|
||||
uint32_t a, b, c; /* internal state */
|
||||
union {
|
||||
const void *ptr;
|
||||
size_t i;
|
||||
|
@ -221,7 +221,7 @@ uint32_t nhash( const void *key, size_t length, uint32_t initval) {
|
|||
a += k[0];
|
||||
b += k[1];
|
||||
c += k[2];
|
||||
mix(a,b,c);
|
||||
mix(a, b, c);
|
||||
length -= 12;
|
||||
k += 3;
|
||||
}
|
||||
|
@ -238,95 +238,95 @@ uint32_t nhash( const void *key, size_t length, uint32_t initval) {
|
|||
*/
|
||||
#ifndef VALGRIND
|
||||
|
||||
switch(length) {
|
||||
switch (length) {
|
||||
case 12:
|
||||
c+=k[2];
|
||||
b+=k[1];
|
||||
a+=k[0];
|
||||
c += k[2];
|
||||
b += k[1];
|
||||
a += k[0];
|
||||
break;
|
||||
case 11:
|
||||
c+=k[2]&0xffffff;
|
||||
b+=k[1];
|
||||
a+=k[0];
|
||||
c += k[2] & 0xffffff;
|
||||
b += k[1];
|
||||
a += k[0];
|
||||
break;
|
||||
case 10:
|
||||
c+=k[2]&0xffff;
|
||||
b+=k[1];
|
||||
a+=k[0];
|
||||
c += k[2] & 0xffff;
|
||||
b += k[1];
|
||||
a += k[0];
|
||||
break;
|
||||
case 9 :
|
||||
c+=k[2]&0xff;
|
||||
b+=k[1];
|
||||
a+=k[0];
|
||||
case 9:
|
||||
c += k[2] & 0xff;
|
||||
b += k[1];
|
||||
a += k[0];
|
||||
break;
|
||||
case 8 :
|
||||
b+=k[1];
|
||||
a+=k[0];
|
||||
case 8:
|
||||
b += k[1];
|
||||
a += k[0];
|
||||
break;
|
||||
case 7 :
|
||||
b+=k[1]&0xffffff;
|
||||
a+=k[0];
|
||||
case 7:
|
||||
b += k[1] & 0xffffff;
|
||||
a += k[0];
|
||||
break;
|
||||
case 6 :
|
||||
b+=k[1]&0xffff;
|
||||
a+=k[0];
|
||||
case 6:
|
||||
b += k[1] & 0xffff;
|
||||
a += k[0];
|
||||
break;
|
||||
case 5 :
|
||||
b+=k[1]&0xff;
|
||||
a+=k[0];
|
||||
case 5:
|
||||
b += k[1] & 0xff;
|
||||
a += k[0];
|
||||
break;
|
||||
case 4 :
|
||||
a+=k[0];
|
||||
case 4:
|
||||
a += k[0];
|
||||
break;
|
||||
case 3 :
|
||||
a+=k[0]&0xffffff;
|
||||
case 3:
|
||||
a += k[0] & 0xffffff;
|
||||
break;
|
||||
case 2 :
|
||||
a+=k[0]&0xffff;
|
||||
case 2:
|
||||
a += k[0] & 0xffff;
|
||||
break;
|
||||
case 1 :
|
||||
a+=k[0]&0xff;
|
||||
case 1:
|
||||
a += k[0] & 0xff;
|
||||
break;
|
||||
case 0 :
|
||||
case 0:
|
||||
return c; /* zero length strings require no mixing */
|
||||
}
|
||||
|
||||
#else /* make valgrind happy */
|
||||
|
||||
k8 = (const uint8_t *)k;
|
||||
switch(length) {
|
||||
switch (length) {
|
||||
case 12:
|
||||
c+=k[2];
|
||||
b+=k[1];
|
||||
a+=k[0];
|
||||
c += k[2];
|
||||
b += k[1];
|
||||
a += k[0];
|
||||
break;
|
||||
case 11:
|
||||
c+=((uint32_t)k8[10])<<16; /* fall through */
|
||||
c += ((uint32_t)k8[10]) << 16; /* fall through */
|
||||
case 10:
|
||||
c+=((uint32_t)k8[9])<<8; /* fall through */
|
||||
case 9 :
|
||||
c+=k8[8]; /* fall through */
|
||||
case 8 :
|
||||
b+=k[1];
|
||||
a+=k[0];
|
||||
c += ((uint32_t)k8[9]) << 8; /* fall through */
|
||||
case 9:
|
||||
c += k8[8]; /* fall through */
|
||||
case 8:
|
||||
b += k[1];
|
||||
a += k[0];
|
||||
break;
|
||||
case 7 :
|
||||
b+=((uint32_t)k8[6])<<16; /* fall through */
|
||||
case 6 :
|
||||
b+=((uint32_t)k8[5])<<8; /* fall through */
|
||||
case 5 :
|
||||
b+=k8[4]; /* fall through */
|
||||
case 4 :
|
||||
a+=k[0];
|
||||
case 7:
|
||||
b += ((uint32_t)k8[6]) << 16; /* fall through */
|
||||
case 6:
|
||||
b += ((uint32_t)k8[5]) << 8; /* fall through */
|
||||
case 5:
|
||||
b += k8[4]; /* fall through */
|
||||
case 4:
|
||||
a += k[0];
|
||||
break;
|
||||
case 3 :
|
||||
a+=((uint32_t)k8[2])<<16; /* fall through */
|
||||
case 2 :
|
||||
a+=((uint32_t)k8[1])<<8; /* fall through */
|
||||
case 1 :
|
||||
a+=k8[0];
|
||||
case 3:
|
||||
a += ((uint32_t)k8[2]) << 16; /* fall through */
|
||||
case 2:
|
||||
a += ((uint32_t)k8[1]) << 8; /* fall through */
|
||||
case 1:
|
||||
a += k8[0];
|
||||
break;
|
||||
case 0 :
|
||||
case 0:
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -338,55 +338,55 @@ uint32_t nhash( const void *key, size_t length, uint32_t initval) {
|
|||
|
||||
/*--------------- all but last block: aligned reads and different mixing */
|
||||
while (length > 12) {
|
||||
a += k[0] + (((uint32_t)k[1])<<16);
|
||||
b += k[2] + (((uint32_t)k[3])<<16);
|
||||
c += k[4] + (((uint32_t)k[5])<<16);
|
||||
mix(a,b,c);
|
||||
a += k[0] + (((uint32_t)k[1]) << 16);
|
||||
b += k[2] + (((uint32_t)k[3]) << 16);
|
||||
c += k[4] + (((uint32_t)k[5]) << 16);
|
||||
mix(a, b, c);
|
||||
length -= 12;
|
||||
k += 6;
|
||||
}
|
||||
|
||||
/*----------------------------- handle the last (probably partial) block */
|
||||
k8 = (const uint8_t *)k;
|
||||
switch(length) {
|
||||
switch (length) {
|
||||
case 12:
|
||||
c+=k[4]+(((uint32_t)k[5])<<16);
|
||||
b+=k[2]+(((uint32_t)k[3])<<16);
|
||||
a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
c += k[4] + (((uint32_t)k[5]) << 16);
|
||||
b += k[2] + (((uint32_t)k[3]) << 16);
|
||||
a += k[0] + (((uint32_t)k[1]) << 16);
|
||||
break;
|
||||
case 11:
|
||||
c+=((uint32_t)k8[10])<<16; /* fall through */
|
||||
c += ((uint32_t)k8[10]) << 16; /* fall through */
|
||||
case 10:
|
||||
c+=k[4];
|
||||
b+=k[2]+(((uint32_t)k[3])<<16);
|
||||
a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
c += k[4];
|
||||
b += k[2] + (((uint32_t)k[3]) << 16);
|
||||
a += k[0] + (((uint32_t)k[1]) << 16);
|
||||
break;
|
||||
case 9 :
|
||||
c+=k8[8]; /* fall through */
|
||||
case 8 :
|
||||
b+=k[2]+(((uint32_t)k[3])<<16);
|
||||
a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
case 9:
|
||||
c += k8[8]; /* fall through */
|
||||
case 8:
|
||||
b += k[2] + (((uint32_t)k[3]) << 16);
|
||||
a += k[0] + (((uint32_t)k[1]) << 16);
|
||||
break;
|
||||
case 7 :
|
||||
b+=((uint32_t)k8[6])<<16; /* fall through */
|
||||
case 6 :
|
||||
b+=k[2];
|
||||
a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
case 7:
|
||||
b += ((uint32_t)k8[6]) << 16; /* fall through */
|
||||
case 6:
|
||||
b += k[2];
|
||||
a += k[0] + (((uint32_t)k[1]) << 16);
|
||||
break;
|
||||
case 5 :
|
||||
b+=k8[4]; /* fall through */
|
||||
case 4 :
|
||||
a+=k[0]+(((uint32_t)k[1])<<16);
|
||||
case 5:
|
||||
b += k8[4]; /* fall through */
|
||||
case 4:
|
||||
a += k[0] + (((uint32_t)k[1]) << 16);
|
||||
break;
|
||||
case 3 :
|
||||
a+=((uint32_t)k8[2])<<16; /* fall through */
|
||||
case 2 :
|
||||
a+=k[0];
|
||||
case 3:
|
||||
a += ((uint32_t)k8[2]) << 16; /* fall through */
|
||||
case 2:
|
||||
a += k[0];
|
||||
break;
|
||||
case 1 :
|
||||
a+=k8[0];
|
||||
case 1:
|
||||
a += k8[0];
|
||||
break;
|
||||
case 0 :
|
||||
case 0:
|
||||
return c; /* zero length requires no mixing */
|
||||
}
|
||||
|
||||
|
@ -396,56 +396,56 @@ uint32_t nhash( const void *key, size_t length, uint32_t initval) {
|
|||
/*--------------- all but the last block: affect some 32 bits of (a,b,c) */
|
||||
while (length > 12) {
|
||||
a += k[0];
|
||||
a += ((uint32_t)k[1])<<8;
|
||||
a += ((uint32_t)k[2])<<16;
|
||||
a += ((uint32_t)k[3])<<24;
|
||||
a += ((uint32_t)k[1]) << 8;
|
||||
a += ((uint32_t)k[2]) << 16;
|
||||
a += ((uint32_t)k[3]) << 24;
|
||||
b += k[4];
|
||||
b += ((uint32_t)k[5])<<8;
|
||||
b += ((uint32_t)k[6])<<16;
|
||||
b += ((uint32_t)k[7])<<24;
|
||||
b += ((uint32_t)k[5]) << 8;
|
||||
b += ((uint32_t)k[6]) << 16;
|
||||
b += ((uint32_t)k[7]) << 24;
|
||||
c += k[8];
|
||||
c += ((uint32_t)k[9])<<8;
|
||||
c += ((uint32_t)k[10])<<16;
|
||||
c += ((uint32_t)k[11])<<24;
|
||||
mix(a,b,c);
|
||||
c += ((uint32_t)k[9]) << 8;
|
||||
c += ((uint32_t)k[10]) << 16;
|
||||
c += ((uint32_t)k[11]) << 24;
|
||||
mix(a, b, c);
|
||||
length -= 12;
|
||||
k += 12;
|
||||
}
|
||||
|
||||
/*-------------------------------- last block: affect all 32 bits of (c) */
|
||||
switch(length) { /* all the case statements fall through */
|
||||
switch (length) { /* all the case statements fall through */
|
||||
case 12:
|
||||
c+=((uint32_t)k[11])<<24;
|
||||
c += ((uint32_t)k[11]) << 24;
|
||||
case 11:
|
||||
c+=((uint32_t)k[10])<<16;
|
||||
c += ((uint32_t)k[10]) << 16;
|
||||
case 10:
|
||||
c+=((uint32_t)k[9])<<8;
|
||||
case 9 :
|
||||
c+=k[8];
|
||||
case 8 :
|
||||
b+=((uint32_t)k[7])<<24;
|
||||
case 7 :
|
||||
b+=((uint32_t)k[6])<<16;
|
||||
case 6 :
|
||||
b+=((uint32_t)k[5])<<8;
|
||||
case 5 :
|
||||
b+=k[4];
|
||||
case 4 :
|
||||
a+=((uint32_t)k[3])<<24;
|
||||
case 3 :
|
||||
a+=((uint32_t)k[2])<<16;
|
||||
case 2 :
|
||||
a+=((uint32_t)k[1])<<8;
|
||||
case 1 :
|
||||
a+=k[0];
|
||||
c += ((uint32_t)k[9]) << 8;
|
||||
case 9:
|
||||
c += k[8];
|
||||
case 8:
|
||||
b += ((uint32_t)k[7]) << 24;
|
||||
case 7:
|
||||
b += ((uint32_t)k[6]) << 16;
|
||||
case 6:
|
||||
b += ((uint32_t)k[5]) << 8;
|
||||
case 5:
|
||||
b += k[4];
|
||||
case 4:
|
||||
a += ((uint32_t)k[3]) << 24;
|
||||
case 3:
|
||||
a += ((uint32_t)k[2]) << 16;
|
||||
case 2:
|
||||
a += ((uint32_t)k[1]) << 8;
|
||||
case 1:
|
||||
a += k[0];
|
||||
break;
|
||||
case 0 :
|
||||
case 0:
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
final(a,b,c);
|
||||
c=(32767&c);
|
||||
final(a, b, c);
|
||||
c = (32767 & c);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
@ -453,6 +453,6 @@ uint32_t nhash( const void *key, size_t length, uint32_t initval) {
|
|||
/*
|
||||
* Fortran argument compatible wrapper
|
||||
*/
|
||||
uint32_t nhash_( const void * key, size_t const * length, uint32_t const * initval) {
|
||||
return nhash (key, *length, *initval);
|
||||
uint32_t nhash_(const void *key, size_t const *length, uint32_t const *initval) {
|
||||
return nhash(key, *length, *initval);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#pragma once
|
||||
|
||||
uint32_t nhash( const void * key, size_t length, uint32_t initval);
|
||||
uint32_t nhash_( void const * key, size_t const * length, uint32_t const * initval);
|
||||
uint32_t nhash(const void* key, size_t length, uint32_t initval);
|
||||
uint32_t nhash_(void const* key, size_t const* length, uint32_t const* initval);
|
||||
|
|
747
wsprd/wsprd.c
747
wsprd/wsprd.c
Plik diff jest za duży
Load Diff
|
@ -46,7 +46,6 @@ struct decoder_options {
|
|||
uint32_t subtraction; // ''
|
||||
};
|
||||
|
||||
|
||||
struct decoder_results {
|
||||
double freq;
|
||||
float sync;
|
||||
|
@ -61,15 +60,14 @@ struct decoder_results {
|
|||
uint32_t cycles;
|
||||
};
|
||||
|
||||
|
||||
void sync_and_demodulate(float *id, float *qd, long np,
|
||||
uint8_t *symbols, float *freq1, float fstep,
|
||||
int32_t *shift1, int32_t lagmin, int32_t lagmax, int32_t lagstep,
|
||||
float *drift1, int32_t symfac, float *sync, int32_t mode);
|
||||
void subtract_signal(float *id, float *qd, long np,
|
||||
float f0, int32_t shift0, float drift0, uint8_t* channel_symbols);
|
||||
float f0, int32_t shift0, float drift0, uint8_t *channel_symbols);
|
||||
void subtract_signal2(float *id, float *qd, long np,
|
||||
float f0, int32_t shift0, float drift0, uint8_t* channel_symbols);
|
||||
float f0, int32_t shift0, float drift0, uint8_t *channel_symbols);
|
||||
int32_t wspr_decode(float *idat, float *qdat, uint32_t npoints,
|
||||
struct decoder_options options, struct decoder_results *decodes,
|
||||
int32_t *n_results);
|
||||
|
|
|
@ -39,42 +39,41 @@
|
|||
//#pragma GCC diagnostic ignored "-Wstringop-overflow"
|
||||
//#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||
|
||||
|
||||
void unpack50(signed char *dat, int32_t *n1, int32_t *n2) {
|
||||
int32_t i, i4;
|
||||
|
||||
i = dat[0];
|
||||
i4 = i&255;
|
||||
*n1 = i4<<20;
|
||||
i4 = i & 255;
|
||||
*n1 = i4 << 20;
|
||||
|
||||
i = dat[1];
|
||||
i4 = i&255;
|
||||
*n1 = *n1+(i4<<12);
|
||||
i4 = i & 255;
|
||||
*n1 = *n1 + (i4 << 12);
|
||||
|
||||
i = dat[2];
|
||||
i4 = i&255;
|
||||
*n1 = *n1+(i4<<4);
|
||||
i4 = i & 255;
|
||||
*n1 = *n1 + (i4 << 4);
|
||||
|
||||
i = dat[3];
|
||||
i4 = i&255;
|
||||
*n1 = *n1+((i4>>4)&15);
|
||||
*n2 = (i4&15)<<18;
|
||||
i4 = i & 255;
|
||||
*n1 = *n1 + ((i4 >> 4) & 15);
|
||||
*n2 = (i4 & 15) << 18;
|
||||
|
||||
i = dat[4];
|
||||
i4 = i&255;
|
||||
*n2 = *n2+(i4<<10);
|
||||
i4 = i & 255;
|
||||
*n2 = *n2 + (i4 << 10);
|
||||
|
||||
i = dat[5];
|
||||
i4 = i&255;
|
||||
*n2 = *n2+(i4<<2);
|
||||
i4 = i & 255;
|
||||
*n2 = *n2 + (i4 << 2);
|
||||
|
||||
i = dat[6];
|
||||
i4 = i&255;
|
||||
*n2 = *n2+((i4>>6)&3);
|
||||
i4 = i & 255;
|
||||
*n2 = *n2 + ((i4 >> 6) & 3);
|
||||
}
|
||||
|
||||
int unpackcall(int32_t ncall, char *call) {
|
||||
char c[]= {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
|
||||
char c[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
|
||||
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z', ' '};
|
||||
int32_t n;
|
||||
|
@ -84,34 +83,34 @@ int unpackcall(int32_t ncall, char *call) {
|
|||
n = ncall;
|
||||
strcpy(call, "......");
|
||||
if (n < 262177560) {
|
||||
i = n%27+10;
|
||||
i = n % 27 + 10;
|
||||
tmp[5] = c[i];
|
||||
n = n/27;
|
||||
i = n%27+10;
|
||||
n = n / 27;
|
||||
i = n % 27 + 10;
|
||||
tmp[4] = c[i];
|
||||
n = n/27;
|
||||
i = n%27+10;
|
||||
n = n / 27;
|
||||
i = n % 27 + 10;
|
||||
tmp[3] = c[i];
|
||||
n = n/27;
|
||||
i = n%10;
|
||||
n = n / 27;
|
||||
i = n % 10;
|
||||
tmp[2] = c[i];
|
||||
n = n/10;
|
||||
i = n%36;
|
||||
n = n / 10;
|
||||
i = n % 36;
|
||||
tmp[1] = c[i];
|
||||
n = n/36;
|
||||
n = n / 36;
|
||||
i = n;
|
||||
tmp[0] = c[i];
|
||||
tmp[6] = '\0';
|
||||
// remove leading whitespace
|
||||
for (i=0; i < 5; i++) {
|
||||
if ( tmp[i] != c[36] )
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (tmp[i] != c[36])
|
||||
break;
|
||||
}
|
||||
sprintf(call, "%-6s", &tmp[i]);
|
||||
// remove trailing whitespace
|
||||
for (i=0; i < 6; i++) {
|
||||
if ( call[i] == c[36] ) {
|
||||
call[i]='\0';
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (call[i] == c[36]) {
|
||||
call[i] = '\0';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -121,29 +120,29 @@ int unpackcall(int32_t ncall, char *call) {
|
|||
}
|
||||
|
||||
int unpackgrid(int32_t ngrid, char *grid) {
|
||||
char c[]= {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
|
||||
char c[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
|
||||
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z', ' '};
|
||||
int dlat, dlong;
|
||||
|
||||
ngrid = ngrid>>7;
|
||||
if ( ngrid < 32400 ) {
|
||||
dlat = (ngrid%180)-90;
|
||||
dlong = (ngrid/180)*2 - 180 + 2;
|
||||
if ( dlong < -180 )
|
||||
dlong = dlong+360;
|
||||
if ( dlong > 180 )
|
||||
dlong = dlong+360;
|
||||
int nlong = 60.0*(180.0-dlong)/5.0;
|
||||
int n1 = nlong/240;
|
||||
int n2 = (nlong - 240*n1)/24;
|
||||
grid[0] = c[10+n1];
|
||||
ngrid = ngrid >> 7;
|
||||
if (ngrid < 32400) {
|
||||
dlat = (ngrid % 180) - 90;
|
||||
dlong = (ngrid / 180) * 2 - 180 + 2;
|
||||
if (dlong < -180)
|
||||
dlong = dlong + 360;
|
||||
if (dlong > 180)
|
||||
dlong = dlong + 360;
|
||||
int nlong = 60.0 * (180.0 - dlong) / 5.0;
|
||||
int n1 = nlong / 240;
|
||||
int n2 = (nlong - 240 * n1) / 24;
|
||||
grid[0] = c[10 + n1];
|
||||
grid[2] = c[n2];
|
||||
|
||||
int nlat = 60.0*(dlat+90)/2.5;
|
||||
n1 = nlat/240;
|
||||
n2 = (nlat-240*n1)/24;
|
||||
grid[1] = c[10+n1];
|
||||
int nlat = 60.0 * (dlat + 90) / 2.5;
|
||||
n1 = nlat / 240;
|
||||
n2 = (nlat - 240 * n1) / 24;
|
||||
grid[1] = c[10 + n1];
|
||||
grid[3] = c[n2];
|
||||
} else {
|
||||
strcpy(grid, "XXXX");
|
||||
|
@ -153,24 +152,24 @@ int unpackgrid(int32_t ngrid, char *grid) {
|
|||
}
|
||||
|
||||
int unpackpfx(int32_t nprefix, char *call) {
|
||||
char nc, pfx[4]="", tmpcall[7]="";
|
||||
char nc, pfx[4] = "", tmpcall[7] = "";
|
||||
int i;
|
||||
int32_t n;
|
||||
|
||||
strcpy(tmpcall, call);
|
||||
if ( nprefix < 60000 ) {
|
||||
if (nprefix < 60000) {
|
||||
// add a prefix of 1 to 3 characters
|
||||
n = nprefix;
|
||||
for (i=2; i >= 0; i--) {
|
||||
nc = n%37;
|
||||
if ( (nc >= 0) & (nc <= 9) ) {
|
||||
pfx[i] = nc+48;
|
||||
} else if ( (nc >= 10) & (nc <= 35) ) {
|
||||
pfx[i] = nc+55;
|
||||
for (i = 2; i >= 0; i--) {
|
||||
nc = n % 37;
|
||||
if ((nc >= 0) & (nc <= 9)) {
|
||||
pfx[i] = nc + 48;
|
||||
} else if ((nc >= 10) & (nc <= 35)) {
|
||||
pfx[i] = nc + 55;
|
||||
} else {
|
||||
pfx[i] = ' ';
|
||||
}
|
||||
n = n/37;
|
||||
n = n / 37;
|
||||
}
|
||||
|
||||
strcpy(call, pfx);
|
||||
|
@ -179,20 +178,20 @@ int unpackpfx(int32_t nprefix, char *call) {
|
|||
|
||||
} else {
|
||||
// add a suffix of 1 or 2 characters
|
||||
nc = nprefix-60000;
|
||||
if ( (nc >= 0) & (nc <= 9) ) {
|
||||
pfx[0] = nc+48;
|
||||
nc = nprefix - 60000;
|
||||
if ((nc >= 0) & (nc <= 9)) {
|
||||
pfx[0] = nc + 48;
|
||||
strcpy(call, tmpcall);
|
||||
strncat(call, "/", 1);
|
||||
strncat(call, pfx, 1);
|
||||
} else if ( (nc >= 10) & (nc <= 35) ) {
|
||||
pfx[0] = nc+55;
|
||||
} else if ((nc >= 10) & (nc <= 35)) {
|
||||
pfx[0] = nc + 55;
|
||||
strcpy(call, tmpcall);
|
||||
strncat(call, "/", 1);
|
||||
strncat(call, pfx, 1);
|
||||
} else if ( (nc >= 36) & (nc <= 125) ) {
|
||||
pfx[0] = (nc-26)/10+48;
|
||||
pfx[1] = (nc-26)%10+48;
|
||||
} else if ((nc >= 36) & (nc <= 125)) {
|
||||
pfx[0] = (nc - 26) / 10 + 48;
|
||||
pfx[1] = (nc - 26) % 10 + 48;
|
||||
strcpy(call, tmpcall);
|
||||
strncat(call, "/", 1);
|
||||
strncat(call, pfx, 2);
|
||||
|
@ -213,26 +212,26 @@ void deinterleave(unsigned char *sym) {
|
|||
j = ((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
|
||||
if (j < 162) {
|
||||
tmp[p] = sym[j];
|
||||
p = p+1;
|
||||
p = p + 1;
|
||||
}
|
||||
i = i+1;
|
||||
i = i + 1;
|
||||
}
|
||||
for (i=0; i < 162; i++) {
|
||||
for (i = 0; i < 162; i++) {
|
||||
sym[i] = tmp[i];
|
||||
}
|
||||
}
|
||||
|
||||
// used by qsort
|
||||
int doublecomp(const void* elem1, const void* elem2) {
|
||||
if (*(const double*)elem1 < *(const double*)elem2)
|
||||
int doublecomp(const void *elem1, const void *elem2) {
|
||||
if (*(const double *)elem1 < *(const double *)elem2)
|
||||
return -1;
|
||||
return *(const double*)elem1 > *(const double*)elem2;
|
||||
return *(const double *)elem1 > *(const double *)elem2;
|
||||
}
|
||||
|
||||
int floatcomp(const void* elem1, const void* elem2) {
|
||||
if (*(const float*)elem1 < *(const float*)elem2)
|
||||
int floatcomp(const void *elem1, const void *elem2) {
|
||||
if (*(const float *)elem1 < *(const float *)elem2)
|
||||
return -1;
|
||||
return *(const float*)elem1 > *(const float*)elem2;
|
||||
return *(const float *)elem1 > *(const float *)elem2;
|
||||
}
|
||||
|
||||
int unpk_(signed char *message, char *hashtab, char *call_loc_pow, char *call, char *loc, char *pwr, char *callsign) {
|
||||
|
@ -240,11 +239,11 @@ int unpk_(signed char *message, char *hashtab, char *call_loc_pow, char *call, c
|
|||
char grid[5], grid6[7], cdbm[3];
|
||||
|
||||
unpack50(message, &n1, &n2);
|
||||
if ( !unpackcall(n1, callsign) )
|
||||
if (!unpackcall(n1, callsign))
|
||||
return 1;
|
||||
if ( !unpackgrid(n2, grid) )
|
||||
if (!unpackgrid(n2, grid))
|
||||
return 1;
|
||||
int ntype = (n2&127) - 64;
|
||||
int ntype = (n2 & 127) - 64;
|
||||
callsign[12] = 0;
|
||||
grid[4] = 0;
|
||||
|
||||
|
@ -261,11 +260,11 @@ int unpk_(signed char *message, char *hashtab, char *call_loc_pow, char *call, c
|
|||
* Type 3: hash, 6 digit grid, power - ntype is negative.
|
||||
*/
|
||||
|
||||
if ( (ntype >= 0) && (ntype <= 62) ) {
|
||||
int nu=ntype%10;
|
||||
if ( nu == 0 || nu == 3 || nu == 7 ) {
|
||||
if ((ntype >= 0) && (ntype <= 62)) {
|
||||
int nu = ntype % 10;
|
||||
if (nu == 0 || nu == 3 || nu == 7) {
|
||||
ndbm = ntype;
|
||||
memset(call_loc_pow, 0, sizeof(char)*23);
|
||||
memset(call_loc_pow, 0, sizeof(char) * 23);
|
||||
sprintf(cdbm, "%2d", ndbm);
|
||||
strncat(call_loc_pow, callsign, strlen(callsign));
|
||||
strncat(call_loc_pow, " ", 1);
|
||||
|
@ -274,11 +273,11 @@ int unpk_(signed char *message, char *hashtab, char *call_loc_pow, char *call, c
|
|||
strncat(call_loc_pow, cdbm, 2);
|
||||
strncat(call_loc_pow, "\0", 1);
|
||||
ihash = nhash(callsign, strlen(callsign), (uint32_t)146);
|
||||
strcpy(hashtab+ihash*13, callsign);
|
||||
strcpy(hashtab + ihash * 13, callsign);
|
||||
|
||||
memset(call, 0, strlen(callsign)+1);
|
||||
memset(loc, 0, strlen(grid)+1);
|
||||
memset(pwr, 0, 2+1);
|
||||
memset(call, 0, strlen(callsign) + 1);
|
||||
memset(loc, 0, strlen(grid) + 1);
|
||||
memset(pwr, 0, 2 + 1);
|
||||
strncat(call, callsign, strlen(callsign));
|
||||
strncat(call, "\0", 1);
|
||||
strncat(loc, grid, strlen(grid));
|
||||
|
@ -288,62 +287,62 @@ int unpk_(signed char *message, char *hashtab, char *call_loc_pow, char *call, c
|
|||
|
||||
} else {
|
||||
nadd = nu;
|
||||
if ( nu > 3 )
|
||||
nadd = nu-3;
|
||||
if ( nu > 7 )
|
||||
nadd = nu-7;
|
||||
n3 = n2/128+32768*(nadd-1);
|
||||
if ( !unpackpfx(n3, callsign) )
|
||||
if (nu > 3)
|
||||
nadd = nu - 3;
|
||||
if (nu > 7)
|
||||
nadd = nu - 7;
|
||||
n3 = n2 / 128 + 32768 * (nadd - 1);
|
||||
if (!unpackpfx(n3, callsign))
|
||||
return 1;
|
||||
ndbm = ntype - nadd;
|
||||
memset(call_loc_pow, 0, sizeof(char)*23);
|
||||
memset(call_loc_pow, 0, sizeof(char) * 23);
|
||||
sprintf(cdbm, "%2d", ndbm);
|
||||
strncat(call_loc_pow, callsign, strlen(callsign));
|
||||
strncat(call_loc_pow, " ", 1);
|
||||
strncat(call_loc_pow, cdbm, 2);
|
||||
strncat(call_loc_pow, "\0", 1);
|
||||
int nu = ndbm%10;
|
||||
if ( nu == 0 || nu == 3 || nu == 7 || nu == 10 ) { // make sure power is OK
|
||||
int nu = ndbm % 10;
|
||||
if (nu == 0 || nu == 3 || nu == 7 || nu == 10) { // make sure power is OK
|
||||
ihash = nhash(callsign, strlen(callsign), (uint32_t)146);
|
||||
strcpy(hashtab+ihash*13, callsign);
|
||||
strcpy(hashtab + ihash * 13, callsign);
|
||||
} else {
|
||||
noprint = 1;
|
||||
}
|
||||
|
||||
memset(call, 0, strlen(callsign)+1);
|
||||
memset(call, 0, strlen(callsign) + 1);
|
||||
memset(loc, 0, 1);
|
||||
memset(pwr, 0, 2+1);
|
||||
memset(pwr, 0, 2 + 1);
|
||||
strncat(call, callsign, strlen(callsign));
|
||||
strncat(call, "\0", 1);
|
||||
strncat(loc, "\0", 1);
|
||||
strncat(pwr, cdbm, 2);
|
||||
strncat(pwr, "\0", 1);
|
||||
}
|
||||
} else if ( ntype < 0 ) {
|
||||
ndbm = -(ntype+1);
|
||||
memset(grid6, 0, sizeof(char)*7);
|
||||
strncat(grid6, callsign+5, 1);
|
||||
} else if (ntype < 0) {
|
||||
ndbm = -(ntype + 1);
|
||||
memset(grid6, 0, sizeof(char) * 7);
|
||||
strncat(grid6, callsign + 5, 1);
|
||||
strncat(grid6, callsign, 5);
|
||||
int nu = ndbm%10;
|
||||
if ( (nu == 0 || nu == 3 || nu == 7 || nu == 10) &&
|
||||
(isalpha(grid6[0]) && isalpha(grid6[1]) && isdigit(grid6[2]) && isdigit(grid6[3]) ) ) {
|
||||
int nu = ndbm % 10;
|
||||
if ((nu == 0 || nu == 3 || nu == 7 || nu == 10) &&
|
||||
(isalpha(grid6[0]) && isalpha(grid6[1]) && isdigit(grid6[2]) && isdigit(grid6[3]))) {
|
||||
// not testing 4'th and 5'th chars because of this case: <PA0SKT/2> JO33 40
|
||||
// grid is only 4 chars even though this is a hashed callsign...
|
||||
// isalpha(grid6[4]) && isalpha(grid6[5]) ) ) {
|
||||
ihash = nhash(callsign, strlen(callsign), (uint32_t)146);
|
||||
strcpy(hashtab+ihash*13, callsign);
|
||||
strcpy(hashtab + ihash * 13, callsign);
|
||||
} else {
|
||||
noprint = 1;
|
||||
}
|
||||
|
||||
ihash = (n2-ntype-64)/128;
|
||||
if ( strncmp(hashtab+ihash*13, "\0", 1) != 0 ) {
|
||||
sprintf(callsign, "<%s>", hashtab+ihash*13);
|
||||
ihash = (n2 - ntype - 64) / 128;
|
||||
if (strncmp(hashtab + ihash * 13, "\0", 1) != 0) {
|
||||
sprintf(callsign, "<%s>", hashtab + ihash * 13);
|
||||
} else {
|
||||
sprintf(callsign, "%5s", "<...>");
|
||||
}
|
||||
|
||||
memset(call_loc_pow, 0, sizeof(char)*23);
|
||||
memset(call_loc_pow, 0, sizeof(char) * 23);
|
||||
sprintf(cdbm, "%2d", ndbm);
|
||||
strncat(call_loc_pow, callsign, strlen(callsign));
|
||||
strncat(call_loc_pow, " ", 1);
|
||||
|
@ -352,9 +351,9 @@ int unpk_(signed char *message, char *hashtab, char *call_loc_pow, char *call, c
|
|||
strncat(call_loc_pow, cdbm, 2);
|
||||
strncat(call_loc_pow, "\0", 1);
|
||||
|
||||
memset(call, 0, strlen(callsign)+1);
|
||||
memset(loc, 0, strlen(grid6)+1);
|
||||
memset(pwr, 0, 2+1);
|
||||
memset(call, 0, strlen(callsign) + 1);
|
||||
memset(loc, 0, strlen(grid6) + 1);
|
||||
memset(pwr, 0, 2 + 1);
|
||||
strncat(call, callsign, strlen(callsign));
|
||||
strncat(call, "\0", 1);
|
||||
strncat(loc, grid6, strlen(grid6));
|
||||
|
@ -363,7 +362,7 @@ int unpk_(signed char *message, char *hashtab, char *call_loc_pow, char *call, c
|
|||
strncat(pwr, "\0", 1);
|
||||
|
||||
// I don't know what to do with these... They show up as "A000AA" grids.
|
||||
if ( ntype == -64 )
|
||||
if (ntype == -64)
|
||||
noprint = 1;
|
||||
}
|
||||
return noprint;
|
||||
|
|
|
@ -36,7 +36,7 @@ int unpackpfx(int32_t nprefix, char *call);
|
|||
void deinterleave(unsigned char *sym);
|
||||
|
||||
// used by qsort
|
||||
int doublecomp(const void* elem1, const void* elem2);
|
||||
int floatcomp(const void* elem1, const void* elem2);
|
||||
int doublecomp(const void *elem1, const void *elem2);
|
||||
int floatcomp(const void *elem1, const void *elem2);
|
||||
|
||||
int unpk_(signed char *message, char *hashtab, char *call_loc_pow, char *call, char *loc, char *pwr, char *callsign);
|
||||
|
|
|
@ -12,29 +12,28 @@
|
|||
#include "./nhash.h"
|
||||
#include "./fano.h"
|
||||
|
||||
|
||||
char get_locator_character_code(char ch) {
|
||||
if( ch >=48 && ch <=57 ) { //0-9
|
||||
return ch-48;
|
||||
if (ch >= 48 && ch <= 57) { // 0-9
|
||||
return ch - 48;
|
||||
}
|
||||
if( ch == 32 ) { //space
|
||||
if (ch == 32) { // space
|
||||
return 36;
|
||||
}
|
||||
if( ch >= 65 && ch <= 82 ) { //A-Z
|
||||
return ch-65;
|
||||
if (ch >= 65 && ch <= 82) { // A-Z
|
||||
return ch - 65;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
char get_callsign_character_code(char ch) {
|
||||
if( ch >=48 && ch <=57 ) { //0-9
|
||||
return ch-48;
|
||||
if (ch >= 48 && ch <= 57) { // 0-9
|
||||
return ch - 48;
|
||||
}
|
||||
if( ch == 32 ) { //space
|
||||
if (ch == 32) { // space
|
||||
return 36;
|
||||
}
|
||||
if( ch >= 65 && ch <= 90 ) { //A-Z
|
||||
return ch-55;
|
||||
if (ch >= 65 && ch <= 90) { // A-Z
|
||||
return ch - 55;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -42,8 +41,8 @@ char get_callsign_character_code(char ch) {
|
|||
long unsigned int pack_grid4_power(char *grid4, int power) {
|
||||
long unsigned int m;
|
||||
|
||||
m=(179-10*grid4[0]-grid4[2])*180+10*grid4[1]+grid4[3];
|
||||
m=m*128+power+64;
|
||||
m = (179 - 10 * grid4[0] - grid4[2]) * 180 + 10 * grid4[1] + grid4[3];
|
||||
m = m * 128 + power + 64;
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -51,101 +50,101 @@ long unsigned int pack_call(char *callsign) {
|
|||
int i;
|
||||
long unsigned int n;
|
||||
char call6[6];
|
||||
memset(call6,32,sizeof(char)*6);
|
||||
memset(call6, 32, sizeof(char) * 6);
|
||||
// callsign is 6 characters in length. Exactly.
|
||||
int call_len = strlen(callsign);
|
||||
if( call_len > 6 ) {
|
||||
if (call_len > 6) {
|
||||
return 0;
|
||||
}
|
||||
if( isdigit(*(callsign+2)) ) {
|
||||
for (i=0; i<6; i++) {
|
||||
if( callsign[i] == 0 ) {
|
||||
call6[i]=32;
|
||||
if (isdigit(*(callsign + 2))) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (callsign[i] == 0) {
|
||||
call6[i] = 32;
|
||||
} else {
|
||||
call6[i]=*(callsign+i);
|
||||
call6[i] = *(callsign + i);
|
||||
}
|
||||
}
|
||||
} else if( isdigit(*(callsign+1)) ) {
|
||||
for (i=0; i<6; i++) {
|
||||
if( i==0 || callsign[i-1]==0 ) {
|
||||
call6[i]=32;
|
||||
} else if (isdigit(*(callsign + 1))) {
|
||||
for (i = 0; i < 6; i++) {
|
||||
if (i == 0 || callsign[i - 1] == 0) {
|
||||
call6[i] = 32;
|
||||
} else {
|
||||
call6[i]=*(callsign+i-1);
|
||||
call6[i] = *(callsign + i - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i=0; i<6; i++) {
|
||||
call6[i]=get_callsign_character_code(call6[i]);
|
||||
for (i = 0; i < 6; i++) {
|
||||
call6[i] = get_callsign_character_code(call6[i]);
|
||||
}
|
||||
n = call6[0];
|
||||
n = n*36+call6[1];
|
||||
n = n*10+call6[2];
|
||||
n = n*27+call6[3]-10;
|
||||
n = n*27+call6[4]-10;
|
||||
n = n*27+call6[5]-10;
|
||||
n = n * 36 + call6[1];
|
||||
n = n * 10 + call6[2];
|
||||
n = n * 27 + call6[3] - 10;
|
||||
n = n * 27 + call6[4] - 10;
|
||||
n = n * 27 + call6[5] - 10;
|
||||
return n;
|
||||
}
|
||||
|
||||
void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd ) {
|
||||
void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd) {
|
||||
int i;
|
||||
char *call6;
|
||||
call6=malloc(sizeof(char)*6);
|
||||
memset(call6,32,sizeof(char)*6);
|
||||
int i1=strcspn(callsign,"/");
|
||||
call6 = malloc(sizeof(char) * 6);
|
||||
memset(call6, 32, sizeof(char) * 6);
|
||||
int i1 = strcspn(callsign, "/");
|
||||
|
||||
if( callsign[i1+2] == 0 ) {
|
||||
//single char suffix
|
||||
for (i=0; i<i1; i++) {
|
||||
call6[i]=callsign[i];
|
||||
if (callsign[i1 + 2] == 0) {
|
||||
// single char suffix
|
||||
for (i = 0; i < i1; i++) {
|
||||
call6[i] = callsign[i];
|
||||
}
|
||||
*n=pack_call(call6);
|
||||
*nadd=1;
|
||||
int nc = callsign[i1+1];
|
||||
if( nc >= 48 && nc <= 57 ) {
|
||||
*m=nc-48;
|
||||
} else if ( nc >= 65 && nc <= 90 ) {
|
||||
*m=nc-65+10;
|
||||
*n = pack_call(call6);
|
||||
*nadd = 1;
|
||||
int nc = callsign[i1 + 1];
|
||||
if (nc >= 48 && nc <= 57) {
|
||||
*m = nc - 48;
|
||||
} else if (nc >= 65 && nc <= 90) {
|
||||
*m = nc - 65 + 10;
|
||||
} else {
|
||||
*m=38;
|
||||
*m = 38;
|
||||
}
|
||||
*m=60000-32768+*m;
|
||||
} else if( callsign[i1+3]==0 ) {
|
||||
//two char suffix
|
||||
for (i=0; i<i1; i++) {
|
||||
call6[i]=callsign[i];
|
||||
*m = 60000 - 32768 + *m;
|
||||
} else if (callsign[i1 + 3] == 0) {
|
||||
// two char suffix
|
||||
for (i = 0; i < i1; i++) {
|
||||
call6[i] = callsign[i];
|
||||
}
|
||||
*n=pack_call(call6);
|
||||
*nadd=1;
|
||||
*m=10*(callsign[i1+1]-48)+(callsign[i1+2]-48);
|
||||
*m=60000 + 26 + *m;
|
||||
*n = pack_call(call6);
|
||||
*nadd = 1;
|
||||
*m = 10 * (callsign[i1 + 1] - 48) + (callsign[i1 + 2] - 48);
|
||||
*m = 60000 + 26 + *m;
|
||||
} else {
|
||||
char* pfx=strtok(callsign,"/");
|
||||
call6=strtok(pfx," "); // FIXME-CHECK
|
||||
*n=pack_call(call6);
|
||||
int plen=strlen(pfx);
|
||||
if( plen ==1 ) {
|
||||
*m=36;
|
||||
*m=37*(*m)+36;
|
||||
} else if( plen == 2 ) {
|
||||
*m=36;
|
||||
char *pfx = strtok(callsign, "/");
|
||||
call6 = strtok(pfx, " "); // FIXME-CHECK
|
||||
*n = pack_call(call6);
|
||||
int plen = strlen(pfx);
|
||||
if (plen == 1) {
|
||||
*m = 36;
|
||||
*m = 37 * (*m) + 36;
|
||||
} else if (plen == 2) {
|
||||
*m = 36;
|
||||
} else {
|
||||
*m=0;
|
||||
*m = 0;
|
||||
}
|
||||
for (i=0; i<plen; i++) {
|
||||
for (i = 0; i < plen; i++) {
|
||||
int nc = callsign[i];
|
||||
if( nc >= 48 && nc <= 57 ) {
|
||||
nc=nc-48;
|
||||
} else if ( nc >= 65 && nc <= 90 ) {
|
||||
nc=nc-65+10;
|
||||
if (nc >= 48 && nc <= 57) {
|
||||
nc = nc - 48;
|
||||
} else if (nc >= 65 && nc <= 90) {
|
||||
nc = nc - 65 + 10;
|
||||
} else {
|
||||
nc=36;
|
||||
nc = 36;
|
||||
}
|
||||
*m=37*(*m)+nc;
|
||||
*m = 37 * (*m) + nc;
|
||||
}
|
||||
*nadd=0;
|
||||
if( *m > 32768 ) {
|
||||
*m=*m-32768;
|
||||
*nadd=1;
|
||||
*nadd = 0;
|
||||
if (*m > 32768) {
|
||||
*m = *m - 32768;
|
||||
*nadd = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -154,162 +153,160 @@ void interleave(unsigned char *sym) {
|
|||
unsigned char tmp[162];
|
||||
unsigned char p, i, j;
|
||||
|
||||
p=0;
|
||||
i=0;
|
||||
while (p<162) {
|
||||
j=((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
|
||||
if (j < 162 ) {
|
||||
tmp[j]=sym[p];
|
||||
p=p+1;
|
||||
p = 0;
|
||||
i = 0;
|
||||
while (p < 162) {
|
||||
j = ((i * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
|
||||
if (j < 162) {
|
||||
tmp[j] = sym[p];
|
||||
p = p + 1;
|
||||
}
|
||||
i=i+1;
|
||||
i = i + 1;
|
||||
}
|
||||
for (i=0; i<162; i++) {
|
||||
sym[i]=tmp[i];
|
||||
for (i = 0; i < 162; i++) {
|
||||
sym[i] = tmp[i];
|
||||
}
|
||||
}
|
||||
|
||||
int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* symbols) {
|
||||
int m=0, n=0, ntype=0;
|
||||
int get_wspr_channel_symbols(char *rawmessage, char *hashtab, unsigned char *symbols) {
|
||||
int m = 0, n = 0, ntype = 0;
|
||||
int i, j, ihash;
|
||||
unsigned char pr3[162]= {
|
||||
1,1,0,0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,1,0,
|
||||
0,1,0,1,1,1,1,0,0,0,0,0,0,0,1,0,0,1,0,1,
|
||||
0,0,0,0,0,0,1,0,1,1,0,0,1,1,0,1,0,0,0,1,
|
||||
1,0,1,0,0,0,0,1,1,0,1,0,1,0,1,0,1,0,0,1,
|
||||
0,0,1,0,1,1,0,0,0,1,1,0,1,0,1,0,0,0,1,0,
|
||||
0,0,0,0,1,0,0,1,0,0,1,1,1,0,1,1,0,0,1,1,
|
||||
0,1,0,0,0,1,1,1,0,0,0,0,0,1,0,1,0,0,1,1,
|
||||
0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,1,1,0,
|
||||
0,0
|
||||
};
|
||||
int nu[10]= {0,-1,1,0,-1,2,1,0,-1,1};
|
||||
unsigned char pr3[162] = {
|
||||
1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0,
|
||||
0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1,
|
||||
0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1,
|
||||
1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1,
|
||||
0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1,
|
||||
0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1,
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0,
|
||||
0, 0};
|
||||
int nu[10] = {0, -1, 1, 0, -1, 2, 1, 0, -1, 1};
|
||||
char *callsign, *grid, *powstr;
|
||||
char grid4[5], message[23];
|
||||
|
||||
memset(message,0,sizeof(char)*23);
|
||||
i=0;
|
||||
while ( rawmessage[i] != 0 && i<23 ) {
|
||||
message[i]=rawmessage[i];
|
||||
memset(message, 0, sizeof(char) * 23);
|
||||
i = 0;
|
||||
while (rawmessage[i] != 0 && i < 23) {
|
||||
message[i] = rawmessage[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
int i1=strcspn(message," ");
|
||||
int i2=strcspn(message,"/");
|
||||
int i3=strcspn(message,"<");
|
||||
int i4=strcspn(message,">");
|
||||
int mlen=strlen(message);
|
||||
int i1 = strcspn(message, " ");
|
||||
int i2 = strcspn(message, "/");
|
||||
int i3 = strcspn(message, "<");
|
||||
int i4 = strcspn(message, ">");
|
||||
int mlen = strlen(message);
|
||||
|
||||
// Use the presence and/or absence of "<" and "/" to decide what
|
||||
// type of message. No sanity checks! Beware!
|
||||
|
||||
if( (i1>3) & (i1<7) & (i2==mlen) & (i3==mlen) ) {
|
||||
if ((i1 > 3) & (i1 < 7) & (i2 == mlen) & (i3 == mlen)) {
|
||||
// Type 1 message: K9AN EN50 33
|
||||
// xxnxxxx xxnn nn
|
||||
callsign = strtok(message," ");
|
||||
grid = strtok(NULL," ");
|
||||
powstr = strtok(NULL," ");
|
||||
callsign = strtok(message, " ");
|
||||
grid = strtok(NULL, " ");
|
||||
powstr = strtok(NULL, " ");
|
||||
int power = atoi(powstr);
|
||||
n = pack_call(callsign);
|
||||
|
||||
for (i=0; i<4; i++) {
|
||||
grid4[i]=get_locator_character_code(*(grid+i));
|
||||
for (i = 0; i < 4; i++) {
|
||||
grid4[i] = get_locator_character_code(*(grid + i));
|
||||
}
|
||||
m = pack_grid4_power(grid4,power);
|
||||
m = pack_grid4_power(grid4, power);
|
||||
|
||||
} else if ( i3 == 0 && i4 < mlen ) {
|
||||
} else if (i3 == 0 && i4 < mlen) {
|
||||
// Type 3: <K1ABC> EN50WC 33
|
||||
// <PJ4/K1ABC> FK52UD 37
|
||||
// send hash instead of callsign to make room for 6 char grid.
|
||||
// if 4-digit locator is specified, 2 spaces are added to the end.
|
||||
callsign=strtok(message,"<> ");
|
||||
grid=strtok(NULL," ");
|
||||
powstr=strtok(NULL," ");
|
||||
callsign = strtok(message, "<> ");
|
||||
grid = strtok(NULL, " ");
|
||||
powstr = strtok(NULL, " ");
|
||||
int power = atoi(powstr);
|
||||
if( power < 0 ) power=0;
|
||||
if( power > 60 ) power=60;
|
||||
power=power+nu[power%10];
|
||||
ntype=-(power+1);
|
||||
ihash=nhash(callsign,strlen(callsign),(uint32_t)146);
|
||||
m=128*ihash + ntype + 64;
|
||||
if (power < 0) power = 0;
|
||||
if (power > 60) power = 60;
|
||||
power = power + nu[power % 10];
|
||||
ntype = -(power + 1);
|
||||
ihash = nhash(callsign, strlen(callsign), (uint32_t)146);
|
||||
m = 128 * ihash + ntype + 64;
|
||||
|
||||
char grid6[6];
|
||||
memset(grid6,32,sizeof(char)*6);
|
||||
j=strlen(grid);
|
||||
for(i=0; i<j-1; i++) {
|
||||
grid6[i]=grid[i+1];
|
||||
memset(grid6, 32, sizeof(char) * 6);
|
||||
j = strlen(grid);
|
||||
for (i = 0; i < j - 1; i++) {
|
||||
grid6[i] = grid[i + 1];
|
||||
}
|
||||
grid6[5]=grid[0];
|
||||
n=pack_call(grid6);
|
||||
} else if ( i2 < mlen ) { // just looks for a right slash
|
||||
grid6[5] = grid[0];
|
||||
n = pack_call(grid6);
|
||||
} else if (i2 < mlen) { // just looks for a right slash
|
||||
// Type 2: PJ4/K1ABC 37
|
||||
callsign=strtok(message," ");
|
||||
if( strlen(callsign) < i2 ) return 0; //guards against pathological case
|
||||
powstr=strtok(NULL," ");
|
||||
callsign = strtok(message, " ");
|
||||
if (strlen(callsign) < i2) return 0; // guards against pathological case
|
||||
powstr = strtok(NULL, " ");
|
||||
int power = atoi(powstr);
|
||||
if( power < 0 ) power=0;
|
||||
if( power > 60 ) power=60;
|
||||
power=power+nu[power%10];
|
||||
if (power < 0) power = 0;
|
||||
if (power > 60) power = 60;
|
||||
power = power + nu[power % 10];
|
||||
int n1, ng, nadd;
|
||||
pack_prefix(callsign, &n1, &ng, &nadd);
|
||||
ntype=power + 1 + nadd;
|
||||
m=128*ng+ntype+64;
|
||||
n=n1;
|
||||
ntype = power + 1 + nadd;
|
||||
m = 128 * ng + ntype + 64;
|
||||
n = n1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// pack 50 bits + 31 (0) tail bits into 11 bytes
|
||||
unsigned char it, data[11];
|
||||
memset(data,0,sizeof(char)*11);
|
||||
it=0xFF & (n>>20);
|
||||
data[0]=it;
|
||||
it=0xFF & (n>>12);
|
||||
data[1]=it;
|
||||
it=0xFF & (n>>4);
|
||||
data[2]=it;
|
||||
it= ((n&(0x0F))<<4) + ((m>>18)&(0x0F));
|
||||
data[3]=it;
|
||||
it=0xFF & (m>>10);
|
||||
data[4]=it;
|
||||
it=0xFF & (m>>2);
|
||||
data[5]=it;
|
||||
it=(m & 0x03)<<6 ;
|
||||
data[6]=it;
|
||||
data[7]=0;
|
||||
data[8]=0;
|
||||
data[9]=0;
|
||||
data[10]=0;
|
||||
|
||||
memset(data, 0, sizeof(char) * 11);
|
||||
it = 0xFF & (n >> 20);
|
||||
data[0] = it;
|
||||
it = 0xFF & (n >> 12);
|
||||
data[1] = it;
|
||||
it = 0xFF & (n >> 4);
|
||||
data[2] = it;
|
||||
it = ((n & (0x0F)) << 4) + ((m >> 18) & (0x0F));
|
||||
data[3] = it;
|
||||
it = 0xFF & (m >> 10);
|
||||
data[4] = it;
|
||||
it = 0xFF & (m >> 2);
|
||||
data[5] = it;
|
||||
it = (m & 0x03) << 6;
|
||||
data[6] = it;
|
||||
data[7] = 0;
|
||||
data[8] = 0;
|
||||
data[9] = 0;
|
||||
data[10] = 0;
|
||||
|
||||
// make sure that the 11-byte data vector is unpackable
|
||||
// unpack it with the routine that the decoder will use and display
|
||||
// the result. let the operator decide whether it worked.
|
||||
// char hashtab[32768][13];
|
||||
// memset(hashtab,0,sizeof(char)*32768*13);
|
||||
// char hashtab[32768][13];
|
||||
// memset(hashtab,0,sizeof(char)*32768*13);
|
||||
|
||||
char *check_call_loc_pow, *check_callsign, *call, *loc, *pwr;
|
||||
check_call_loc_pow=malloc(sizeof(char)*23);
|
||||
check_callsign=malloc(sizeof(char)*13);
|
||||
call=malloc(sizeof(char)*13);
|
||||
loc=malloc(sizeof(char)*7);
|
||||
pwr=malloc(sizeof(char)*3);
|
||||
check_call_loc_pow = malloc(sizeof(char) * 23);
|
||||
check_callsign = malloc(sizeof(char) * 13);
|
||||
call = malloc(sizeof(char) * 13);
|
||||
loc = malloc(sizeof(char) * 7);
|
||||
pwr = malloc(sizeof(char) * 3);
|
||||
signed char check_data[11];
|
||||
memcpy(check_data,data,sizeof(char)*11);
|
||||
unpk_(check_data,hashtab,check_call_loc_pow,call,loc,pwr,check_callsign);
|
||||
// printf("Will decode as: %s\n",check_call_loc_pow);
|
||||
memcpy(check_data, data, sizeof(char) * 11);
|
||||
unpk_(check_data, hashtab, check_call_loc_pow, call, loc, pwr, check_callsign);
|
||||
// printf("Will decode as: %s\n",check_call_loc_pow);
|
||||
|
||||
unsigned int nbytes=11; // The message with tail is packed into 11 bytes.
|
||||
unsigned int nencoded=(nbytes * 2 * 8); // This is how much encode() writes
|
||||
unsigned int nbytes = 11; // The message with tail is packed into 11 bytes.
|
||||
unsigned int nencoded = (nbytes * 2 * 8); // This is how much encode() writes
|
||||
unsigned char channelbits[nencoded];
|
||||
memset(channelbits,0,sizeof(char)*nencoded);
|
||||
memset(channelbits, 0, sizeof(char) * nencoded);
|
||||
|
||||
encode(channelbits,data,nbytes);
|
||||
encode(channelbits, data, nbytes);
|
||||
|
||||
interleave(channelbits);
|
||||
|
||||
for (i=0; i<162; i++) {
|
||||
symbols[i]=2*channelbits[i]+pr3[i];
|
||||
for (i = 0; i < 162; i++) {
|
||||
symbols[i] = 2 * channelbits[i] + pr3[i];
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -4,6 +4,6 @@ char get_locator_character_code(char ch);
|
|||
char get_callsign_character_code(char ch);
|
||||
long unsigned int pack_grid4_power(char *grid4, int power);
|
||||
long unsigned int pack_call(char *callsign);
|
||||
void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd );
|
||||
void pack_prefix(char *callsign, int32_t *n, int32_t *m, int32_t *nadd);
|
||||
void interleave(unsigned char *sym);
|
||||
int get_wspr_channel_symbols(char* message, char* hashtab, unsigned char* symbols);
|
||||
int get_wspr_channel_symbols(char *message, char *hashtab, unsigned char *symbols);
|
||||
|
|
Ładowanie…
Reference in New Issue