serial: let port subclasses handle their own debug logging
We want to print out QCDM messages as hex, not ASCII. So let each port type print out it's own communication as it wants to.
This commit is contained in:
@@ -268,6 +268,37 @@ mm_at_serial_port_queue_command_cached (MMAtSerialPort *self,
|
||||
user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
|
||||
{
|
||||
static GString *debug = NULL;
|
||||
const char *s;
|
||||
|
||||
if (!debug)
|
||||
debug = g_string_sized_new (256);
|
||||
|
||||
g_string_append (debug, prefix);
|
||||
g_string_append (debug, " '");
|
||||
|
||||
s = buf;
|
||||
while (len--) {
|
||||
if (g_ascii_isprint (*s))
|
||||
g_string_append_c (debug, *s);
|
||||
else if (*s == '\r')
|
||||
g_string_append (debug, "<CR>");
|
||||
else if (*s == '\n')
|
||||
g_string_append (debug, "<LF>");
|
||||
else
|
||||
g_string_append_printf (debug, "\\%d", *s);
|
||||
|
||||
s++;
|
||||
}
|
||||
|
||||
g_string_append_c (debug, '\'');
|
||||
g_debug ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str);
|
||||
g_string_truncate (debug, 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
MMAtSerialPort *
|
||||
@@ -323,4 +354,5 @@ mm_at_serial_port_class_init (MMAtSerialPortClass *klass)
|
||||
port_class->parse_unsolicited = parse_unsolicited;
|
||||
port_class->parse_response = parse_response;
|
||||
port_class->handle_response = handle_response;
|
||||
port_class->debug_log = debug_log;
|
||||
}
|
||||
|
@@ -152,6 +152,24 @@ mm_qcdm_serial_port_queue_command_cached (MMQcdmSerialPort *self,
|
||||
user_data);
|
||||
}
|
||||
|
||||
static void
|
||||
debug_log (MMSerialPort *port, const char *prefix, const char *buf, gsize len)
|
||||
{
|
||||
static GString *debug = NULL;
|
||||
const char *s = buf;
|
||||
|
||||
if (!debug)
|
||||
debug = g_string_sized_new (512);
|
||||
|
||||
g_string_append (debug, prefix);
|
||||
|
||||
while (len--)
|
||||
g_string_append_printf (debug, " %02x", (guint8) (*s++ & 0xFF));
|
||||
|
||||
g_debug ("(%s): %s", mm_port_get_device (MM_PORT (port)), debug->str);
|
||||
g_string_truncate (debug, 0);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
@@ -197,4 +215,5 @@ mm_qcdm_serial_port_class_init (MMQcdmSerialPortClass *klass)
|
||||
port_class->parse_response = parse_response;
|
||||
port_class->handle_response = handle_response;
|
||||
port_class->config_fd = config_fd;
|
||||
port_class->debug_log = debug_log;
|
||||
}
|
||||
|
@@ -343,40 +343,12 @@ real_config_fd (MMSerialPort *self, int fd, GError **error)
|
||||
}
|
||||
|
||||
static void
|
||||
serial_debug (MMSerialPort *self, const char *prefix, const char *buf, int len)
|
||||
serial_debug (MMSerialPort *self, const char *prefix, const char *buf, gsize len)
|
||||
{
|
||||
static GString *debug = NULL;
|
||||
const char *s;
|
||||
g_return_if_fail (len > 0);
|
||||
|
||||
if (!mm_options_debug ())
|
||||
return;
|
||||
|
||||
if (len < 0)
|
||||
len = strlen (buf);
|
||||
|
||||
if (!debug)
|
||||
debug = g_string_sized_new (256);
|
||||
|
||||
g_string_append (debug, prefix);
|
||||
g_string_append (debug, " '");
|
||||
|
||||
s = buf;
|
||||
while (len--) {
|
||||
if (g_ascii_isprint (*s))
|
||||
g_string_append_c (debug, *s);
|
||||
else if (*s == '\r')
|
||||
g_string_append (debug, "<CR>");
|
||||
else if (*s == '\n')
|
||||
g_string_append (debug, "<LF>");
|
||||
else
|
||||
g_string_append_printf (debug, "\\%d", *s);
|
||||
|
||||
s++;
|
||||
}
|
||||
|
||||
g_string_append_c (debug, '\'');
|
||||
g_debug ("(%s): %s", mm_port_get_device (MM_PORT (self)), debug->str);
|
||||
g_string_truncate (debug, 0);
|
||||
if (mm_options_debug () && MM_SERIAL_PORT_GET_CLASS (self)->debug_log)
|
||||
MM_SERIAL_PORT_GET_CLASS (self)->debug_log (self, prefix, buf, len);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@@ -88,6 +88,11 @@ struct _MMSerialPortClass {
|
||||
*/
|
||||
gboolean (*config_fd) (MMSerialPort *self, int fd, GError **error);
|
||||
|
||||
void (*debug_log) (MMSerialPort *self,
|
||||
const char *prefix,
|
||||
const char *buf,
|
||||
gsize len);
|
||||
|
||||
/* Signals */
|
||||
void (*buffer_full) (MMSerialPort *port, const GByteArray *buffer);
|
||||
};
|
||||
|
Reference in New Issue
Block a user