---
gatchat/gatchat.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++----
gatchat/gatchat.h | 8 +++
2 files changed, 124 insertions(+), 9 deletions(-)
diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c
index e85d908..6a9329c 100644
--- a/gatchat/gatchat.c
+++ b/gatchat/gatchat.c
@@ -53,6 +53,7 @@ struct at_command {
GAtNotifyFunc listing;
gpointer user_data;
GDestroyNotify notify;
+ gint cmd_len;
};
struct at_notify_node {
@@ -208,7 +209,8 @@ static struct at_command *at_command_create(guint gid, const char
*cmd,
}
c->cmd[len] = '\0';
-
+ /* Normal AT Command without length */
+ c->cmd_len = -1;
c->gid = gid;
c->expect_pdu = expect_pdu;
c->prefixes = prefixes;
@@ -733,7 +735,7 @@ static gboolean can_write_data(gpointer data)
struct at_chat *chat = data;
struct at_command *cmd;
gsize bytes_written;
- gsize towrite;
+ gsize towrite = 0;
gsize len;
char *cr;
gboolean wakeup_first = FALSE;
@@ -747,7 +749,13 @@ static gboolean can_write_data(gpointer data)
if (cmd == NULL)
return FALSE;
- len = strlen(cmd->cmd);
+ if (cmd->cmd_len == -1) {
+ /* Normal AT Command length */
+ len = strlen(cmd->cmd);
+ } else {
+ /* SMS text mode AT command length */
+ len = cmd->cmd_len;
+ }
/* For some reason write watcher fired, but we've already
* written the entire command out to the io channel,
@@ -781,12 +789,25 @@ static gboolean can_write_data(gpointer data)
wakeup_no_response, chat);
}
- towrite = len - chat->cmd_bytes_written;
-
- cr = strchr(cmd->cmd + chat->cmd_bytes_written, '\r');
-
- if (cr)
- towrite = cr - (cmd->cmd + chat->cmd_bytes_written) + 1;
+ if (cmd->cmd_len == -1) {
+ /* Normal AT Command write */
+ towrite = len - chat->cmd_bytes_written;
+ cr = strchr(cmd->cmd + chat->cmd_bytes_written, '\r');
+ if (cr)
+ towrite = cr - (cmd->cmd + chat->cmd_bytes_written) + 1;
+ } else {
+ /* SMS text mode AT command write */
+ if (chat->cmd_bytes_written == 0) {
+ /* SMS text mode AT command write prefix */
+ cr = strchr(cmd->cmd + chat->cmd_bytes_written, '\r');
+ if (cr)
+ towrite = cr - (cmd->cmd
+ + chat->cmd_bytes_written) + 1;
+ } else {
+ /* SMS text mode AT command write message content */
+ towrite = len - chat->cmd_bytes_written;
+ }
+ }
#ifdef WRITE_SCHEDULER_DEBUG
if (towrite > 5)
@@ -1433,3 +1454,89 @@ gboolean g_at_chat_unregister_all(GAtChat *chat)
return at_chat_unregister_group(chat->parent, chat->group);
}
+
+/*
+ * Create SMS text mode command with length
+ */
+static struct at_command *at_command_with_len_create(const char *cmd,
+ int cmdlen, const char **prefix_list, GAtResultFunc func,
+ gpointer user_data, GDestroyNotify notify) {
+ struct at_command *c;
+ gsize len;
+
+ char **prefixes = NULL;
+
+ if (prefix_list) {
+ int num_prefixes = 0;
+ int i;
+
+ while (prefix_list[num_prefixes])
+ num_prefixes += 1;
+
+ prefixes = g_new(char *, num_prefixes + 1);
+
+ for (i = 0; i < num_prefixes; i++)
+ prefixes[i] = strdup(prefix_list[i]);
+
+ prefixes[num_prefixes] = NULL;
+ }
+
+ c = g_try_new0(struct at_command, 1);
+
+ if (!c)
+ return 0;
+
+ len = cmdlen;
+ c->cmd = g_try_new(char, len+1);
+
+ if (!c->cmd) {
+ g_free(c);
+ return 0;
+ }
+
+ memcpy(c->cmd, cmd, len);
+
+ /* SMS text mode AT command with length */
+ c->cmd[len] = '\0';
+ c->cmd_len = len;
+
+ c->expect_pdu = FALSE;
+ c->prefixes = prefixes;
+ c->callback = func;
+ c->listing = NULL;
+ c->user_data = user_data;
+ c->notify = notify;
+
+ return c;
+}
+/*
+ * Send AT command with length.
+ * Such as SMS text mode which contains 0x00 or 0x0A, 0x0D
+ */
+guint g_at_chat_send_with_len(GAtChat *child, const char *cmd, int cmdlen,
+ const char **prefix_list,
+ GAtResultFunc func, gpointer user_data,
+ GDestroyNotify notify) {
+
+ struct at_command *c;
+ struct at_chat *chat;
+ chat = child->parent;
+
+ if (chat == NULL || chat->command_queue == NULL)
+ return 0;
+
+ c = at_command_with_len_create(cmd, cmdlen, prefix_list, func,
+ user_data, notify);
+
+ if (!c)
+ return 0;
+
+ c->id = chat->next_cmd_id++;
+
+ g_queue_push_tail(chat->command_queue, c);
+
+ if (g_queue_get_length(chat->command_queue) == 1)
+ chat_wakeup_writer(chat);
+
+ return c->id;
+}
diff --git a/gatchat/gatchat.h b/gatchat/gatchat.h
index f61fe53..edd2137 100644
--- a/gatchat/gatchat.h
+++ b/gatchat/gatchat.h
@@ -137,6 +137,14 @@ gboolean g_at_chat_set_wakeup_command(GAtChat *chat, const char
*cmd,
void g_at_chat_add_terminator(GAtChat *chat, char *terminator,
int len, gboolean success);
+/*
+ * Send AT command with length.
+ * Such as SMS text mode which contains 0x00 or 0x0A, 0x0D
+ */
+guint g_at_chat_send_with_len(GAtChat *chat, const char *cmd, int cmdlen,
+ const char **prefix_list, GAtResultFunc func,
+ gpointer user_data, GDestroyNotify notify);
+
#ifdef __cplusplus
}
#endif
--
1.6.3.3