intel: XMM7360: Print raw serial port data when it is actually sent/dispatched

With serial port interlocking just queuing serial port data does not mean
it will be immediately sent - the other serial port could be still busy.

For debugging serial port issues it is often necessary to see the exact
moment the data was sent or received.

Implement debug_log method for MMPortSerialXmmrpcXmm7360 and log raw serial
port data there (just as MMPortSerialAt does) instead of doing this in the
command queuing function.
The debug_log method is called by MMPortSerial base when the data is about
to be actually sent to the serial port.

Additionally, log command response body where it is actually returned to
higher layers rather than in the unsolicited response handler.

Signed-off-by: Maciej S. Szmigiero <mail@maciej.szmigiero.name>
This commit is contained in:
Maciej S. Szmigiero
2025-06-14 16:02:23 -05:00
committed by Dan Williams
parent 912e857831
commit 6c4b90de79
@@ -535,6 +535,12 @@ serial_command_ready (MMPortSerial *port,
g_byte_array_remove_range (response_buffer, 0, response_buffer->len);
g_byte_array_unref (response_buffer);
if (response &&
response->type == XMM7360_RPC_RESPONSE_TYPE_RESPONSE) {
xmm7360_byte_array_log (port, "", response->body);
xmm7360_rpc_msg_args_log (port, "", response->content);
}
g_task_return_pointer (task, response, (GDestroyNotify) xmm7360_rpc_response_free);
g_object_unref (task);
}
@@ -569,10 +575,9 @@ mm_port_serial_xmmrpc_xmm7360_command (MMPortSerialXmmrpcXmm7360 *self,
task = g_task_new (self, NULL, callback, user_data);
/* Body logged in debug_log() */
mm_obj_dbg (self, "--> %s%s", is_async ? "(async) " : "", xmm_7360_rpc_call_id_get_string (callid));
xmm7360_byte_array_log (self, "", buf);
mm_port_serial_command (MM_PORT_SERIAL (self),
buf,
timeout_seconds,
@@ -656,8 +661,7 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response_buffer)
if (response->type == XMM7360_RPC_RESPONSE_TYPE_RESPONSE) {
mm_obj_dbg (port, "<-- (response)");
xmm7360_byte_array_log (port, "", response->body);
xmm7360_rpc_msg_args_log (port, "", response->content);
/* Body logged in serial_command_ready() */
return;
}
@@ -692,6 +696,37 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response_buffer)
g_byte_array_remove_range (response_buffer, 0, response_buffer->len);
}
static void
debug_log (MMPortSerial *self,
const gchar *prefix,
const gchar *buf,
gsize len)
{
static GString *debug = NULL;
const char *s;
if (g_strcmp0 (prefix, "<--") == 0) {
/* Incoming data is already logged in parse functions */
return;
}
if (!debug)
debug = g_string_sized_new (256);
g_string_append (debug, prefix);
g_string_append (debug, " raw [");
s = buf;
while (len--) {
g_string_append_printf (debug, "%02x", (guint8)*s);
s++;
}
g_string_append_c (debug, ']');
mm_obj_dbg (self, "%s", debug->str);
g_string_truncate (debug, 0);
}
/*****************************************************************************/
MMPortSerialXmmrpcXmm7360 *
@@ -747,4 +782,5 @@ mm_port_serial_xmmrpc_xmm7360_class_init (MMPortSerialXmmrpcXmm7360Class *klass)
serial_class->parse_response = parse_response;
serial_class->parse_unsolicited = parse_unsolicited;
serial_class->debug_log = debug_log;
}