more fancy print_message for debug
authoretisserant
Tue, 02 Oct 2007 17:56:11 +0200
changeset 301 f4b64aa848e1
parent 300 b83d063c4dc4
child 302 7ba4302a9999
more fancy print_message for debug
drivers/can_peak_win32/can_peak_win32.c
drivers/can_socket/can_socket.c
drivers/can_virtual/can_virtual.c
examples/DS401_Master/TestMasterMicroMod.h
examples/TestMasterMicroMod/TestMasterMicroMod.h
examples/TestMasterSlave/TestMasterSlave.h
include/can_driver.h
include/def.h
--- a/drivers/can_peak_win32/can_peak_win32.c	Tue Oct 02 17:45:25 2007 +0200
+++ b/drivers/can_peak_win32/can_peak_win32.c	Tue Oct 02 17:56:11 2007 +0200
@@ -66,34 +66,6 @@
 	return 0x0000;
 }
 
-#define MyCase(fc) case fc: printf(#fc);break;
-void print_message(Message *m)
-{
-	int i;
-	switch(m->cob_id.w >> 7)
-	{
-		MyCase(SYNC)
-		MyCase(TIME_STAMP)
-		MyCase(PDO1tx)
-		MyCase(PDO1rx)
-		MyCase(PDO2tx)
-		MyCase(PDO2rx)
-		MyCase(PDO3tx)
-		MyCase(PDO3rx)
-		MyCase(PDO4tx)
-		MyCase(PDO4rx)
-		MyCase(SDOtx)
-		MyCase(SDOrx)
-		MyCase(NODE_GUARD)
-		MyCase(NMT)
-	}
-	printf(" rtr:%d", m->rtr);
-	printf(" len:%d", m->len);
-	for (i = 0 ; i < m->len ; i++)
-		printf(" %02x", m->data[i]);
-	printf("\n");
-}
-
 void
 canInit (s_BOARD *board)
 {
--- a/drivers/can_socket/can_socket.c	Tue Oct 02 17:45:25 2007 +0200
+++ b/drivers/can_socket/can_socket.c	Tue Oct 02 17:56:11 2007 +0200
@@ -59,38 +59,6 @@
 
 #include "can_driver.h"
 
-#if defined DEBUG_WAR_CONSOLE_ON || defined DEBUG_ERR_CONSOLE_ON
-#include "def.h"
-
-#define MyCase(fc) case fc: printf(#fc);break;
-void print_message(Message *m)
-{
-    int i;
-    switch(m->cob_id.w >> 7)
-    {
-        MyCase(SYNC)
-        MyCase(TIME_STAMP)
-        MyCase(PDO1tx)
-        MyCase(PDO1rx)
-        MyCase(PDO2tx)
-        MyCase(PDO2rx)
-        MyCase(PDO3tx)
-        MyCase(PDO3rx)
-        MyCase(PDO4tx)
-        MyCase(PDO4rx)
-        MyCase(SDOtx)
-        MyCase(SDOrx)
-        MyCase(NODE_GUARD)
-        MyCase(NMT)
-    }
-    printf(" rtr:%d", m->rtr);
-    printf(" len:%d", m->len);
-    for (i = 0 ; i < m->len ; i++)
-        printf(" %02x", m->data[i]);
-    printf("\n");
-}
-
-#endif
 /*********functions which permit to communicate with the board****************/
 UNS8
 canReceive_driver (CAN_HANDLE fd0, Message * m)
--- a/drivers/can_virtual/can_virtual.c	Tue Oct 02 17:45:25 2007 +0200
+++ b/drivers/can_virtual/can_virtual.c	Tue Oct 02 17:56:11 2007 +0200
@@ -27,6 +27,7 @@
 #include <stdio.h>
 #include <unistd.h>
 
+#define NEED_PRINT_MESSAGE
 #include "can_driver.h"
 #include "def.h"
 
@@ -49,34 +50,6 @@
 	return 0;
 }
 
