struct modem_script

Скрипт для устройства

Прототип:

#include <sys/modem.h>
struct modem_script {
char curstate; /* This state */
char curflags; /* Set to zero */
char newstate; /* State to goto on a match (0 means done) */
char newflags; /* Flags to use for nextstate */
char newtimeout; /* Timeout to use for nextstate */
char newquiet; /* Quiet time to use for nextstate */
short retvalue; /* Return value on match with nextstate 0 */
char *pattern; /* Input matching pattern */
char *response; /* Output response to a pattern match in input */
char *progress; /* A progress message passed to the io callback on state change */
};

Описание:

Тип позволяет производить разметку скриптов для устройства. Структура включает следующие поля:

curstate
The current state. Execution always begins at state 1, which must be the first array element of table. Multiple elements may have the same current state, in which case any received input is matched against each pattern member for that state.
curflags
The flags to use on a pattern match of a response:
MODEM_NOECHO
don't echo the response through the io() callback.
MODEM_BAUD
extract any number in the response and assign it to baud.
newstate
When a pattern match occurs with pattern, this is the next state. A state transition causes response to be output and newflags, newtimeout, and newquiet to be saved and associated with the new state. Changing to a new state of 0 causes modem_script() to return with the value in retvalue.
newflags
Saved on a state transition and passed to modem_read() when waiting for a response in the new state. For information about these flags, see modem_read().
newtimeout
Saved on a state transition and passed to modem_read() when waiting for a response in the new state. This timeout is described in modem_read().
newquiet
Saved on a state transition and passed to modem_read() when waiting for a response in the new state. This quiet timeout is described in modem_read().
retvalue
The return value when the script terminates with a pattern match, and the new state is 0.
pattern
A pattern to match against received characters. The pattern is matched using fnmatch(). Only patterns in the current state or the wildcard state of 0 are matched. On a match, the current state changes to newstate.
response
On a pattern match, this response is output to the device. If the curflags don't have MODEM_NOECHO set, the response is given to the callback function passed as the io parameter.
progress
On a pattern match, this progress string is passed to the callback function passed as the io parameter.

Here's an example that demonstrates the operation of the script:

/*
* curstate curflags newstate newflags newtimeout newquiet retvalue pattern response
*/
struct modem_script table[] = {
{1, 0, 1, 0, 2, 5, 0, NULL, "ATZ\\r\\P0a"},
{1, 0, 2, 0, 30, 5, 0, "*ok*", "ATDT5910934"},
{2, MODEM_BAUD, 3, MODEM_LASTLINE, 10, 5, 0, "*connect*", NULL},
{3, 0, 4, 0, 8, 5, 0, "*login:*", "guest"},
{4, MODEM_NOECHO, 5, 0, 15, 5, 0, "*password:*", "xxxx"},
{5, 0, 0, 0, 0, 0, 0, "*$ *", NULL},
{0, 0, 0, 0, 0, 0, 1, "*no carrier*", NULL},
{0, 0, 0, 0, 0, 0, 2, "*no answer*", NULL},
{0, 0, 0, 0, 0, 0, 3, "*no dialtone*", NULL},
{0, 0, 0, 0, 0, 0, 4, "*busy*", NULL},
{ NULL }
};

Классификация:

ЗОСРВ «Нейтрино»

Тематические ссылки:

fnmatch(), modem_read(), modem_script()




Предыдущий раздел: Описание API системной библиотеки