got rid of stdio.h

- point 1 of #8 is done
- fixed EoT marker
- added 'install' Makefile section for the libm17
pull/20/head
Wojciech Kaczmarski 2024-01-05 17:34:07 +01:00
rodzic d582dbd14a
commit 5cf820845d
7 zmienionych plików z 86 dodań i 46 usunięć

1
.gitignore vendored
Wyświetl plik

@ -4,3 +4,4 @@
/SP5WWP/m17-packet/m17-packet-encode /SP5WWP/m17-packet/m17-packet-encode
/SP5WWP/m17-packet/m17-packet-decode /SP5WWP/m17-packet/m17-packet-decode
/SP5WWP/.vscode /SP5WWP/.vscode
*.json

Wyświetl plik

@ -15,6 +15,9 @@ clean:
fclean: fclean:
rm -f $(TARGET) rm -f $(TARGET)
install:
sudo install $(TARGET) /usr/local/lib
$(TARGET): $(OBJS) $(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(CC) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS)

Wyświetl plik

@ -2,9 +2,12 @@
// M17 C library - encode/symbols.c // M17 C library - encode/symbols.c
// //
// Wojciech Kaczmarski, SP5WWP // Wojciech Kaczmarski, SP5WWP
// M17 Project, 29 December 2023 // M17 Project, 5 January 2024
//-------------------------------------------------------------------- //--------------------------------------------------------------------
#include "symbols.h" #include "symbols.h"
// dibits-symbols map (TX) //dibits-symbols map (TX)
const int8_t symbol_map[4]={+1, +3, -1, -3}; const int8_t symbol_map[4]={+1, +3, -1, -3};
//End of Transmission symbol pattern
const float eot_symbols[8]={+3, +3, +3, +3, +3, +3, -3, +3};

Wyświetl plik

@ -2,7 +2,7 @@
// M17 C library - encode/symbols.h // M17 C library - encode/symbols.h
// //
// Wojciech Kaczmarski, SP5WWP // Wojciech Kaczmarski, SP5WWP
// M17 Project, 28 December 2023 // M17 Project, 5 January 2024
//------------------------------- //-------------------------------
#pragma once #pragma once
@ -11,9 +11,12 @@ extern "C" {
#endif #endif
#include <stdint.h> #include <stdint.h>
// dibits-symbols map (TX) //dibits-symbols map (TX)
extern const int8_t symbol_map[4]; extern const int8_t symbol_map[4];
//End of Transmission symbol pattern
extern const float eot_symbols[8];
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

Wyświetl plik

@ -2,66 +2,80 @@
// M17 C library - lib.c // M17 C library - lib.c
// //
// Wojciech Kaczmarski, SP5WWP // Wojciech Kaczmarski, SP5WWP
// M17 Project, 29 December 2023 // M17 Project, 5 January 2024
//-------------------------------------------------------------------- //--------------------------------------------------------------------
#include <stdio.h>
#include <encode/symbols.h> #include <encode/symbols.h>
#include "lib.h" #include "lib.h"
//misc /**
void send_preamble(const uint8_t type) * @brief Generate symbol stream for a preamble.
*
* @param out Frame buffer (192 floats)
* @param cnt Pointer to a variable holding the number of written symbols.
* @param type Preamble type (pre-BERT or pre-LSF).
*/
void send_preamble(float out[SYM_PER_FRA], uint32_t *cnt, const uint8_t type)
{ {
float symb;
if(type) //pre-BERT 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; out[(*cnt)++]=-3.0;
fwrite((uint8_t*)&symb, sizeof(float), 1, stdout); out[(*cnt)++]=+3.0;
symb=+3.0;
fwrite((uint8_t*)&symb, sizeof(float), 1, stdout);
} }
} }
else //pre-LSF 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; out[(*cnt)++]=+3.0;
fwrite((uint8_t*)&symb, sizeof(float), 1, stdout); out[(*cnt)++]=-3.0;
symb=-3.0;
fwrite((uint8_t*)&symb, sizeof(float), 1, stdout);
} }
} }
} }
void send_syncword(const uint16_t syncword) /**
* @brief Generate symbol stream for a syncword.
*
* @param out Output buffer (8 floats).
* @param cnt Pointer to a variable holding the number of written symbols.
* @param syncword Syncword.
*/
void send_syncword(float out[SYM_PER_SWD], uint32_t *cnt, const uint16_t syncword)
{ {
float symb; for(uint8_t i=0; i<SYM_PER_SWD*2; i+=2)
for(uint8_t i=0; i<16; i+=2)
{ {
symb=symbol_map[(syncword>>(14-i))&3]; out[(*cnt)++]=symbol_map[(syncword>>(14-i))&3];
fwrite((uint8_t*)&symb, sizeof(float), 1, stdout);
} }
} }
//send the data (can be used for both LSF and frames) //send the data (can be used for both LSF and frames)
void send_data(const uint8_t* in) /**
* @brief Generate symbol stream for frame contents (without syncword).
* Can be used for both LSF and data frames.
*
* @param out Output buffer (184 floats).
* @param cnt Pointer to a variable holding the number of written symbols.
* @param in Data input.
*/
void send_data(float out[SYM_PER_PLD], uint32_t *cnt, const uint8_t* in)
{ {
float s=0.0;
for(uint16_t i=0; i<SYM_PER_PLD; i++) //40ms * 4800 - 8 (syncword) 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]]; out[(*cnt)++]=symbol_map[in[2*i]*2+in[2*i+1]];
fwrite((uint8_t*)&s, sizeof(float), 1, stdout);
} }
} }
void send_eot(void) /**
* @brief Generate symbol stream for the End of Transmission marker.
*
* @param out Output buffer (192 floats).
* @param cnt Pointer to a variable holding the number of written symbols.
*/
void send_eot(float out[SYM_PER_FRA], uint32_t *cnt)
{ {
float symb=+3.0; for(uint16_t i=0; i<SYM_PER_FRA; i++) //40ms * 4800 = 192
for(uint16_t i=0; i<192; i++) //40ms * 4800 = 192
{ {
fwrite((uint8_t*)&symb, sizeof(float), 1, stdout); out[(*cnt)++]=eot_symbols[i%8];
} }
} }

