Porównaj commity

...

5 Commity

Autor SHA1 Wiadomość Data
Wojciech Kaczmarski 48918370d1
Delete SP5WWP/m17-decoder/m17-decoder-sym 2023-09-07 15:39:42 +02:00
Wojciech Kaczmarski 667ead0806
Delete SP5WWP/m17-coder/m17-coder-sym 2023-09-07 15:39:32 +02:00
Wojciech Kaczmarski 9b586a36fe
Delete SP5WWP/m17-packet/m17-packet-encode 2023-09-07 15:39:22 +02:00
Wojciech Kaczmarski f8ead61a57
`m17-packet-encode` update
Still WIP
2023-09-07 15:38:46 +02:00
Wojciech Kaczmarski 1029b86066
Various updates
Added new consts/#defines
WIP packet encoder
2023-09-07 12:34:39 +02:00
5 zmienionych plików z 159 dodań i 67 usunięć

Wyświetl plik

@ -4,10 +4,13 @@
#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_SWD 8 //symbols per syncword
#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 +38,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

@ -10,7 +10,7 @@
#include "crc.h"
#define DECODE_CALLSIGNS
//#define SHOW_VITERBI_ERRS
#define SHOW_VITERBI_ERRS
float sample; //last raw sample from the stdin
float last[8]; //look-back buffer for finding syncwords

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"
@ -22,54 +23,63 @@ uint8_t dst_raw[10]={'A', 'L', 'L', '\0'}; //raw, unencoded des
uint8_t src_raw[10]={'N', '0', 'C', 'A', 'L', 'L', '\0'}; //raw, unencoded source address
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 data[25]; //raw payload, packed bits
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
uint16_t pkt_sym_cnt=0; //packet symbol counter, used to fill the packet
uint8_t pkt_cnt=0; //packet frame counter (1..32) init'd at 0
uint8_t pkt_chunk[25+1]; //chunk of Packet Data, up to 25 bytes plus 6 bits of Packet Metadata
uint8_t full_packet_data[32*25]; //full packet data, bytes
//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;
}
}
}
void send_Syncword(const uint16_t sword)
void fill_Syncword(float* out, uint16_t* cnt, const uint16_t sword)
{
float symb;
float symb=0.0f;
for(uint8_t i=0; i<16; i+=2)
{
symb=symbol_map[(sword>>(14-i))&3];
write(STDOUT_FILENO, (uint8_t*)&symb, sizeof(float));
out[*cnt]=symb;
(*cnt)++;
}
}
//send the data (can be used for both LSF and frames)
void send_data(uint8_t* in)
//fill packet symbols array with data (can be used for both LSF and frames)
void fill_data(float* out, uint16_t* cnt, const uint8_t* in)
{
float s=0.0;
float symb=0.0f;
for(uint16_t i=0; i<SYM_PER_PLD; i++) //40ms * 4800 - 8 (syncword)
{
s=symbol_map[in[2*i]*2+in[2*i+1]];
write(STDOUT_FILENO, (uint8_t*)&s, sizeof(float));
symb=symbol_map[in[2*i]*2+in[2*i+1]];
out[*cnt]=symb;
(*cnt)++;
}
}
@ -277,8 +287,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 +335,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 +359,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,12 +391,14 @@ 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);
pkt_sym_cnt=SYM_PER_FRA;
//send LSF syncword
send_Syncword(SYNC_LSF);
fill_Syncword(full_packet, &pkt_sym_cnt, SYNC_LSF);
//reorder bits
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
@ -388,15 +416,13 @@ int main(int argc, char* argv[])
}
}
//send LSF
send_data(rf_bits);
//fill packet with LSF
fill_data(full_packet, &pkt_sym_cnt, rf_bits);
/*
//encode the packet frame
conv_Encode_Frame();
//send packet frame syncword
send_Syncword(SYNC_PKT);
//reorder bits
for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
rf_bits[i]=enc_bits[intrl_seq[i]];
@ -416,5 +442,65 @@ int main(int argc, char* argv[])
//send packet frame data
send_data(rf_bits);
*/
//read Packet Data from stdin
memset(full_packet_data, 0, 32*25);
memset(pkt_chunk, 0, 25+1);
pkt_cnt=0;
uint16_t tmp=num_bytes;
while(num_bytes)
{
//send packet frame syncword
fill_Syncword(full_packet, &pkt_sym_cnt, SYNC_PKT);
if(num_bytes>=25)
{
while(fread(pkt_chunk, 1, 25, stdin)<1);
memcpy(&full_packet_data[pkt_cnt*25], pkt_chunk, 25);
pkt_chunk[25]=pkt_cnt<<2;
printf("FN:%02d (full frame)\n", pkt_cnt);
num_bytes-=25;
}
else
{
while(fread(pkt_chunk, 1, num_bytes, stdin)<1);
memset(&pkt_chunk[num_bytes], 0, 25-num_bytes); //zero-padding
memcpy(&full_packet_data[pkt_cnt*25], pkt_chunk, 25);
pkt_chunk[25]=pkt_cnt<<2;
printf("FN:%02d (partial frame)\n", pkt_cnt);
num_bytes=0;
}
pkt_cnt++;
}
num_bytes=tmp; //bring back the num_bytes value
printf("DATA: %s\n", full_packet_data);
//send packet frame syncword - last frame with CRC and EOT bit
fill_Syncword(full_packet, &pkt_sym_cnt, SYNC_PKT);
uint16_t crc=CRC_M17(full_packet_data, num_bytes);
pkt_chunk[0]=crc>>8; //2-byte CRC
pkt_chunk[1]=crc&0xFF;
memset(&pkt_chunk[2], 0, 23);
pkt_chunk[25]=(1<<7)|((num_bytes%25)<<2); //EOT bit set to 1, counter set to the amount of bytes in the previous frame
printf("CRC: %04X\n", crc);
//send EOT
for(uint8_t i=0; i<SYM_PER_FRA/SYM_PER_SWD; i++) //192/8=24
fill_Syncword(full_packet, &pkt_sym_cnt, EOT_MRKR);
//dump baseband to a file
fp=fopen(fname, "wb");
for(uint16_t i=0; i<pkt_sym_cnt; i++)
{
int16_t val=roundf(full_packet[i]*RRC_DEV);
fwrite(&val, 2, 1, fp);
}
fclose(fp);
return 0;
}