Porównaj commity

...

9 Commity

Autor SHA1 Wiadomość Data
Wojciech Kaczmarski cf1e16a294
Merge pull request #9 from argilo/eof-eot
Correctly handle EoF, and transmit EoT
2023-09-13 10:33:13 +02:00
Wojciech Kaczmarski 7b7f262819
Merge pull request #8 from argilo/fix-fn-lich-cnt
Fix wrapping of frame number and LICH counter
2023-09-13 10:25:08 +02:00
Wojciech Kaczmarski e65852d984
Merge pull request #7 from argilo/update-gitignore
Add m17-packet-encode to .gitignore
2023-09-13 10:24:09 +02:00
Wojciech Kaczmarski cca5c11eaf
Merge pull request #6 from argilo/null-terminate-callsign
Add null termination after callsign
2023-09-13 10:20:00 +02:00
Clayton Smith 896d57ad0a Correctly handle EoF, and transmit EoT 2023-09-12 20:55:16 -04:00
Clayton Smith db510efe1e Fix wrapping of frame number and LICH counter 2023-09-12 17:26:27 -04:00
Clayton Smith a2491ac4c0 Add m17-packet-encode to .gitignore 2023-09-12 15:09:27 -04:00
Clayton Smith 48e528224e Add null termination after callsign 2023-09-12 15:03:28 -04:00
Wojciech Kaczmarski 83e3357693
`m17-decoder` update
- new cross-correlator
- Makefile update
2023-09-12 17:11:27 +02:00
7 zmienionych plików z 76 dodań i 40 usunięć

1
.gitignore vendored
Wyświetl plik

@ -2,3 +2,4 @@
/SP5WWP/grc/symbol_recovery.py
/SP5WWP/m17-coder/m17-coder-sym
/SP5WWP/m17-decoder/m17-decoder-sym
/SP5WWP/m17-packet/m17-packet-encode

Wyświetl plik

@ -12,9 +12,14 @@ extern "C" {
#define SYM_PER_FRA 192 //symbols per whole 40 ms frame
#define RRC_DEV 7168.0f //.rrc file deviation for +1.0 symbol
#define XCORR_THRESH 0.90 //arbitrary threshold between 0 and 1
#define SW_MEAN -0.75 //mean(str_sync)=mean(pkt_sync)
#define SW_STD 8.21583836f //std(str_sync)*sqrt(length(str_sync)-1)
//syncword patterns (RX) TODO:Compute those at runtime from the consts below
const int8_t str_sync[8]={-3, -3, -3, -3, +3, +3, -3, +3};
const int8_t lsf_sync[8]={+3, +3, +3, +3, -3, -3, +3, -3};
const int8_t str_sync[8]={-3, -3, -3, -3, +3, +3, -3, +3};
const int8_t pkt_sync[8]={+3, -3, +3, +3, -3, -3, -3, -3};
//symbol levels (RX)
const float symbs[4]={-3.0, -1.0, +1.0, +3.0};

Wyświetl plik

@ -16,17 +16,18 @@ struct LSF
uint8_t type[2];
uint8_t meta[112/8];
uint8_t crc[2];
} lsf;
} lsf, next_lsf;
uint8_t lich[6]; //48 bits packed raw, unencoded LICH
uint8_t lich_encoded[12]; //96 bits packed, encoded LICH
uint8_t enc_bits[SYM_PER_PLD*2]; //type-2 bits, unpacked
uint8_t rf_bits[SYM_PER_PLD*2]; //type-4 bits, unpacked
uint8_t data[16]; //raw payload, packed bits
uint8_t data[16], next_data[16]; //raw payload, packed bits
uint16_t fn=0; //16-bit Frame Number (for the stream mode)
uint8_t lich_cnt=0; //0..5 LICH counter, derived from the Frame Number
uint8_t lich_cnt=0; //0..5 LICH counter
uint8_t got_lsf=0; //have we filled the LSF struct yet?
uint8_t finished=0;
void send_Preamble(const uint8_t type)
{
@ -76,6 +77,15 @@ void send_data(uint8_t* in)
}
}
void send_EoT()
{
float symb=+3.0;
for(uint16_t i=0; i<192; i++) //40ms * 4800 = 192
{
write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float));
}
}
//out - unpacked bits
//in - packed raw bits
//fn - frame number
@ -249,23 +259,35 @@ int main(void)
//printf("%d -> %d -> %d\n", 1, intrl_seq[1], intrl_seq[intrl_seq[1]]); //interleaver bijective reciprocality test, f(f(x))=x
//return 0;
while(1)
if(fread(&(next_lsf.dst), 6, 1, stdin)<1) finished=1;
if(fread(&(next_lsf.src), 6, 1, stdin)<1) finished=1;
if(fread(&(next_lsf.type), 2, 1, stdin)<1) finished=1;
if(fread(&(next_lsf.meta), 14, 1, stdin)<1) finished=1;
if(fread(next_data, 16, 1, stdin)<1) finished=1;
while(!finished)
{
lsf = next_lsf;
//calculate LSF CRC
uint16_t ccrc=LSF_CRC(&lsf);
lsf.crc[0]=ccrc>>8;
lsf.crc[1]=ccrc&0xFF;
memcpy(data, next_data, sizeof(data));
//we could discard the data we already have
if(fread(&(next_lsf.dst), 6, 1, stdin)<1) finished=1;
if(fread(&(next_lsf.src), 6, 1, stdin)<1) finished=1;
if(fread(&(next_lsf.type), 2, 1, stdin)<1) finished=1;
if(fread(&(next_lsf.meta), 14, 1, stdin)<1) finished=1;
if(fread(next_data, 16, 1, stdin)<1) finished=1;
if(got_lsf) //stream frames
{
//we could discard the data we already have
while(fread(&(lsf.dst), 1, 6, stdin)<1);
while(fread(&(lsf.src), 1, 6, stdin)<1);
while(fread(&(lsf.type), 1, 2, stdin)<1);
while(fread(&(lsf.meta), 1, 14, stdin)<1);
while(fread(data, 1, 16, stdin)<1);
//send stream frame syncword
send_Syncword(SYNC_STR);
//derive the LICH_CNT from the Frame Number
lich_cnt=fn%6;
//extract LICH from the whole LSF
switch(lich_cnt)
{
@ -352,7 +374,7 @@ int main(void)
}
//encode the rest of the frame
conv_Encode_Frame(&enc_bits[96], data, fn);
conv_Encode_Frame(&enc_bits[96], data, finished ? (fn | 0x8000) : fn);
//reorder bits
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
@ -384,7 +406,10 @@ int main(void)
printf("\n");*/
//increment the Frame Number
fn++;
fn = (fn + 1) % 0x8000;
//increment the LICH counter
lich_cnt = (lich_cnt + 1) % 6;
//debug-only
#ifdef FN60_DEBUG
@ -394,17 +419,6 @@ int main(void)
}
else //LSF
{
while(fread(&(lsf.dst), 1, 6, stdin)<1);
while(fread(&(lsf.src), 1, 6, stdin)<1);
while(fread(&(lsf.type), 1, 2, stdin)<1);
while(fread(&(lsf.meta), 1, 14, stdin)<1);
while(fread(data, 1, 16, stdin)<1);
//calculate LSF CRC
uint16_t ccrc=LSF_CRC(&lsf);
lsf.crc[0]=ccrc>>8;
lsf.crc[1]=ccrc&0xFF;
got_lsf=1;
//encode LSF data
@ -457,6 +471,9 @@ int main(void)
printf("%02X", lsf.crc[i]);
printf("\n");*/
}
if (finished)
send_EoT();
}
return 0;

