Various updates

Added new consts/#defines
WIP packet encoder
pull/6/head
Wojciech Kaczmarski 2023-09-07 12:34:39 +02:00 zatwierdzone przez GitHub
rodzic b8f4f852b0
commit 1029b86066
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 86 dodań i 51 usunięć

Wyświetl plik

@ -4,10 +4,12 @@
#ifdef __cplusplus
extern "C" {
#endif
#define FLT_LEN 81 //baseband filter length (number of taps)
#define SW_LEN 80 //syncword detector length
#define XC_LEN 90 //cross-correlator lookback length in samples
#define SYM_PER_PLD 184 //symbols per payload in a frame
#define FLT_LEN 81 //baseband filter length (number of taps)
#define SW_LEN 80 //syncword detector length
#define XC_LEN 90 //cross-correlator lookback length in samples
#define SYM_PER_PLD 184 //symbols per payload in a frame
#define SYM_PER_FRA 192 //symbols per whole 40 ms frame
#define RRC_DEV 7168.0f //.rrc file deviation for +1.0 symbol
//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};
@ -35,36 +37,39 @@ const uint8_t P_1[61]={1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,
//puncturing pattern P_2
const uint8_t P_2[12]={1,1,1,1,1,1,1,1,1,1,1,0};
//puncturing pattern P_3
const uint8_t P_3[8]={1,1,1,1,1,1,1,0};
//RRC filter - 10 samples per symbol, 8 symbols span
const float taps[FLT_LEN]=
{
-0.003195702904062073, -0.002930279157647190, -0.001940667871554463,
-0.000356087678023658, 0.001547011339077758, 0.003389554791179751,
0.004761898604225673, 0.005310860846138910, 0.004824746306020221,
0.003297923526848786, 0.000958710871218619, -0.001749908029791816,
-0.004238694106631223, -0.005881783042101693, -0.006150256456781309,
-0.004745376707651645, -0.001704189656473565, 0.002547854551539951,
0.007215575568844704, 0.011231038205363532, 0.013421952197060707,
0.012730475385624438, 0.008449554307303753, 0.000436744366018287,
-0.010735380379191660, -0.023726883538258272, -0.036498030780605324,
-0.046500883189991064, -0.050979050575999614, -0.047340680079891187,
-0.033554880492651755, -0.008513823955725943, 0.027696543159614194,
0.073664520037517042, 0.126689053778116234, 0.182990955139333916,
0.238080025892859704, 0.287235637987091563, 0.326040247765297220,
0.350895727088112619, 0.359452932027607974, 0.350895727088112619,
0.326040247765297220, 0.287235637987091563, 0.238080025892859704,
0.182990955139333916, 0.126689053778116234, 0.073664520037517042,
0.027696543159614194, -0.008513823955725943, -0.033554880492651755,
-0.047340680079891187, -0.050979050575999614, -0.046500883189991064,
-0.036498030780605324, -0.023726883538258272, -0.010735380379191660,
0.000436744366018287, 0.008449554307303753, 0.012730475385624438,
0.013421952197060707, 0.011231038205363532, 0.007215575568844704,
0.002547854551539951, -0.001704189656473565, -0.004745376707651645,
-0.006150256456781309, -0.005881783042101693, -0.004238694106631223,
-0.001749908029791816, 0.000958710871218619, 0.003297923526848786,
0.004824746306020221, 0.005310860846138910, 0.004761898604225673,
0.003389554791179751, 0.001547011339077758, -0.000356087678023658,
-0.001940667871554463, -0.002930279157647190, -0.003195702904062073
-0.003195702904062073f, -0.002930279157647190f, -0.001940667871554463f,
-0.000356087678023658f, 0.001547011339077758f, 0.003389554791179751f,
0.004761898604225673f, 0.005310860846138910f, 0.004824746306020221f,
0.003297923526848786f, 0.000958710871218619f, -0.001749908029791816f,
-0.004238694106631223f, -0.005881783042101693f, -0.006150256456781309f,
-0.004745376707651645f, -0.001704189656473565f, 0.002547854551539951f,
0.007215575568844704f, 0.011231038205363532f, 0.013421952197060707f,
0.012730475385624438f, 0.008449554307303753f, 0.000436744366018287f,
-0.010735380379191660f, -0.023726883538258272f, -0.036498030780605324f,
-0.046500883189991064f, -0.050979050575999614f, -0.047340680079891187f,
-0.033554880492651755f, -0.008513823955725943f, 0.027696543159614194f,
0.073664520037517042f, 0.126689053778116234f, 0.182990955139333916f,
0.238080025892859704f, 0.287235637987091563f, 0.326040247765297220f,
0.350895727088112619f, 0.359452932027607974f, 0.350895727088112619f,
0.326040247765297220f, 0.287235637987091563f, 0.238080025892859704f,
0.182990955139333916f, 0.126689053778116234f, 0.073664520037517042f,
0.027696543159614194f, -0.008513823955725943f, -0.033554880492651755f,
-0.047340680079891187f, -0.050979050575999614f, -0.046500883189991064f,
-0.036498030780605324f, -0.023726883538258272f, -0.010735380379191660f,
0.000436744366018287f, 0.008449554307303753f, 0.012730475385624438f,
0.013421952197060707f, 0.011231038205363532f, 0.007215575568844704f,
0.002547854551539951f, -0.001704189656473565f, -0.004745376707651645f,
-0.006150256456781309f, -0.005881783042101693f, -0.004238694106631223f,
-0.001749908029791816f, 0.000958710871218619f, 0.003297923526848786f,
0.004824746306020221f, 0.005310860846138910f, 0.004761898604225673f,
0.003389554791179751f, 0.001547011339077758f, -0.000356087678023658f,
-0.001940667871554463f, -0.002930279157647190f, -0.003195702904062073f
};
//randomizing pattern

Wyświetl plik

@ -1,5 +1,5 @@
m17-coder-sym: m17-coder-sym.c golay.c crc.c
gcc -O2 -w -lm m17-coder-sym.c golay.c crc.c -o m17-coder-sym
gcc -O2 -w m17-coder-sym.c golay.c crc.c -o m17-coder-sym -lm
clean:
rm m17-coder-sym

Wyświetl plik

@ -1,5 +1,5 @@
m17-packet-encode: m17-packet-encode.c crc.c
gcc -O2 -w -lm m17-packet-encode.c crc.c -o m17-packet-encode
gcc -O2 -w m17-packet-encode.c crc.c -o m17-packet-encode -lm
clean:
rm m17-packet-encode

Wyświetl plik

@ -2,6 +2,7 @@
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <math.h>
#include "../inc/m17.h"
#include "crc.h"
@ -23,30 +24,32 @@ uint8_t src_raw[10]={'N', '0', 'C', 'A', 'L', 'L', '\0'}; //raw, unencoded sou
uint8_t can=0; //Channel Access Number, default: 0
uint16_t num_bytes=0; //number of bytes in packet, max 800-2=798
uint8_t data[25]; //raw payload, packed bits
uint8_t got_lsf=0; //have we filled the LSF struct yet?
uint8_t fname[128]={'\0'}; //output file
void send_Preamble(const uint8_t type)
FILE* fp;
float full_packet[6912+88]; //full packet, symbols as floats - (40+40+32*40+40+40)/1000*4800
//pream, LSF, 32 frames, ending frame, EOT plus RRC flushing
//type - 0 - preamble before LSF (standard)
//type - 1 - preamble before BERT transmission
void fill_Preamble(float* out, const uint8_t type)
{
float symb;
if(type) //pre-BERT
{
for(uint16_t i=0; i<192/2; i++) //40ms * 4800 = 192
for(uint16_t i=0; i<SYM_PER_FRA/2; i++) //40ms * 4800 = 192
{
symb=-3.0;
write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float));
symb=+3.0;
write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float));
out[2*i] =-3.0;
out[2*i+1]=+3.0;
}
}
else //pre-LSF
{
for(uint16_t i=0; i<192/2; i++) //40ms * 4800 = 192
for(uint16_t i=0; i<SYM_PER_FRA/2; i++) //40ms * 4800 = 192
{
symb=+3.0;
write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float));
symb=-3.0;
write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float));
out[2*i] =+3.0;
out[2*i+1]=-3.0;
}
}
}
@ -277,8 +280,9 @@ uint8_t encode_callsign(uint64_t* out, const uint8_t* inp)
int main(int argc, char* argv[])
{
//scan command line options for input data
//TODO: support for strings with spaces
if(argc>=2)
//TODO: support for strings with spaces, the code below is NOT foolproof!
//the user has to provide a minimum of 2 parameters: number of bytes and output filename
if(argc>=4)
{
for(uint8_t i=1; i<argc-1; i++)
{
@ -324,6 +328,16 @@ int main(int argc, char* argv[])
return -1;
}
}
else if(argv[i][1]=='o') //-o - output filename
{
if(strlen(argv[i+1])>0)
memcpy(fname, &argv[i+1][0], strlen(argv[i+1]));
else
{
fprintf(stderr, "Invalid filename. Exiting...\n");
return -1;
}
}
else
{
fprintf(stderr, "Unknown param. Exiting...\n");
@ -338,12 +352,17 @@ int main(int argc, char* argv[])
return -1;
}
//assert number of bytes
//assert number of bytes and filename
if(num_bytes==0)
{
fprintf(stderr, "Number of bytes not set. Exiting...\n");
return -1;
}
else if(strlen(fname)==0)
{
fprintf(stderr, "Filename not specified. Exiting...\n");
return -1;
}
//encode dst, src for the lsf struct
uint64_t dst_encoded=0, src_encoded=0;
@ -365,10 +384,12 @@ int main(int argc, char* argv[])
//encode LSF data
conv_Encode_LSF(enc_bits, &lsf);
/*
//send preamble
send_Preamble(0);
//fill preamble
memset((uint8_t*)full_packet, 0, sizeof(float)*(6912+88));
fill_Preamble(full_packet, 0);
/*
//send LSF syncword
send_Syncword(SYNC_LSF);
@ -416,5 +437,14 @@ int main(int argc, char* argv[])
//send packet frame data
send_data(rf_bits);
*/
fp=fopen(fname, "wb");
for(uint16_t i=0; i<SYM_PER_FRA; i++)
{
int16_t val=roundf(full_packet[i]*RRC_DEV);
fwrite(&val, 2, 1, fp);
}
fclose(fp);
return 0;
}