3 * AT chat library with GLib integration
5 * Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "gatresult.h"
30 #include "gatsyntax.h"
36 typedef struct _GAtChat GAtChat;
38 typedef void (*GAtResultFunc)(gboolean success, GAtResult *result,
40 typedef void (*GAtNotifyFunc)(GAtResult *result, gpointer user_data);
42 enum _GAtChatTerminator {
43 G_AT_CHAT_TERMINATOR_OK,
44 G_AT_CHAT_TERMINATOR_ERROR,
45 G_AT_CHAT_TERMINATOR_NO_DIALTONE,
46 G_AT_CHAT_TERMINATOR_BUSY,
47 G_AT_CHAT_TERMINATOR_NO_CARRIER,
48 G_AT_CHAT_TERMINATOR_CONNECT,
49 G_AT_CHAT_TERMINATOR_NO_ANSWER,
50 G_AT_CHAT_TERMINATOR_CMS_ERROR,
51 G_AT_CHAT_TERMINATOR_CME_ERROR,
52 G_AT_CHAT_TERMINATOR_EXT_ERROR,
55 typedef enum _GAtChatTerminator GAtChatTerminator;
57 GAtChat *g_at_chat_new(GIOChannel *channel, GAtSyntax *syntax);
58 GAtChat *g_at_chat_new_blocking(GIOChannel *channel, GAtSyntax *syntax);
60 GIOChannel *g_at_chat_get_channel(GAtChat *chat);
61 GAtIO *g_at_chat_get_io(GAtChat *chat);
63 GAtChat *g_at_chat_ref(GAtChat *chat);
64 void g_at_chat_unref(GAtChat *chat);
66 GAtChat *g_at_chat_clone(GAtChat *chat);
68 GAtChat *g_at_chat_set_slave(GAtChat *chat, GAtChat *slave);
69 GAtChat *g_at_chat_get_slave(GAtChat *chat);
71 void g_at_chat_suspend(GAtChat *chat);
72 void g_at_chat_resume(GAtChat *chat);
74 gboolean g_at_chat_set_disconnect_function(GAtChat *chat,
75 GAtDisconnectFunc disconnect, gpointer user_data);
78 * If the function is not NULL, then on every read/write from the GIOChannel
79 * provided to GAtChat the logging function will be called with the
80 * input/output string and user data
82 gboolean g_at_chat_set_debug(GAtChat *chat,
83 GAtDebugFunc func, gpointer user_data);
86 * Queue an AT command for execution. The command contents are given
87 * in cmd. Once the command executes, the callback function given by
88 * func is called with user provided data in user_data.
90 * Returns an id of the queued command which can be canceled using
91 * g_at_chat_cancel. If an error occurred, an id of 0 is returned.
93 * This function can be used in three ways:
94 * - Send a simple command such as g_at_chat_send(p, "AT+CGMI?", ...
96 * - Send a compound command: g_at_chat_send(p, "AT+CMD1;+CMD2", ...
98 * - Send a command requiring a prompt. The command up to '\r' is sent
99 * after which time a '> ' prompt is expected from the modem. Further
100 * contents of the command are sent until a '\r' or end of string is
101 * encountered. If end of string is encountered, the Ctrl-Z character
102 * is sent automatically. There is no need to include the Ctrl-Z
105 * The valid_resp field can be used to send an array of strings which will
106 * be accepted as a valid response for this command. This is treated as a
107 * simple prefix match. If a response line comes in from the modem and it
108 * does not match any of the prefixes in valid_resp, it is treated as an
109 * unsolicited notification. If valid_resp is NULL, then all response
110 * lines after command submission and final response line are treated as
111 * part of the command response. This can be used to get around broken
112 * modems which send unsolicited notifications during command processing.
114 guint g_at_chat_send(GAtChat *chat, const char *cmd,
115 const char **valid_resp, GAtResultFunc func,
116 gpointer user_data, GDestroyNotify notify);
119 * Same as the above command, except that the caller wishes to receive the
120 * intermediate responses immediately through the GAtNotifyFunc callback.
121 * The final response will still be sent to GAtResultFunc callback. The
122 * final GAtResult will not contain any lines from the intermediate responses.
123 * This is useful for listing commands such as CPBR.
125 guint g_at_chat_send_listing(GAtChat *chat, const char *cmd,
126 const char **valid_resp,
127 GAtNotifyFunc listing, GAtResultFunc func,
128 gpointer user_data, GDestroyNotify notify);
131 * Same as g_at_chat_send_listing except every response line in valid_resp
132 * is expected to be followed by a PDU. The listing function will be called
133 * with the intermediate response and the following PDU line.
135 * This is useful for PDU listing commands like the +CMGL
137 guint g_at_chat_send_pdu_listing(GAtChat *chat, const char *cmd,
138 const char **valid_resp,
139 GAtNotifyFunc listing, GAtResultFunc func,
140 gpointer user_data, GDestroyNotify notify);
143 * Same as g_at_chat_send except parser will know to expect short prompt syntax
146 guint g_at_chat_send_and_expect_short_prompt(GAtChat *chat, const char *cmd,
147 const char **valid_resp, GAtResultFunc func,
148 gpointer user_data, GDestroyNotify notify);
150 gboolean g_at_chat_cancel(GAtChat *chat, guint id);
151 gboolean g_at_chat_cancel_all(GAtChat *chat);
153 guint g_at_chat_register(GAtChat *chat, const char *prefix,
154 GAtNotifyFunc func, gboolean expect_pdu,
155 gpointer user_data, GDestroyNotify notify);
157 gboolean g_at_chat_unregister(GAtChat *chat, guint id);
158 gboolean g_at_chat_unregister_all(GAtChat *chat);
160 gboolean g_at_chat_set_wakeup_command(GAtChat *chat, const char *cmd,
161 guint timeout, guint msec);
163 void g_at_chat_add_terminator(GAtChat *chat, char *terminator,
164 int len, gboolean success);
165 void g_at_chat_blacklist_terminator(GAtChat *chat,
166 GAtChatTerminator terminator);
172 #endif /* __GATCHAT_H */