Can_open_slavenode

Dependencies:   mbed

Revision:
1:285c99dcbb25
Parent:
0:6219434a0cb5
--- a/source/port_helper.cpp	Mon May 30 07:14:41 2011 +0000
+++ b/source/port_helper.cpp	Mon May 30 08:26:03 2011 +0000
@@ -16,90 +16,120 @@
 
 void initHelper()
 {
-	Debug.baud(57600);
-	printf(" CANopen port of CANfestival slave node (DS-401) \n");
+    Debug.baud(57600);
+    printf(" CANopen port of CANfestival slave node (DS-401) \n");
 }
 
 void serviceHelper()
 {
-	static uint32_t cnt = 0;
-	// indicate that the stack is running
-	if (cnt++ > 100){
-		cnt = 0;
-		running_status = !running_status;
-	}
+    static uint32_t cnt = 0;
+    // indicate that the stack is running
+    if (cnt++ > 100){
+        cnt = 0;
+        running_status = !running_status;
+    }
 }
 
 
 void printMsg(Message& msg)
 {
-	CANMessage m(msg.cob_id, (char*)msg.data, msg.len, static_cast<CANType>(msg.rtr), CANStandard);
-	// call the CANMessage formatted method
-	printMsg(m);
+    CANMessage m(msg.cob_id, (char*)msg.data, msg.len, static_cast<CANType>(msg.rtr), CANStandard);
+    // call the CANMessage formatted method
+    printMsg(m);
 }
 
 void printMsg(CANMessage& msg)
 {
-	// print the message
-	printf("ID: 0x%03X DLC: %d Data(0->7): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
-	msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], 
-	msg.data[3], msg.data[4], msg.data[5], msg.data[6], msg.data[7]);
+    switch(msg.len){
+        case 1:
+            printf("ID: 0x%04X DLC: %d Data(0): 0x%02X\n", msg.id, msg.len, msg.data[0]);
+            break;
+        case 2:
+            printf("ID: 0x%04X DLC: %d Data(0->1): 0x%02X 0x%02X\n", msg.id, msg.len, msg.data[0], msg.data[1]);
+            break;
+        case 3:
+            printf("ID: 0x%04X DLC: %d Data(0->2): 0x%02X 0x%02X 0x%02X\n",
+                msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2]);
+            break;
+        case 4:
+            printf("ID: 0x%04X DLC: %d Data(0->3): 0x%02X 0x%02X 0x%02X 0x%02X\n",
+                msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3]);
+            break;
+        case 5:
+            printf("ID: 0x%04X DLC: %d Data(0->4): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+                msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4]);
+            break;
+        case 6:
+            printf("ID: 0x%04X DLC: %d Data(0->5): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+                msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5]);
+            break;
+        case 7:
+            printf("ID: 0x%04X DLC: %d Data(0->6): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+                msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5], msg.data[6]);
+            break;
+        case 8:
+            printf("ID: 0x%04X DLC: %d Data(0->7): 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X 0x%02X\n",
+                msg.id, msg.len, msg.data[0], msg.data[1], msg.data[2], msg.data[3], msg.data[4], msg.data[5], msg.data[6], msg.data[7]);
+            break;
+        default: 
+            break;
+    }
 
 }
 
 void serviceCOMCommands()
 {
-	static char msg[64];
-	static char w_loc=0;
-	if (Debug.readable()){
-		// store the data
-		if (w_loc < 64){
-			msg[w_loc++] = Debug.getc();
-		}
-		// clear the buffer and try again
-		else{
-			// clear the buffer
-			memset(msg, 0, 64);
-			w_loc = 0;
-			return;
-		}
-		// parse the message and act on it
-		if ((msg[w_loc-1] == '\r') || (msg[w_loc-1] == '\n') ){
-			// process the message and look for something familiar
-			if (strncmp(msg, "help", strlen("help")) == 0){
-			 	// print the help menu
-				printf("\t HELP OPTIONS (case sesnitive):\n");
-				printf("\t  help - display the available options\n");
-				printf("\t  id=xxx - change the node id\n");
-				printf("\t  about - get info about the node\n");
-				printf("\t  input=x - a decimal number\n");
-			}
-			else if (strncmp(msg, "id=", strlen("id=")) == 0){
-				// change the node ID
-				int res = atoi(msg+strlen("id="));
-				if ( (res > 0) && (res < 128) ){
-					nodeID = res;
-					printf("the new node_id = %d\n", nodeID);
-					change_node_id = 1;
-				}
-				else{
-					printf("invalid parameter");
-				}
-			}
-			else if (strncmp(msg, "about", strlen("about")) == 0){
-				// our call tag
-				printf(" CANopen port of CANfestival slave node (DS-401) \n");
-			}
-			else if (strncmp(msg, "input=", strlen("input=")) == 0){
-				// store the input value
-				digital_input[0] = (uint8_t)atoi(msg+strlen("input="));
-				printf("you entered %d", digital_input[0]);
-			}
-			// clear the buffer
-			memset(msg, 0, 64);
-			w_loc = 0;
-		}
-	}
+    static char msg[64];
+    static char w_loc=0;
+    if (Debug.readable()){
+        // store the data
+        if (w_loc < 64){
+            msg[w_loc++] = Debug.getc();
+        }
+        // clear the buffer and try again
+        else{
+            // clear the buffer
+            memset(msg, 0, 64);
+            w_loc = 0;
+            return;
+        }
+        // parse the message and act on it
+        if ((msg[w_loc-1] == '\r') || (msg[w_loc-1] == '\n') ){
+            // process the message and look for something familiar
+            if (strncmp(msg, "help", strlen("help")) == 0){
+                 // print the help menu
+                printf("\t HELP OPTIONS (case sesnitive):\n");
+                printf("\t  help - display the available options\n");
+                printf("\t  id=xxx - change the node id\n");
+                printf("\t  about - get info about the node\n");
+                printf("\t  input=x - a decimal number\n");
+            }
+            else if (strncmp(msg, "id=", strlen("id=")) == 0){
+                // change the node ID
+                int res = atoi(msg+strlen("id="));
+                if ( (res > 0) && (res < 128) ){
+                    nodeID = res;
+                    printf("the new node_id = %d\n", nodeID);
+                    change_node_id = 1;
+                }
+                else{
+                    printf("invalid parameter");
+                }
+            }
+            else if (strncmp(msg, "about", strlen("about")) == 0){
+                // our call tag
+                printf(" CANopen port of CANfestival slave node (DS-401) \n");
+            }
+            else if (strncmp(msg, "input=", strlen("input=")) == 0){
+                // store the input value
+                digital_input[0] = (uint8_t)atoi(msg+strlen("input="));
+                printf("you entered %d", digital_input[0]);
+            }
+            // clear the buffer
+            memset(msg, 0, 64);
+            w_loc = 0;
+        }
+    }
 }
 
 /*