[gnome-color-manager: 28/80] huey: add a simple hacky program that parses the USB logs



commit 5dd0b234b8d600af39239d2d7c0d9439656dfd90
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jul 17 22:55:12 2010 +0100

    huey: add a simple hacky program that parses the USB logs

 configure.ac               |    1 +
 docs/Makefile.am           |    1 +
 docs/huey/.gitignore       |    4 +
 docs/huey/Makefile.am      |   17 ++++
 docs/huey/gcm-parse-huey.c |  208 ++++++++++++++++++++++++++++++++++++++++++++
 src/gcm-huey-example.c     |   17 ++++-
 6 files changed, 247 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 56ab10b..f3d2974 100644
--- a/configure.ac
+++ b/configure.ac
@@ -316,6 +316,7 @@ po/Makefile.in
 rules/Makefile
 src/Makefile
 docs/Makefile
+docs/huey/Makefile
 docs/api/Makefile
 docs/api/version.xml
 libcolor-glib/Makefile
diff --git a/docs/Makefile.am b/docs/Makefile.am
index 265f2ec..c47b279 100644
--- a/docs/Makefile.am
+++ b/docs/Makefile.am
@@ -1,2 +1,3 @@
 SUBDIRS = 						\
+	huey
 	api
diff --git a/docs/huey/.gitignore b/docs/huey/.gitignore
new file mode 100644
index 0000000..938a2f7
--- /dev/null
+++ b/docs/huey/.gitignore
@@ -0,0 +1,4 @@
+.deps
+gcm-parse-huey
+*.o
+*.parsed
diff --git a/docs/huey/Makefile.am b/docs/huey/Makefile.am
new file mode 100644
index 0000000..bdb4ac1
--- /dev/null
+++ b/docs/huey/Makefile.am
@@ -0,0 +1,17 @@
+## We require new-style dependency handling.
+AUTOMAKE_OPTIONS = 1.7
+
+INCLUDES =						\
+	$(GLIB_CFLAGS)
+
+bin_PROGRAMS =						\
+	gcm-parse-huey
+
+gcm_parse_huey_SOURCES =				\
+	gcm-parse-huey.c
+
+gcm_parse_huey_LDADD =					\
+	$(GLIB_LIBS)
+
+gcm_parse_huey_CFLAGS =					\
+	$(WARNINGFLAGS_C)
diff --git a/docs/huey/gcm-parse-huey.c b/docs/huey/gcm-parse-huey.c
new file mode 100644
index 0000000..f0f9d66
--- /dev/null
+++ b/docs/huey/gcm-parse-huey.c
@@ -0,0 +1,208 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU Lesser General Public License Version 2.1
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <stdlib.h>
+
+#include <glib.h>
+
+#define HUEY_RETVAL_SUCCESS		0x00
+#define HUEY_RETVAL_LOCKED		0xc0
+#define HUEY_RETVAL_UNKNOWN_5A		0x5a /* seen in profiling */
+#define HUEY_RETVAL_ERROR		0x80
+#define HUEY_RETVAL_UNKNOWN_81		0x81 /* seen once in init */
+#define HUEY_RETVAL_RETRY		0x90
+
+static const gchar *
+get_return_string (guchar value)
+{
+	if (value == HUEY_RETVAL_SUCCESS)
+		return "success";
+	if (value == HUEY_RETVAL_LOCKED)
+		return "locked";
+	if (value == HUEY_RETVAL_ERROR)
+		return "error";
+	if (value == HUEY_RETVAL_RETRY)
+		return "retry";
+	if (value == HUEY_RETVAL_UNKNOWN_5A)
+		return "unknown5a";
+	if (value == HUEY_RETVAL_UNKNOWN_81)
+		return "unknown81";
+	return NULL;
+}
+
+static const gchar *
+get_command_string (guchar value)
+{
+	if (value == 0x00)
+		return "status";
+	if (value == 0x02)
+		return "get-green";
+	if (value == 0x03)
+		return "get-blue";
+	if (value == 0x05)
+		return "set-value";
+	if (value == 0x06)
+		return "get-value";
+	if (value == 0x07)
+		return "unknown07";
+	if (value == 0x08)
+		return "reg-read";
+	if (value == 0x0e)
+		return "unlock";
+	if (value == 0x0f)
+		return "unknown0f";
+	if (value == 0x10)
+		return "unknown10";
+	if (value == 0x11)
+		return "unknown11";
+	if (value == 0x12)
+		return "unknown12";
+	if (value == 0x13)
+		return "unknown13";
+	if (value == 0x15)
+		return "unknown15(status?)";
+	if (value == 0x16)
+		return "sample&get-red";
+	if (value == 0x21)
+		return "unknown21";
+	if (value == 0x17)
+		return "ambient";
+	if (value == 0x18)
+		return "set-leds";
+	if (value == 0x19)
+		return "unknown19";
+	return NULL;
+}
+
+gint
+main (gint argc, gchar *argv[])
+{
+	gboolean ret;
+	gchar *data = NULL;
+	gchar **split = NULL;
+	GString *output = NULL;
+	GError *error = NULL;
+	guint i;
+	const gchar *line;
+	gboolean reply = FALSE;
+
+	if (argc != 3) {
+		g_print ("need to specify two files\n");
+		goto out;
+	}
+
+	g_print ("parsing %s into %s... ", argv[1], argv[2]);
+
+	/* read file */
+	ret = g_file_get_contents (argv[1], &data, NULL, &error);
+	if (!ret) {
+		g_print ("failed to read: %s\n", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	/* parse string */
+	output = g_string_new ("// automatically generated, do not edit\n");
+	split = g_strsplit (data, "\n", -1);
+	for (i=0; split[i] != NULL; i++) {
+		line = split[i];
+
+		/* timestamp */
+		if (line[0] == '[')
+			continue;
+
+		/* function */
+		if (line[0] == '-') {
+			g_string_append (output, "\n");
+			if (g_str_has_suffix (line, "URB_FUNCTION_CLASS_INTERFACE:"))
+				g_string_append (output, "[class-interface]     ");
+			else if (g_str_has_suffix (line, "URB_FUNCTION_CONTROL_TRANSFER:"))
+				g_string_append (output, "[control-transfer]    ");
+			else if (g_str_has_suffix (line, "URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:"))
+				g_string_append (output, "[interrupt-transfer]  ");
+			else
+				g_string_append (output, "[unknown]             ");
+		}
+
+		if (g_strstr_len (line, -1, "USBD_TRANSFER_DIRECTION_IN") != NULL) {
+			g_string_append (output, " <--- ");
+			reply = TRUE;
+		}
+		if (g_strstr_len (line, -1, "USBD_TRANSFER_DIRECTION_OUT") != NULL) {
+			g_string_append (output, " ---> ");
+			reply = FALSE;
+		}
+
+		if (g_strstr_len (line, -1, "00000000:") != NULL) {
+			gchar **tok;
+			guint j;
+			guchar cmd;
+			const gchar *annote;
+			tok = g_strsplit (&line[14], " ", -1);
+
+			/* only know how to parse 8 bytes */
+			if (g_strv_length (tok) != 8)
+				continue;
+			for (j=0; j<8; j++) {
+				annote = NULL;
+				cmd = g_ascii_strtoll (tok[j], NULL, 16);
+				if (j == 0 && reply) {
+					annote = get_return_string (cmd);
+					if (annote == NULL)
+						g_warning ("return code 0x%02x not known in %s", cmd, &line[14]);
+				}
+				if ((j == 0 && !reply) ||
+				    (j == 1 && reply)) {
+					annote = get_command_string (cmd);
+					if (annote == NULL)
+						g_warning ("command code 0x%02x not known", cmd);
+				}
+				if (annote != NULL)
+					g_string_append_printf (output, "%02x(%s) ", cmd, annote);
+				else
+					g_string_append_printf (output, "%02x ", cmd);
+			}
+			g_strfreev (tok);
+		}
+
+//		g_print ("%i:%s\n", i, split[i]);
+	}
+
+	/* write file */
+	ret = g_file_set_contents (argv[2], output->str, -1, &error);
+	if (!ret) {
+		g_print ("failed to read: %s\n", error->message);
+		g_error_free (error);
+		goto out;
+	}
+	
+	g_print ("done!\n");
+
+out:
+	if (output != NULL)
+		g_string_free (output, TRUE);
+	g_free (data);
+	g_strfreev (split);
+	return 0;
+}
+
diff --git a/src/gcm-huey-example.c b/src/gcm-huey-example.c
index 2d1e65c..0aefde9 100644
--- a/src/gcm-huey-example.c
+++ b/src/gcm-huey-example.c
@@ -37,7 +37,9 @@
 
 #define HUEY_RETVAL_SUCCESS		0x00
 #define HUEY_RETVAL_LOCKED		0xc0
+#define HUEY_RETVAL_UNKNOWN_5A		0x5a /* seen in profiling */
 #define HUEY_RETVAL_ERROR		0x80
+#define HUEY_RETVAL_UNKNOWN_81		0x81 /* seen once in init */
 #define HUEY_RETVAL_RETRY		0x90
 
 /* returns: "Cir001" -- Cirrus Logic? Circuit1?... */
@@ -113,9 +115,21 @@
 /* returns: all NULL all of the time */
 #define HUEY_COMMAND_UNKNOWN_0F		0x0f
 
+/* something to do with sampling */
+#define HUEY_COMMAND_UNKNOWN_10		0x10
+
+/* something to do with sampling (that needs a retry with code 5a) */
+#define HUEY_COMMAND_UNKNOWN_11		0x11
+
+/* something to do with sampling */
+#define HUEY_COMMAND_UNKNOWN_12		0x12
+
 /* returns: all NULL all of the time */
 #define HUEY_COMMAND_UNKNOWN_13		0x13
 
+/* returns: seems to be sent, but not requested */
+#define HUEY_COMMAND_UNKNOWN_15		0x15
+
 /* input:   16 00 01 00 01 00 01 00
  * returns: 00 16 00 00 00 00 00 00
  *
@@ -149,7 +163,8 @@
 /* returns: 90 17 03 00 00 00 00 00  then on second read:
  * 	    00 17 03 00 00 62 57 00 in light (or)
  * 	    00 17 03 00 00 00 08 00 in dark
- * 	no idea	--^^	   ^---^ = 16bits data?
+ * 	no idea	--^^  |    ^---^ = 16bits data?
+ *                    \-- only ever 0 or 2 (only ever saw 2 once...)
  */
 #define HUEY_COMMAND_AMBIENT		0x17
 



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