at-serial-port: new properties to define and manage a set of init commands
We are now able to specify a list of AT commands to be run whenever the port is opened for the first time (i.e. open_count from 0 to 1). These commands are to be treated as a 'port initialization' sequence, where port-configuration specific AT commands are defined (e.g. ATE0).
This commit is contained in:
@@ -31,6 +31,8 @@ G_DEFINE_TYPE (MMAtSerialPort, mm_at_serial_port, MM_TYPE_SERIAL_PORT)
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_REMOVE_ECHO,
|
||||
PROP_INIT_SEQUENCE_ENABLED,
|
||||
PROP_INIT_SEQUENCE,
|
||||
LAST_PROP
|
||||
};
|
||||
|
||||
@@ -44,7 +46,10 @@ typedef struct {
|
||||
|
||||
MMAtPortFlag flags;
|
||||
|
||||
/* Properties */
|
||||
gboolean remove_echo;
|
||||
guint init_sequence_enabled;
|
||||
gchar **init_sequence;
|
||||
} MMAtSerialPortPrivate;
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -417,6 +422,40 @@ mm_at_serial_port_get_flags (MMAtSerialPort *self)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
mm_at_serial_port_run_init_sequence (MMAtSerialPort *self)
|
||||
{
|
||||
MMAtSerialPortPrivate *priv = MM_AT_SERIAL_PORT_GET_PRIVATE (self);
|
||||
guint i;
|
||||
|
||||
if (!priv->init_sequence)
|
||||
return;
|
||||
|
||||
mm_dbg ("(%s): running init sequence...", mm_port_get_device (MM_PORT (self)));
|
||||
|
||||
/* Just queue the init commands, don't wait for reply */
|
||||
for (i = 0; priv->init_sequence[i]; i++) {
|
||||
mm_at_serial_port_queue_command (self,
|
||||
priv->init_sequence[i],
|
||||
3,
|
||||
FALSE,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
config (MMSerialPort *self)
|
||||
{
|
||||
MMAtSerialPortPrivate *priv = MM_AT_SERIAL_PORT_GET_PRIVATE (self);
|
||||
|
||||
if (priv->init_sequence_enabled)
|
||||
mm_at_serial_port_run_init_sequence (MM_AT_SERIAL_PORT (self));
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
MMAtSerialPort *
|
||||
mm_at_serial_port_new (const char *name)
|
||||
{
|
||||
@@ -434,6 +473,8 @@ mm_at_serial_port_init (MMAtSerialPort *self)
|
||||
|
||||
/* By default, remove echo */
|
||||
priv->remove_echo = TRUE;
|
||||
/* By default, run init sequence during first port opening */
|
||||
priv->init_sequence_enabled = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -446,6 +487,13 @@ set_property (GObject *object, guint prop_id,
|
||||
case PROP_REMOVE_ECHO:
|
||||
priv->remove_echo = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_INIT_SEQUENCE_ENABLED:
|
||||
priv->init_sequence_enabled = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_INIT_SEQUENCE:
|
||||
g_strfreev (priv->init_sequence);
|
||||
priv->init_sequence = g_value_dup_boxed (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -462,6 +510,12 @@ get_property (GObject *object, guint prop_id,
|
||||
case PROP_REMOVE_ECHO:
|
||||
g_value_set_boolean (value, priv->remove_echo);
|
||||
break;
|
||||
case PROP_INIT_SEQUENCE_ENABLED:
|
||||
g_value_set_boolean (value, priv->init_sequence_enabled);
|
||||
break;
|
||||
case PROP_INIT_SEQUENCE:
|
||||
g_value_set_boxed (value, priv->init_sequence);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@@ -509,6 +563,7 @@ mm_at_serial_port_class_init (MMAtSerialPortClass *klass)
|
||||
port_class->parse_response = parse_response;
|
||||
port_class->handle_response = handle_response;
|
||||
port_class->debug_log = debug_log;
|
||||
port_class->config = config;
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_REMOVE_ECHO,
|
||||
@@ -517,4 +572,20 @@ mm_at_serial_port_class_init (MMAtSerialPortClass *klass)
|
||||
"Built-in echo removal should be applied",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_INIT_SEQUENCE_ENABLED,
|
||||
g_param_spec_boolean (MM_AT_SERIAL_PORT_INIT_SEQUENCE_ENABLED,
|
||||
"Init sequence enabled",
|
||||
"Whether the initialization sequence should be run",
|
||||
TRUE,
|
||||
G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_INIT_SEQUENCE,
|
||||
g_param_spec_boxed (MM_AT_SERIAL_PORT_INIT_SEQUENCE,
|
||||
"Init sequence",
|
||||
"Initialization sequence",
|
||||
G_TYPE_STRV,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
@@ -66,6 +66,8 @@ typedef void (*MMAtSerialResponseFn) (MMAtSerialPort *port,
|
||||
gpointer user_data);
|
||||
|
||||
#define MM_AT_SERIAL_PORT_REMOVE_ECHO "remove-echo"
|
||||
#define MM_AT_SERIAL_PORT_INIT_SEQUENCE_ENABLED "init-sequence-enabled"
|
||||
#define MM_AT_SERIAL_PORT_INIT_SEQUENCE "init-sequence"
|
||||
|
||||
struct _MMAtSerialPort {
|
||||
MMSerialPort parent;
|
||||
@@ -120,4 +122,7 @@ void mm_at_serial_port_set_flags (MMAtSerialPort *self,
|
||||
|
||||
MMAtPortFlag mm_at_serial_port_get_flags (MMAtSerialPort *self);
|
||||
|
||||
/* Tell the port to run its init sequence, if any, right away */
|
||||
void mm_at_serial_port_run_init_sequence (MMAtSerialPort *self);
|
||||
|
||||
#endif /* MM_AT_SERIAL_PORT_H */
|
||||
|
@@ -947,6 +947,11 @@ mm_serial_port_open (MMSerialPort *self, GError **error)
|
||||
success:
|
||||
priv->open_count++;
|
||||
mm_dbg ("(%s) device open count is %d (open)", device, priv->open_count);
|
||||
|
||||
/* Run additional port config if just opened */
|
||||
if (priv->open_count == 1 && MM_SERIAL_PORT_GET_CLASS (self)->config)
|
||||
MM_SERIAL_PORT_GET_CLASS (self)->config (self);
|
||||
|
||||
return TRUE;
|
||||
|
||||
error:
|
||||
|
@@ -87,11 +87,15 @@ struct _MMSerialPortClass {
|
||||
GCallback callback,
|
||||
gpointer callback_data);
|
||||
|
||||
/* Called to configure the serial port after it's opened. On error, should
|
||||
/* Called to configure the serial port fd after it's opened. On error, should
|
||||
* return FALSE and set 'error' as appropriate.
|
||||
*/
|
||||
gboolean (*config_fd) (MMSerialPort *self, int fd, GError **error);
|
||||
|
||||
/* Called to configure the serial port after it's opened. Errors, if any,
|
||||
* should get ignored. */
|
||||
void (*config) (MMSerialPort *self);
|
||||
|
||||
void (*debug_log) (MMSerialPort *self,
|
||||
const char *prefix,
|
||||
const char *buf,
|
||||
|
Reference in New Issue
Block a user