Added BPSK31 varicode decoding.

feature/args
ha7ilm 2016-05-04 23:46:23 +02:00
rodzic 84e00184af
commit ec37c6583c
3 zmienionych plików z 286 dodań i 8 usunięć

46
csdr.c
Wyświetl plik

@ -163,6 +163,8 @@ int clone_(int bufsize_param)
}
}
#define FREAD_U8 fread (input_buffer, sizeof(unsigned char), the_bufsize, stdin)
#define FWRITE_U8 fwrite (output_buffer, sizeof(unsigned char), the_bufsize, stdout)
#define FREAD_R fread (input_buffer, sizeof(float), the_bufsize, stdin)
#define FREAD_C fread (input_buffer, sizeof(float)*2, the_bufsize, stdin)
#define FWRITE_R fwrite (output_buffer, sizeof(float), the_bufsize, stdout)
@ -352,7 +354,7 @@ int main(int argc, char *argv[])
char** fifo_buffers = (char**)malloc(sizeof(char*)*fifo_num_buffers);
for(int i=0;i<fifo_num_buffers;i++) fifo_buffers[i]=(char*)malloc(sizeof(char)*fifo_buffer_size);
SET_NONBLOCK(STDIN_FILENO);
SET_NONBLOCK(STDOUT_FILENO);
@ -375,7 +377,7 @@ int main(int argc, char *argv[])
for(;;)
{
select(highfd, &read_fds, NULL, NULL, NULL);
//try to read until buffer is full
if(FD_ISSET(STDIN_FILENO, &read_fds)) for(;;)
{
@ -383,9 +385,9 @@ int main(int argc, char *argv[])
//fprintf(stderr, "r %d %d | %d %d\n", read_bytes, fifo_buffer_size-fifo_actual_buffer_rd_pos, fifo_actual_buffer_rd, fifo_actual_buffer_rd_pos);
if(!read_bytes || ((read_bytes<0)&&(fifo_error=read_bytes)) ) break;
fifo_actual_buffer_rd_pos+=read_bytes;
if(!((fifo_actual_buffer_rd==fifo_actual_buffer_wr-1)||(fifo_actual_buffer_wr==0&&fifo_actual_buffer_rd==fifo_num_buffers-1)))
if(!((fifo_actual_buffer_rd==fifo_actual_buffer_wr-1)||(fifo_actual_buffer_wr==0&&fifo_actual_buffer_rd==fifo_num_buffers-1)))
{
if(fifo_actual_buffer_rd_pos==fifo_buffer_size)
if(fifo_actual_buffer_rd_pos==fifo_buffer_size)
{
fifo_overrun_shown = 0;
fifo_actual_buffer_rd++;
@ -394,8 +396,8 @@ int main(int argc, char *argv[])
}
}
else
{
if(fifo_actual_buffer_rd_pos==fifo_buffer_size)
{
if(fifo_actual_buffer_rd_pos==fifo_buffer_size)
{
fifo_actual_buffer_rd_pos = 0; //rewrite same buffer
if(!fifo_overrun_shown) { fifo_overrun_shown=1; fprintf(stderr, "fifo: circular buffer full, dropping samples\n"); }
@ -409,8 +411,8 @@ int main(int argc, char *argv[])
int written_bytes=write(STDOUT_FILENO, fifo_buffers[fifo_actual_buffer_wr]+fifo_actual_buffer_wr_pos, fifo_buffer_size-fifo_actual_buffer_wr_pos);
//fprintf(stderr, "w %d %d | %d %d\n", written_bytes, fifo_buffer_size-fifo_actual_buffer_wr_pos, fifo_actual_buffer_wr, fifo_actual_buffer_wr_pos);
if(!written_bytes || ((written_bytes<0)&&(fifo_error=written_bytes)) ) break;
fifo_actual_buffer_wr_pos+=written_bytes;
if(fifo_actual_buffer_wr_pos==fifo_buffer_size)
fifo_actual_buffer_wr_pos+=written_bytes;
if(fifo_actual_buffer_wr_pos==fifo_buffer_size)
{
fifo_actual_buffer_wr++;
fifo_actual_buffer_wr_pos = 0;
@ -1832,6 +1834,34 @@ int main(int argc, char *argv[])
}
}
if(!strcmp(argv[1],"bpsk31_varicode2ascii_sy_u8")) //not tested
{
unsigned long long status_shr = 0;
unsigned char output;
if(!sendbufsize(initialize_buffers())) return -2;
unsigned char i=0;
for(;;)
{
if((output=psk31_varicode_push(&status_shr, getchar()))) { putchar(output); fflush(stdout); }
if(i++) continue; //do the following at every 256th execution of the loop body:
FEOF_CHECK;
TRY_YIELD;
}
}
if(!strcmp(argv[1],"invert_sy_sy")) //not tested
{
if(!sendbufsize(initialize_buffers())) return -2;
unsigned char i=0;
for(;;)
{
putchar(!getchar());
if(i++) continue; //do the following at every 256th execution of the loop body:
FEOF_CHECK;
TRY_YIELD;
}
}
if(!strcmp(argv[1],"none"))
{
return 0;

246
libcsdr.c
Wyświetl plik

@ -949,6 +949,252 @@ void logpower_cf(complexf* input, float* output, int size, float add_db)
for(int i=0;i<size;i++) output[i]=10*output[i]+add_db; //@logpower_cf: pass 3
}
/*
_____ _ _ _ _ _ _
| __ \(_) (_) | | | | | | |
| | | |_ __ _ _| |_ __ _| | __| | ___ _ __ ___ ___ __| |
| | | | |/ _` | | __/ _` | | / _` |/ _ \ '_ ` _ \ / _ \ / _` |
| |__| | | (_| | | || (_| | | | (_| | __/ | | | | | (_) | (_| |
|_____/|_|\__, |_|\__\__,_|_| \__,_|\___|_| |_| |_|\___/ \__,_|
__/ |
|___/
*/
typedef struct psk31_varicode_item_s
{
unsigned long long code;
int bitcount;
unsigned char ascii;
} psk31_varicode_item_t;
psk31_varicode_item_t psk31_varicode_items[] =
{
{ .code = 0b1010101011, .bitcount=10, .ascii=0x00 }, //NUL, null
{ .code = 0b1011011011, .bitcount=10, .ascii=0x01 }, //SOH, start of heading
{ .code = 0b1011101101, .bitcount=10, .ascii=0x02 }, //STX, start of text
{ .code = 0b1101110111, .bitcount=10, .ascii=0x03 }, //ETX, end of text
{ .code = 0b1011101011, .bitcount=10, .ascii=0x04 }, //EOT, end of transmission
{ .code = 0b1101011111, .bitcount=10, .ascii=0x05 }, //ENQ, enquiry
{ .code = 0b1011101111, .bitcount=10, .ascii=0x06 }, //ACK, acknowledge
{ .code = 0b1011111101, .bitcount=10, .ascii=0x07 }, //BEL, bell
{ .code = 0b1011111111, .bitcount=10, .ascii=0x08 }, //BS, backspace
{ .code = 0b11101111, .bitcount=8, .ascii=0x09 }, //TAB, horizontal tab
{ .code = 0b11101, .bitcount=5, .ascii=0x0a }, //LF, NL line feed, new line
{ .code = 0b1101101111, .bitcount=10, .ascii=0x0b }, //VT, vertical tab
{ .code = 0b1011011101, .bitcount=10, .ascii=0x0c }, //FF, NP form feed, new page
{ .code = 0b11111, .bitcount=5, .ascii=0x0d }, //CR, carriage return (overwrite)
{ .code = 0b1101110101, .bitcount=10, .ascii=0x0e }, //SO, shift out
{ .code = 0b1110101011, .bitcount=10, .ascii=0x0f }, //SI, shift in
{ .code = 0b1011110111, .bitcount=10, .ascii=0x10 }, //DLE, data link escape
{ .code = 0b1011110101, .bitcount=10, .ascii=0x11 }, //DC1, device control 1
{ .code = 0b1110101101, .bitcount=10, .ascii=0x12 }, //DC2, device control 2
{ .code = 0b1110101111, .bitcount=10, .ascii=0x13 }, //DC3, device control 3
{ .code = 0b1101011011, .bitcount=10, .ascii=0x14 }, //DC4, device control 4
{ .code = 0b1101101011, .bitcount=10, .ascii=0x15 }, //NAK, negative acknowledge
{ .code = 0b1101101101, .bitcount=10, .ascii=0x16 }, //SYN, synchronous idle
{ .code = 0b1101010111, .bitcount=10, .ascii=0x17 }, //ETB, end of trans. block
{ .code = 0b1101111011, .bitcount=10, .ascii=0x18 }, //CAN, cancel
{ .code = 0b1101111101, .bitcount=10, .ascii=0x19 }, //EM, end of medium
{ .code = 0b1110110111, .bitcount=10, .ascii=0x1a }, //SUB, substitute
{ .code = 0b1101010101, .bitcount=10, .ascii=0x1b }, //ESC, escape
{ .code = 0b1101011101, .bitcount=10, .ascii=0x1c }, //FS, file separator
{ .code = 0b1110111011, .bitcount=10, .ascii=0x1d }, //GS, group separator
{ .code = 0b1011111011, .bitcount=10, .ascii=0x1e }, //RS, record separator
{ .code = 0b1101111111, .bitcount=10, .ascii=0x1f }, //US, unit separator
{ .code = 0b1, .bitcount=1, .ascii=0x20 }, //szóköz
{ .code = 0b111111111, .bitcount=9, .ascii=0x21 }, //!
{ .code = 0b101011111, .bitcount=9, .ascii=0x22 }, //"
{ .code = 0b111110101, .bitcount=9, .ascii=0x23 }, //#
{ .code = 0b111011011, .bitcount=9, .ascii=0x24 }, //$
{ .code = 0b1011010101, .bitcount=10, .ascii=0x25 }, //%
{ .code = 0b1010111011, .bitcount=10, .ascii=0x26 }, //&
{ .code = 0b101111111, .bitcount=9, .ascii=0x27 }, //'
{ .code = 0b11111011, .bitcount=8, .ascii=0x28 }, //(
{ .code = 0b11110111, .bitcount=8, .ascii=0x29 }, //)
{ .code = 0b101101111, .bitcount=9, .ascii=0x2a }, //*
{ .code = 0b111011111, .bitcount=9, .ascii=0x2b }, //+
{ .code = 0b1110101, .bitcount=7, .ascii=0x2c }, //,
{ .code = 0b110101, .bitcount=6, .ascii=0x2d }, //-
{ .code = 0b1010111, .bitcount=7, .ascii=0x2e }, //.
{ .code = 0b110101111, .bitcount=9, .ascii=0x2f }, ///
{ .code = 0b10110111, .bitcount=8, .ascii=0x30 }, //0
{ .code = 0b10111101, .bitcount=8, .ascii=0x31 }, //1
{ .code = 0b11101101, .bitcount=8, .ascii=0x32 }, //2
{ .code = 0b11111111, .bitcount=8, .ascii=0x33 }, //3
{ .code = 0b101110111, .bitcount=9, .ascii=0x34 }, //4
{ .code = 0b101011011, .bitcount=9, .ascii=0x35 }, //5
{ .code = 0b101101011, .bitcount=9, .ascii=0x36 }, //6
{ .code = 0b110101101, .bitcount=9, .ascii=0x37 }, //7
{ .code = 0b110101011, .bitcount=9, .ascii=0x38 }, //8
{ .code = 0b110110111, .bitcount=9, .ascii=0x39 }, //9
{ .code = 0b11110101, .bitcount=8, .ascii=0x3a }, //:
{ .code = 0b110111101, .bitcount=9, .ascii=0x3b }, //;
{ .code = 0b111101101, .bitcount=9, .ascii=0x3c }, //<
{ .code = 0b1010101, .bitcount=7, .ascii=0x3d }, //=
{ .code = 0b111010111, .bitcount=9, .ascii=0x3e }, //>
{ .code = 0b1010101111, .bitcount=10, .ascii=0x3f }, //?
{ .code = 0b1010111101, .bitcount=10, .ascii=0x40 }, //@
{ .code = 0b1111101, .bitcount=7, .ascii=0x41 }, //A
{ .code = 0b11101011, .bitcount=8, .ascii=0x42 }, //B
{ .code = 0b10101101, .bitcount=8, .ascii=0x43 }, //C
{ .code = 0b10110101, .bitcount=8, .ascii=0x44 }, //D
{ .code = 0b1110111, .bitcount=7, .ascii=0x45 }, //E
{ .code = 0b11011011, .bitcount=8, .ascii=0x46 }, //F
{ .code = 0b11111101, .bitcount=8, .ascii=0x47 }, //G
{ .code = 0b101010101, .bitcount=9, .ascii=0x48 }, //H
{ .code = 0b1111111, .bitcount=7, .ascii=0x49 }, //I
{ .code = 0b111111101, .bitcount=9, .ascii=0x4a }, //J
{ .code = 0b101111101, .bitcount=9, .ascii=0x4b }, //K
{ .code = 0b11010111, .bitcount=8, .ascii=0x4c }, //L
{ .code = 0b10111011, .bitcount=8, .ascii=0x4d }, //M
{ .code = 0b11011101, .bitcount=8, .ascii=0x4e }, //N
{ .code = 0b10101011, .bitcount=8, .ascii=0x4f }, //O
{ .code = 0b11010101, .bitcount=8, .ascii=0x50 }, //P
{ .code = 0b111011101, .bitcount=9, .ascii=0x51 }, //Q
{ .code = 0b10101111, .bitcount=8, .ascii=0x52 }, //R
{ .code = 0b1101111, .bitcount=7, .ascii=0x53 }, //S
{ .code = 0b1101101, .bitcount=7, .ascii=0x54 }, //T
{ .code = 0b101010111, .bitcount=9, .ascii=0x55 }, //U
{ .code = 0b110110101, .bitcount=9, .ascii=0x56 }, //V
{ .code = 0b101011101, .bitcount=9, .ascii=0x57 }, //W
{ .code = 0b101110101, .bitcount=9, .ascii=0x58 }, //X
{ .code = 0b101111011, .bitcount=9, .ascii=0x59 }, //Y
{ .code = 0b1010101101, .bitcount=10, .ascii=0x5a }, //Z
{ .code = 0b111110111, .bitcount=9, .ascii=0x5b }, //[
{ .code = 0b111101111, .bitcount=9, .ascii=0x5c }, //\
{ .code = 0b111111011, .bitcount=9, .ascii=0x5d }, //]
{ .code = 0b1010111111, .bitcount=10, .ascii=0x5e }, //^
{ .code = 0b101101101, .bitcount=9, .ascii=0x5f }, //_
{ .code = 0b1011011111, .bitcount=10, .ascii=0x60 }, //`
{ .code = 0b1011, .bitcount=4, .ascii=0x61 }, //a
{ .code = 0b1011111, .bitcount=7, .ascii=0x62 }, //b
{ .code = 0b101111, .bitcount=6, .ascii=0x63 }, //c
{ .code = 0b101101, .bitcount=6, .ascii=0x64 }, //d
{ .code = 0b11, .bitcount=2, .ascii=0x65 }, //e
{ .code = 0b111101, .bitcount=6, .ascii=0x66 }, //f
{ .code = 0b1011011, .bitcount=7, .ascii=0x67 }, //g
{ .code = 0b101011, .bitcount=6, .ascii=0x68 }, //h
{ .code = 0b1101, .bitcount=4, .ascii=0x69 }, //i
{ .code = 0b111101011, .bitcount=9, .ascii=0x6a }, //j
{ .code = 0b10111111, .bitcount=8, .ascii=0x6b }, //k
{ .code = 0b11011, .bitcount=5, .ascii=0x6c }, //l
{ .code = 0b111011, .bitcount=6, .ascii=0x6d }, //m
{ .code = 0b1111, .bitcount=4, .ascii=0x6e }, //n
{ .code = 0b111, .bitcount=3, .ascii=0x6f }, //o
{ .code = 0b111111, .bitcount=6, .ascii=0x70 }, //p
{ .code = 0b110111111, .bitcount=9, .ascii=0x71 }, //q
{ .code = 0b10101, .bitcount=5, .ascii=0x72 }, //r
{ .code = 0b10111, .bitcount=5, .ascii=0x73 }, //s
{ .code = 0b101, .bitcount=3, .ascii=0x74 }, //t
{ .code = 0b110111, .bitcount=6, .ascii=0x75 }, //u
{ .code = 0b1111011, .bitcount=7, .ascii=0x76 }, //v
{ .code = 0b1101011, .bitcount=7, .ascii=0x77 }, //w
{ .code = 0b11011111, .bitcount=8, .ascii=0x78 }, //x
{ .code = 0b1011101, .bitcount=7, .ascii=0x79 }, //y
{ .code = 0b111010101, .bitcount=9, .ascii=0x7a }, //z
{ .code = 0b1010110111, .bitcount=10, .ascii=0x7b }, //{
{ .code = 0b110111011, .bitcount=9, .ascii=0x7c }, //|
{ .code = 0b1010110101, .bitcount=10, .ascii=0x7d }, //}
{ .code = 0b1011010111, .bitcount=10, .ascii=0x7e }, //~
{ .code = 0b1110110101, .bitcount=10, .ascii=0x7f }, //DEL
};
const int n_psk31_varicode_items = sizeof(psk31_varicode_items) / sizeof(psk31_varicode_item_t);
unsigned long long psk31_varicode_masklen_helper[] =
{
0b0000000000000000000000000000000000000000000000000000000000000000,
0b0000000000000000000000000000000000000000000000000000000000000001,
0b0000000000000000000000000000000000000000000000000000000000000011,
0b0000000000000000000000000000000000000000000000000000000000000111,
0b0000000000000000000000000000000000000000000000000000000000001111,
0b0000000000000000000000000000000000000000000000000000000000011111,
0b0000000000000000000000000000000000000000000000000000000000111111,
0b0000000000000000000000000000000000000000000000000000000001111111,
0b0000000000000000000000000000000000000000000000000000000011111111,
0b0000000000000000000000000000000000000000000000000000000111111111,
0b0000000000000000000000000000000000000000000000000000001111111111,
0b0000000000000000000000000000000000000000000000000000011111111111,
0b0000000000000000000000000000000000000000000000000000111111111111,
0b0000000000000000000000000000000000000000000000000001111111111111,
0b0000000000000000000000000000000000000000000000000011111111111111,
0b0000000000000000000000000000000000000000000000000111111111111111,
0b0000000000000000000000000000000000000000000000001111111111111111,
0b0000000000000000000000000000000000000000000000011111111111111111,
0b0000000000000000000000000000000000000000000000111111111111111111,
0b0000000000000000000000000000000000000000000001111111111111111111,
0b0000000000000000000000000000000000000000000011111111111111111111,
0b0000000000000000000000000000000000000000000111111111111111111111,
0b0000000000000000000000000000000000000000001111111111111111111111,
0b0000000000000000000000000000000000000000011111111111111111111111,
0b0000000000000000000000000000000000000000111111111111111111111111,
0b0000000000000000000000000000000000000001111111111111111111111111,
0b0000000000000000000000000000000000000011111111111111111111111111,
0b0000000000000000000000000000000000000111111111111111111111111111,
0b0000000000000000000000000000000000001111111111111111111111111111,
0b0000000000000000000000000000000000011111111111111111111111111111,
0b0000000000000000000000000000000000111111111111111111111111111111,
0b0000000000000000000000000000000001111111111111111111111111111111,
0b0000000000000000000000000000000011111111111111111111111111111111,
0b0000000000000000000000000000000111111111111111111111111111111111,
0b0000000000000000000000000000001111111111111111111111111111111111,
0b0000000000000000000000000000011111111111111111111111111111111111,
0b0000000000000000000000000000111111111111111111111111111111111111,
0b0000000000000000000000000001111111111111111111111111111111111111,
0b0000000000000000000000000011111111111111111111111111111111111111,
0b0000000000000000000000000111111111111111111111111111111111111111,
0b0000000000000000000000001111111111111111111111111111111111111111,
0b0000000000000000000000011111111111111111111111111111111111111111,
0b0000000000000000000000111111111111111111111111111111111111111111,
0b0000000000000000000001111111111111111111111111111111111111111111,
0b0000000000000000000011111111111111111111111111111111111111111111,
0b0000000000000000000111111111111111111111111111111111111111111111,
0b0000000000000000001111111111111111111111111111111111111111111111,
0b0000000000000000011111111111111111111111111111111111111111111111,
0b0000000000000000111111111111111111111111111111111111111111111111,
0b0000000000000001111111111111111111111111111111111111111111111111,
0b0000000000000011111111111111111111111111111111111111111111111111,
0b0000000000000111111111111111111111111111111111111111111111111111,
0b0000000000001111111111111111111111111111111111111111111111111111,
0b0000000000011111111111111111111111111111111111111111111111111111,
0b0000000000111111111111111111111111111111111111111111111111111111,
0b0000000001111111111111111111111111111111111111111111111111111111,
0b0000000011111111111111111111111111111111111111111111111111111111,
0b0000000111111111111111111111111111111111111111111111111111111111,
0b0000001111111111111111111111111111111111111111111111111111111111,
0b0000011111111111111111111111111111111111111111111111111111111111,
0b0000111111111111111111111111111111111111111111111111111111111111,
0b0001111111111111111111111111111111111111111111111111111111111111,
0b0011111111111111111111111111111111111111111111111111111111111111,
0b0111111111111111111111111111111111111111111111111111111111111111
};
char psk31_varicode_push(unsigned long long* status_shr, unsigned char symbol)
{
*status_shr=((*status_shr)<<1)|(!!symbol); //shift new bit in shift register
//fprintf(stderr,"*status_shr = %llx\n", *status_shr);
if((*status_shr)&0xFFF==0) return 0;
for(int i=0;i<n_psk31_varicode_items;i++)
{
//fprintf(stderr,"| i = %d | %llx ?= %llx | bitsall = %d\n", i, psk31_varicode_items[i].code<<2, (*status_shr)&psk31_varicode_masklen_helper[(psk31_varicode_items[i].bitcount+4)&63], (psk31_varicode_items[i].bitcount+4)&63);
if((psk31_varicode_items[i].code<<2)==((*status_shr)&psk31_varicode_masklen_helper[(psk31_varicode_items[i].bitcount+4)&63]))
{ /*fprintf(stderr,">>>>>>>>> %d %x %c\n", i, psk31_varicode_items[i].ascii, psk31_varicode_items[i].ascii);*/ return psk31_varicode_items[i].ascii; }
}
return 0;
}
/*
*/
/*
_____ _ _
| __ \ | | (_)

Wyświetl plik

@ -178,3 +178,5 @@ void convert_f_i16(float* input, short* output, int input_size);
void convert_i16_f(short* input, float* output, int input_size);
int is_nan(float f);
char psk31_varicode_push(unsigned long long* status_shr, unsigned char symbol);