Wyświetl plik

@ -1,5 +1,5 @@
m17-decoder-sym: m17-decoder-sym.c golay.c viterbi.c crc.c
gcc -O2 -lm m17-decoder-sym.c golay.c viterbi.c crc.c -o m17-decoder-sym
gcc -Wall -O2 m17-decoder-sym.c golay.c viterbi.c crc.c -o m17-decoder-sym -lm
clean:
rm m17-decoder-sym

Wyświetl plik

@ -1,8 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include "../inc/m17.h"
#include "golay.h"
@ -14,7 +14,7 @@
float sample; //last raw sample from the stdin
float last[8]; //look-back buffer for finding syncwords
float xcorr; //cross correlation for finding syncwords
float xcorr, meanx, normx; //cross correlation related variables for finding syncwords
float pld[SYM_PER_PLD]; //raw frame symbols
uint16_t soft_bit[2*SYM_PER_PLD]; //raw frame soft bits
uint16_t d_soft_bit[2*SYM_PER_PLD]; //deinterleaved soft bits
@ -69,7 +69,7 @@ void decode_callsign(uint8_t *outp, const uint8_t *inp)
{
if(encoded==0xFFFFFFFFFFFF) //broadcast
{
sprintf(outp, "#BCAST");
sprintf((char*)outp, "#BCAST");
}
else
{
@ -87,6 +87,7 @@ void decode_callsign(uint8_t *outp, const uint8_t *inp)
encoded/=40;
i++;
}
outp[i]=0;
}
int main(void)
@ -94,7 +95,7 @@ int main(void)
while(1)
{
//wait for another symbol
while(fread((uint8_t*)&sample, 1, 4, stdin)<1);
if(fread((uint8_t*)&sample, 4, 1, stdin)<1) break;
if(!syncd)
{
@ -107,22 +108,30 @@ int main(void)
last[7]=sample;
//calculate cross-correlation
xcorr=0;
meanx=0.0f;
for(uint8_t i=0; i<8; i++)
meanx+=last[i];
meanx=meanx/8.0f;
xcorr=0.0f;
normx=0.0f;
for(uint8_t i=0; i<8; i++)
{
xcorr+=last[i]*str_sync[i];
xcorr+=(last[i]-meanx)*(str_sync[i]-SW_MEAN);
normx+=(last[i]-meanx)*(last[i]-meanx);
}
xcorr=xcorr/(sqrtf(normx)*SW_STD);
//printf("%f\n", xcorr);
if(xcorr>62.0) //Frame syncword detected
if(xcorr>XCORR_THRESH) //Frame syncword detected
{
syncd=1;
pushed=0;
fl=0;
}
else if(xcorr<-62) //LSF syncword
else if(xcorr<-XCORR_THRESH) //LSF syncword
{
syncd=1;
pushed=0;

Wyświetl plik

@ -21,7 +21,7 @@ int main(void)
while(1)
{
//wait for another baseband sample
while(fread((uint8_t*)&sample, 1, 2, stdin)<1);
if(fread((uint8_t*)&sample, 2, 1, stdin)<1) break;
//push the root-nyquist filter's buffer
for(uint8_t i=0; i<FLT_LEN-1; i++)

Wyświetl plik

@ -393,7 +393,11 @@ int main(int argc, char* argv[])
//obtain data and append with CRC
memset(full_packet_data, 0, 32*25);
while(fread(full_packet_data, 1, num_bytes, stdin)<1);
if(fread(full_packet_data, num_bytes, 1, stdin)<1)
{
fprintf(stderr, "Packet data too short. Exiting...\n");
return -1;
}
uint16_t packet_crc=CRC_M17(full_packet_data, num_bytes);
full_packet_data[num_bytes] =packet_crc>>8;
full_packet_data[num_bytes+1]=packet_crc&0xFF;