gatchat: Add support for sending HDLC frame start and end markers

This commit is contained in:
Marcel Holtmann 2011-08-09 13:40:10 -07:00
parent ee19210585
commit 5fea0c006a
2 changed files with 23 additions and 6 deletions

View File

@ -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)

View File

@ -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,