M17_Implementations/SP5WWP/lib/lib.c

82 wiersze
2.2 KiB
C

//--------------------------------------------------------------------
// M17 C library - lib.c
//
// Wojciech Kaczmarski, SP5WWP
// M17 Project, 5 January 2024
//--------------------------------------------------------------------
#include <encode/symbols.h>
#include "lib.h"
/**
* @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)
{
if(type) //pre-BERT
{
for(uint16_t i=0; i<SYM_PER_FRA/2; i++) //40ms * 4800 = 192
{
out[(*cnt)++]=-3.0;
out[(*cnt)++]=+3.0;
}
}
else //pre-LSF
{
for(uint16_t i=0; i<SYM_PER_FRA/2; i++) //40ms * 4800 = 192
{
out[(*cnt)++]=+3.0;
out[(*cnt)++]=-3.0;
}
}
}
/**
* @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)
{
for(uint8_t i=0; i<SYM_PER_SWD*2; i+=2)
{
out[(*cnt)++]=symbol_map[(syncword>>(14-i))&3];
}
}
//send the data (can be used for both LSF and frames)
/**
* @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)
{
for(uint16_t i=0; i<SYM_PER_PLD; i++) //40ms * 4800 - 8 (syncword)
{
out[(*cnt)++]=symbol_map[in[2*i]*2+in[2*i+1]];
}
}
/**
* @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)
{
for(uint16_t i=0; i<SYM_PER_FRA; i++) //40ms * 4800 = 192
{
out[(*cnt)++]=eot_symbols[i%8];
}
}