Move from local to external osmo* libraries

src/libdebug -> libosmocore
src/libselect -> libosmocore
src/libtimer -> libosmocore
src/libosmocc -> libosmo-cc
src/libg711 -> libosmo-cc
This commit is contained in:
Andreas Eversberg
2024-01-05 14:20:36 +01:00
parent 6cd2c3e323
commit 3158c48365
198 changed files with 4202 additions and 12564 deletions

View File

@@ -12,15 +12,15 @@ datenklo_SOURCES = \
datenklo_LDADD = \
$(COMMON_LA) \
$(top_builddir)/src/liboptions/liboptions.a \
$(top_builddir)/src/libdebug/libdebug.a \
$(top_builddir)/src/libfsk/libfsk.a \
$(top_builddir)/src/libtimer/libtimer.a \
$(top_builddir)/src/libfm/libfm.a \
$(top_builddir)/src/libfilter/libfilter.a \
$(top_builddir)/src/libsound/libsound.a \
$(top_builddir)/src/libwave/libwave.a \
$(top_builddir)/src/libdisplay/libdisplay.a \
$(top_builddir)/src/libsample/libsample.a \
$(top_builddir)/src/liblogging/liblogging.a \
$(LIBOSMOCORE_LIBS) \
$(ALSA_LIBS) \
$(FUSE_LIBS) \
-lm

View File

