93 lines
3.3 KiB
Diff
93 lines
3.3 KiB
Diff
From: Aleksander Morgado <aleksander@aleksander.es>
|
|
Date: Sat, 25 Mar 2017 18:18:46 +0100
|
|
Subject: [PATCH] port-serial: new method to explicitly set flow control
|
|
settings
|
|
|
|
---
|
|
src/mm-port-serial.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
src/mm-port-serial.h | 5 +++++
|
|
2 files changed, 55 insertions(+)
|
|
|
|
diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c
|
|
index f2b97a02486d..e55f90625020 100644
|
|
--- a/src/mm-port-serial.c
|
|
+++ b/src/mm-port-serial.c
|
|
@@ -1778,6 +1778,56 @@ mm_port_serial_flash (MMPortSerial *self,
|
|
|
|
/*****************************************************************************/
|
|
|
|
+gboolean
|
|
+mm_port_serial_set_flow_control (MMPortSerial *self,
|
|
+ MMFlowControl flow_control,
|
|
+ GError **error)
|
|
+{
|
|
+ struct termios options;
|
|
+ gboolean had_xon_xoff;
|
|
+ gboolean had_rts_cts;
|
|
+
|
|
+ /* retrieve current settings */
|
|
+ memset (&options, 0, sizeof (struct termios));
|
|
+ if (tcgetattr (self->priv->fd, &options) != 0) {
|
|
+ g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
|
+ "couldn't get serial port attributes: %s", g_strerror (errno));
|
|
+ return FALSE;
|
|
+ }
|
|
+
|
|
+ /* clear all flow control flags */
|
|
+
|
|
+ had_xon_xoff = !!(options.c_iflag & (IXON | IXOFF));
|
|
+ options.c_iflag &= ~(IXON | IXOFF | IXANY);
|
|
+
|
|
+ had_rts_cts = !!(options.c_cflag & (CRTSCTS));
|
|
+ options.c_cflag &= ~(CRTSCTS);
|
|
+
|
|
+ /* setup the requested flags */
|
|
+ switch (flow_control) {
|
|
+ case MM_FLOW_CONTROL_XON_XOFF:
|
|
+ mm_dbg ("(%s): enabling XON/XOFF flow control", mm_port_get_device (MM_PORT (self)));
|
|
+ options.c_iflag |= (IXON | IXOFF | IXANY);
|
|
+ break;
|
|
+ case MM_FLOW_CONTROL_RTS_CTS:
|
|
+ mm_dbg ("(%s): enabling RTS/CTS flow control", mm_port_get_device (MM_PORT (self)));
|
|
+ options.c_cflag |= (CRTSCTS);
|
|
+ break;
|
|
+ case MM_FLOW_CONTROL_NONE:
|
|
+ if (had_xon_xoff)
|
|
+ mm_dbg ("(%s): disabling XON/XOFF flow control", mm_port_get_device (MM_PORT (self)));
|
|
+ if (had_rts_cts)
|
|
+ mm_dbg ("(%s): disabling RTS/CTS flow control", mm_port_get_device (MM_PORT (self)));
|
|
+ break;
|
|
+ default:
|
|
+ g_assert_not_reached ();
|
|
+ }
|
|
+
|
|
+ return internal_tcsetattr (self, self->priv->fd, &options, error);
|
|
+}
|
|
+
|
|
+/*****************************************************************************/
|
|
+
|
|
MMPortSerial *
|
|
mm_port_serial_new (const char *name, MMPortType ptype)
|
|
{
|
|
diff --git a/src/mm-port-serial.h b/src/mm-port-serial.h
|
|
index 708e39123412..223b9ce1c4a4 100644
|
|
--- a/src/mm-port-serial.h
|
|
+++ b/src/mm-port-serial.h
|
|
@@ -21,6 +21,7 @@
|
|
#include <glib-object.h>
|
|
#include <gio/gio.h>
|
|
|
|
+#include "mm-modem-helpers.h"
|
|
#include "mm-port.h"
|
|
|
|
#define MM_TYPE_PORT_SERIAL (mm_port_serial_get_type ())
|
|
@@ -150,4 +151,8 @@ GByteArray *mm_port_serial_command_finish (MMPortSerial *self,
|
|
GAsyncResult *res,
|
|
GError **error);
|
|
|
|
+gboolean mm_port_serial_set_flow_control (MMPortSerial *self,
|
|
+ MMFlowControl flow_control,
|
|
+ GError **error);
|
|
+
|
|
#endif /* MM_PORT_SERIAL_H */
|