diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-08-24 11:39:19 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-08-24 12:32:28 +0200 |
commit | d9ea4a304c06d28c5f8d780abe6f57cc179ba2a8 (patch) | |
tree | 045dfade86a05d0c7428991c1162e3d8dc788832 /src/mm-at-serial-port.c | |
parent | d74336e96dc24b578324f45d57e108d686a95df5 (diff) |
at-serial-port: allow sending 'raw' commands
Commands treated as 'raw' won't get the 'AT' prefix and will also not get the
trailing carriage return.
Diffstat (limited to 'src/mm-at-serial-port.c')
-rw-r--r-- | src/mm-at-serial-port.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/mm-at-serial-port.c b/src/mm-at-serial-port.c index 38ec38e4..840f38a0 100644 --- a/src/mm-at-serial-port.c +++ b/src/mm-at-serial-port.c @@ -281,7 +281,7 @@ parse_unsolicited (MMSerialPort *port, GByteArray *response) /*****************************************************************************/ static GByteArray * -at_command_to_byte_array (const char *command) +at_command_to_byte_array (const char *command, gboolean is_raw) { GByteArray *buf; int cmdlen; @@ -291,14 +291,19 @@ at_command_to_byte_array (const char *command) cmdlen = strlen (command); buf = g_byte_array_sized_new (cmdlen + 3); - /* Make sure there's an AT in the front */ - if (!g_str_has_prefix (command, "AT")) - g_byte_array_append (buf, (const guint8 *) "AT", 2); + if (!is_raw) { + /* Make sure there's an AT in the front */ + if (!g_str_has_prefix (command, "AT")) + g_byte_array_append (buf, (const guint8 *) "AT", 2); + } + g_byte_array_append (buf, (const guint8 *) command, cmdlen); - /* Make sure there's a trailing carriage return */ - if (command[cmdlen - 1] != '\r') - g_byte_array_append (buf, (const guint8 *) "\r", 1); + if (!is_raw) { + /* Make sure there's a trailing carriage return */ + if (command[cmdlen - 1] != '\r') + g_byte_array_append (buf, (const guint8 *) "\r", 1); + } return buf; } @@ -307,6 +312,7 @@ void mm_at_serial_port_queue_command (MMAtSerialPort *self, const char *command, guint32 timeout_seconds, + gboolean is_raw, GCancellable *cancellable, MMAtSerialResponseFn callback, gpointer user_data) @@ -317,7 +323,7 @@ mm_at_serial_port_queue_command (MMAtSerialPort *self, g_return_if_fail (MM_IS_AT_SERIAL_PORT (self)); g_return_if_fail (command != NULL); - buf = at_command_to_byte_array (command); + buf = at_command_to_byte_array (command, is_raw); g_return_if_fail (buf != NULL); mm_serial_port_queue_command (MM_SERIAL_PORT (self), @@ -333,6 +339,7 @@ void mm_at_serial_port_queue_command_cached (MMAtSerialPort *self, const char *command, guint32 timeout_seconds, + gboolean is_raw, GCancellable *cancellable, MMAtSerialResponseFn callback, gpointer user_data) @@ -343,7 +350,7 @@ mm_at_serial_port_queue_command_cached (MMAtSerialPort *self, g_return_if_fail (MM_IS_AT_SERIAL_PORT (self)); g_return_if_fail (command != NULL); - buf = at_command_to_byte_array (command); + buf = at_command_to_byte_array (command, is_raw); g_return_if_fail (buf != NULL); mm_serial_port_queue_command_cached (MM_SERIAL_PORT (self), |