Browse Source

Use the level and transmission values in digital voice packets.

master
Jeroen Vreeken 2 years ago
parent
commit
d9a07121f3
4 changed files with 53 additions and 37 deletions
  1. +1
    -1
      dml_streamer.c
  2. +16
    -14
      dml_trx.c
  3. +34
    -20
      trx_dv.c
  4. +2
    -2
      trx_dv.h

+ 1
- 1
dml_streamer.c View File

@ -33,7 +33,7 @@
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <inttypes.h>
#include <openssl/pem.h>


+ 16
- 14
dml_trx.c View File

@ -55,6 +55,8 @@
#define TIME_VALID_DOWNLINK (5*60)
#define TIME_VALID_OWN (60*60)
#define DML_TRX_LEVEL_MSG 255
#define debug(...) printf(__VA_ARGS__)
static bool fullduplex = false;
@ -77,8 +79,8 @@ static int send_data_fprs(void *data, size_t size, unsigned int link, void *arg)
static void recv_data(void *data, size_t size);
static void recv_data_fprs(void *data, size_t size, uint64_t timestamp);
static bool rx_state = false;
static bool tx_state = false;
static uint8_t rx_state = false;
static uint8_t tx_state = false;
static char command[100];
static int command_len = 0;
@ -451,7 +453,7 @@ static void stream_header_cb(struct dml_host *host, struct dml_stream *ds, void
if (ds == cur_con) {
fprintf(stderr, "Play header\n");
trx_dv_send(mac_dev, mac_bcast, 'A', header, header_size);
trx_dv_send(mac_dev, mac_bcast, 'A', header, header_size, DML_TRX_LEVEL_MSG);
} else {
fprintf(stderr, "Stream mismatch: %p %p\n", ds, cur_con);
}
@ -582,7 +584,7 @@ static void recv_data(void *data, size_t size)
uint8_t *datab = data;
uint8_t mode = datab[6];
bool state = datab[7] & 0x1;
uint8_t state = datab[7];
// printf("mode %d state %d\n", mode, state);
@ -598,7 +600,7 @@ static void recv_data(void *data, size_t size)
}
if (size > 8) {
trx_dv_send(data, mac_bcast, mode, datab + 8, size - 8);
trx_dv_send(data, mac_bcast, mode, datab + 8, size - 8, state);
}
}
}
@ -611,11 +613,11 @@ static int rx_watchdog(void *arg)
memcpy(data, rx_state ? mac_last : mac_bcast, 6);
data[6] = 0;
data[7] = false;
data[7] = 0;
send_data(data, 8, stream_dv);
rx_state = false;
rx_state = 0;
/* Flush command buffer */
command_len = 0;
@ -625,10 +627,10 @@ static int rx_watchdog(void *arg)
data = soundlib_get(SOUND_MSG_SILENCE, &size);
if (data) {
trx_dv_send(mac_dev, mac_bcast, 'A', data, size);
trx_dv_send(mac_dev, mac_bcast, 'A', data, size);
trx_dv_send(mac_dev, mac_bcast, 'A', data, size);
trx_dv_send(mac_dev, mac_bcast, 'A', data, size);
trx_dv_send(mac_dev, mac_bcast, 'A', data, size, DML_TRX_LEVEL_MSG);
trx_dv_send(mac_dev, mac_bcast, 'A', data, size, DML_TRX_LEVEL_MSG);
trx_dv_send(mac_dev, mac_bcast, 'A', data, size, DML_TRX_LEVEL_MSG);
trx_dv_send(mac_dev, mac_bcast, 'A', data, size, DML_TRX_LEVEL_MSG);
}
struct sound_msg_e *e = sound_msg_q;
@ -640,7 +642,7 @@ static int rx_watchdog(void *arg)
if (size < sendsize)
sendsize = size;
trx_dv_send(mac_dev, mac_bcast, 'A', data, sendsize);
trx_dv_send(mac_dev, mac_bcast, 'A', data, sendsize, DML_TRX_LEVEL_MSG);
data += sendsize;
size -= sendsize;
}
@ -658,14 +660,14 @@ static int rx_watchdog(void *arg)
return 0;
}
static int dv_in_cb(void *arg, uint8_t from[6], uint8_t to[6], uint8_t *dv, size_t size, int mode)
static int dv_in_cb(void *arg, uint8_t from[6], uint8_t to[6], uint8_t *dv, size_t size, int mode, uint8_t level)
{
uint8_t data[8 + size];
if (!rx_state) {
printf("rx_state to on\n");
}
rx_state = true;
rx_state = level;
memcpy(data, from, 6);
memcpy(mac_last, from, 6);


+ 34
- 20
trx_dv.c View File

@ -40,7 +40,7 @@ static void (*dv_mac_cb)(uint8_t *mac) = NULL;
#define TRX_DV_WATCHDOG 5
static int (*in_cb)(void *arg, uint8_t from[6], uint8_t to[6], uint8_t *dv, size_t size, int mode) = NULL;
static int (*in_cb)(void *arg, uint8_t from[6], uint8_t to[6], uint8_t *dv, size_t size, int mode, uint8_t level) = NULL;
static int (*ctrl_cb)(void *arg, uint8_t from[6], uint8_t to[6], char *ctrl, size_t size) = NULL;
static int (*fprs_cb)(void *arg, uint8_t from[6], uint8_t *fprs, size_t size) = NULL;
static void *in_cb_arg = NULL;
@ -92,12 +92,18 @@ static int trx_dv_in_cb(void *arg)
mode = CODEC2_MODE_700C;
datasize = 4;
break;
#ifdef CODEC2_MODE_1300C
case ETH_P_CODEC2_1300C:
mode = CODEC2_MODE_1300C;
datasize = 7;
case ETH_P_CODEC2_WB:
mode = CODEC2_MODE_WB;
datasize = 8;
break;
case ETH_P_CODEC2_450:
mode = CODEC2_MODE_450;
datasize = 3;
break;
case ETH_P_CODEC2_450PWB:
mode = CODEC2_MODE_450PWB;
datasize = 3;
break;
#endif
case ETH_P_ALAW:
mode = 'A';
datasize = ret - 16;
@ -122,7 +128,7 @@ static int trx_dv_in_cb(void *arg)
return 0;
}
if (ret >= datasize + 14) {
in_cb(in_cb_arg, dv_frame + 6, dv_frame, dv_frame + 16, datasize, mode);
in_cb(in_cb_arg, dv_frame + 6, dv_frame, dv_frame + 16, datasize, mode, dv_frame[15]);
}
} else {
printf("frame not the right size: %zd: \n", ret);
@ -136,7 +142,7 @@ static int trx_dv_in_cb(void *arg)
}
int trx_dv_send(uint8_t from[6], uint8_t to[6], int mode, uint8_t *dv, size_t size)
int trx_dv_send(uint8_t from[6], uint8_t to[6], int mode, uint8_t *dv, size_t size, uint8_t level)
{
uint16_t type;
ssize_t max_size = 0;
@ -178,12 +184,18 @@ int trx_dv_send(uint8_t from[6], uint8_t to[6], int mode, uint8_t *dv, size_t si
type = htons(ETH_P_CODEC2_700C);
max_size = 4;
break;
#ifdef CODEC2_MODE_1300C
case CODEC2_MODE_1300C:
type = htons(ETH_P_CODEC2_1300C);
max_size = 7;
case CODEC2_MODE_WB:
type = htons(ETH_P_CODEC2_WB);
max_size = 8;
break;
case CODEC2_MODE_450:
type = htons(ETH_P_CODEC2_450);
max_size = 3;
break;
case CODEC2_MODE_450PWB:
type = htons(ETH_P_CODEC2_450PWB);
max_size = 3;
break;
#endif
case 'A':
type = htons(ETH_P_ALAW);
max_size = 320;
@ -212,8 +224,8 @@ int trx_dv_send(uint8_t from[6], uint8_t to[6], int mode, uint8_t *dv, size_t si
memcpy(dv_frame + 0, to, 6);
memcpy(dv_frame + 6, from, 6);
memcpy(dv_frame + 12, &type, 2);
dv_frame[14] = 0;
dv_frame[15] = 1;
dv_frame[14] = from[0] ^ from[1] ^ from[2] ^ from[3] ^ from[4] ^ from[5];
dv_frame[15] = level;
memcpy(dv_frame + 16, dv, out_size);
ssize_t ret = send(dv_sock, dv_frame, 16 + out_size, 0);
@ -286,10 +298,12 @@ int trx_dv_duration(size_t size, int mode)
return (size * 40) / 4;
case CODEC2_MODE_700C:
return (size * 40) / 4;
#ifdef CODEC2_MODE_1300C
case CODEC2_MODE_1300C:
return (size * 40) / 7;
#endif
case CODEC2_MODE_450:
return (size * 40) / 3;
case CODEC2_MODE_450PWB:
return (size * 40) / 3;
case CODEC2_MODE_WB:
return (size * 20) / 8;
case 'A':
case 'U':
return size / 8;
@ -371,7 +385,7 @@ static int trx_dv_watchdog(void *arg)
}
int trx_dv_init(char *dev,
int (*new_in_cb)(void *arg, uint8_t from[6], uint8_t to[6], uint8_t *dv, size_t size, int mode),
int (*new_in_cb)(void *arg, uint8_t from[6], uint8_t to[6], uint8_t *dv, size_t size, int mode, uint8_t level),
int (*new_ctrl_cb)(void *arg, uint8_t from[6], uint8_t to[6], char *ctrl, size_t size),
int (*new_fprs_cb)(void *arg, uint8_t from[6], uint8_t *fprs, size_t size),
void *arg,


+ 2
- 2
trx_dv.h View File

@ -22,12 +22,12 @@
#include <stdint.h>
int trx_dv_init(char *dev,
int (*new_in_cb)(void *arg, uint8_t from[6], uint8_t to[6], uint8_t *dv, size_t size, int mode),
int (*new_in_cb)(void *arg, uint8_t from[6], uint8_t to[6], uint8_t *dv, size_t size, int mode, uint8_t level),
int (*new_ctrl_cb)(void *arg, uint8_t from[6], uint8_t to[6], char *ctrl, size_t size),
int (*new_fprs_cb)(void *arg, uint8_t from[6], uint8_t *fprs, size_t size),
void *arg,
void (*new_mac_cb)(uint8_t *mac));
int trx_dv_send(uint8_t from[6], uint8_t to[6], int mode, uint8_t *dv, size_t size);
int trx_dv_send(uint8_t from[6], uint8_t to[6], int mode, uint8_t *dv, size_t size, uint8_t level);
int trx_dv_send_control(uint8_t from[6], uint8_t to[6], char *control);
int trx_dv_send_fprs(uint8_t from[6], uint8_t to[6], uint8_t *data, size_t size);
/* Duration (ms) of DV data */


Loading…
Cancel
Save