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.
This commit is contained in:
@@ -213,6 +213,7 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
|
|||||||
ctx->port,
|
ctx->port,
|
||||||
"AT^CURC=0",
|
"AT^CURC=0",
|
||||||
3,
|
3,
|
||||||
|
FALSE, /* raw */
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)curc_ready,
|
(MMAtSerialResponseFn)curc_ready,
|
||||||
ctx);
|
ctx);
|
||||||
@@ -232,6 +233,7 @@ huawei_custom_init_step (HuaweiCustomInitContext *ctx)
|
|||||||
ctx->port,
|
ctx->port,
|
||||||
"AT^GETPORTMODE",
|
"AT^GETPORTMODE",
|
||||||
3,
|
3,
|
||||||
|
FALSE, /* raw */
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)getportmode_ready,
|
(MMAtSerialResponseFn)getportmode_ready,
|
||||||
ctx);
|
ctx);
|
||||||
|
@@ -130,6 +130,7 @@ longcheer_custom_init_step (LongcheerCustomInitContext *ctx)
|
|||||||
ctx->port,
|
ctx->port,
|
||||||
"AT+GMR",
|
"AT+GMR",
|
||||||
3,
|
3,
|
||||||
|
FALSE, /* raw */
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)gmr_ready,
|
(MMAtSerialResponseFn)gmr_ready,
|
||||||
ctx);
|
ctx);
|
||||||
|
@@ -124,6 +124,7 @@ sierra_custom_init_step (SierraCustomInitContext *ctx)
|
|||||||
ctx->port,
|
ctx->port,
|
||||||
"AT+GCAP",
|
"AT+GCAP",
|
||||||
3,
|
3,
|
||||||
|
FALSE, /* raw */
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)gcap_ready,
|
(MMAtSerialResponseFn)gcap_ready,
|
||||||
ctx);
|
ctx);
|
||||||
|
@@ -129,6 +129,7 @@ x22x_custom_init_step (X22xCustomInitContext *ctx)
|
|||||||
ctx->port,
|
ctx->port,
|
||||||
"AT+GMR",
|
"AT+GMR",
|
||||||
3,
|
3,
|
||||||
|
FALSE, /* raw */
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)gmr_ready,
|
(MMAtSerialResponseFn)gmr_ready,
|
||||||
ctx);
|
ctx);
|
||||||
|
@@ -281,7 +281,7 @@ parse_unsolicited (MMSerialPort *port, GByteArray *response)
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
static GByteArray *
|
static GByteArray *
|
||||||
at_command_to_byte_array (const char *command)
|
at_command_to_byte_array (const char *command, gboolean is_raw)
|
||||||
{
|
{
|
||||||
GByteArray *buf;
|
GByteArray *buf;
|
||||||
int cmdlen;
|
int cmdlen;
|
||||||
@@ -291,14 +291,19 @@ at_command_to_byte_array (const char *command)
|
|||||||
cmdlen = strlen (command);
|
cmdlen = strlen (command);
|
||||||
buf = g_byte_array_sized_new (cmdlen + 3);
|
buf = g_byte_array_sized_new (cmdlen + 3);
|
||||||
|
|
||||||
/* Make sure there's an AT in the front */
|
if (!is_raw) {
|
||||||
if (!g_str_has_prefix (command, "AT"))
|
/* Make sure there's an AT in the front */
|
||||||
g_byte_array_append (buf, (const guint8 *) "AT", 2);
|
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);
|
g_byte_array_append (buf, (const guint8 *) command, cmdlen);
|
||||||
|
|
||||||
/* Make sure there's a trailing carriage return */
|
if (!is_raw) {
|
||||||
if (command[cmdlen - 1] != '\r')
|
/* Make sure there's a trailing carriage return */
|
||||||
g_byte_array_append (buf, (const guint8 *) "\r", 1);
|
if (command[cmdlen - 1] != '\r')
|
||||||
|
g_byte_array_append (buf, (const guint8 *) "\r", 1);
|
||||||
|
}
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@@ -307,6 +312,7 @@ void
|
|||||||
mm_at_serial_port_queue_command (MMAtSerialPort *self,
|
mm_at_serial_port_queue_command (MMAtSerialPort *self,
|
||||||
const char *command,
|
const char *command,
|
||||||
guint32 timeout_seconds,
|
guint32 timeout_seconds,
|
||||||
|
gboolean is_raw,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
MMAtSerialResponseFn callback,
|
MMAtSerialResponseFn callback,
|
||||||
gpointer user_data)
|
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 (MM_IS_AT_SERIAL_PORT (self));
|
||||||
g_return_if_fail (command != NULL);
|
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);
|
g_return_if_fail (buf != NULL);
|
||||||
|
|
||||||
mm_serial_port_queue_command (MM_SERIAL_PORT (self),
|
mm_serial_port_queue_command (MM_SERIAL_PORT (self),
|
||||||
@@ -333,6 +339,7 @@ void
|
|||||||
mm_at_serial_port_queue_command_cached (MMAtSerialPort *self,
|
mm_at_serial_port_queue_command_cached (MMAtSerialPort *self,
|
||||||
const char *command,
|
const char *command,
|
||||||
guint32 timeout_seconds,
|
guint32 timeout_seconds,
|
||||||
|
gboolean is_raw,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
MMAtSerialResponseFn callback,
|
MMAtSerialResponseFn callback,
|
||||||
gpointer user_data)
|
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 (MM_IS_AT_SERIAL_PORT (self));
|
||||||
g_return_if_fail (command != NULL);
|
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);
|
g_return_if_fail (buf != NULL);
|
||||||
|
|
||||||
mm_serial_port_queue_command_cached (MM_SERIAL_PORT (self),
|
mm_serial_port_queue_command_cached (MM_SERIAL_PORT (self),
|
||||||
|
@@ -93,6 +93,7 @@ void mm_at_serial_port_set_response_parser (MMAtSerialPort *self,
|
|||||||
void mm_at_serial_port_queue_command (MMAtSerialPort *self,
|
void mm_at_serial_port_queue_command (MMAtSerialPort *self,
|
||||||
const char *command,
|
const char *command,
|
||||||
guint32 timeout_seconds,
|
guint32 timeout_seconds,
|
||||||
|
gboolean is_raw,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
MMAtSerialResponseFn callback,
|
MMAtSerialResponseFn callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
@@ -100,6 +101,7 @@ void mm_at_serial_port_queue_command (MMAtSerialPort *self,
|
|||||||
void mm_at_serial_port_queue_command_cached (MMAtSerialPort *self,
|
void mm_at_serial_port_queue_command_cached (MMAtSerialPort *self,
|
||||||
const char *command,
|
const char *command,
|
||||||
guint32 timeout_seconds,
|
guint32 timeout_seconds,
|
||||||
|
gboolean is_raw,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
MMAtSerialResponseFn callback,
|
MMAtSerialResponseFn callback,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
@@ -201,6 +201,7 @@ at_sequence_parse_response (MMAtSerialPort *port,
|
|||||||
ctx->port,
|
ctx->port,
|
||||||
ctx->current->command,
|
ctx->current->command,
|
||||||
ctx->current->timeout,
|
ctx->current->timeout,
|
||||||
|
FALSE,
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)at_sequence_parse_response,
|
(MMAtSerialResponseFn)at_sequence_parse_response,
|
||||||
ctx);
|
ctx);
|
||||||
@@ -209,6 +210,7 @@ at_sequence_parse_response (MMAtSerialPort *port,
|
|||||||
ctx->port,
|
ctx->port,
|
||||||
ctx->current->command,
|
ctx->current->command,
|
||||||
ctx->current->timeout,
|
ctx->current->timeout,
|
||||||
|
FALSE,
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)at_sequence_parse_response,
|
(MMAtSerialResponseFn)at_sequence_parse_response,
|
||||||
ctx);
|
ctx);
|
||||||
@@ -288,6 +290,7 @@ mm_base_modem_at_sequence_full (MMBaseModem *self,
|
|||||||
ctx->port,
|
ctx->port,
|
||||||
ctx->current->command,
|
ctx->current->command,
|
||||||
ctx->current->timeout,
|
ctx->current->timeout,
|
||||||
|
FALSE,
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)at_sequence_parse_response,
|
(MMAtSerialResponseFn)at_sequence_parse_response,
|
||||||
ctx);
|
ctx);
|
||||||
@@ -535,6 +538,7 @@ mm_base_modem_at_command_full (MMBaseModem *self,
|
|||||||
port,
|
port,
|
||||||
command,
|
command,
|
||||||
timeout,
|
timeout,
|
||||||
|
FALSE,
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)at_command_parse_response,
|
(MMAtSerialResponseFn)at_command_parse_response,
|
||||||
ctx);
|
ctx);
|
||||||
@@ -543,6 +547,7 @@ mm_base_modem_at_command_full (MMBaseModem *self,
|
|||||||
port,
|
port,
|
||||||
command,
|
command,
|
||||||
timeout,
|
timeout,
|
||||||
|
FALSE,
|
||||||
ctx->cancellable,
|
ctx->cancellable,
|
||||||
(MMAtSerialResponseFn)at_command_parse_response,
|
(MMAtSerialResponseFn)at_command_parse_response,
|
||||||
ctx);
|
ctx);
|
||||||
|
@@ -583,6 +583,7 @@ serial_probe_at (MMPortProbe *self)
|
|||||||
MM_AT_SERIAL_PORT (task->serial),
|
MM_AT_SERIAL_PORT (task->serial),
|
||||||
task->at_commands->command,
|
task->at_commands->command,
|
||||||
task->at_commands->timeout,
|
task->at_commands->timeout,
|
||||||
|
FALSE,
|
||||||
task->at_probing_cancellable,
|
task->at_probing_cancellable,
|
||||||
(MMAtSerialResponseFn)serial_probe_at_parse_response,
|
(MMAtSerialResponseFn)serial_probe_at_parse_response,
|
||||||
self);
|
self);
|
||||||
|
Reference in New Issue
Block a user