[PATCH 17/25] efw-downloader: subcmd-device: support debug output for response of Fireworks protocol

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It's helpful to dump communication result optionally.

This commit adds debug option for the purpose.

Signed-off-by: Takashi Sakamoto <o-takashi@xxxxxxxxxxxxx>
---
 efw-downloader/src/subcmd-device.c | 40 ++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)

diff --git a/efw-downloader/src/subcmd-device.c b/efw-downloader/src/subcmd-device.c
index 5ac0ac6..329eef0 100644
--- a/efw-downloader/src/subcmd-device.c
+++ b/efw-downloader/src/subcmd-device.c
@@ -28,8 +28,31 @@ static int print_help()
     return EXIT_FAILURE;
 }
 
-static int parse_args(int argc, char **argv, const char **path, const char **op_name)
+static void handle_responded_signal(EfwProto *proto, HinawaSndEfwStatus status, guint seqnum,
+                      guint category, guint command, const guint32 *frame, guint frame_size)
 {
+    gchar *label = g_enum_to_string(HINAWA_TYPE_SND_EFW_STATUS, status);
+    int i;
+
+    printf("responded:\n");
+    printf("  status: %s\n", label);
+    printf("  seqnum: %d\n", seqnum);
+    printf("  category; %d\n", category);
+    printf("  command: %d\n", command);
+
+    if (frame_size > 0) {
+        printf("  frame:\n");
+        for (i = 0; i < frame_size; ++i)
+            printf("  [%3x]: %08x\n", i, frame[i]);
+    }
+
+    g_free(label);
+}
+
+static int parse_args(int argc, char **argv, const char **path, const char **op_name, gboolean *debug)
+{
+    int i;
+
     if (argc < 2)
         return -EINVAL;
     assert(strncmp(argv[1], "device", sizeof("device")) == 0);
@@ -42,6 +65,15 @@ static int parse_args(int argc, char **argv, const char **path, const char **op_
         return -EINVAL;
     *op_name = argv[3];
 
+    *debug = FALSE;
+    for (i = 0; i < argc; ++i) {
+        if (strncmp(argv[i], "--debug", sizeof(--debug)) == 0 ||
+            strncmp(argv[i], "-d", sizeof(--debug)) == 0) {
+            *debug = TRUE;
+            break;
+        }
+    }
+
     return 0;
 }
 
@@ -54,6 +86,7 @@ int subcmd_device(int argc, char **argv)
     } *entry, entries[] = {
     };
     GError *error = NULL;
+    gboolean debug;
     const char *path;
     const char *op_name;
     HinawaFwNode *node;
@@ -65,7 +98,7 @@ int subcmd_device(int argc, char **argv)
     int err;
     int i;
 
-    err = parse_args(argc, argv, &path, &op_name);
+    err = parse_args(argc, argv, &path, &op_name, &debug);
     if (err < 0)
         return print_help(0, NULL, NULL, NULL);
 
@@ -103,6 +136,9 @@ int subcmd_device(int argc, char **argv)
     }
 
     proto = efw_proto_new();
+    if (debug)
+        g_signal_connect(proto, "responded", (GCallback)handle_responded_signal, NULL);
+
     efw_proto_bind(proto, node, &error);
     if (error != NULL) {
         if (g_error_matches(error, HINAWA_FW_NODE_ERROR, HINAWA_FW_NODE_ERROR_FAILED)) {
-- 
2.25.1




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux