diff rvinterf/etm/etmbasic.c @ 188:9f4f331ac24d

fc-tmsh: implemented handling of ETM_CORE responses
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 25 Nov 2013 02:11:47 +0000
parents 4714fdfca39c
children a95d253ef952
line wrap: on
line diff
--- a/rvinterf/etm/etmbasic.c	Sun Nov 24 23:25:59 2013 +0000
+++ b/rvinterf/etm/etmbasic.c	Mon Nov 25 02:11:47 2013 +0000
@@ -9,30 +9,52 @@
 #include <stdlib.h>
 #include "../pktmux.h"
 #include "../limits.h"
+#include "etm.h"
 
 extern u_char rvi_msg[];
 extern int rvi_msg_len;
 
 void
+print_etm_pkt_raw(err)
+	char *err;
+{
+	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
+	int i;
+
+	sprintf(buf, "%s:", err);
+	dp = index(buf, '\0');
+	for (i = 2; i < rvi_msg_len; i++) {
+		sprintf(dp, " %02X", rvi_msg[i]);
+		dp += 3;
+	}
+	async_msg_output(buf);
+}
+
+void
 etm_packet_rx()
 {
-	char buf[MAX_PKT_FROM_TARGET*3+80], *dp;
 	int i, c;
 
 	if (rvi_msg_len < 4) {
-		async_msg_output("!!! Short ETM Rx packet !!!");
+runt:		print_etm_pkt_raw("ETM Runt");
+		return;
+	}
+	c = 0;
+	for (i = 2; i < rvi_msg_len; i++)
+		c ^= rvi_msg[i];
+	if (c) {
+		print_etm_pkt_raw("BAD CKSUM");
 		return;
 	}
-	strcpy(buf, "Pkt from ETM:");
-	dp = index(buf, '\0');
-	c = 0;
-	for (i = 2; i < rvi_msg_len; i++) {
-		sprintf(dp, " %02X", rvi_msg[i]);
-		dp += 3;
-		c ^= rvi_msg[i];
+	switch (rvi_msg[2]) {
+	case ETM_CORE:
+		if (rvi_msg_len < 6)
+			goto runt;
+		tmcore_msg_rx();
+		return;
+	default:
+		print_etm_pkt_raw("ETM Unknown");
 	}
-	sprintf(dp, " chksum %s", c ? "BAD" : "OK");
-	async_msg_output(buf);
 }
 
 void