@@ -75,12 +75,14 @@
#include <string.h>
#include <errno.h>
#include <math.h>
#include "../libdebug/debug.h"
#include "../libtimer/timer.h"
#include "../liblogging/logging.h"
#include <osmocom/core/timer.h>
#include "../libsample/sample.h"
#include "../libfsk/fsk.h"
#include "am791x.h"
#define FLOAT_TO_TIMEOUT(f) floor(f), ((f) - floor(f)) * 1000000
#define db2level(db) pow(10, (double)(db) / 20.0)
#define level2db(level) (20 * log10(level))
@@ -373,19 +375,19 @@ static int fsk_send_bit(void *inst)
/* main channel returns TD */
if (!am791x->block_td) {
#ifdef HEAVY_DEBUG
PDEBUG(DDSP, DEBUG_DEBUG, "Modulating bit '%d' for MAIN channel\n", bit);
LOGP(DDSP, LOGL_DEBUG, "Modulating bit '%d' for MAIN channel\n", bit);
#endif
return bit;
}
/* back channel returns BTD */
if (!am791x->block_btd) {
#ifdef HEAVY_DEBUG
PDEBUG(DDSP, DEBUG_DEBUG, "Modulating bit '%d' for BACK channel\n", bbit);
LOGP(DDSP, LOGL_DEBUG, "Modulating bit '%d' for BACK channel\n", bbit);
#endif
return bbit;
}
#ifdef HEAVY_DEBUG
PDEBUG(DDSP, DEBUG_DEBUG, "Modulating bit '1', because TD & BTD is ignored\n");
LOGP(DDSP, LOGL_DEBUG, "Modulating bit '1', because TD & BTD is ignored\n");
#endif
return 1;
}
@@ -399,7 +401,7 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level)
int *block, *cd;
#ifdef HEAVY_DEBUG
PDEBUG(DDSP, DEBUG_DEBUG, "Demodulated bit '%d' (level = %.0f dBm, quality = %%%.0f)\n", bit, level2db(level), quality * 100.0);
LOGP(DDSP, LOGL_DEBUG, "Demodulated bit '%d' (level = %.0f dBm, quality = %%%.0f)\n", bit, level2db(level), quality * 100.0);
#endif
if (!am791x->rx_back_channel) {
@@ -416,12 +418,12 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level)
handle_rx_state(am791x);
} else
if (!(*block) && !(*cd) && level > am791x->cd_on && quality >= RX_QUALITY) {
PDEBUG(DDSP, DEBUG_DEBUG, "Good quality (level = %.0f dBm, quality = %%%.0f)\n", level2db(level), quality * 100.0);
LOGP(DDSP, LOGL_DEBUG, "Good quality (level = %.0f dBm, quality = %%%.0f)\n", level2db(level), quality * 100.0);
*cd = 1;
handle_rx_state(am791x);
} else
if (*cd && (level < am791x->cd_off || quality < RX_QUALITY)) {
PDEBUG(DDSP, DEBUG_DEBUG, "Bad quality (level = %.0f dBm, quality = %%%.0f)\n", level2db(level), quality * 100.0);
LOGP(DDSP, LOGL_DEBUG, "Bad quality (level = %.0f dBm, quality = %%%.0f)\n", level2db(level), quality * 100.0);
*cd = 0;
handle_rx_state(am791x);
}
@@ -437,24 +439,24 @@ static void fsk_receive_bit(void *inst, int bit, double quality, double level)
/* main channel forwards bit to RD */
if (!am791x->block_rd) {
#ifdef HEAVY_DEBUG
PDEBUG(DDSP, DEBUG_DEBUG, " -> Forwarding bit '%d' to MAIN channel\n", bit);
LOGP(DDSP, LOGL_DEBUG, " -> Forwarding bit '%d' to MAIN channel\n", bit);
#endif
am791x->rd_cb(am791x->inst, bit, quality * 100.0, level2db(level));
} else {
#ifdef HEAVY_DEBUG
PDEBUG(DDSP, DEBUG_DEBUG, " -> Forwarding bit '1' to MAIN channel, because RD is set to MARK\n");
LOGP(DDSP, LOGL_DEBUG, " -> Forwarding bit '1' to MAIN channel, because RD is set to MARK\n");
#endif
am791x->rd_cb(am791x->inst, 1, NAN, NAN);
}
/* main channel forwards bit to RD */
if (!am791x->block_brd) {
#ifdef HEAVY_DEBUG
PDEBUG(DDSP, DEBUG_DEBUG, " -> Forwarding bit '%d' to BACK channel\n", bit);
LOGP(DDSP, LOGL_DEBUG, " -> Forwarding bit '%d' to BACK channel\n", bit);
#endif
am791x->brd_cb(am791x->inst, bit, quality * 100.0, level2db(level));
} else {
#ifdef HEAVY_DEBUG
PDEBUG(DDSP, DEBUG_DEBUG, " -> Forwarding bit '1' to BACK channel, because BRD is set to MARK\n");
LOGP(DDSP, LOGL_DEBUG, " -> Forwarding bit '1' to BACK channel, because BRD is set to MARK\n");
#endif
am791x->brd_cb(am791x->inst, 1, NAN, NAN);
}
@@ -529,9 +531,9 @@ static void set_filters(am791x_t *am791x)
/* transmitter used */
if (f0_tx > 0 && am791x->f0_tx == 0) {
PDEBUG(DDSP, DEBUG_DEBUG, "Setting modulator to %s channel's frequencies (F0 = %d, F1 = %d), baudrate %.0f\n", name_tx, f0_tx, f1_tx, am791x->tx_baud);
LOGP(DDSP, LOGL_DEBUG, "Setting modulator to %s channel's frequencies (F0 = %d, F1 = %d), baudrate %.0f\n", name_tx, f0_tx, f1_tx, am791x->tx_baud);
if (fsk_mod_init(&am791x->fsk_tx, am791x, fsk_send_bit, am791x->samplerate, am791x->tx_baud, (double)f0_tx, (double)f1_tx, am791x->tx_level, 0, 1) < 0)
PDEBUG(DDSP, DEBUG_ERROR, "FSK RX init failed!\n");
LOGP(DDSP, LOGL_ERROR, "FSK RX init failed!\n");
else {
am791x->f0_tx = f0_tx;
am791x->f1_tx = f1_tx;
@@ -548,9 +550,9 @@ static void set_filters(am791x_t *am791x)
/* receiver used */
if (f0_rx > 0 && am791x->f0_rx == 0) {
PDEBUG(DDSP, DEBUG_DEBUG, "Setting demodulator to %s channel's frequencies (F0 = %d, F1 = %d), baudrate %.0f\n", name_rx, f0_rx, f1_rx, am791x->rx_baud);
LOGP(DDSP, LOGL_DEBUG, "Setting demodulator to %s channel's frequencies (F0 = %d, F1 = %d), baudrate %.0f\n", name_rx, f0_rx, f1_rx, am791x->rx_baud);
if (fsk_demod_init(&am791x->fsk_rx, am791x, fsk_receive_bit, am791x->samplerate, am791x->rx_baud, (double)f0_rx, (double)f1_rx, BIT_ADJUST) < 0)
PDEBUG(DDSP, DEBUG_ERROR, "FSK RX init failed!\n");
LOGP(DDSP, LOGL_ERROR, "FSK RX init failed!\n");
else {
am791x->f0_rx = f0_rx;
am791x->f1_rx = f1_rx;
@@ -562,14 +564,14 @@ static void set_filters(am791x_t *am791x)
static void new_tx_state(am791x_t *am791x, enum am791x_st state)
{
if (am791x->tx_state != state)
PDEBUG(DAM791X, DEBUG_DEBUG, "Change TX state %s -> %s\n", am791x_state_names[am791x->tx_state], am791x_state_names[state]);
LOGP(DAM791X, LOGL_DEBUG, "Change TX state %s -> %s\n", am791x_state_names[am791x->tx_state], am791x_state_names[state]);
am791x->tx_state = state;
}
static void new_rx_state(am791x_t *am791x, enum am791x_st state)
{
if (am791x->rx_state != state)
PDEBUG(DAM791X, DEBUG_DEBUG, "Change RX state %s -> %s\n", am791x_state_names[am791x->rx_state], am791x_state_names[state]);
LOGP(DAM791X, LOGL_DEBUG, "Change RX state %s -> %s\n", am791x_state_names[am791x->rx_state], am791x_state_names[state]);
am791x->rx_state = state;
}
@@ -577,7 +579,7 @@ static void new_rx_state(am791x_t *am791x, enum am791x_st state)
static void set_flag(int *flag_p, int value, const char *name)
{
if (*flag_p != value) {
PDEBUG(DAM791X, DEBUG_DEBUG, " -> %s\n", name);
LOGP(DAM791X, LOGL_DEBUG, " -> %s\n", name);
*flag_p = value;
}
}
@@ -588,7 +590,7 @@ static void set_flag(int *flag_p, int value, const char *name)
static void go_main_channel_tx(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Enable transmitter on main channel\n");
LOGP(DAM791X, LOGL_DEBUG, "Enable transmitter on main channel\n");
/* only block RD, if not full duplex and not 4-wire (loopback mode) */
if (!am791x->fullduplex && !am791x->loopback_main) {
@@ -599,7 +601,7 @@ static void go_main_channel_tx(am791x_t *am791x)
/* activate TD now and set CTS timer (RCON) */
set_flag(&am791x->block_td, 0, "TD RELEASED");
set_flag(&am791x->tx_silence, 0, "RESET SILENCE");
timer_start(&am791x->tx_timer, am791x->t_rcon);
osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_rcon));
new_tx_state(am791x, AM791X_STATE_RCON);
set_filters(am791x);
/* check CD to be blocked */
@@ -613,7 +615,7 @@ static void go_main_channel_tx(am791x_t *am791x)
static void rcon_release_rts(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "RTS was released\n");
LOGP(DAM791X, LOGL_DEBUG, "RTS was released\n");
set_flag(&am791x->block_td, 1, "TD IGNORED");
set_flag(&am791x->tx_silence, 1, "SET SILENCE");
@@ -629,7 +631,7 @@ static void rcon_release_rts(am791x_t *am791x)
static void rcon_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Transmission started\n");
LOGP(DAM791X, LOGL_DEBUG, "Transmission started\n");
new_tx_state(am791x, AM791X_STATE_DATA);
/* CTS on */
@@ -638,7 +640,7 @@ static void rcon_done(am791x_t *am791x)
static void tx_data_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "RTS was released\n");
LOGP(DAM791X, LOGL_DEBUG, "RTS was released\n");
new_tx_state(am791x, AM791X_STATE_RCOFF);
set_flag(&am791x->block_td, 1, "TD IGNORED");
@@ -650,12 +652,12 @@ static void tx_data_done(am791x_t *am791x)
if (!am791x->fullduplex) {
set_flag(&am791x->squelch, 1, "SET SQUELCH (ON)");
}
timer_start(&am791x->tx_timer, am791x->t_rcoff);
osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_rcoff));
}
static void rcoff_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Transmission over\n");
LOGP(DAM791X, LOGL_DEBUG, "Transmission over\n");
/* CTS off */
am791x->cts_cb(am791x->inst, 0);
@@ -665,17 +667,17 @@ static void rcoff_done(am791x_t *am791x)
return;
}
if (!am791x->sto) {
timer_start(&am791x->tx_timer, am791x->t_sq - am791x->t_rcoff);
osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_sq - am791x->t_rcoff));
new_tx_state(am791x, AM791X_STATE_SQ_OFF);
return;
}
timer_start(&am791x->tx_timer, am791x->t_sto - am791x->t_rcoff);
osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_sto - am791x->t_rcoff));
new_tx_state(am791x, AM791X_STATE_STO_OFF);
}
static void sq_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Squelch over\n");
LOGP(DAM791X, LOGL_DEBUG, "Squelch over\n");
set_flag(&am791x->block_cd, 0, "CD RELEASED");
new_tx_state(am791x, AM791X_STATE_INIT);
@@ -690,16 +692,16 @@ static void sq_done(am791x_t *am791x)
static void sto_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "STO over\n");
LOGP(DAM791X, LOGL_DEBUG, "STO over\n");
set_flag(&am791x->tx_sto, 0, "stop STO");
timer_start(&am791x->tx_timer, am791x->t_sq - am791x->t_sto);
osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_sq - am791x->t_sto));
new_tx_state(am791x, AM791X_STATE_SQ_OFF);
}
static void go_back_channel_tx(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Enable transmitter on back channel\n");
LOGP(DAM791X, LOGL_DEBUG, "Enable transmitter on back channel\n");
if (!am791x->loopback_back) {
set_flag(&am791x->block_brd, 1, "BRD = MARK");
@@ -709,7 +711,7 @@ static void go_back_channel_tx(am791x_t *am791x)
/* activate BTD now and set BCTS timer (BRCON) */
set_flag(&am791x->block_btd, 0, "BTD RELEASED");
set_flag(&am791x->tx_silence, 0, "RESET SILENCE");
timer_start(&am791x->tx_timer, am791x->t_brcon);
osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_brcon));
new_tx_state(am791x, AM791X_STATE_BRCON);
set_filters(am791x);
/* check BCD to be blocked */
@@ -723,7 +725,7 @@ static void go_back_channel_tx(am791x_t *am791x)
static void brcon_release_brts(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "BRTS was released\n");
LOGP(DAM791X, LOGL_DEBUG, "BRTS was released\n");
set_flag(&am791x->tx_silence, 1, "SET SILENCE");
new_tx_state(am791x, AM791X_STATE_INIT);
@@ -732,7 +734,7 @@ static void brcon_release_brts(am791x_t *am791x)
static void brcon_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Transmission started\n");
LOGP(DAM791X, LOGL_DEBUG, "Transmission started\n");
new_tx_state(am791x, AM791X_STATE_BDATA);
/* BCTS on */
@@ -741,16 +743,16 @@ static void brcon_done(am791x_t *am791x)
static void tx_bdata_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "BRTS was released\n");
LOGP(DAM791X, LOGL_DEBUG, "BRTS was released\n");
set_flag(&am791x->block_btd, 1, "BTD IGNORED");
set_flag(&am791x->tx_silence, 1, "SET SILENCE");
timer_start(&am791x->tx_timer, am791x->t_brcoff);
osmo_timer_schedule(&am791x->tx_timer, FLOAT_TO_TIMEOUT(am791x->t_brcoff));
}
static void brcoff_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Transmission over\n");
LOGP(DAM791X, LOGL_DEBUG, "Transmission over\n");
/* BCTS off */
am791x->bcts_cb(am791x->inst, 0);
@@ -791,7 +793,7 @@ static void handle_tx_state(am791x_t *am791x)
rcon_release_rts(am791x);
break;
}
if (!timer_running(&am791x->tx_timer)) {
if (!osmo_timer_pending(&am791x->tx_timer)) {
rcon_done(am791x);
break;
}
@@ -803,19 +805,19 @@ static void handle_tx_state(am791x_t *am791x)
}
break;
case AM791X_STATE_RCOFF:
if (!timer_running(&am791x->tx_timer)) {
if (!osmo_timer_pending(&am791x->tx_timer)) {
rcoff_done(am791x);
break;
}
break;
case AM791X_STATE_STO_OFF:
if (!timer_running(&am791x->tx_timer)) {
if (!osmo_timer_pending(&am791x->tx_timer)) {
sto_done(am791x);
break;
}
break;
case AM791X_STATE_SQ_OFF:
if (!timer_running(&am791x->tx_timer)) {
if (!osmo_timer_pending(&am791x->tx_timer)) {
sq_done(am791x);
break;
}
@@ -826,7 +828,7 @@ static void handle_tx_state(am791x_t *am791x)
brcon_release_brts(am791x);
break;
}
if (!timer_running(&am791x->tx_timer)) {
if (!osmo_timer_pending(&am791x->tx_timer)) {
brcon_done(am791x);
break;
}
@@ -838,27 +840,27 @@ static void handle_tx_state(am791x_t *am791x)
}
break;
case AM791X_STATE_BRCOFF:
if (!timer_running(&am791x->tx_timer)) {
if (!osmo_timer_pending(&am791x->tx_timer)) {
brcoff_done(am791x);
break;
}
break;
default:
PDEBUG(DAM791X, DEBUG_ERROR, "State %s not handled!\n", am791x_state_names[am791x->rx_state]);
LOGP(DAM791X, LOGL_ERROR, "State %s not handled!\n", am791x_state_names[am791x->rx_state]);
}
}
static void go_main_channel_rx(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Enable receiver on main channel\n");
LOGP(DAM791X, LOGL_DEBUG, "Enable receiver on main channel\n");
timer_start(&am791x->rx_timer, am791x->t_cdon);
osmo_timer_schedule(&am791x->rx_timer, FLOAT_TO_TIMEOUT(am791x->t_cdon));
new_rx_state(am791x, AM791X_STATE_CDON);
}
static void cdon_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Reception started\n");
LOGP(DAM791X, LOGL_DEBUG, "Reception started\n");
set_flag(&am791x->block_rd, 0, "RD RELEASED");
new_rx_state(am791x, AM791X_STATE_DATA);
@@ -872,23 +874,23 @@ static void cdon_done(am791x_t *am791x)
static void cdon_no_cd(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier is gone\n");
LOGP(DAM791X, LOGL_DEBUG, "Carrier is gone\n");
timer_stop(&am791x->rx_timer);
osmo_timer_del(&am791x->rx_timer);
new_rx_state(am791x, AM791X_STATE_INIT);
}
static void rx_data_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier lost\n");
LOGP(DAM791X, LOGL_DEBUG, "Carrier lost\n");
timer_start(&am791x->rx_timer, am791x->t_cdoff);
osmo_timer_schedule(&am791x->rx_timer, FLOAT_TO_TIMEOUT(am791x->t_cdoff));
new_rx_state(am791x, AM791X_STATE_CDOFF);
}
static void cdoff_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Reception finished\n");
LOGP(DAM791X, LOGL_DEBUG, "Reception finished\n");
set_flag(&am791x->block_rd, 1, "RD = MARK");
new_rx_state(am791x, AM791X_STATE_INIT);
@@ -902,23 +904,23 @@ static void cdoff_done(am791x_t *am791x)
static void cdoff_cd(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier recovered\n");
LOGP(DAM791X, LOGL_DEBUG, "Carrier recovered\n");
timer_stop(&am791x->rx_timer);
osmo_timer_del(&am791x->rx_timer);
new_rx_state(am791x, AM791X_STATE_DATA);
}
static void go_back_channel_rx(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Enable receiver on back channel\n");
LOGP(DAM791X, LOGL_DEBUG, "Enable receiver on back channel\n");
timer_start(&am791x->rx_timer, am791x->t_bcdon);
osmo_timer_schedule(&am791x->rx_timer, FLOAT_TO_TIMEOUT(am791x->t_bcdon));
new_rx_state(am791x, AM791X_STATE_BCDON);
}
static void bcdon_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier was detected\n");
LOGP(DAM791X, LOGL_DEBUG, "Carrier was detected\n");
set_flag(&am791x->block_brd, 0, "BRD RELEASED");
new_rx_state(am791x, AM791X_STATE_BDATA);
@@ -932,23 +934,23 @@ static void bcdon_done(am791x_t *am791x)
static void bcdon_no_cd(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier is gone\n");
LOGP(DAM791X, LOGL_DEBUG, "Carrier is gone\n");
timer_stop(&am791x->rx_timer);
osmo_timer_del(&am791x->rx_timer);
new_rx_state(am791x, AM791X_STATE_INIT);
}
static void rx_bdata_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier lost\n");
LOGP(DAM791X, LOGL_DEBUG, "Carrier lost\n");
timer_start(&am791x->rx_timer, am791x->t_bcdoff);
osmo_timer_schedule(&am791x->rx_timer, FLOAT_TO_TIMEOUT(am791x->t_bcdoff));
new_rx_state(am791x, AM791X_STATE_BCDOFF);
}
static void bcdoff_done(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Reception finished\n");
LOGP(DAM791X, LOGL_DEBUG, "Reception finished\n");
if (!am791x->bell_202)
set_flag(&am791x->block_brd, 1, "BRD = MARK");
@@ -963,9 +965,9 @@ static void bcdoff_done(am791x_t *am791x)
static void bcdoff_cd(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Carrier recovered\n");
LOGP(DAM791X, LOGL_DEBUG, "Carrier recovered\n");
timer_stop(&am791x->rx_timer);
osmo_timer_del(&am791x->rx_timer);
new_rx_state(am791x, AM791X_STATE_BDATA);
}
@@ -992,7 +994,7 @@ static void handle_rx_state(am791x_t *am791x)
break;
/* all main channel states ... */
case AM791X_STATE_CDON:
if (!timer_running(&am791x->rx_timer)) {
if (!osmo_timer_pending(&am791x->rx_timer)) {
cdon_done(am791x);
break;
}
@@ -1008,7 +1010,7 @@ static void handle_rx_state(am791x_t *am791x)
}
break;
case AM791X_STATE_CDOFF:
if (!timer_running(&am791x->rx_timer)) {
if (!osmo_timer_pending(&am791x->rx_timer)) {
cdoff_done(am791x);
break;
}
@@ -1019,7 +1021,7 @@ static void handle_rx_state(am791x_t *am791x)
break;
/* all back channel states ... */
case AM791X_STATE_BCDON:
if (!timer_running(&am791x->rx_timer)) {
if (!osmo_timer_pending(&am791x->rx_timer)) {
bcdon_done(am791x);
break;
}
@@ -1035,7 +1037,7 @@ static void handle_rx_state(am791x_t *am791x)
}
break;
case AM791X_STATE_BCDOFF:
if (!timer_running(&am791x->rx_timer)) {
if (!osmo_timer_pending(&am791x->rx_timer)) {
bcdoff_done(am791x);
break;
}
@@ -1045,7 +1047,7 @@ static void handle_rx_state(am791x_t *am791x)
}
break;
default:
PDEBUG(DAM791X, DEBUG_ERROR, "State %s not handled!\n", am791x_state_names[am791x->rx_state]);
LOGP(DAM791X, LOGL_ERROR, "State %s not handled!\n", am791x_state_names[am791x->rx_state]);
}
}
@@ -1086,10 +1088,10 @@ int am791x_init(am791x_t *am791x, void *inst, enum am791x_type type, uint8_t mc,
memset(am791x, 0, sizeof(*am791x));
/* init timers */
timer_init(&am791x->tx_timer, tx_timeout, am791x);
timer_init(&am791x->rx_timer, rx_timeout, am791x);
osmo_timer_setup(&am791x->tx_timer, tx_timeout, am791x);
osmo_timer_setup(&am791x->rx_timer, rx_timeout, am791x);
PDEBUG(DAM791X, DEBUG_DEBUG, "Initializing instance of AM791%d:\n", type);
LOGP(DAM791X, LOGL_DEBUG, "Initializing instance of AM791%d:\n", type);
am791x->inst = inst;
am791x->type = type;
@@ -1119,13 +1121,13 @@ int am791x_init(am791x_t *am791x, void *inst, enum am791x_type type, uint8_t mc,
/* exit routine, must be called when exit */
void am791x_exit(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Exit instance of AM791%d:\n", am791x->type);
LOGP(DAM791X, LOGL_DEBUG, "Exit instance of AM791%d:\n", am791x->type);
/* bring to reset state, be sure to clean FSK processes */
am791x_reset(am791x);
timer_exit(&am791x->tx_timer);
timer_exit(&am791x->rx_timer);
osmo_timer_del(&am791x->tx_timer);
osmo_timer_del(&am791x->rx_timer);
}
/* get some default baud rate for each mode, before IOCTL sets it (if it sets it) */
@@ -1149,8 +1151,8 @@ int am791x_mc(am791x_t *am791x, uint8_t mc, int samplerate, double tx_baud, doub
if (!((am791x->type) ? am791x_modes[mc].sup_7911 : am791x_modes[mc].sup_7910))
rc = -EINVAL;
PDEBUG(DAM791X, DEBUG_INFO, "Setting mode %d: %s\n", mc, am791x_modes[mc].description);
PDEBUG(DAM791X, DEBUG_DEBUG, " -> Baud rate: %.1f/%.1f\n", rx_baud, tx_baud);
LOGP(DAM791X, LOGL_INFO, "Setting mode %d: %s\n", mc, am791x_modes[mc].description);
LOGP(DAM791X, LOGL_DEBUG, " -> Baud rate: %.1f/%.1f\n", rx_baud, tx_baud);
am791x->mc = mc;
am791x->samplerate = samplerate;
@@ -1187,10 +1189,10 @@ int am791x_mc(am791x_t *am791x, uint8_t mc, int samplerate, double tx_baud, doub
/* reset at any time, may be called any time by upper layer */
void am791x_reset(am791x_t *am791x)
{
PDEBUG(DAM791X, DEBUG_INFO, "Reset!\n");
LOGP(DAM791X, LOGL_INFO, "Reset!\n");
timer_stop(&am791x->tx_timer);
timer_stop(&am791x->rx_timer);
osmo_timer_del(&am791x->tx_timer);
osmo_timer_del(&am791x->rx_timer);
if (am791x->f0_tx) {
fsk_mod_cleanup(&am791x->fsk_tx);
@@ -1228,7 +1230,7 @@ void am791x_reset(am791x_t *am791x)
/* change input lines */
void am791x_dtr(am791x_t *am791x, int dtr)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Terminal is%s ready!\n", (dtr) ? "" : " not");
LOGP(DAM791X, LOGL_DEBUG, "Terminal is%s ready!\n", (dtr) ? "" : " not");
/* set filters, if DTR becomes on */
if (!am791x->line_dtr && dtr) {
@@ -1242,7 +1244,7 @@ void am791x_dtr(am791x_t *am791x, int dtr)
void am791x_rts(am791x_t *am791x, int rts)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Terminal %s RTS.\n", (rts) ? "sets" : "clears");
LOGP(DAM791X, LOGL_DEBUG, "Terminal %s RTS.\n", (rts) ? "sets" : "clears");
am791x->line_rts = rts;
handle_state(am791x);
@@ -1250,7 +1252,7 @@ void am791x_rts(am791x_t *am791x, int rts)
void am791x_brts(am791x_t *am791x, int rts)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Terminal %s BRTS.\n", (rts) ? "sets" : "clears");
LOGP(DAM791X, LOGL_DEBUG, "Terminal %s BRTS.\n", (rts) ? "sets" : "clears");
am791x->line_brts = rts;
handle_state(am791x);
@@ -1258,7 +1260,7 @@ void am791x_brts(am791x_t *am791x, int rts)
void am791x_ring(am791x_t *am791x, int ring)
{
PDEBUG(DAM791X, DEBUG_DEBUG, "Terminal %s RING.\n", (ring) ? "sets" : "clears");
LOGP(DAM791X, LOGL_DEBUG, "Terminal %s RING.\n", (ring) ? "sets" : "clears");
am791x->line_ring = ring;
handle_state(am791x);

View File

@@ -67,7 +67,7 @@ typedef struct am791x {
int f0_rx, f1_rx;
/* timers */
struct timer tx_timer, rx_timer;
struct osmo_timer_list tx_timer, rx_timer;
double t_rcon;
double t_rcoff;
double t_brcon;

View File

@@ -32,12 +32,14 @@
#include <fcntl.h>
#include <math.h>
#include "../libsample/sample.h"
#include "../libtimer/timer.h"
#include <osmocom/core/select.h>
#include <osmocom/core/timer.h>
#include "../libfsk/fsk.h"
#include "../libsound/sound.h"
#include "../libwave/wave.h"
#include "../libdisplay/display.h"
#include "../libdebug/debug.h"
#include "../liblogging/logging.h"
#include "../libmobile/get_time.c"
#include "device.h"
#include "am791x.h"
#include "uart.h"
@@ -217,7 +219,7 @@ static void cts(void *inst, int cts)
return;
if (datenklo->auto_rts) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Received CTS=%d in Automatic RTS Mode.\n", cts);
LOGP(DDATENKLO, LOGL_INFO, "Received CTS=%d in Automatic RTS Mode.\n", cts);
datenklo->auto_rts_cts = cts;
return;
}
@@ -226,7 +228,7 @@ static void cts(void *inst, int cts)
datenklo->lines |= TIOCM_CTS;
else
datenklo->lines &= ~TIOCM_CTS;
PDEBUG(DDATENKLO, DEBUG_INFO, "Indicating to terminal that CTS is %s\n", (cts) ? "on" : "off");
LOGP(DDATENKLO, LOGL_INFO, "Indicating to terminal that CTS is %s\n", (cts) ? "on" : "off");
}
/* modem changes CTS state (back channel) */
@@ -238,7 +240,7 @@ static void bcts(void *inst, int cts)
return;
if (datenklo->auto_rts) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Received BCTS=%d in Automatic RTS Mode.\n", cts);
LOGP(DDATENKLO, LOGL_INFO, "Received BCTS=%d in Automatic RTS Mode.\n", cts);
datenklo->auto_rts_cts = cts;
return;
}
@@ -247,7 +249,7 @@ static void bcts(void *inst, int cts)
datenklo->lines |= TIOCM_CTS;
else
datenklo->lines &= ~TIOCM_CTS;
PDEBUG(DDATENKLO, DEBUG_INFO, "Indicating to terminal that BCTS is %s\n", (cts) ? "on" : "off");
LOGP(DDATENKLO, LOGL_INFO, "Indicating to terminal that BCTS is %s\n", (cts) ? "on" : "off");
}
/* modem changes CD state */
@@ -259,7 +261,7 @@ static void cd(void *inst, int cd)
return;
if (datenklo->auto_rts) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Received CD=%d in Automatic RTS Mode.\n", cd);
LOGP(DDATENKLO, LOGL_INFO, "Received CD=%d in Automatic RTS Mode.\n", cd);
datenklo->auto_rts_cd = cd;
return;
}
@@ -268,7 +270,7 @@ static void cd(void *inst, int cd)
datenklo->lines |= TIOCM_CD;
else
datenklo->lines &= ~TIOCM_CD;
PDEBUG(DDATENKLO, DEBUG_INFO, "Indicating to terminal that CD is %s\n", (cd) ? "on" : "off");
LOGP(DDATENKLO, LOGL_INFO, "Indicating to terminal that CD is %s\n", (cd) ? "on" : "off");
}
/* modem changes CD state (back channel) */
@@ -280,7 +282,7 @@ static void bcd(void *inst, int cd)
return;
if (datenklo->auto_rts) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Received BCD=%d in Automatic RTS Mode.\n", cd);
LOGP(DDATENKLO, LOGL_INFO, "Received BCD=%d in Automatic RTS Mode.\n", cd);
datenklo->auto_rts_cd = cd;
return;
}
@@ -289,7 +291,7 @@ static void bcd(void *inst, int cd)
datenklo->lines |= TIOCM_CD;
else
datenklo->lines &= ~TIOCM_CD;
PDEBUG(DDATENKLO, DEBUG_INFO, "Indicating to terminal that BCD is %s\n", (cd) ? "on" : "off");
LOGP(DDATENKLO, LOGL_INFO, "Indicating to terminal that BCD is %s\n", (cd) ? "on" : "off");
}
/* modem request bit */
@@ -405,7 +407,7 @@ static int tx(void *inst)
if (datenklo->onlcr_char) {
datenklo->onlcr_char = 0;
data = '\n';
PDEBUG(DDATENKLO, DEBUG_DEBUG, "ONLCR: sending NL\n");
LOGP(DDATENKLO, LOGL_DEBUG, "ONLCR: sending NL\n");
goto out;
}
@@ -414,7 +416,7 @@ again:
if (fill == (size_t)datenklo->tx_fifo_full) {
/* tell cuse to write again */
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Set POLLOUT!\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Set POLLOUT!\n");
datenklo->revents |= POLLOUT;
device_set_poll_events(datenklo->device, datenklo->revents);
}
@@ -424,12 +426,12 @@ again:
datenklo->auto_rts_on = 0;
if (datenklo->tcsetsw) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Transmission finished, applying termios now.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Transmission finished, applying termios now.\n");
memcpy(&datenklo->termios, &datenklo->tcsetsw_termios, sizeof(datenklo->termios));
if (datenklo->tcsetsw == 2) {
flush_rx(datenklo);
if ((datenklo->revents & POLLIN)) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Reset POLLIN (flushed)\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Reset POLLIN (flushed)\n");
datenklo->revents &= ~POLLIN;
device_set_poll_events(datenklo->device, datenklo->revents);
}
@@ -450,26 +452,26 @@ again:
/* process output features */
if (datenklo->opost) {
if (datenklo->olcuc) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "OLCUC: 0x%02x -> 0x%02x\n", data, toupper(data));
LOGP(DDATENKLO, LOGL_DEBUG, "OLCUC: 0x%02x -> 0x%02x\n", data, toupper(data));
data = toupper(data);
}
if (datenklo->onlret && data == '\r') {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "ONLRET: ignore CR\n");
LOGP(DDATENKLO, LOGL_DEBUG, "ONLRET: ignore CR\n");
goto again;
}
if (datenklo->ocrnl && data == '\r') {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "OCRNL: CR -> NL\n");
LOGP(DDATENKLO, LOGL_DEBUG, "OCRNL: CR -> NL\n");
data = '\n';
}
if (datenklo->onlcr && data == '\n') {
datenklo->onlcr_char = 1;
data = '\r';
PDEBUG(DDATENKLO, DEBUG_DEBUG, "ONLCR: sending CR\n");
LOGP(DDATENKLO, LOGL_DEBUG, "ONLCR: sending CR\n");
}
}
out:
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Transmitting byte 0x%02x to UART.\n", data);
LOGP(DDATENKLO, LOGL_DEBUG, "Transmitting byte 0x%02x to UART.\n", data);
return data;
}
@@ -480,35 +482,35 @@ static void rx(void *inst, int data, uint32_t __attribute__((unused)) flags)
datenklo_t *datenklo = (datenklo_t *)inst;
size_t space;
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Received byte 0x%02x ('%c') from UART.\n", data, (data >= 32 && data <= 126) ? data : '.');
LOGP(DDATENKLO, LOGL_DEBUG, "Received byte 0x%02x ('%c') from UART.\n", data, (data >= 32 && data <= 126) ? data : '.');
/* process input features */
if (datenklo->ignbrk && (flags & UART_BREAK)) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "IGNBRK: ignore BREAK\n");
LOGP(DDATENKLO, LOGL_DEBUG, "IGNBRK: ignore BREAK\n");
return;
}
if (datenklo->istrip && (data & 0x80)) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "ISTRIP: 0x%02x -> 0x%02x\n", data, data & 0x7f);
LOGP(DDATENKLO, LOGL_DEBUG, "ISTRIP: 0x%02x -> 0x%02x\n", data, data & 0x7f);
data &= 0x7f;
}
if (datenklo->inlcr && data == '\n') {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "INLCR: NL -> CR\n");
LOGP(DDATENKLO, LOGL_DEBUG, "INLCR: NL -> CR\n");
data = '\r';
}
if (datenklo->igncr && data == '\r') {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "IGNCR: ignore CR\n");
LOGP(DDATENKLO, LOGL_DEBUG, "IGNCR: ignore CR\n");
return;
}
if (datenklo->icrnl && data == '\r') {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "ICRNL: CR -> NL\n");
LOGP(DDATENKLO, LOGL_DEBUG, "ICRNL: CR -> NL\n");
data = '\n';
}
if (datenklo->iuclc) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "IUCLC: 0x%02x -> 0x%02x\n", data, tolower(data));
LOGP(DDATENKLO, LOGL_DEBUG, "IUCLC: 0x%02x -> 0x%02x\n", data, tolower(data));
data = tolower(data);
}
if (datenklo->echo) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "ECHO: write to output\n");
LOGP(DDATENKLO, LOGL_DEBUG, "ECHO: write to output\n");
space = (datenklo->tx_fifo_out - datenklo->tx_fifo_in - 1 + datenklo->tx_fifo_size) % datenklo->tx_fifo_size;
if (space) {
datenklo->tx_fifo[datenklo->tx_fifo_in++] = data;
@@ -519,7 +521,7 @@ static void rx(void *inst, int data, uint32_t __attribute__((unused)) flags)
/* empty buffer gets data */
if (datenklo->rx_fifo_out == datenklo->rx_fifo_in) {
/* tell cuse to read again */
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Set POLLIN!\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Set POLLIN!\n");
datenklo->revents |= POLLIN;
device_set_poll_events(datenklo->device, datenklo->revents);
}
@@ -528,13 +530,13 @@ static void rx(void *inst, int data, uint32_t __attribute__((unused)) flags)
if (!space) {
err_overflow:
PDEBUG(DDATENKLO, DEBUG_NOTICE, "RX buffer overflow, dropping!\n");
LOGP(DDATENKLO, LOGL_NOTICE, "RX buffer overflow, dropping!\n");
return;
}
if (datenklo->parmrk) {
if ((flags & (UART_BREAK | UART_PARITY_ERROR))) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "PARMRK: 0x%02x -> 0xff,0x00,0x%02x\n", data, data);
LOGP(DDATENKLO, LOGL_DEBUG, "PARMRK: 0x%02x -> 0xff,0x00,0x%02x\n", data, data);
if (space < 3)
goto err_overflow;
datenklo->rx_fifo[datenklo->rx_fifo_in++] = 0xff;
@@ -544,7 +546,7 @@ static void rx(void *inst, int data, uint32_t __attribute__((unused)) flags)
datenklo->rx_fifo_in %= datenklo->rx_fifo_size;
space--;
} else if (data == 0xff) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "PARMRK: 0xff -> 0xff,0xff\n");
LOGP(DDATENKLO, LOGL_DEBUG, "PARMRK: 0xff -> 0xff,0xff\n");
if (space < 2)
goto err_overflow;
datenklo->rx_fifo[datenklo->rx_fifo_in++] = 0xff;
@@ -567,18 +569,18 @@ static void set_lines(datenklo_t *datenklo, int new)
int old = datenklo->lines;
if (!(old & TIOCM_DTR) && (new & TIOCM_DTR)) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal turns DTR on\n");
LOGP(DDATENKLO, LOGL_INFO, "Terminal turns DTR on\n");
flush_tx(datenklo);
flush_rx(datenklo);
am791x_dtr(&datenklo->am791x, 1);
}
if ((old & TIOCM_DTR) && !(new & TIOCM_DTR)) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal turns DTR off\n");
LOGP(DDATENKLO, LOGL_INFO, "Terminal turns DTR off\n");
am791x_dtr(&datenklo->am791x, 0);
}
if (!(old & TIOCM_RTS) && (new & TIOCM_RTS)) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal turns RTS on\n");
LOGP(DDATENKLO, LOGL_INFO, "Terminal turns RTS on\n");
if (datenklo->auto_rts)
new |= TIOCM_CTS | TIOCM_CD;
else {
@@ -589,7 +591,7 @@ static void set_lines(datenklo_t *datenklo, int new)
}
}
if ((old & TIOCM_RTS) && !(new & TIOCM_RTS)) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal turns RTS off\n");
LOGP(DDATENKLO, LOGL_INFO, "Terminal turns RTS off\n");
if (datenklo->auto_rts)
new &= ~(TIOCM_CTS | TIOCM_CD);
else {
@@ -609,7 +611,7 @@ static void process_auto_rts(datenklo_t *datenklo)
if (!datenklo->auto_rts)
return;
if (datenklo->auto_rts_on && !datenklo->auto_rts_rts && !datenklo->auto_rts_cd) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Automatically raising RTS.\n");
LOGP(DDATENKLO, LOGL_INFO, "Automatically raising RTS.\n");
datenklo->auto_rts_rts = 1;
if (!datenklo->tx_back)
am791x_rts(&datenklo->am791x, 1);
@@ -617,7 +619,7 @@ static void process_auto_rts(datenklo_t *datenklo)
am791x_brts(&datenklo->am791x, 1);
}
if (!datenklo->auto_rts_on && datenklo->auto_rts_rts) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Automatically dropping RTS.\n");
LOGP(DDATENKLO, LOGL_INFO, "Automatically dropping RTS.\n");
datenklo->auto_rts_rts = 0;
if (!datenklo->tx_back)
am791x_rts(&datenklo->am791x, 0);
@@ -634,7 +636,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz)
ssize_t rc = 0;
#ifdef HEAVY_DEBUG
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Device has been read for ioctl (cmd = %d, size = %zu).\n", cmd, out_bufsz);
LOGP(DDATENKLO, LOGL_DEBUG, "Device has been read for ioctl (cmd = %d, size = %zu).\n", cmd, out_bufsz);
#endif
switch (cmd) {
@@ -643,7 +645,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz)
if (!out_bufsz)
break;
#ifdef HEAVY_DEBUG
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests termios.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests termios.\n");
#endif
memcpy(buf, &datenklo->termios, rc);
break;
@@ -652,7 +654,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz)
if (!out_bufsz)
break;
#ifdef HEAVY_DEBUG
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests line states.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests line states.\n");
#endif
status = datenklo->lines | TIOCM_LE | TIOCM_DSR;
memcpy(buf, &status, rc);
@@ -662,7 +664,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz)
if (!out_bufsz)
break;
#ifdef HEAVY_DEBUG
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests window size.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests window size.\n");
#endif
struct winsize *winsize = (struct winsize *)buf;
winsize->ws_row = 25;
@@ -677,7 +679,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz)
status = (datenklo->rx_fifo_in - datenklo->rx_fifo_out + datenklo->rx_fifo_size) % datenklo->rx_fifo_size;
memcpy(buf, &status, rc);
#ifdef HEAVY_DEBUG
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests RX buffer fill states.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests RX buffer fill states.\n");
#endif
break;
case TIOCOUTQ:
@@ -685,7 +687,7 @@ static ssize_t dk_ioctl_get(void *inst, int cmd, void *buf, size_t out_bufsz)
if (!out_bufsz)
break;
#ifdef HEAVY_DEBUG
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal requests TX buffer fill states.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal requests TX buffer fill states.\n");
#endif
status = (datenklo->tx_fifo_in - datenklo->tx_fifo_out + datenklo->tx_fifo_size) % datenklo->tx_fifo_size;
memcpy(buf, &status, rc);
@@ -786,15 +788,15 @@ static void set_termios(datenklo_t *datenklo, const void *buf)
new_echo = !!(datenklo->termios.c_lflag & ECHO);
if (old_baud != new_baud && (!datenklo->force_tx_baud || !datenklo->force_rx_baud)) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal changes baud rate to %.1f Baud.\n", new_baud);
LOGP(DDATENKLO, LOGL_INFO, "Terminal changes baud rate to %.1f Baud.\n", new_baud);
if ((datenklo->lines & TIOCM_DTR) && !new_baud) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Baudrate is set to 0, we drop DTR\n");
LOGP(DDATENKLO, LOGL_INFO, "Baudrate is set to 0, we drop DTR\n");
am791x_dtr(&datenklo->am791x, 0);
}
datenklo->baudrate = new_baud;
am791x_mc(&datenklo->am791x, datenklo->mc, datenklo->samplerate, tx_baud_rate(datenklo), rx_baud_rate(datenklo));
if ((datenklo->lines & TIOCM_DTR) && !old_baud) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Baudrate is set from 0, we raise DTR\n");
LOGP(DDATENKLO, LOGL_INFO, "Baudrate is set from 0, we raise DTR\n");
am791x_dtr(&datenklo->am791x, 1);
}
}
@@ -802,10 +804,10 @@ static void set_termios(datenklo_t *datenklo, const void *buf)
if (old_databits != new_databits
|| old_parity != new_parity
|| old_stopbits != new_stopbits) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal changes serial mode to %d%c%d.\n", cflag2databits(datenklo->termios.c_cflag), parity2char(cflag2parity(datenklo->termios.c_cflag)), cflag2stopbits(datenklo->termios.c_cflag));
LOGP(DDATENKLO, LOGL_INFO, "Terminal changes serial mode to %d%c%d.\n", cflag2databits(datenklo->termios.c_cflag), parity2char(cflag2parity(datenklo->termios.c_cflag)), cflag2stopbits(datenklo->termios.c_cflag));
rc = uart_init(&datenklo->uart, datenklo, cflag2databits(datenklo->termios.c_cflag), cflag2parity(datenklo->termios.c_cflag), cflag2stopbits(datenklo->termios.c_cflag), tx, rx);
if (rc < 0)
PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to initialize UART.\n");
LOGP(DDATENKLO, LOGL_ERROR, "Failed to initialize UART.\n");
}
if (old_stopbits != new_stopbits
@@ -835,8 +837,8 @@ static void set_termios(datenklo_t *datenklo, const void *buf)
datenklo->onlret = new_onlret;
datenklo->olcuc = new_olcuc;
datenklo->echo = new_echo;
PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal sets serial flags:\n");
PDEBUG(DDATENKLO, DEBUG_INFO, "%cignbrk %cparmrk %cistrip %cinlcr %cigncr %cicrnl %ciuclc %copost %conlcr %cocrnl %conlret %colcuc %cecho\n",
LOGP(DDATENKLO, LOGL_INFO, "Terminal sets serial flags:\n");
LOGP(DDATENKLO, LOGL_INFO, "%cignbrk %cparmrk %cistrip %cinlcr %cigncr %cicrnl %ciuclc %copost %conlcr %cocrnl %conlret %colcuc %cecho\n",
(datenklo->ignbrk) ? '+' : '-',
(datenklo->parmrk) ? '+' : '-',
(datenklo->istrip) ? '+' : '-',
@@ -862,7 +864,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
size_t space;
#ifdef HEAVY_DEBUG
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Device has been written for ioctl (cmd = %d, size = %zu).\n", cmd, in_bufsz);
LOGP(DDATENKLO, LOGL_DEBUG, "Device has been written for ioctl (cmd = %d, size = %zu).\n", cmd, in_bufsz);
#endif
switch (cmd) {
@@ -870,7 +872,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
rc = sizeof(datenklo->termios);
if (!in_bufsz)
break;
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sets termios now.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sets termios now.\n");
set_termios(datenklo, buf);
break;
case TCSETSW:
@@ -878,9 +880,9 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
rc = sizeof(datenklo->termios);
if (!in_bufsz)
break;
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sets termios after draining output buffer.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sets termios after draining output buffer.\n");
if (1 || datenklo->tx_fifo_out == datenklo->tx_fifo_in) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Output buffer empty, applying termios now.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Output buffer empty, applying termios now.\n");
set_termios(datenklo, buf);
break;
}
@@ -895,12 +897,12 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
if (!in_bufsz)
break;
memcpy(&status, buf, rc);
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal flushes buffer (status = %d).\n", status);
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal flushes buffer (status = %d).\n", status);
if (status == TCIOFLUSH || status == TCOFLUSH) {
flush_tx(datenklo);
if (!(datenklo->revents & POLLOUT)) {
/* tell cuse to write again */
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Set POLLOUT (flushed)\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Set POLLOUT (flushed)\n");
datenklo->revents |= POLLOUT;
device_set_poll_events(datenklo->device, datenklo->revents);
}
@@ -908,7 +910,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
if (status == TCIOFLUSH || status == TCIFLUSH) {
flush_rx(datenklo);
if ((datenklo->revents & POLLIN)) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Reset POLLIN (flushed)\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Reset POLLIN (flushed)\n");
datenklo->revents &= ~POLLIN;
device_set_poll_events(datenklo->device, datenklo->revents);
}
@@ -916,7 +918,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
break;
case TCSBRK:
rc = 0;
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sends break\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sends break\n");
datenklo->break_bits = tx_baud_rate(datenklo) * 3 / 10;
break;
case TCSBRKP:
@@ -924,7 +926,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
if (!in_bufsz)
break;
memcpy(&status, buf, rc);
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sends break (duration = %d).\n", status);
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sends break (duration = %d).\n", status);
if (status == 0)
status = 3;
if (status > 30)
@@ -933,12 +935,12 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
break;
case TIOCSBRK:
rc = 0;
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns break on\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns break on\n");
datenklo->break_on = 1;
break;
case TIOCCBRK:
rc = 0;
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns break off\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns break off\n");
datenklo->break_on = 0;
break;
case TIOCMBIS:
@@ -946,7 +948,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
if (!in_bufsz)
break;
memcpy(&status, buf, rc);
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sets line status (0x%x).\n", status);
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sets line status (0x%x).\n", status);
status = datenklo->lines | status;
set_lines(datenklo, status);
break;
@@ -955,7 +957,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
if (!in_bufsz)
break;
memcpy(&status, buf, rc);
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal clears line status (0x%x).\n", status);
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal clears line status (0x%x).\n", status);
status = datenklo->lines & ~status;
set_lines(datenklo, status);
break;
@@ -964,30 +966,30 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
if (!in_bufsz)
break;
memcpy(&status, buf, rc);
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal specifies line status (0x%x).\n", status);
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal specifies line status (0x%x).\n", status);
set_lines(datenklo, status);
break;
case TIOCGSID:
PDEBUG(DDATENKLO, DEBUG_DEBUG, "TIOGSID -> ENOTTY\n");
LOGP(DDATENKLO, LOGL_DEBUG, "TIOGSID -> ENOTTY\n");
rc = -ENOTTY;
break;
case TIOCGPGRP:
PDEBUG(DDATENKLO, DEBUG_DEBUG, "TIOCGPGRP -> ENOTTY\n");
LOGP(DDATENKLO, LOGL_DEBUG, "TIOCGPGRP -> ENOTTY\n");
rc = -ENOTTY;
break;
case TIOCSCTTY:
PDEBUG(DDATENKLO, DEBUG_DEBUG, "TIOCSCTTY -> ENOTTY\n");
LOGP(DDATENKLO, LOGL_DEBUG, "TIOCSCTTY -> ENOTTY\n");
rc = -ENOTTY;
break;
case TIOCSPGRP:
PDEBUG(DDATENKLO, DEBUG_DEBUG, "TIOCSPGRP -> ENOTTY\n");
LOGP(DDATENKLO, LOGL_DEBUG, "TIOCSPGRP -> ENOTTY\n");
rc = -ENOTTY;
break;
case TIOCSWINSZ:
rc = sizeof(struct winsize);
if (!in_bufsz)
break;
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal sets window size.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal sets window size.\n");
break;
case TCXONC:
rc = sizeof(status);
@@ -996,15 +998,15 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
memcpy(&status, buf, rc);
switch (status) {
case TCOOFF:
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns off output.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns off output.\n");
datenklo->output_off = 1;
break;
case TCOON:
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns on output.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns on output.\n");
datenklo->output_off = 0;
break;
case TCIOFF:
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns off input.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns off input.\n");
space = (datenklo->rx_fifo_out - datenklo->rx_fifo_in - 1 + datenklo->rx_fifo_size) % datenklo->rx_fifo_size;
if (space < 1)
break;
@@ -1012,7 +1014,7 @@ static ssize_t dk_ioctl_set(void *inst, int cmd, const void *buf, size_t in_bufs
datenklo->rx_fifo_in %= datenklo->rx_fifo_size;
break;
case TCION:
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Terminal turns on input.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Terminal turns on input.\n");
space = (datenklo->rx_fifo_out - datenklo->rx_fifo_in - 1 + datenklo->rx_fifo_size) % datenklo->rx_fifo_size;
if (space < 1)
break;
@@ -1034,12 +1036,12 @@ static int dk_open(void *inst, int flags)
datenklo_t *datenklo = (datenklo_t *)inst;
if (datenklo->open_count) {
PDEBUG(DDATENKLO, DEBUG_NOTICE, "Device is busy.\n");
LOGP(DDATENKLO, LOGL_NOTICE, "Device is busy.\n");
return -EBUSY;
}
datenklo->open_count++;
datenklo->flags = flags;
PDEBUG(DDATENKLO, DEBUG_INFO, "Device has been opened.\n");
LOGP(DDATENKLO, LOGL_INFO, "Device has been opened.\n");
int status = datenklo->lines | TIOCM_DTR | TIOCM_RTS;
set_lines(datenklo, status);
@@ -1051,7 +1053,7 @@ static void dk_close(void *inst)
{
datenklo_t *datenklo = (datenklo_t *)inst;
PDEBUG(DDATENKLO, DEBUG_INFO, "Device has been closed.\n");
LOGP(DDATENKLO, LOGL_INFO, "Device has been closed.\n");
datenklo->open_count--;
int status = datenklo->lines & ~(TIOCM_DTR | TIOCM_RTS);
set_lines(datenklo, status);
@@ -1071,7 +1073,7 @@ static void debug_data(const char *buf, int count)
count--;
}
text[i] = '\0';
PDEBUG(DDATENKLO, DEBUG_DEBUG, " \"%s\"\n", text);
LOGP(DDATENKLO, LOGL_DEBUG, " \"%s\"\n", text);
}
}
@@ -1091,7 +1093,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags)
if (vmin && vtime) {
/* first: start timer */
if (!datenklo->vtimeout)
timer_start(&datenklo->vtimer, (double)vtime * 0.1);
osmo_timer_schedule(&datenklo->vtimer, vtime/10,(vtime % 10) * 100000);
/* no data: block (in blocking IO) */
if (fill == 0) {
/* special value to tell device there is no data right now, we have to block */
@@ -1104,7 +1106,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags)
}
/* enough data or timeout or nonblocking IO: stop timer and return what we have */
datenklo->vtimeout = 0;
timer_stop(&datenklo->vtimer);
osmo_timer_del(&datenklo->vtimer);
}
/* both MIN and TIME are zero */
if (!vmin && !vtime) {
@@ -1117,7 +1119,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags)
if (!vmin && vtime) {
/* first: start timer */
if (!datenklo->vtimeout)
timer_start(&datenklo->vtimer, (double)vtime * 0.1);
osmo_timer_schedule(&datenklo->vtimer, vtime/10,(vtime % 10) * 100000);
if (fill == 0) {
/* no data and no timeout: block (in blocking IO) */
if (!datenklo->vtimeout) {
@@ -1130,7 +1132,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags)
}
/* data: stop timer and return what we have */
datenklo->vtimeout = 0;
timer_stop(&datenklo->vtimer);
osmo_timer_del(&datenklo->vtimer);
}
/* MIN is nonzero, TIME is zero */
if (vmin && !vtime) {
@@ -1142,7 +1144,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags)
/* enough data in buffer: return what we have */
}
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Device has been read from. (fill = %zu)\n", fill);
LOGP(DDATENKLO, LOGL_DEBUG, "Device has been read from. (fill = %zu)\n", fill);
/* get data from fifo */
count = 0;
@@ -1160,7 +1162,7 @@ static ssize_t dk_read(void *inst, char *buf, size_t size, int flags)
if (!fill) {
/* tell cuse not to read anymore */
if ((datenklo->revents & POLLIN)) {
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Reset POLLIN (now empty)!\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Reset POLLIN (now empty)!\n");
datenklo->revents &= ~POLLIN;
device_set_poll_events(datenklo->device, datenklo->revents);
}
@@ -1177,17 +1179,17 @@ static ssize_t dk_write(void *inst, const char *buf, size_t size, int __attribut
size_t i;
if (!(datenklo->lines & TIOCM_DTR)) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Dropping data, DTR is off!\n");
LOGP(DDATENKLO, LOGL_INFO, "Dropping data, DTR is off!\n");
return -EIO;
}
if (!(datenklo->lines & TIOCM_RTS)) {
PDEBUG(DDATENKLO, DEBUG_INFO, "Dropping data, RTS is off!\n");
LOGP(DDATENKLO, LOGL_INFO, "Dropping data, RTS is off!\n");
return -EIO;
}
if (size > (size_t)datenklo->tx_fifo_size - 1) {
PDEBUG(DDATENKLO, DEBUG_NOTICE, "Device sends us too many data. (size = %zu)\n", size);
LOGP(DDATENKLO, LOGL_NOTICE, "Device sends us too many data. (size = %zu)\n", size);
return -EIO;
}
@@ -1199,7 +1201,7 @@ static ssize_t dk_write(void *inst, const char *buf, size_t size, int __attribut
return -EAGAIN;
}
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Device has been written to. (space = %zu)\n", space);
LOGP(DDATENKLO, LOGL_DEBUG, "Device has been written to. (space = %zu)\n", space);
debug_data(buf, size);
if (datenklo->auto_rts)
@@ -1215,7 +1217,7 @@ static ssize_t dk_write(void *inst, const char *buf, size_t size, int __attribut
if ((datenklo->revents & POLLOUT) && fill >= (size_t)datenklo->tx_fifo_full) {
/* tell cuse not to write */
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Reset POLLOUT (buffer full)\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Reset POLLOUT (buffer full)\n");
datenklo->revents &= ~POLLOUT;
device_set_poll_events(datenklo->device, datenklo->revents);
}
@@ -1227,7 +1229,7 @@ static void dk_flush_tx(void *inst)
{
datenklo_t *datenklo = (datenklo_t *)inst;
PDEBUG(DDATENKLO, DEBUG_INFO, "Terminal sends interrupt while writing, flushing TX buffer\n");
LOGP(DDATENKLO, LOGL_INFO, "Terminal sends interrupt while writing, flushing TX buffer\n");
flush_tx(datenklo);
}
@@ -1270,7 +1272,7 @@ static void vtime_timeout(void *data)
void datenklo_init_global(void)
{
if (pthread_mutex_init(&mutex, NULL)) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to init mutex.\n");
LOGP(DDATENKLO, LOGL_ERROR, "Failed to init mutex.\n");
exit(0);
}
}
@@ -1282,7 +1284,7 @@ int datenklo_init(datenklo_t *datenklo, const char *dev_name, enum am791x_type a
tcflag_t flag;
cc_t *cc;
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Creating Datenklo instance.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Creating Datenklo instance.\n");
memset(datenklo, 0, sizeof(*datenklo));
@@ -1332,7 +1334,7 @@ int datenklo_init(datenklo_t *datenklo, const char *dev_name, enum am791x_type a
datenklo->device = device_init(datenklo, dev_name, dk_open, dk_close, dk_read, dk_write, dk_ioctl_get, dk_ioctl_set, dk_flush_tx, dk_lock, dk_unlock);
if (!datenklo->device) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to attach virtual device '%s' using cuse.\n", dev_name);
LOGP(DDATENKLO, LOGL_ERROR, "Failed to attach virtual device '%s' using cuse.\n", dev_name);
rc = -errno;
goto error;
}
@@ -1342,7 +1344,7 @@ int datenklo_init(datenklo_t *datenklo, const char *dev_name, enum am791x_type a
datenklo->baudrate = cflag2baud(datenklo->termios.c_cflag);
rc = am791x_init(&datenklo->am791x, datenklo, am791x_type, datenklo->mc, datenklo->samplerate, tx_baud_rate(datenklo), rx_baud_rate(datenklo), cts, bcts, cd, bcd, td, btd, rd, brd);
if (rc < 0) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to initialize AM791X modem chip.\n");
LOGP(DDATENKLO, LOGL_ERROR, "Failed to initialize AM791X modem chip.\n");
goto error;
}
@@ -1352,16 +1354,16 @@ int datenklo_init(datenklo_t *datenklo, const char *dev_name, enum am791x_type a
datenklo->tx_fifo = calloc(datenklo->tx_fifo_size, 1);
datenklo->rx_fifo = calloc(datenklo->rx_fifo_size, 1);
if (!datenklo->tx_fifo || !datenklo->rx_fifo) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "No mem!\n");
LOGP(DDATENKLO, LOGL_ERROR, "No mem!\n");
rc = -ENOMEM;
goto error;
}
timer_init(&datenklo->vtimer, vtime_timeout, datenklo);
osmo_timer_setup(&datenklo->vtimer, vtime_timeout, datenklo);
rc = uart_init(&datenklo->uart, datenklo, cflag2databits(datenklo->termios.c_cflag), cflag2parity(datenklo->termios.c_cflag), cflag2stopbits(datenklo->termios.c_cflag), tx, rx);
if (rc < 0) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to initialize UART.\n");
LOGP(DDATENKLO, LOGL_ERROR, "Failed to initialize UART.\n");
goto error;
}
@@ -1397,7 +1399,7 @@ int datenklo_open_audio(datenklo_t *datenklo, const char *audiodev, int buffer,
/* init sound */
datenklo->audio = sound_open(audiodev, NULL, NULL, NULL, channels, 0.0, datenklo->samplerate, datenklo->buffer_size, 1.0, 1.0, 4000.0, 2.0);
if (!datenklo->audio) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "No sound device!\n");
LOGP(DDATENKLO, LOGL_ERROR, "No sound device!\n");
return -EIO;
}
#endif
@@ -1405,28 +1407,28 @@ int datenklo_open_audio(datenklo_t *datenklo, const char *audiodev, int buffer,
if (write_rx_wave) {
rc = wave_create_record(&datenklo->wave_rx_rec, write_rx_wave, datenklo->samplerate, channels, 1.0);
if (rc < 0) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n");
LOGP(DDATENKLO, LOGL_ERROR, "Failed to create WAVE recoding instance!\n");
return rc;
}
}
if (write_tx_wave) {
rc = wave_create_record(&datenklo->wave_tx_rec, write_tx_wave, datenklo->samplerate, channels, 1.0);
if (rc < 0) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to create WAVE recoding instance!\n");
LOGP(DDATENKLO, LOGL_ERROR, "Failed to create WAVE recoding instance!\n");
return rc;
}
}
if (read_rx_wave) {
rc = wave_create_playback(&datenklo->wave_rx_play, read_rx_wave, &datenklo->samplerate, &channels, 1.0);
if (rc < 0) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to create WAVE playback instance!\n");
LOGP(DDATENKLO, LOGL_ERROR, "Failed to create WAVE playback instance!\n");
return rc;
}
}
if (read_tx_wave) {
rc = wave_create_playback(&datenklo->wave_tx_play, read_tx_wave, &datenklo->samplerate, &channels, 1.0);
if (rc < 0) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Failed to create WAVE playback instance!\n");
LOGP(DDATENKLO, LOGL_ERROR, "Failed to create WAVE playback instance!\n");
return rc;
}
}
@@ -1521,14 +1523,14 @@ void datenklo_main(datenklo_t *datenklo, int loopback)
process_auto_rts(datenklo->slave);
/* process timers */
process_timer();
osmo_select_main(1);
#ifdef HAVE_ALSA
count = sound_read(datenklo->audio, samples, datenklo->buffer_size, num_chan, rf_level_db);
if (count < 0) {
PDEBUG(DDSP, DEBUG_ERROR, "Failed to read RX data from audio device (rc = %d)\n", count);
LOGP(DDSP, LOGL_ERROR, "Failed to read RX data from audio device (rc = %d)\n", count);
if (count == -EPIPE) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Trying to recover!\n");
LOGP(DDATENKLO, LOGL_ERROR, "Trying to recover!\n");
continue;
}
break;
@@ -1561,9 +1563,9 @@ void datenklo_main(datenklo_t *datenklo, int loopback)
count = samplerate / 1000;
#endif
if (count < 0) {
PDEBUG(DDSP, DEBUG_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count);
LOGP(DDSP, LOGL_ERROR, "Failed to get number of samples in buffer (rc = %d)!\n", count);
if (count == -EPIPE) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Trying to recover!\n");
LOGP(DDATENKLO, LOGL_ERROR, "Trying to recover!\n");
continue;
}
break;
@@ -1611,9 +1613,9 @@ void datenklo_main(datenklo_t *datenklo, int loopback)
/* write audio */
rc = sound_write(datenklo->audio, samples, power, count, NULL, NULL, num_chan);
if (rc < 0) {
PDEBUG(DDSP, DEBUG_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc);
LOGP(DDSP, LOGL_ERROR, "Failed to write TX data to audio device (rc = %d)\n", rc);
if (rc == -EPIPE) {
PDEBUG(DDATENKLO, DEBUG_ERROR, "Trying to recover!\n");
LOGP(DDATENKLO, LOGL_ERROR, "Trying to recover!\n");
continue;
}
break;
@@ -1625,8 +1627,6 @@ next_char:
switch (c) {
case 3:
/* quit */
if (clear_console_text)
clear_console_text();
printf("CTRL+c received, quitting!\n");
quit = 1;
goto next_char;
@@ -1655,10 +1655,6 @@ next_char:
pthread_mutex_lock(&mutex);
}
/* get rid of last entry */
if (clear_console_text)
clear_console_text();
/* reset terminal */
tcsetattr(0, TCSANOW, &term_orig);
@@ -1674,9 +1670,9 @@ next_char:
/* cleanup function */
void datenklo_exit(datenklo_t *datenklo)
{
PDEBUG(DDATENKLO, DEBUG_DEBUG, "Destroying Datenklo instance.\n");
LOGP(DDATENKLO, LOGL_DEBUG, "Destroying Datenklo instance.\n");
timer_exit(&datenklo->vtimer);
osmo_timer_del(&datenklo->vtimer);
/* exit device */
if (datenklo->device)

View File

@@ -52,7 +52,7 @@ typedef struct datenklo {
int auto_rts_cts; /* CTS was indicated */
int auto_rts_cd; /* CD was indicated */
int output_off; /* output stopped by flow control */
struct timer vtimer; /* VTIME timer */
struct osmo_timer_list vtimer; /* VTIME timer */
int vtimeout; /* when timeout has fired */
/* data fifos */

View File

@@ -27,7 +27,7 @@
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "../libdebug/debug.h"
#include "../liblogging/logging.h"
#define __USE_GNU
#include <pthread.h>
#include <signal.h>
@@ -122,7 +122,7 @@ static void cuse_read_interrupt(fuse_req_t req, void *data)
if (!device->read_locked)
device->lock_cb();
PDEBUG(DDEVICE, DEBUG_DEBUG, "%s received interrupt from client!\n", device->name);
LOGP(DDEVICE, LOGL_DEBUG, "%s received interrupt from client!\n", device->name);
if (device->read_req) {
device->read_req = NULL;
@@ -167,7 +167,7 @@ static void cuse_device_read(fuse_req_t req, size_t size, off_t off, struct fuse
if (device->read_req) {
device->unlock_cb();
PDEBUG(DDEVICE, DEBUG_ERROR, "%s: Got another read(), while first read() has not been replied, please fix.\n", device->name);
LOGP(DDEVICE, LOGL_ERROR, "%s: Got another read(), while first read() has not been replied, please fix.\n", device->name);
fuse_reply_err(req, EBUSY);
return;
}
@@ -182,7 +182,7 @@ static void cuse_device_read(fuse_req_t req, size_t size, off_t off, struct fuse
/* this means that we block until modem's read() returns 0 or positive value (in nonblocking io, we return -EAGAIN) */
if (!(fi->flags & O_NONBLOCK) && count == -EAGAIN) {
PDEBUG(DDEVICE, DEBUG_DEBUG, "%s has no data available, waiting for data, timer or interrupt.\n", device->name);
LOGP(DDEVICE, LOGL_DEBUG, "%s has no data available, waiting for data, timer or interrupt.\n", device->name);
device->read_req = req;
device->read_size = size;
@@ -216,7 +216,7 @@ static void cuse_write_interrupt(fuse_req_t req, void *data)
if (!device->write_locked)
device->lock_cb();
PDEBUG(DDEVICE, DEBUG_DEBUG, "%s received interrupt from client!\n", device->name);
LOGP(DDEVICE, LOGL_DEBUG, "%s received interrupt from client!\n", device->name);
if (device->write_req) {
device->write_req = NULL;
@@ -262,7 +262,7 @@ static void cuse_device_write(fuse_req_t req, const char *buf, size_t size, off_
if (device->write_req) {
device->unlock_cb();
PDEBUG(DDEVICE, DEBUG_ERROR, "%s: Got another write(), while first write() has not been replied, please fix.\n", device->name);
LOGP(DDEVICE, LOGL_ERROR, "%s: Got another write(), while first write() has not been replied, please fix.\n", device->name);
fuse_reply_err(req, EBUSY);
return;
}
@@ -271,13 +271,13 @@ static void cuse_device_write(fuse_req_t req, const char *buf, size_t size, off_
/* this means that we block until modem's write() returns 0 or positive value (in nonblocking io, we return -EAGAIN) */
if (!(fi->flags & O_NONBLOCK) && count == -EAGAIN) {
PDEBUG(DDEVICE, DEBUG_DEBUG, "%s has no buffer space available, waiting for space or interrupt.\n", device->name);
LOGP(DDEVICE, LOGL_DEBUG, "%s has no buffer space available, waiting for space or interrupt.\n", device->name);
device->write_req = req;
device->write_size = size;
device->write_buf = malloc(size);
if (!buf) {
PDEBUG(DDEVICE, DEBUG_ERROR, "No memory!\n");
LOGP(DDEVICE, LOGL_ERROR, "No memory!\n");
exit(0);
}
memcpy(device->write_buf, buf, size);
@@ -376,7 +376,7 @@ static void cuse_device_ioctl(fuse_req_t req, int cmd, void *arg, struct fuse_fi
}
break;
default:
PDEBUG(DDEVICE, DEBUG_NOTICE, "%s: receives unknown ioctl: 0x%x\n", device->name, cmd);
LOGP(DDEVICE, LOGL_NOTICE, "%s: receives unknown ioctl: 0x%x\n", device->name, cmd);
fuse_reply_err(req, EINVAL);
}
}
@@ -432,7 +432,7 @@ static void cuse_device_flush(fuse_req_t req, struct fuse_file_info *fi)
(void)req;
(void)fi;
device_t *device = get_device_by_thread();
PDEBUG(DDEVICE, DEBUG_NOTICE, "%s: unhandled flush\n", device->name);
LOGP(DDEVICE, LOGL_NOTICE, "%s: unhandled flush\n", device->name);
}
static void cuse_device_fsync(fuse_req_t req, int datasync, struct fuse_file_info *fi)
@@ -441,7 +441,7 @@ static void cuse_device_fsync(fuse_req_t req, int datasync, struct fuse_file_inf
(void)datasync;
(void)fi;
device_t *device = get_device_by_thread();
PDEBUG(DDEVICE, DEBUG_NOTICE, "%s: unhandled fsync\n", device->name);
LOGP(DDEVICE, LOGL_NOTICE, "%s: unhandled fsync\n", device->name);
}
@@ -478,9 +478,9 @@ static void *device_child(void *arg)
device->thread_started = 1;
PDEBUG(DDEVICE, DEBUG_INFO, "Device '%s' started.\n", device->name);
LOGP(DDEVICE, LOGL_INFO, "Device '%s' started.\n", device->name);
cuse_lowlevel_main(argc, argv, &ci, &cuse_device_clop, NULL);
PDEBUG(DDEVICE, DEBUG_INFO, "Device '%s' terminated.\n", device->name);
LOGP(DDEVICE, LOGL_INFO, "Device '%s' terminated.\n", device->name);
device->thread_stopped = 1;
@@ -496,7 +496,7 @@ void *device_init(void *inst, const char *name, int (*open)(void *inst, int flag
device = calloc(1, sizeof(*device));
if (!device) {
PDEBUG(DDEVICE, DEBUG_ERROR, "No memory!\n");
LOGP(DDEVICE, LOGL_ERROR, "No memory!\n");
errno = ENOMEM;
goto error;
}
@@ -514,7 +514,7 @@ void *device_init(void *inst, const char *name, int (*open)(void *inst, int flag
rc = pthread_create(&device->thread, NULL, device_child, device);
if (rc < 0) {
PDEBUG(DDEVICE, DEBUG_ERROR, "Failed to create device thread!\n");
LOGP(DDEVICE, LOGL_ERROR, "Failed to create device thread!\n");
errno = -rc;
goto error;
}

View File

@@ -26,9 +26,9 @@
#include <errno.h>
#include <math.h>
#include "../libsample/sample.h"
#include "../libtimer/timer.h"
#include <osmocom/core/timer.h>
#include "../liboptions/options.h"
#include "../libdebug/debug.h"
#include "../liblogging/logging.h"
#include "../libfsk/fsk.h"
#include "../libwave/wave.h"
#include "../libdisplay/display.h"
@@ -80,6 +80,7 @@ void print_help(const char *arg0)
printf(" --config [~/]<path to config file>\n");
printf(" Give a config file to use. If it starts with '~/', path is at home dir.\n");
printf(" Each line in config file is one option, '-' or '--' must not be given!\n");
logging_print_help();
printf(" -T --am791x-type 7910 | 7911\n");
printf(" Give modem chip type. (Default = 791%d)\n", am791x_type);
printf(" -M --mc <mode>\n");
@@ -158,13 +159,11 @@ static int handle_options(int short_option, int argi, char **argv)
print_help(argv[0]);
return 0;
case 'v':
if (!strcasecmp(argv[argi], "list")) {
debug_list_cat();
rc = parse_logging_opt(argv[argi]);
if (rc > 0)
return 0;
}
rc = parse_debug_opt(argv[argi]);
if (rc < 0) {
fprintf(stderr, "Failed to parse debug option, please use -h for help.\n");
fprintf(stderr, "Failed to parse logging option, please use -h for help.\n");
return rc;
}
break;
@@ -265,6 +264,8 @@ int main(int argc, char *argv[])
int rc, argi;
int i;
logging_init();
/* handle options / config file */
add_options();
rc = options_config_file(argc, argv, "~/.osmocom/analog/datenklo.conf", handle_options);
@@ -325,3 +326,5 @@ fail:
return 0;
}
void osmo_cc_set_log_cat(void) {}

View File

@@ -21,7 +21,7 @@
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include "../libdebug/debug.h"
#include "../liblogging/logging.h"
#include "uart.h"
static uint32_t calc_parity(uint32_t data, uint8_t data_bits, enum uart_parity parity)
@@ -56,13 +56,13 @@ int uart_init(uart_t *uart, void *inst, uint8_t data_bits, enum uart_parity pari
uart->rx_cb = rx_cb;
uart->data_bits = data_bits;
if (uart->data_bits > 9) {
PDEBUG(DUART, DEBUG_ERROR, "Illegal number of data bits, please fix!\n");
LOGP(DUART, LOGL_ERROR, "Illegal number of data bits, please fix!\n");
abort();
}
uart->parity = parity;
uart->stop_bits = stop_bits;
if (uart->stop_bits < 1 || uart->stop_bits > 2) {
PDEBUG(DUART, DEBUG_ERROR, "Illegal number of stop bits, please fix!\n");
LOGP(DUART, LOGL_ERROR, "Illegal number of stop bits, please fix!\n");
abort();
}
uart->tx_pos = -1;