Nut/OS  5.0.5
API Reference
chat.c File Reference
#include <cfg/os.h>
#include <sys/timer.h>
#include <dev/uart.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <memdebug.h>
#include <dev/chat.h>
Include dependency graph for chat.c:

Functions

void NutTraceChat (FILE *stream, uint8_t flags)
 Control chat tracing.
int NutChatExpectString (NUTCHAT *ci, char *str)
 Wait for a specific string to appear.
int NutChatExpect (NUTCHAT *ci, char *str)
int NutChatSend (NUTCHAT *ci, char *str)
 Process a chat send argument.
NUTCHATNutChatCreate (int fd)
 Create a NUTCHAT structure.
void NutChatDestroy (NUTCHAT *ci)
 Destroy a previously created NUTCHAT structure.
int NutChat (int fd, const char *script)
 Execute a conversational exchange with a serial device.
int NutChat_P (int fd, PGM_P script)
 Execute a conversational exchange with a serial device.

Variables

uint8_tchat_report

Function Documentation

void NutTraceChat ( FILE stream,
uint8_t  flags 
)

Control chat tracing.

Parameters:
streamPointer to a previously opened stream or null to disable trace output.
flagsFlags to enable specific traces.

References fprintf_P, and prog_char.

int NutChatExpectString ( NUTCHAT ci,
char *  str 
)

Wait for a specific string to appear.

Parameters:
ciPointer to a NUTCHAT structure, which must have been created by NutChatCreate().
strExpected string. May be empty if nothing is expected.
Returns:
0 on success, 3 in case of a timeout error while waiting for an expected string, or the index of an abort string plus 4, if one has been received.

References _read(), NUTCHAT::chat_abomat, NUTCHAT::chat_abort, NUTCHAT::chat_aborts, NUTCHAT::chat_fd, CHAT_MAX_REPORT_SIZE, NUTCHAT::chat_repmat, chat_report, NUTCHAT::chat_report_search, NUTCHAT::chat_report_state, fprintf(), fprintf_P, fputc(), fputs_P, and prog_char.

Referenced by NutChatExpect().

Here is the call graph for this function:

int NutChatExpect ( NUTCHAT ci,
char *  str 
)

References NUTCHAT::chat_arg, CHAT_ARG_ABORT, CHAT_ARG_REPORT, CHAT_ARG_TIMEOUT, NUTCHAT::chat_fd, NUTCHAT::chat_repmat, NUTCHAT::chat_report_state, NutChatExpectString(), rc, and strcmp().

Here is the call graph for this function:

int NutChatSend ( NUTCHAT ci,
char *  str 
)

Process a chat send argument.

Parameters:
ciPointer to a NUTCHAT structure, which must have been created by NutChatCreate().
strString containing the chat send argument.
Returns:
0 on success, 1 in case of invalid parameters, 2 in case of an I/O error, 3 in case of a timeout error while waiting for an expected string, or the index of an abort string plus 4, if one has been received.

References _ioctl(), atol(), NUTCHAT::chat_abort, NUTCHAT::chat_aborts, NUTCHAT::chat_arg, CHAT_ARG_ABORT, CHAT_ARG_REPORT, CHAT_ARG_SEND, CHAT_ARG_TIMEOUT, CHAT_DEFAULT_TIMEOUT, NUTCHAT::chat_fd, CHAT_MAX_ABORTS, CHAT_MAX_REPORT_SIZE, chat_report, NUTCHAT::chat_report_search, malloc(), strlen(), and UART_SETREADTIMEOUT.

Here is the call graph for this function:

NUTCHAT* NutChatCreate ( int  fd)

Create a NUTCHAT structure.

Returns:
Pointer to a new NUTCHAT structure.

References NUTCHAT::chat_fd, malloc(), and memset().

Here is the call graph for this function:

void NutChatDestroy ( NUTCHAT ci)

Destroy a previously created NUTCHAT structure.

Parameters:
ciPointer to a NUTCHAT structure, which must have been created by NutChatCreate().

References NUTCHAT::chat_abort, NUTCHAT::chat_aborts, and free().

Here is the call graph for this function:

int NutChat ( int  fd,
const char *  script 
)

Execute a conversational exchange with a serial device.

Its primary purpose is to establish a modem connection.

Parameters:
fdDescriptor of a previously opened device.
scriptPointer to a string containing the chat script.
Returns:
0 on success, 1 in case of invalid parameters, 2 in case of an I/O error, 3 in case of a timeout error while waiting for an expected string, or the index of an abort string plus 4, if one has been received.

References free(), NULL, rc, and strdup().

Here is the call graph for this function:

int NutChat_P ( int  fd,
PGM_P  script 
)

Execute a conversational exchange with a serial device.

Similar to NutChat() except that the chat string is located in program memory.

Returns:
0 on success, 1 in case of invalid parameters, 2 in case of an I/O error, 3 in case of a timeout error while waiting for an expected string, or the index of an abort string plus 4, if one has been received.

References free(), malloc(), rc, strcpy_P, and strlen_P.

Here is the call graph for this function:


Variable Documentation