Wyświetl plik

@ -2,7 +2,7 @@
// M17 C library - lib.h // M17 C library - lib.h
// //
// Wojciech Kaczmarski, SP5WWP // Wojciech Kaczmarski, SP5WWP
// M17 Project, 28 December 2023 // M17 Project, 5 January 2024
//------------------------------- //-------------------------------
#pragma once #pragma once
@ -22,10 +22,10 @@ extern "C" {
//L2 metric threshold //L2 metric threshold
#define DIST_THRESH 2.0f //threshold for distance (syncword detection) #define DIST_THRESH 2.0f //threshold for distance (syncword detection)
void send_preamble(const uint8_t type); void send_preamble(float out[SYM_PER_FRA], uint32_t *cnt, const uint8_t type);
void send_syncword(const uint16_t syncword); void send_syncword(float out[SYM_PER_SWD], uint32_t *cnt, const uint16_t syncword);
void send_data(const uint8_t* in); void send_data(float out[SYM_PER_PLD], uint32_t *cnt, const uint8_t* in);
void send_eot(void); void send_eot(float out[SYM_PER_FRA], uint32_t *cnt);
#ifdef __cplusplus #ifdef __cplusplus
} }

Wyświetl plik

@ -22,6 +22,9 @@ uint8_t lich_encoded[12]; //96 bits packed, encoded LICH
uint8_t enc_bits[SYM_PER_PLD*2]; //type-2 bits, unpacked 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 rf_bits[SYM_PER_PLD*2]; //type-4 bits, unpacked
float frame_buff[192];
uint32_t frame_buff_cnt;
uint8_t data[16], next_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) uint16_t fn=0; //16-bit Frame Number (for the stream mode)
uint8_t lich_cnt=0; //0..5 LICH counter uint8_t lich_cnt=0; //0..5 LICH counter
@ -66,7 +69,8 @@ int main(void)
if(got_lsf) //stream frames if(got_lsf) //stream frames
{ {
//send stream frame syncword //send stream frame syncword
send_syncword(SYNC_STR); frame_buff_cnt=0;
send_syncword(frame_buff, &frame_buff_cnt, SYNC_STR);
//extract LICH from the whole LSF //extract LICH from the whole LSF
switch(lich_cnt) switch(lich_cnt)
@ -178,7 +182,9 @@ int main(void)
fwrite((uint8_t*)&s, sizeof(float), 1, stdout);*/ fwrite((uint8_t*)&s, sizeof(float), 1, stdout);*/
//send frame data //send frame data
send_data(rf_bits); frame_buff_cnt=0;
send_data(frame_buff, &frame_buff_cnt, rf_bits);
fwrite((uint8_t*)frame_buff, SYM_PER_FRA*sizeof(float), 1, stdout);
/*printf("\tDATA: "); /*printf("\tDATA: ");
for(uint8_t i=0; i<16; i++) for(uint8_t i=0; i<16; i++)
@ -204,11 +210,15 @@ int main(void)
//encode LSF data //encode LSF data
conv_encode_LSF(enc_bits, &lsf); conv_encode_LSF(enc_bits, &lsf);
//send out the preamble and LSF //send out the preamble
send_preamble(0); //0 - LSF preamble, as opposed to 1 - BERT preamble frame_buff_cnt=0;
send_preamble(frame_buff, &frame_buff_cnt, 0); //0 - LSF preamble, as opposed to 1 - BERT preamble
fwrite((uint8_t*)frame_buff, SYM_PER_FRA*sizeof(float), 1, stdout);
//send LSF syncword //send LSF syncword
send_syncword(SYNC_LSF); frame_buff_cnt=0;
send_syncword(frame_buff, &frame_buff_cnt, SYNC_LSF);
fwrite((uint8_t*)frame_buff, SYM_PER_SWD*sizeof(float), 1, stdout);
//reorder bits //reorder bits
for(uint16_t i=0; i<SYM_PER_PLD*2; i++) for(uint16_t i=0; i<SYM_PER_PLD*2; i++)
@ -227,7 +237,9 @@ int main(void)
} }
//send LSF data //send LSF data
send_data(rf_bits); frame_buff_cnt=0;
send_data(frame_buff, &frame_buff_cnt, rf_bits);
fwrite((uint8_t*)frame_buff, SYM_PER_PLD*sizeof(float), 1, stdout);
//send dummy symbols (debug) //send dummy symbols (debug)
/*float s=0.0; /*float s=0.0;
@ -253,7 +265,11 @@ int main(void)
} }
if(finished) if(finished)
send_eot(); {
frame_buff_cnt=0;
send_eot(frame_buff, &frame_buff_cnt);
fwrite((uint8_t*)frame_buff, SYM_PER_PLD*sizeof(float), 1, stdout);
}
} }
return 0; return 0;