diff rvinterf/lowlevel/format.c @ 174:3256dc6e84ae

rvinterf: refactored rvtdump compiles and works
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 22 Nov 2013 07:41:31 +0000
parents rvinterf/old/trdump.c@f42854da4563
children 2f214bd03119
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/lowlevel/format.c	Fri Nov 22 07:41:31 2013 +0000
@@ -0,0 +1,150 @@
+/*
+ * This module implements the decoding of Rx packets
+ * into human-readable form.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include "../pktmux.h"
+#include "../limits.h"
+
+extern u_char rxpkt[];
+extern size_t rxpkt_len;
+
+void
+print_rv_trace()
+{
+	char buf[MAX_PKT_FROM_TARGET*4];
+	int i, c;
+	char *dp;
+
+	dp = buf;
+	strcpy(dp, "RV ");
+	dp += 3;
+	/* the SWE static ID is sent MSB first */
+	for (i = 1; i <= 4; i++) {
+		sprintf(dp, "%02X", rxpkt[i]);
+		dp += 2;
+	}
+	/* severity level */
+	sprintf(dp, " %d ", rxpkt[5]);
+	dp = index(dp, '\0');
+	for (i = 6; i < rxpkt_len; i++) {
+		c = rxpkt[i];
+		if (c & 0x80) {
+			*dp++ = 'M';
+			*dp++ = '-';
+			c &= 0x7F;
+		}
+		if (c < 0x20) {
+			*dp++ = '^';
+			*dp++ = c + '@';
+		} else if (c == 0x7F) {
+			*dp++ = '^';
+			*dp++ = '?';
+		} else
+			*dp++ = c;
+	}
+	*dp = '\0';
+	output_line(buf);
+}
+
+void
+print_l1_trace()
+{
+	char buf[MAX_PKT_FROM_TARGET*4+1];
+	int i, c;
+	char *dp;
+
+	dp = buf;
+	strcpy(dp, "L1: ");
+	dp += 4;
+	for (i = 1; i < rxpkt_len; i++) {
+		if ((i+1 < rxpkt_len) &&
+		    (rxpkt[i] == '\r' && rxpkt[i+1] == '\n' ||
+		     rxpkt[i] == '\n' && rxpkt[i+1] == '\r')) {
+			*dp = '\0';
+			output_line(buf);
+			if (i+2 == rxpkt_len)
+				return;
+			dp = buf;
+			*dp++ = '+';
+			*dp++ = ' ';
+			i++;
+			continue;
+		}
+		c = rxpkt[i];
+		if (c & 0x80) {
+			*dp++ = 'M';
+			*dp++ = '-';
+			c &= 0x7F;
+		}
+		if (c < 0x20) {
+			*dp++ = '^';
+			*dp++ = c + '@';
+		} else if (c == 0x7F) {
+			*dp++ = '^';
+			*dp++ = '?';
+		} else
+			*dp++ = c;
+	}
+	/* will get here only if no newline sequence at the end */
+	*dp = '\0';
+	output_line(buf);
+}
+
+void
+print_g23_trace()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+2];
+	int i;
+	char *dp;
+
+	dp = buf;
+	strcpy(dp, "G23:");
+	dp += 4;
+	for (i = 1; i < rxpkt_len; i++) {
+		sprintf(dp, " %02X", rxpkt[i]);
+		dp += 3;
+	}
+	*dp = '\0';
+	output_line(buf);
+}
+
+void
+print_etm_output_raw()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+2];
+	int i;
+	char *dp;
+
+	dp = buf;
+	strcpy(dp, "ETM:");
+	dp += 4;
+	for (i = 1; i < rxpkt_len; i++) {
+		sprintf(dp, " %02X", rxpkt[i]);
+		dp += 3;
+	}
+	*dp = '\0';
+	output_line(buf);
+}
+
+void
+print_unknown_packet()
+{
+	char buf[MAX_PKT_FROM_TARGET*3+5];
+	int i;
+	char *dp;
+
+	dp = buf;
+	strcpy(dp, "UNK:");
+	dp += 4;
+	for (i = 0; i < rxpkt_len; i++) {
+		sprintf(dp, " %02X", rxpkt[i]);
+		dp += 3;
+	}
+	*dp = '\0';
+	output_line(buf);
+}