---
gatchat/gathdlc.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c
index 6c39e6c..38606b8 100644
--- a/gatchat/gathdlc.c
+++ b/gatchat/gathdlc.c
@@ -66,6 +66,10 @@ struct _GAtHDLC {
gboolean in_read_handler;
gboolean destroyed;
gboolean no_carrier_detect;
+ GAtSuspendFunc suspend_func;
+ gpointer suspend_data;
+ guint cmpt;
+ guint suspend_timeout;
};
static void hdlc_record(int fd, gboolean in, guint8 *data, guint16 length)
@@ -128,6 +132,34 @@ guint32 g_at_hdlc_get_recv_accm(GAtHDLC *hdlc)
return hdlc->recv_accm;
}
+void g_at_hdlc_set_suspend_function(GAtHDLC *hdlc, GAtSuspendFunc func,
+ gpointer user_data)
+{
+ if (hdlc == NULL)
+ return;
+
+ hdlc->suspend_func = func;
+ hdlc->suspend_data = user_data;
+}
+
+static gboolean susp_timeout_cb(gpointer user_data)
+{
+ GAtHDLC *hdlc = user_data;
+
+ hdlc->cmpt = 0;
+
+ return FALSE;
+}
+
+static void hdlc_suspend(GAtHDLC *hdlc)
+{
+ g_at_io_set_write_handler(hdlc->io, NULL, NULL);
+ g_at_io_set_read_handler(hdlc->io, NULL, NULL);
+
+ if (hdlc->suspend_func)
+ hdlc->suspend_func(hdlc->suspend_data);
+}
+
static void new_bytes(struct ring_buffer *rbuf, gpointer user_data)
{
GAtHDLC *hdlc = user_data;
@@ -151,6 +183,21 @@ static void new_bytes(struct ring_buffer *rbuf, gpointer
user_data)
hdlc->decode_offset == 0 && *buf == '\r')
break;
+ /* We detect the '+' character to suspend data call if
+ * 3 '+' are detected in less than 500 milliseconds
+ */
+ if (*buf == '+') {
+ if (hdlc->cmpt == 0)
+ hdlc->suspend_timeout = g_timeout_add (500,
+ susp_timeout_cb, hdlc);
+ hdlc->cmpt++;
+ if (hdlc->cmpt == 3)
+ goto suspend;
+ }
+ else {
+ hdlc->cmpt = 0;
+ }
+
if (hdlc->decode_escape == TRUE) {
unsigned char val = *buf ^ HDLC_TRANS;
@@ -195,6 +242,15 @@ out:
if (hdlc->destroyed)
g_free(hdlc);
+
+ return;
+
+suspend:
+ g_source_remove(hdlc->suspend_timeout);
+
+ ring_buffer_reset(rbuf);
+
+ hdlc_suspend(hdlc);
}
GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io)
@@ -236,6 +292,8 @@ GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io)
hdlc->io = g_at_io_ref(io);
g_at_io_set_read_handler(hdlc->io, new_bytes, hdlc);
+ hdlc->cmpt = 0;
+
return hdlc;
error:
--
1.7.1
_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono