This commit is contained in:
Kurt Moraw
2020-12-12 12:36:16 +01:00
parent c8c377468f
commit 16ad58483c
21 changed files with 298 additions and 64 deletions
+11 -7
View File
@@ -89,24 +89,28 @@ void init_packer()
// the payload has a size of PAYLOADLEN
// type ... inserted in the "frame type information" field
// status ... specifies first/last frame of a data stream
uint8_t *Pack(uint8_t *payload, int type, int status, int *plen)
// repeat ... 0=normal frame, 1=repeated frame (do not increment frame counter)
uint8_t *Pack(uint8_t *payload, int type, int status, int *plen, int repeat)
{
FRAME frame; // raw frame without fec
// polulate the raw frame
// make the frame counter
if(status == 0)
framecounter = 0; // first block of a stream
else
if(repeat == 0 || type == 1) // 1=BER test
framecounter++;
if (status == 0)
framecounter = 0; // start of file
// insert frame counter and status bits
frame.counter_LSB = framecounter & 0xff;
int framecnt_MSB = (framecounter >> 8) & 0x03; // Bit 8+9 of framecounter
frame.status = framecnt_MSB << 6;
frame.status += ((status & 0x03)<<4);
frame.status += (type & 0x0f);
//printf("type:%d stat:%d frmnum:%d fifo:%d\n", type, status, framecounter, io_pb_fifo_freespace(0));
// insert the payload
memcpy(frame.payload, payload, PAYLOADLEN);
@@ -344,8 +348,8 @@ uint8_t *getPayload(uint8_t *rxb)
payload[4] = rx_status; // frame lost information
payload[5] = speed >> 8; // measured line speed
payload[6] = speed;
payload[7] = maxLevel; // actual max level on sound capture in %
payload[8] = 0; // free for later use
payload[7] = 0; // free for later use
payload[8] = 0;
payload[9] = 0;
//printf("Frame no.: %d, type:%d, minfo:%d\n",framenumrx,payload[0],payload[3]);
+37 -8
View File
@@ -36,7 +36,6 @@
#include "hsmodem.h"
void toGR_sendData(uint8_t* data, int type, int status);
void bc_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock);
void appdata_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock);
void startModem();
@@ -90,6 +89,8 @@ int codec = 1; // 0=opus, 1=codec2
int init_audio_result = 0;
int init_voice_result = 0;
int safemode = 0;
int main(int argc, char* argv[])
{
int opt = 0;
@@ -300,7 +301,8 @@ void bc_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock)
* 3 ... announcement on / off, duration
* 4 ... DV loudspeaker volume
* 5 ... DV mic volume
* 6..9 ... unused
* 6 ... safe mode number
* 7..9 ... unused
* 10 .. 109 ... PB device name
* 110 .. 209 ... CAP device name
*/
@@ -308,6 +310,8 @@ void bc_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock)
//printf("%d %d %d %d %d %d %d \n",pdata[1], pdata[2], pdata[3], pdata[4], pdata[5], pdata[6], pdata[7]);
io_setAudioDevices(pdata[1], pdata[2], pdata[3], pdata[4], pdata[5], (char *)(pdata + 10), (char *)(pdata + 110));
safemode = pdata[6];
char rxip[20];
strcpy(rxip, inet_ntoa(rxsock->sin_addr));
@@ -474,13 +478,14 @@ void appdata_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock)
closeAllandTerminate();
}
// here we are with payload data to be sent via the modulator
if (len != (PAYLOADLEN + 2))
{
printf("data from app: wrong length:%d (should be %d)\n", len - 2, PAYLOADLEN);
return;
}
//if (getSending() == 1) return; // already sending (Array sending)
if (minfo == 0 || minfo == 3)
@@ -493,9 +498,10 @@ void appdata_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock)
// and bits: symbols * bitsPerSymbol
// and bytes/second: bits/8 = (caprate/txinterpolfactor) * bitsPerSymbol / 8
// one frame has 258 bytes, so we need for 6s: 6* ((caprate/txinterpolfactor) * bitsPerSymbol / 8) /258 + 1 frames
toGR_sendData(pdata + 2, type, minfo,0);
int numframespreamble = 6 * ((caprate / txinterpolfactor) * bitsPerSymbol / 8) / 258 + 1;
for (int i = 0; i < numframespreamble; i++)
toGR_sendData(pdata + 2, type, minfo);
toGR_sendData(pdata + 2, type, minfo,1);
}
else if ((len - 2) < PAYLOADLEN)
{
@@ -503,18 +509,41 @@ void appdata_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock)
uint8_t payload[PAYLOADLEN];
memset(payload, 0, PAYLOADLEN);
memcpy(payload, pdata + 2, len - 2);
toGR_sendData(payload, type, minfo);
toGR_sendData(payload, type, minfo,0);
if (safemode > 0)
{
for (int sm = 0; sm < safemode; sm++)
toGR_sendData(payload, type, minfo, 1);
}
if (minfo == 2)
{
// repeat last frame
for (int rl = 0; rl < (10 - safemode); rl++)
toGR_sendData(payload, type, minfo, 1);
}
}
else
{
toGR_sendData(pdata + 2, type, minfo);
toGR_sendData(pdata + 2, type, minfo,0);
if (safemode > 0)
{
for(int sm=0; sm < safemode; sm++)
toGR_sendData(pdata + 2, type, minfo, 1);
}
if (minfo == 2)
{
// repeat last frame
for(int rl = 0; rl < (10-safemode); rl ++)
toGR_sendData(pdata + 2, type, minfo, 1);
}
}
}
void toGR_sendData(uint8_t* data, int type, int status)
void toGR_sendData(uint8_t* data, int type, int status, int repeat)
{
int len = 0;
uint8_t* txdata = Pack(data, type, status, &len);
uint8_t* txdata = Pack(data, type, status, &len, repeat);
//showbytestring((char *)"BERtx: ", txdata, len);
+4 -2
View File
@@ -88,7 +88,7 @@ enum _VOICEMODES_ {
};
void init_packer();
uint8_t* Pack(uint8_t* payload, int type, int status, int* plen);
uint8_t* Pack(uint8_t* payload, int type, int status, int* plen, int repeat);
uint8_t* unpack_data(uint8_t* rxd, int len);
void convertBytesToSyms_QPSK(uint8_t* bytes, uint8_t* syms, int bytenum);
@@ -142,7 +142,7 @@ void sendAnnouncement();
void sleep_ms(int ms);
int getus();
void GRdata_rxdata(uint8_t* pdata, int len, struct sockaddr_in* rxsock);
void toGR_sendData(uint8_t* data, int type, int status);
void toGR_sendData(uint8_t* data, int type, int status, int repeat);
void modulator(uint8_t sym_in);
int io_pb_fifo_usedBlocks();
@@ -213,6 +213,7 @@ extern int ann_running;
extern int transmissions;
extern int linespeed;
extern uint8_t maxLevel;
extern uint8_t maxTXLevel;
extern int VoiceAudioMode;
extern int opusbitrate;
extern int init_audio_result;
@@ -227,6 +228,7 @@ extern float softwareMICvolume;
extern float softwareLSvolume;
extern int physcaprate;
extern int restart_modems;
extern int safemode;
#ifdef _LINUX_
int isRunning(char* prgname);
+10 -6
View File
@@ -199,7 +199,7 @@ void modulator(uint8_t sym_in)
{
fs = io_pb_fifo_freespace(0);
// wait until there is space in fifo
if(fs) break;
if(fs > 20000) break;
sleep_ms(10);
}
@@ -229,7 +229,8 @@ unsigned int m_st = 7; // filter delay (symbols)
float beta_st = beta_excessBW;//0.30f; // filter excess bandwidth factor
float bandwidth_st = 0.9f; // loop filter bandwidth
uint8_t maxLevel = 0; // maximum level over the last x samples in %
uint8_t maxLevel = 0; // maximum RXlevel over the last x samples in %
uint8_t maxTXLevel = 0; // maximum TXlevel over the last x samples in %
void init_demodulator()
{
@@ -282,7 +283,7 @@ void make_FFTdata(float f)
uint8_t txpl[10000];
if (fftlen > (10000 * 2 + 1))
{
printf("GRdata_FFTdata: txpl too small !!!\n");
printf("FFTdata: txpl too small !!!\n");
return;
}
@@ -300,6 +301,9 @@ void make_FFTdata(float f)
txpl[bidx++] = rxlevel_deteced; // RX level present
txpl[bidx++] = rx_in_sync;
txpl[bidx++] = maxLevel; // actual max level on sound capture in %
txpl[bidx++] = maxTXLevel; // actual max level on sound playback in %
for (int i = 0; i < fftlen; i++)
{
txpl[bidx++] = fft[i] >> 8;
@@ -309,7 +313,7 @@ void make_FFTdata(float f)
}
}
#define MCHECK 1000
#define MCHECK 48000
void getMax(float fv)
{
static float farr[MCHECK];
@@ -334,7 +338,7 @@ void getMax(float fv)
if (farr[i] > max) max = farr[i];
}
maxLevel = (uint8_t)(max*100);
//printf("max: %10.6f\n", max);
//printf("RX max: %10.6f\n", max);
}
}
@@ -414,7 +418,7 @@ static int ccol_idx = 0;
unsigned int sym_out; // output symbol
sym_out = nsym_out;
//measure_speed_syms(1);
measure_speed_syms(1); // do NOT remove, used for speed display in GUI
// try to extract a complete frame
uint8_t symb = sym_out;
+31 -1
View File
@@ -276,7 +276,7 @@ void read_callback(struct SoundIoInStream* instream, int frame_count_min, int fr
}
}
//printf("%d into fifo\n", frame_count);
// needs to sleep or it will not work correctly, no idea why
// needs to sleep or it will not work correctly on Windows, no idea why
sleep_ms(1);
//measure_speed_bps(frame_count);
@@ -300,6 +300,35 @@ void overflow_callback(struct SoundIoInStream* instream)
printf("overflow %d\n", ++count);
}
#define MTXCHECK 48000
void getTXMax(float fv)
{
static float farr[MTXCHECK];
static int idx = 0;
static int f = 1;
if (f)
{
f = 0;
for (int i = 0; i < MTXCHECK; i++)
farr[i] = 1;
}
farr[idx] = fv;
idx++;
if (idx == MTXCHECK)
{
idx = 0;
float max = 0;
for (int i = 0; i < MTXCHECK; i++)
{
if (farr[i] > max) max = farr[i];
}
maxTXLevel = (uint8_t)(max * 100);
//printf("TX max: %10.6f\n", max);
}
}
// #define SINEWAVETEST
#ifdef SINEWAVETEST
@@ -354,6 +383,7 @@ static void write_callback(struct SoundIoOutStream* outstream, int frame_count_m
for (int channel = 0; channel < layout->channel_count; channel += 1)
{
float ftx = f[frame] * softwarePBvolume;
getTXMax(ftx);
if (pbrawdev == false)
{
#ifdef SINEWAVETEST
+3 -3
View File
@@ -132,8 +132,8 @@ void measure_speed_syms(int len)
speed = meanval((int)dspd) * bitsPerSymbol;
// here we have number of elements after 1s
printf("%d sym/s\n",speed);
//printf("%d sym/s\n",speed);
// do NOT uncomment this function for RX, it is used to measure the speed for the GUI
elems=0;
lasttim = tim;
}
@@ -160,7 +160,7 @@ void measure_speed_bps(int len)
speed = meanvalbps((int)dspd);
// here we have number of elements after 1s
printf(" ======================= %d bit/s\n", speed);
//printf(" ======================= %d bit/s\n", speed);
elems = 0;
lasttim = tim;
+2 -2
View File
@@ -165,7 +165,7 @@ void sendCodecToModulator(uint8_t *pdata, int len)
if (vdidx == PAYLOADLEN)
{
vdidx = 0;
toGR_sendData(payload, 6, 1); // 6 ... voice data, 1 ... valid voice data
toGR_sendData(payload, 6, 1 ,0); // 6 ... voice data, 1 ... valid voice data
}
while (1)
@@ -179,7 +179,7 @@ void sendCodecToModulator(uint8_t *pdata, int len)
// send a dummy frame, a frame with 0 voice data
uint8_t dummy[PAYLOADLEN];
memset(dummy, 0, PAYLOADLEN);
toGR_sendData(dummy, 6, 0);
toGR_sendData(dummy, 6, 0, 0);
}
else
break;