From 5fea0c006a1138e4bad4b6330938033ad7fb0887 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Tue, 9 Aug 2011 13:40:10 -0700 Subject: gatchat: Add support for sending HDLC frame start and end markers --- gatchat/gathdlc.c | 28 ++++++++++++++++++++++------ gatchat/gathdlc.h | 1 + 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'gatchat') diff --git a/gatchat/gathdlc.c b/gatchat/gathdlc.c index de6a9726..53dd1fb5 100644 --- a/gatchat/gathdlc.c +++ b/gatchat/gathdlc.c @@ -70,6 +70,8 @@ struct _GAtHDLC { int record_fd; gboolean in_read_handler; gboolean destroyed; + gboolean wakeup_sent; + gboolean start_frame_marker; gboolean no_carrier_detect; GAtSuspendFunc suspend_func; gpointer suspend_data; @@ -328,7 +330,6 @@ out: GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io) { GAtHDLC *hdlc; - unsigned char *buf; struct ring_buffer* write_buffer; if (io == NULL) @@ -357,11 +358,6 @@ GAtHDLC *g_at_hdlc_new_from_io(GAtIO *io) g_queue_push_tail(hdlc->write_queue, write_buffer); - /* Write an initial 0x7e as wakeup character */ - buf = ring_buffer_write_ptr(write_buffer, 0); - *buf = HDLC_FLAG; - ring_buffer_write_advance(write_buffer, 1); - hdlc->decode_buffer = g_try_malloc(BUFFER_SIZE); if (!hdlc->decode_buffer) goto error; @@ -563,6 +559,17 @@ gboolean g_at_hdlc_send(GAtHDLC *hdlc, const unsigned char *data, gsize size) i = 0; buf = ring_buffer_write_ptr(write_buffer, 0); + if (hdlc->start_frame_marker == TRUE) { + /* Protocol requires 0x7e as start marker */ + *buf++ = HDLC_FLAG; + pos++; + } else if (hdlc->wakeup_sent == FALSE) { + /* Write an initial 0x7e as wakeup character */ + *buf++ = HDLC_FLAG; + pos++; + hdlc->wakeup_sent = TRUE; + } + while (pos < avail && i < size) { if (escape == TRUE) { fcs = HDLC_FCS(fcs, data[i]); @@ -616,6 +623,7 @@ gboolean g_at_hdlc_send(GAtHDLC *hdlc, const unsigned char *data, gsize size) if (pos + 1 > avail) return FALSE; + /* Add 0x7e as end marker */ *buf = HDLC_FLAG; pos++; @@ -626,6 +634,14 @@ gboolean g_at_hdlc_send(GAtHDLC *hdlc, const unsigned char *data, gsize size) return TRUE; } +void g_at_hdlc_set_start_frame_marker(GAtHDLC *hdlc, gboolean marker) +{ + if (hdlc == NULL) + return; + + hdlc->start_frame_marker = marker; +} + void g_at_hdlc_set_no_carrier_detect(GAtHDLC *hdlc, gboolean detect) { if (hdlc == NULL) diff --git a/gatchat/gathdlc.h b/gatchat/gathdlc.h index e82b33e2..a7aab2fe 100644 --- a/gatchat/gathdlc.h +++ b/gatchat/gathdlc.h @@ -55,6 +55,7 @@ void g_at_hdlc_set_recording(GAtHDLC *hdlc, const char *filename); GAtIO *g_at_hdlc_get_io(GAtHDLC *hdlc); +void g_at_hdlc_set_start_frame_marker(GAtHDLC *hdlc, gboolean marker); void g_at_hdlc_set_no_carrier_detect(GAtHDLC *hdlc, gboolean detect); void g_at_hdlc_set_suspend_function(GAtHDLC *hdlc, GAtSuspendFunc func, -- cgit v1.2.3