Better error handling for unix and peak_linux.
authoretisserant
Tue, 17 Apr 2007 10:48:17 +0200
changeset 162 8331c670a3de
parent 161 c4908cc776a9
child 163 212a9ea3b968
Better error handling for unix and peak_linux.
drivers/can_peak_linux/can_peak_linux.c
drivers/unix/unix.c
--- a/drivers/can_peak_linux/can_peak_linux.c	Sun Apr 15 00:49:34 2007 +0200
+++ b/drivers/can_peak_linux/can_peak_linux.c	Tue Apr 17 10:48:17 2007 +0200
@@ -44,7 +44,7 @@
   if ((errno = CAN_Read(fd0, & peakMsg))) {		// Blocks until no new message or error.
     if(errno != -EIDRM && errno != -EPERM) // error is not "Can Port closed while reading" 
     {
-    	perror("!!! Peak board : error of reading. (from f_can_receive function) \n");
+    	perror("canReceive_driver (Peak_Linux) : error of reading.\n");
     }
     return 1;
   }
@@ -77,7 +77,7 @@
   	peakMsg.DATA[data] = m->data[data];         	/* data bytes, up to 8 */
   
   if((errno = CAN_Write(fd0, & peakMsg))) {
-    perror("!!! Peak board : error of writing. (from canSend function) \n");
+    perror("canSend_driver (Peak_Linux) : error of writing.\n");
     return 1;
   }
   return 0;
@@ -115,8 +115,12 @@
     fd0 = LINUX_CAN_Open(busname, O_RDWR);
   }
 
-  if(baudrate = TranslateBaudeRate(board->baudrate))
+  if(fd0 && (baudrate = TranslateBaudeRate(board->baudrate)))
+  {
    	CAN_Init(fd0, baudrate, CAN_INIT_TYPE_ST);
+  }else{
+  	fprintf(stderr, "canOpen_driver (Peak_Linux) : error opening %s\n", busname);
+  }
 
    return (CAN_HANDLE)fd0;
 }
--- a/drivers/unix/unix.c	Sun Apr 15 00:49:34 2007 +0200
+++ b/drivers/unix/unix.c	Tue Apr 17 10:48:17 2007 +0200
@@ -158,17 +158,21 @@
 	}
 #endif	
 	CAN_HANDLE fd0 = DLL_CALL(canOpen)(board);
-
-	canports[i].used = 1;
-	canports[i].fd = fd0;
-	canports[i].d = d;
-
-	CreateReceiveTask(&(canports[i]), &canports[i].receiveTask, &canReceiveLoop);
+	if(fd0){
+		canports[i].used = 1;
+		canports[i].fd = fd0;
+		canports[i].d = d;
 	
-	EnterMutex();
-	d->canHandle = (CAN_PORT)&canports[i];
-	LeaveMutex();
-	return (CAN_PORT)&canports[i];
+		CreateReceiveTask(&(canports[i]), &canports[i].receiveTask, &canReceiveLoop);
+		
+		EnterMutex();
+		d->canHandle = (CAN_PORT)&canports[i];
+		LeaveMutex();
+		return (CAN_PORT)&canports[i];
+	}else{
+        	fprintf(stderr,"CanOpen : Cannot open board {busname='%s',baudrate='%s'}\n",board->busname, board->baudrate);
+		return NULL;
+	}
 }
 
 int canClose(CO_Data * d)