Browse Source

Use the transmission and level values.

master
Jeroen Vreeken 2 years ago
parent
commit
5cc71b1e44
9 changed files with 126 additions and 21 deletions
  1. +5
    -4
      eth_ar.c
  2. +3
    -3
      eth_ar/eth_ar.h
  3. +52
    -0
      eth_ar_test.c
  4. +11
    -4
      freedv_eth.c
  5. +3
    -2
      freedv_eth.h
  6. +10
    -2
      freedv_eth_baseband_in.c
  7. +21
    -1
      freedv_eth_queue.c
  8. +9
    -2
      freedv_eth_rx.c
  9. +12
    -3
      freedv_eth_rxa.c

+ 5
- 4
eth_ar.c View File

@ -22,6 +22,7 @@
#include <string.h>
#include <inttypes.h>
#include <stdlib.h>
#include <math.h>
/*
8 character callsign, 4 bit ssid
@ -146,21 +147,21 @@ int eth_ar_mac_ssid_mask(uint8_t masked_mac[6], const uint8_t mac[6])
uint8_t eth_ar_dbm_encode(double dbm)
{
double enc = (dbm * 2.0) - 128.0;
double enc = (dbm * 2.0) + 255.5;
if (enc < 0)
return 0;
if (enc > 255)
return 255;
return (uint8_t)(enc + 0.5);
return (uint8_t)(enc);
}
double eth_ar_dbm_decode(uint8_t enc)
{
if (enc) {
return -128.0 + (enc / 2.0);
return -127.5 + (enc / 2.0);
} else {
return 0.0;
return -INFINITY;
}
}

+ 3
- 3
eth_ar/eth_ar.h View File

@ -34,9 +34,9 @@ extern "C" {
#define ETH_P_CODEC2_700 0x7306
#define ETH_P_CODEC2_700B 0x7307
#define ETH_P_CODEC2_700C 0x7308
#define ETH_P_CODEC2_1300C 0x7309
#define ETH_P_CODEC2_450PWB 0x730a
#define ETH_P_CODEC2_WB 0x730b
#define ETH_P_CODEC2_WB 0x7309
#define ETH_P_CODEC2_450 0x730a
#define ETH_P_CODEC2_450PWB 0x730b
#define ETH_P_AR_CONTROL 0x7342


+ 52
- 0
eth_ar_test.c View File

@ -35,11 +35,63 @@ static int test_eth_ar_call2mac(void)
return 0;
}
struct dbm_value {
uint8_t enc;
double val;
} dbm_values[] = {
{ 0, -INFINITY },
{ 255, 0.0 },
{ 254, -0.5 },
{ 1, -127 },
{ 2, -126.5 },
{ 10, -122.5 },
{ 33, -111 },
{ 77, -89 },
};
static int test_eth_ar_dbm_encode(void)
{
int i;
for (i = 0; i < sizeof(dbm_values)/sizeof(dbm_values[0]); i++) {
double val = dbm_values[i].val;
uint8_t enc = dbm_values[i].enc;
uint8_t enct = eth_ar_dbm_encode(val);
if (enct != enc) {
fprintf(stderr, "eth_ar_dbm_encode(%f) -> 0x%02x != 0x%02x\n",
val, enct, enc);
// return -1;
}
}
return 0;
}
static int test_eth_ar_dbm_decode(void)
{
int i;
for (i = 0; i < sizeof(dbm_values)/sizeof(dbm_values[0]); i++) {
double val = dbm_values[i].val;
uint8_t enc = dbm_values[i].enc;
double valt = eth_ar_dbm_decode(enc);
if (valt != val) {
fprintf(stderr, "eth_ar_dbm_decode(0x%02x) -> %f != %f\n",
enc, valt, val);
// return -1;
}
}
return 0;
}
struct fprs_test {
char *name;
int (*func)(void);
} tests[] = {
{ "eth_ar_call2mac", test_eth_ar_call2mac },
{ "eth_ar_dbm_encode", test_eth_ar_dbm_encode },
{ "eth_ar_dbm_decode", test_eth_ar_dbm_decode },
};
int main(int argc, char **argv)


+ 11
- 4
freedv_eth.c View File

@ -88,7 +88,8 @@ enum rx_mode {
static enum rx_mode rx_mode;
void freedv_eth_voice_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, bool local_rx)
void freedv_eth_voice_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, bool local_rx,
uint8_t transmission, double level_dbm)
{
struct tx_packet *packet;
@ -104,7 +105,7 @@ void freedv_eth_voice_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint
freedv_eth_transcode(packet, tx_codecmode, eth_type);
packet->local_rx = local_rx;
enqueue_voice(packet);
enqueue_voice(packet, 0, -10);
}
if (local_rx && baseband_out) {
if (len > tx_packet_max())
@ -180,9 +181,9 @@ static int cb_int_tx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t
freedv_eth_transcode(packet, tx_codecmode, eth_type);
enqueue_voice(packet);
int q = enqueue_voice(packet, transmission, eth_ar_dbm_decode(level));
if (baseband_out) {
if (q && baseband_out) {
packet = tx_packet_alloc();
packet->len = len;
memcpy(packet->data, data, len);
@ -376,6 +377,12 @@ int main(int argc, char **argv)
} else if (!strcmp(freedv_mode_str, "800XA")) {
freedv_mode = FREEDV_MODE_800XA;
freedv_hasdata = true;
} else if (!strcmp(freedv_mode_str, "700C")) {
freedv_mode = FREEDV_MODE_700C;
freedv_hasdata = true;
} else if (!strcmp(freedv_mode_str, "700D")) {
freedv_mode = FREEDV_MODE_700D;
freedv_hasdata = true;
} else {
printf("Invalid FreeDV mode\n");
return -1;


+ 3
- 2
freedv_eth.h View File

@ -74,8 +74,9 @@ void tx_packet_free(struct tx_packet *packet);
struct tx_packet *dequeue_voice(void);
struct tx_packet *peek_voice(void);
void enqueue_voice(struct tx_packet *packet);
int enqueue_voice(struct tx_packet *packet, uint8_t transmission, double level_dbm);
bool queue_voice_filled(void);
void queue_voice_end(uint8_t transmission);
struct tx_packet *dequeue_baseband(void);
struct tx_packet *peek_baseband(void);
@ -93,7 +94,7 @@ struct tx_packet *peek_control(void);
void enqueue_control(struct tx_packet *packet);
bool queue_control_filled(void);
void freedv_eth_voice_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, bool local_rx);
void freedv_eth_voice_rx(uint8_t to[6], uint8_t from[6], uint16_t eth_type, uint8_t *data, size_t len, bool local_rx, uint8_t transmission, double level);
bool freedv_eth_cdc(void);
int freedv_eth_transcode(struct tx_packet *packet, int to_codecmode, uint16_t from_type);


+ 10
- 2
freedv_eth_baseband_in.c View File

@ -37,6 +37,8 @@ static struct sound_resample *sr = NULL;
static float rx_gain = 1.0;
SpeexPreprocessState *st;
static uint8_t transmission = 0;
static double level_dbm = -10;
bool freedv_eth_baseband_in_cdc(void)
{
@ -54,11 +56,17 @@ void freedv_eth_baseband_in(int16_t *samples, int nr)
sound_resample_perform_gain_limit(sr, mod_a, samples, nr_a, nr, rx_gain);
cdc = io_hl_aux2_get();
bool new_cdc = io_hl_aux2_get();
if (!new_cdc && cdc) {
queue_voice_end(transmission);
transmission++;
}
cdc = new_cdc;
if (cdc) {
freedv_eth_voice_rx(bcast, mac, ETH_P_NATIVE16,
(uint8_t *)mod_a, nr_a * sizeof(int16_t), false);
(uint8_t *)mod_a, nr_a * sizeof(int16_t), false,
transmission, level_dbm);
}
}


+ 21
- 1
freedv_eth_queue.c View File

@ -23,6 +23,9 @@
static _Atomic(struct tx_packet *) tx_packet_pool = NULL;
static uint8_t voice_transmission = 0;
static double voice_level = -INFINITY;
struct tx_packet *tx_packet_alloc(void)
{
struct tx_packet *packet;
@ -72,11 +75,22 @@ struct tx_packet *peek_voice(void)
return queue_voice;
}
void enqueue_voice(struct tx_packet *packet)
int enqueue_voice(struct tx_packet *packet, uint8_t transmission, double level_dbm)
{
if (queue_voice && transmission != voice_transmission) {
if (level_dbm < voice_level) {
tx_packet_free(packet);
return 0;
}
}
voice_transmission = transmission;
voice_level = level_dbm;
packet->next = NULL;
*queue_voice_tail = packet;
queue_voice_tail = &packet->next;
return 1;
}
bool queue_voice_filled(void)
@ -84,6 +98,12 @@ bool queue_voice_filled(void)
return queue_voice;
}
void queue_voice_end(uint8_t transmission)
{
if (transmission == voice_transmission)
voice_level = -INFINITY;
}
static struct tx_packet *queue_baseband = NULL;
static struct tx_packet **queue_baseband_tail = &queue_baseband;


+ 9
- 2
freedv_eth_rx.c View File

@ -39,6 +39,9 @@ static void *silence_packet = NULL;
static struct sound_resample *sr = NULL;
struct freedv *freedv;
static uint8_t transmission = 128;
static double level_dbm = -80.0;
static uint8_t rx_add[6], mac[6];
#define RX_SYNC_ZERO 15.0
@ -105,7 +108,8 @@ void freedv_eth_rx(int16_t *hw_samples, int hw_nr)
freedv_eth_voice_rx(
bcast, rx_add, eth_type_rx,
packed_codec_bits + i * bytes_per_eth_frame,
bytes_per_eth_frame, true);
bytes_per_eth_frame, true,
transmission, level_dbm);
}
printf(".");
fflush(NULL);
@ -120,7 +124,8 @@ void freedv_eth_rx(int16_t *hw_samples, int hw_nr)
freedv_eth_voice_rx(
bcast, rx_add, eth_type_rx,
silence_packet,
bytes_per_eth_frame, true);
bytes_per_eth_frame, true,
transmission, level_dbm);
}
}
}
@ -132,6 +137,8 @@ void freedv_eth_rx(int16_t *hw_samples, int hw_nr)
printf("Reset RX add\n");
memcpy(rx_add, mac, 6);
cdc_voice = false;
queue_voice_end(transmission);
transmission++;
}


+ 12
- 3
freedv_eth_rxa.c View File

@ -41,6 +41,9 @@ static float rx_gain = 1.0;
static char dtmf_control_start = '*';
static char dtmf_control_stop = '#';
static uint8_t transmission = 0;
static double level_dbm = -60;
enum dtmf_state {
DTMF_IDLE,
DTMF_CONTROL,
@ -79,16 +82,22 @@ void freedv_eth_rxa(int16_t *samples, int nr)
int nr_a = sound_resample_nr_out(sr, nr);
int16_t mod_a[nr_a];
bool detected;
bool new_cdc;
sound_resample_perform_gain_limit(sr, mod_a, samples, nr_a, nr, rx_gain);
if (emphasis_d)
emphasis_de(emphasis_d, mod_a, nr_a);
if (ctcss_sql) {
cdc = ctcss_detect_rx(mod_a, nr_a);
new_cdc = ctcss_detect_rx(mod_a, nr_a);
} else {
cdc = io_hl_dcd_get();
new_cdc = io_hl_dcd_get();
}
if (cdc && !new_cdc) {
queue_voice_end(transmission);
transmission++;
}
cdc = new_cdc;
dtmf_rx(mod_a, nr_a, cb_control, &detected);
if (detected) {
@ -99,7 +108,7 @@ void freedv_eth_rxa(int16_t *samples, int nr)
}
if (cdc) {
freedv_eth_voice_rx(bcast, mac, ETH_P_NATIVE16, (uint8_t *)mod_a, nr_a * sizeof(int16_t), true);
freedv_eth_voice_rx(bcast, mac, ETH_P_NATIVE16, (uint8_t *)mod_a, nr_a * sizeof(int16_t), true, transmission, level_dbm);
} else {
dtmf_state = DTMF_IDLE;
}


Loading…
Cancel
Save