serial-port: new method to reopen a port
We will fully close the port and the re-open it again keeping the same open_count that we had before.
This commit is contained in:
@@ -1205,6 +1205,36 @@ mm_serial_port_queue_command_cached (MMSerialPort *self,
|
||||
internal_queue_command (self, command, take_command, TRUE, timeout_seconds, cancellable, callback, user_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mm_serial_port_reopen (MMSerialPort *self,
|
||||
GError **error)
|
||||
{
|
||||
MMSerialPortPrivate *priv;
|
||||
guint initial_open_count;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (MM_IS_SERIAL_PORT (self), FALSE);
|
||||
|
||||
priv = MM_SERIAL_PORT_GET_PRIVATE (self);
|
||||
initial_open_count = priv->open_count;
|
||||
|
||||
mm_dbg ("(%s) reopening port (%u)",
|
||||
mm_port_get_device (MM_PORT (self)),
|
||||
initial_open_count);
|
||||
|
||||
for (i = 0; i < initial_open_count; i++)
|
||||
mm_serial_port_close (self);
|
||||
|
||||
for (i = 0; i < initial_open_count; i++) {
|
||||
if (!mm_serial_port_open (self, error)) {
|
||||
g_prefix_error (error, "Couldn't reopen port (%u): ", i);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_speed (MMSerialPort *self, speed_t *speed, GError **error)
|
||||
{
|
||||
@@ -1676,7 +1706,7 @@ mm_serial_port_class_init (MMSerialPortClass *klass)
|
||||
g_object_class_install_property
|
||||
(object_class, PROP_FLASH_OK,
|
||||
g_param_spec_boolean (MM_SERIAL_PORT_FLASH_OK,
|
||||
"FlaskOk",
|
||||
"FlashOk",
|
||||
"Flashing the port (0 baud for a short period) "
|
||||
"is allowed.",
|
||||
TRUE,
|
||||
|
@@ -39,6 +39,7 @@
|
||||
#define MM_SERIAL_PORT_FD "fd" /* Construct-only */
|
||||
#define MM_SERIAL_PORT_SPEW_CONTROL "spew-control" /* Construct-only */
|
||||
#define MM_SERIAL_PORT_FLASH_OK "flash-ok" /* Construct-only */
|
||||
#define MM_SERIAL_PORT_FLASH_REOPEN "flash-reopen" /* Construct-only */
|
||||
|
||||
typedef struct _MMSerialPort MMSerialPort;
|
||||
typedef struct _MMSerialPortClass MMSerialPortClass;
|
||||
@@ -122,6 +123,9 @@ gboolean mm_serial_port_open (MMSerialPort *self,
|
||||
|
||||
void mm_serial_port_close (MMSerialPort *self);
|
||||
|
||||
gboolean mm_serial_port_reopen (MMSerialPort *self,
|
||||
GError **error);
|
||||
|
||||
gboolean mm_serial_port_flash (MMSerialPort *self,
|
||||
guint32 flash_time,
|
||||
gboolean ignore_errors,
|
||||
|
Reference in New Issue
Block a user