Removal of some pointless callback parameters in the spandsp AT command

interpreter, and fixes for my congential inability to reliably spell psuedo,
er, pseudo, er, whatever.
This commit is contained in:
Steve Underwood 2014-01-16 00:47:29 +08:00
parent f4a4ba1716
commit f7a407feca
11 changed files with 76 additions and 68 deletions

View File

@ -504,7 +504,7 @@ SPAN_DECLARE(int) decode_msg(ademco_contactid_report_t *report, const char buf[]
int x;
char buf2[20];
/* We need to remap normal DTMF (0-0, *, #, A-D) to Ademco's psuedo-hex (0-0, B-F, nothing for A)
/* We need to remap normal DTMF (0-0, *, #, A-D) to Ademco's pseudo-hex (0-0, B-F, nothing for A)
and calculate the checksum */
for (sum = 0, s = buf, t = buf2; *s; s++, t++)
{

View File

@ -222,9 +222,9 @@ SPAN_DECLARE(void) at_put_response(at_state_t *s, const char *t)
buf[1] = s->p.s_regs[4];
buf[2] = '\0';
if (s->p.result_code_format == ASCII_RESULT_CODES)
s->at_tx_handler(s, s->at_tx_user_data, buf, 2);
s->at_tx_handler(s, s->at_tx_user_data, (uint8_t *) t, strlen(t));
s->at_tx_handler(s, s->at_tx_user_data, buf, 2);
s->at_tx_handler(s->at_tx_user_data, buf, 2);
s->at_tx_handler(s->at_tx_user_data, (uint8_t *) t, strlen(t));
s->at_tx_handler(s->at_tx_user_data, buf, 2);
}
/*- End of function --------------------------------------------------------*/
@ -249,7 +249,7 @@ SPAN_DECLARE(void) at_put_response_code(at_state_t *s, int code)
break;
case NUMERIC_RESULT_CODES:
snprintf((char *) buf, sizeof(buf), "%d%c", code, s->p.s_regs[3]);
s->at_tx_handler(s, s->at_tx_user_data, buf, strlen((char *) buf));
s->at_tx_handler(s->at_tx_user_data, buf, strlen((char *) buf));
break;
default:
/* No result codes */
@ -361,7 +361,7 @@ SPAN_DECLARE(void) at_call_event(at_state_t *s, int event)
{
s->rx_data[s->rx_data_bytes++] = DLE;
s->rx_data[s->rx_data_bytes++] = ETX;
s->at_tx_handler(s, s->at_tx_user_data, s->rx_data, s->rx_data_bytes);
s->at_tx_handler(s->at_tx_user_data, s->rx_data, s->rx_data_bytes);
s->rx_data_bytes = 0;
}
if (s->at_rx_mode != AT_MODE_OFFHOOK_COMMAND && s->at_rx_mode != AT_MODE_ONHOOK_COMMAND)
@ -881,7 +881,7 @@ static int process_class1_cmd(at_state_t *s, const char **t)
result = true;
if (s->class1_handler)
result = s->class1_handler(s, s->class1_user_data, direction, operation, val);
result = s->class1_handler(s->class1_user_data, direction, operation, val);
switch (result)
{
case 0:
@ -5461,7 +5461,7 @@ SPAN_DECLARE(int) at_modem_control(at_state_t *s, int op, const char *num)
break;
}
/*endswitch*/
return s->modem_control_handler(s, s->modem_control_user_data, op, num);
return s->modem_control_handler(s->modem_control_user_data, op, num);
}
/*- End of function --------------------------------------------------------*/
@ -5474,7 +5474,7 @@ SPAN_DECLARE(void) at_interpreter(at_state_t *s, const char *cmd, int len)
const char *t;
if (s->p.echo)
s->at_tx_handler(s, s->at_tx_user_data, (uint8_t *) cmd, len);
s->at_tx_handler(s->at_tx_user_data, (uint8_t *) cmd, len);
for (i = 0; i < len; i++)
{
@ -5582,6 +5582,15 @@ SPAN_DECLARE(void) at_set_class1_handler(at_state_t *s, at_class1_handler_t hand
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(void) at_set_modem_control_handler(at_state_t *s,
at_modem_control_handler_t modem_control_handler,
void *modem_control_user_data)
{
s->modem_control_handler = modem_control_handler;
s->modem_control_user_data = modem_control_user_data;
}
/*- End of function --------------------------------------------------------*/
SPAN_DECLARE(logging_state_t *) at_get_logging_state(at_state_t *s)
{
return &s->logging;

View File

@ -38,9 +38,9 @@ modem control commands.
typedef struct at_state_s at_state_t;
typedef int (*at_modem_control_handler_t)(at_state_t *s, void *user_data, int op, const char *num);
typedef int (*at_tx_handler_t)(at_state_t *s, void *user_data, const uint8_t *buf, size_t len);
typedef int (*at_class1_handler_t)(at_state_t *s, void *user_data, int direction, int operation, int val);
typedef int (*at_modem_control_handler_t)(void *user_data, int op, const char *num);
typedef int (*at_tx_handler_t)(void *user_data, const uint8_t *buf, size_t len);
typedef int (*at_class1_handler_t)(void *user_data, int direction, int operation, int val);
enum at_rx_mode_e
{
@ -173,6 +173,11 @@ SPAN_DECLARE(void) at_set_class1_handler(at_state_t *s, at_class1_handler_t hand
\return A pointer to the logging context */
SPAN_DECLARE(logging_state_t *) at_get_logging_state(at_state_t *s);
SPAN_DECLARE(void) at_set_modem_control_handler(at_state_t *s,
at_modem_control_handler_t modem_control_handler,
void *modem_control_user_data);
/*! Initialise an AT interpreter context.
\brief Initialise an AT interpreter context.
\param s The AT context.

View File

@ -1358,55 +1358,54 @@ SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples)
}
/*- End of function --------------------------------------------------------*/
static int t31_modem_control_handler(at_state_t *s, void *user_data, int op, const char *num)
static int t31_modem_control_handler(void *user_data, int op, const char *num)
{
t31_state_t *t;
t31_state_t *s;
t = (t31_state_t *) user_data;
s = (t31_state_t *) user_data;
switch (op)
{
case AT_MODEM_CONTROL_CALL:
t->call_samples = 0;
t38_core_restart(&t->t38_fe.t38);
s->call_samples = 0;
t38_core_restart(&s->t38_fe.t38);
break;
case AT_MODEM_CONTROL_ANSWER:
t->call_samples = 0;
t38_core_restart(&t->t38_fe.t38);
s->call_samples = 0;
t38_core_restart(&s->t38_fe.t38);
break;
case AT_MODEM_CONTROL_ONHOOK:
if (t->non_ecm_tx.holding)
if (s->non_ecm_tx.holding)
{
t->non_ecm_tx.holding = false;
s->non_ecm_tx.holding = false;
/* Tell the application to release further data */
at_modem_control(&t->at_state, AT_MODEM_CONTROL_CTS, (void *) 1);
at_modem_control(&s->at_state, AT_MODEM_CONTROL_CTS, (void *) 1);
}
/*endif*/
if (t->at_state.rx_signal_present)
if (s->at_state.rx_signal_present)
{
t->at_state.rx_data[t->at_state.rx_data_bytes++] = DLE;
t->at_state.rx_data[t->at_state.rx_data_bytes++] = ETX;
t->at_state.at_tx_handler(&t->at_state,
t->at_state.at_tx_user_data,
t->at_state.rx_data,
t->at_state.rx_data_bytes);
t->at_state.rx_data_bytes = 0;
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX;
s->at_state.at_tx_handler(s->at_state.at_tx_user_data,
s->at_state.rx_data,
s->at_state.rx_data_bytes);
s->at_state.rx_data_bytes = 0;
}
/*endif*/
restart_modem(t, FAX_MODEM_SILENCE_TX);
restart_modem(s, FAX_MODEM_SILENCE_TX);
break;
case AT_MODEM_CONTROL_RESTART:
restart_modem(t, (int) (intptr_t) num);
restart_modem(s, (int) (intptr_t) num);
return 0;
case AT_MODEM_CONTROL_DTE_TIMEOUT:
if (num)
t->dte_data_timeout = t->call_samples + ms_to_samples((intptr_t) num);
s->dte_data_timeout = s->call_samples + ms_to_samples((intptr_t) num);
else
t->dte_data_timeout = 0;
s->dte_data_timeout = 0;
/*endif*/
return 0;
}
/*endswitch*/
return t->modem_control_handler(t, t->modem_control_user_data, op, num);
return s->modem_control_handler(s, s->modem_control_user_data, op, num);
}
/*- End of function --------------------------------------------------------*/
@ -1437,8 +1436,7 @@ static void non_ecm_rx_status(void *user_data, int status)
{
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX;
s->at_state.at_tx_handler(&s->at_state,
s->at_state.at_tx_user_data,
s->at_state.at_tx_handler(s->at_state.at_tx_user_data,
s->at_state.rx_data,
s->at_state.rx_data_bytes);
s->at_state.rx_data_bytes = 0;
@ -1480,8 +1478,7 @@ static void non_ecm_put_bit(void *user_data, int bit)
s->at_state.rx_data[s->at_state.rx_data_bytes++] = (uint8_t) s->audio.current_byte;
if (s->at_state.rx_data_bytes >= 250)
{
s->at_state.at_tx_handler(&s->at_state,
s->at_state.at_tx_user_data,
s->at_state.at_tx_handler(s->at_state.at_tx_user_data,
s->at_state.rx_data,
s->at_state.rx_data_bytes);
s->at_state.rx_data_bytes = 0;
@ -1515,8 +1512,7 @@ static void non_ecm_put(void *user_data, const uint8_t buf[], int len)
s->at_state.rx_data[s->at_state.rx_data_bytes++] = buf[i];
if (s->at_state.rx_data_bytes >= 250)
{
s->at_state.at_tx_handler(&s->at_state,
s->at_state.at_tx_user_data,
s->at_state.at_tx_handler(s->at_state.at_tx_user_data,
s->at_state.rx_data,
s->at_state.rx_data_bytes);
s->at_state.rx_data_bytes = 0;
@ -1860,7 +1856,7 @@ static void hdlc_accept_frame(void *user_data, const uint8_t *msg, int len, int
/*endfor*/
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX;
s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
s->at_state.at_tx_handler(s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
s->at_state.rx_data_bytes = 0;
if (msg[1] == 0x13 && ok)
{
@ -2025,8 +2021,8 @@ static void t31_v21_rx(t31_state_t *s)
s->hdlc_tx.len = 0;
s->hdlc_tx.final = false;
s->dled = false;
hdlc_rx_init(&s->audio.modems.hdlc_rx, false, true, HDLC_FRAMING_OK_THRESHOLD, hdlc_accept_frame, s);
fax_modems_start_slow_modem(&s->audio.modems, FAX_MODEM_V21_RX);
hdlc_rx_init(&s->audio.modems.hdlc_rx, false, true, HDLC_FRAMING_OK_THRESHOLD, hdlc_accept_frame, s);
s->at_state.transmit = true;
}
/*- End of function --------------------------------------------------------*/
@ -2447,7 +2443,7 @@ static __inline__ void dle_unstuff(t31_state_t *s, const char *stuffed, int len)
}
/*- End of function --------------------------------------------------------*/
static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int operation, int val)
static int process_class1_cmd(void *user_data, int direction, int operation, int val)
{
int new_modem;
int new_transmit;
@ -2549,7 +2545,7 @@ static int process_class1_cmd(at_state_t *t, void *user_data, int direction, int
/*endfor*/
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX;
s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
s->at_state.at_tx_handler(s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
s->at_state.rx_data_bytes = 0;
}
/*endif*/
@ -2710,7 +2706,7 @@ SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len)
{
s->at_state.rx_data[s->at_state.rx_data_bytes++] = DLE;
s->at_state.rx_data[s->at_state.rx_data_bytes++] = ETX;
s->at_state.at_tx_handler(&s->at_state, s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
s->at_state.at_tx_handler(s->at_state.at_tx_user_data, s->at_state.rx_data, s->at_state.rx_data_bytes);
}
/*endif*/
s->at_state.rx_data_bytes = 0;
@ -2983,6 +2979,7 @@ static int t31_t38_fe_init(t31_state_t *t,
t->hdlc_tx.ptr = 0;
/* Prepare the non-ecm HDLC bit stream -> T.38 HDLC -> non-ecm HDLC bit stream path */
hdlc_tx_init(&s->hdlc_tx_non_ecm, false, 1, false, hdlc_tx_underflow2, s);
hdlc_rx_init(&s->hdlc_rx_non_ecm, false, true, 2, hdlc_accept_non_ecm_frame, t);
return 0;

View File

@ -478,7 +478,7 @@ static int general_test(at_state_t *s)
}
/*- End of function --------------------------------------------------------*/
static int modem_call_control(at_state_t *s, void *user_data, int op, const char *num)
static int modem_call_control(void *user_data, int op, const char *num)
{
switch (op)
{
@ -534,7 +534,7 @@ static int modem_call_control(at_state_t *s, void *user_data, int op, const char
}
/*- End of function --------------------------------------------------------*/
static int at_tx_handler(at_state_t *s, void *user_data, const uint8_t *buf, size_t len)
static int at_tx_handler(void *user_data, const uint8_t *buf, size_t len)
{
int i;

View File

@ -66,7 +66,7 @@ static int master(void)
for (i = 0; i < 10; i++)
{
if (psuedo_terminal_create(&modem[i]))
if (pseudo_terminal_create(&modem[i]))
{
printf("Failure\n");
exit(2);
@ -89,7 +89,7 @@ static int master(void)
for (i = 0; i < 10; i++)
{
if (psuedo_terminal_close(&modem[i]))
if (pseudo_terminal_close(&modem[i]))
{
printf("Failure\n");
exit(2);

View File

@ -53,7 +53,7 @@
int next_id = 0;
const char *device_root_name = "/dev/spandsp";
int psuedo_terminal_close(modem_t *modem)
int pseudo_terminal_close(modem_t *modem)
{
#if defined(WIN32)
if (modem->master)
@ -84,7 +84,7 @@ int psuedo_terminal_close(modem_t *modem)
}
/*- End of function --------------------------------------------------------*/
int psuedo_terminal_create(modem_t *modem)
int pseudo_terminal_create(modem_t *modem)
{
#if defined(WIN32)
COMMTIMEOUTS timeouts = {0};
@ -170,7 +170,7 @@ int psuedo_terminal_create(modem_t *modem)
if (!SetCommTimeouts(modem->master, &timeouts))
{
span_log(&modem->logging, SPAN_LOG_ERROR, "Cannot set up non-blocking read on %s\n", modem->devlink);
psuedo_terminal_close(modem);
pseudo_terminal_close(modem);
return -1;
}
modem->threadAbort = CreateEvent(NULL, true, false, NULL);
@ -184,14 +184,14 @@ int psuedo_terminal_create(modem_t *modem)
if (symlink(modem->stty, modem->devlink))
{
span_log(&modem->logging, SPAN_LOG_ERROR, "Fatal error: failed to create %s symbolic link\n", modem->devlink);
psuedo_terminal_close(modem);
pseudo_terminal_close(modem);
return -1;
}
if (fcntl(modem->master, F_SETFL, fcntl(modem->master, F_GETFL, 0) | O_NONBLOCK))
{
span_log(&modem->logging, SPAN_LOG_ERROR, "Cannot set up non-blocking read on %s\n", ttyname(modem->master));
psuedo_terminal_close(modem);
pseudo_terminal_close(modem);
return -1;
}
#endif

View File

@ -41,6 +41,6 @@ struct modem_s
typedef struct modem_s modem_t;
int psuedo_terminal_close(modem_t *modem);
int pseudo_terminal_close(modem_t *modem);
int psuedo_terminal_create(modem_t *modem);
int pseudo_terminal_create(modem_t *modem);

View File

@ -134,7 +134,7 @@ static void phase_e_handler(t30_state_t *s, void *user_data, int result)
}
/*- End of function --------------------------------------------------------*/
static int at_tx_handler(at_state_t *s, void *user_data, const uint8_t *buf, size_t len)
static int at_tx_handler(void *user_data, const uint8_t *buf, size_t len)
{
#if defined(WIN32)
DWORD res;
@ -220,7 +220,7 @@ static int t31_call_control(t31_state_t *s, void *user_data, int op, const char
{
case 1:
x[0] = (num) ? 0x11 : 0x13;
at_tx_handler(&t31_state->at_state, user_data, x, 1);
at_tx_handler(user_data, x, 1);
break;
case 2:
break;
@ -815,7 +815,7 @@ int main(int argc, char *argv[])
}
}
if (psuedo_terminal_create(&modem[0]))
if (pseudo_terminal_create(&modem[0]))
printf("Failure\n");
#if !defined(WIN32)
@ -825,7 +825,7 @@ int main(int argc, char *argv[])
#endif
t30_tests(t38_mode, use_ecm, use_gui, log_audio, test_sending, g1050_model_no, g1050_speed_pattern_no);
if (psuedo_terminal_close(&modem[0]))
if (pseudo_terminal_close(&modem[0]))
printf("Failure\n");
printf("Tests passed\n");
return 0;

View File

@ -374,7 +374,7 @@ static int modem_call_control(t31_state_t *s, void *user_data, int op, const cha
}
/*- End of function --------------------------------------------------------*/
static int at_tx_handler(at_state_t *s, void *user_data, const uint8_t *buf, size_t len)
static int at_tx_handler(void *user_data, const uint8_t *buf, size_t len)
{
size_t i;

View File

@ -81,7 +81,7 @@ static int t38_tx_packet_handler(t38_core_state_t *s, void *user_data, const uin
return 0;
}
static int t31_at_tx_handler(at_state_t *s, void *user_data, const uint8_t *buf, size_t len)
static int t31_at_tx_handler(void *user_data, const uint8_t *buf, size_t len)
{
modem_t *modem = user_data;
@ -1024,7 +1024,6 @@ static void wake_modem_thread(modem_t *modem)
static int control_handler(modem_t *modem, const char *num, int op)
{
switch_core_session_t *session = NULL;
at_state_t *at_state;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Control Handler op:%d state:[%s] %s\n",
op, modem_state2name(modem_get_state(modem)), modem->devlink);
@ -1103,16 +1102,14 @@ static int control_handler(modem_t *modem, const char *num, int op)
u_char x[1];
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1,
"Modem %s [%s] - CTS %s\n", modem->devlink, modem_state2name(modem_get_state(modem)), (int) (intptr_t) num ? "XON" : "XOFF");
at_state = t31_get_at_state(modem->t31_state);
if (num) {
x[0] = 0x11;
t31_at_tx_handler(at_state, modem, x, 1);
t31_at_tx_handler(modem, x, 1);
switch_clear_flag(modem, MODEM_FLAG_XOFF);
wake_modem_thread(modem);
} else {
x[0] = 0x13;
t31_at_tx_handler(at_state, modem, x, 1);
t31_at_tx_handler(modem, x, 1);
switch_set_flag(modem, MODEM_FLAG_XOFF);
}
}