-#define MyCase(fc) case fc: printf(#fc);break;
-void print_message(Message *m)
-{
-	int i;
-	switch(m->cob_id.w >> 7)
-	{
-		MyCase(SYNC)
-		MyCase(TIME_STAMP)
-		MyCase(PDO1tx)
-		MyCase(PDO1rx)
-		MyCase(PDO2tx)
-		MyCase(PDO2rx)
-		MyCase(PDO3tx)
-		MyCase(PDO3rx)
-		MyCase(PDO4tx)
-		MyCase(PDO4rx)
-		MyCase(SDOtx)
-		MyCase(SDOrx)
-		MyCase(NODE_GUARD)
-		MyCase(NMT)
-	}
-	printf(" rtr:%d", m->rtr);
-	printf(" len:%d", m->len);
-	for (i = 0 ; i < m->len ; i++)
-		printf(" %02x", m->data[i]);
-	printf("\n");
-}
-
 /***************************************************************************/
 UNS8 canSend_driver(CAN_HANDLE fd0, Message *m)
 {
--- a/examples/DS401_Master/TestMasterMicroMod.h	Tue Oct 02 17:45:25 2007 +0200
+++ b/examples/DS401_Master/TestMasterMicroMod.h	Tue Oct 02 17:56:11 2007 +0200
@@ -24,7 +24,6 @@
 #else
 #define eprintf(...) printf (__VA_ARGS__)
 #endif
-//void print_message(Message *m);
 
 /*UNS8 canSend(CAN_HANDLE fd0, Message *m);*/
 
--- a/examples/TestMasterMicroMod/TestMasterMicroMod.h	Tue Oct 02 17:45:25 2007 +0200
+++ b/examples/TestMasterMicroMod/TestMasterMicroMod.h	Tue Oct 02 17:56:11 2007 +0200
@@ -24,7 +24,6 @@
 #else
 #define eprintf(...) printf (__VA_ARGS__)
 #endif
-//void print_message(Message *m);
 
 /*UNS8 canSend(CAN_HANDLE fd0, Message *m);*/
 
--- a/examples/TestMasterSlave/TestMasterSlave.h	Tue Oct 02 17:45:25 2007 +0200
+++ b/examples/TestMasterSlave/TestMasterSlave.h	Tue Oct 02 17:56:11 2007 +0200
@@ -25,7 +25,6 @@
 #else
 #define eprintf(...) printf (__VA_ARGS__)
 #endif
-void print_message(Message *m);
 
 /*UNS8 canSend(CAN_HANDLE fd0, Message *m);*/
 
--- a/include/can_driver.h	Tue Oct 02 17:45:25 2007 +0200
+++ b/include/can_driver.h	Tue Oct 02 17:56:11 2007 +0200
@@ -49,4 +49,63 @@
 CAN_HANDLE DLL_CALL(canOpen)(s_BOARD *)FCT_PTR_INIT;
 int DLL_CALL(canClose)(CAN_HANDLE)FCT_PTR_INIT;
 
+#if defined DEBUG_WAR_CONSOLE_ON || defined DEBUG_ERR_CONSOLE_ON || defined NEED_PRINT_MESSAGE
+#include "def.h"
+
+#define _P(fc) case fc: printf(#fc" ");break;
+
+static inline void print_message(Message *m)
+{
+    int i;
+    printf("id:%02x ", m->cob_id.w & 0x7F);
+    UNS8 fc = m->cob_id.w >> 7;
+    switch(fc)
+    {
+        _P(SYNC)
+        _P(TIME_STAMP)
+        _P(PDO1tx)
+        _P(PDO1rx)
+        _P(PDO2tx)
+        _P(PDO2rx)
+        _P(PDO3tx)
+        _P(PDO3rx)
+        _P(PDO4tx)
+        _P(PDO4rx)
+        _P(SDOtx)
+        _P(SDOrx)
+        _P(NODE_GUARD)
+        _P(NMT)
+    }
+    if( fc == SDOtx)
+    {
+        switch(m->data[0] >> 5)
+        {
+            /* scs: server command specifier */
+            _P(UPLOAD_SEGMENT_RESPONSE)
+            _P(DOWNLOAD_SEGMENT_RESPONSE)
+            _P(INITIATE_DOWNLOAD_RESPONSE)
+            _P(INITIATE_UPLOAD_RESPONSE)
+            _P(ABORT_TRANSFER_REQUEST)
+        }
+    }else if( fc == SDOrx)
+    {
+        switch(m->data[0] >> 5)
+        {
+            /* ccs: client command specifier */
+            _P(DOWNLOAD_SEGMENT_REQUEST)
+            _P(INITIATE_DOWNLOAD_REQUEST)
+            _P(INITIATE_UPLOAD_REQUEST)
+            _P(UPLOAD_SEGMENT_REQUEST)
+            _P(ABORT_TRANSFER_REQUEST)
+        }
+    }
+    printf(" rtr:%d", m->rtr);
+    printf(" len:%d", m->len);
+    for (i = 0 ; i < m->len ; i++)
+        printf(" %02x", m->data[i]);
+    printf("\n");
+}
+
 #endif
+
+#endif
--- a/include/def.h	Tue Oct 02 17:45:25 2007 +0200
+++ b/include/def.h	Tue Oct 02 17:56:11 2007 +0200
@@ -78,6 +78,21 @@
 #define SDO_CLIENT  0x2
 #define SDO_UNKNOWN 0x3             
 
+/* SDOrx ccs: client command specifier */
+#define DOWNLOAD_SEGMENT_REQUEST     0
+#define INITIATE_DOWNLOAD_REQUEST    1
+#define INITIATE_UPLOAD_REQUEST      2
+#define UPLOAD_SEGMENT_REQUEST       3
+#define ABORT_TRANSFER_REQUEST       4
+
+/* SDOtx scs: server command specifier */
+#define UPLOAD_SEGMENT_RESPONSE      0
+#define DOWNLOAD_SEGMENT_RESPONSE    1
+#define INITIATE_DOWNLOAD_RESPONSE   3
+#define INITIATE_UPLOAD_RESPONSE     2
+#define ABORT_TRANSFER_REQUEST       4
+
+
 /*  Function Codes 
    ---------------
   defined in the canopen DS301