paparazzi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paparazzi-commits] [4319] Debugging updates to fms_serial_port.c


From: Allen Ibara
Subject: [paparazzi-commits] [4319] Debugging updates to fms_serial_port.c
Date: Sat, 07 Nov 2009 02:28:07 +0000

Revision: 4319
          http://svn.sv.gnu.org/viewvc/?view=rev&root=paparazzi&revision=4319
Author:   aibara
Date:     2009-11-07 02:28:07 +0000 (Sat, 07 Nov 2009)
Log Message:
-----------
Debugging updates to fms_serial_port.c

Modified Paths:
--------------
    paparazzi3/trunk/sw/airborne/fms/fms_serial_port.c

Modified: paparazzi3/trunk/sw/airborne/fms/fms_serial_port.c
===================================================================
--- paparazzi3/trunk/sw/airborne/fms/fms_serial_port.c  2009-11-07 02:18:10 UTC 
(rev 4318)
+++ paparazzi3/trunk/sw/airborne/fms/fms_serial_port.c  2009-11-07 02:28:07 UTC 
(rev 4319)
@@ -3,10 +3,14 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
-#define TRACE(type,fmt,args...)
+//#define TRACE(type,fmt,args...)    fprintf(stderr, fmt, args)
+#define TRACE(type,fmt,args...) 
 #define TRACE_ERROR 1
 
 struct FmsSerialPort* serial_port_new(void) {
@@ -23,21 +27,24 @@
   
   speed_t speed;
   if ((me->fd = open(device, O_RDWR | O_NONBLOCK)) < 0) {
-    TRACE(TRACE_ERROR,"opening %s (%s)\n", device, strerror(errno));
+    TRACE(TRACE_ERROR,"%s, open failed: %s (%d)\n", device, strerror(errno), 
errno);
     return -1;
   }
   if (tcgetattr(me->fd, &me->orig_termios) < 0) {
-    TRACE(TRACE_ERROR,"getting term settings (%s)\n", strerror(errno));
+    TRACE(TRACE_ERROR,"%s, get term settings failed: %s (%d)\n", device, 
strerror(errno), errno);
+    close(me->fd);
     return -1;
   }   
   me->cur_termios = me->orig_termios;
   term_conf_callback(&me->cur_termios, &speed);
   if (cfsetispeed(&me->cur_termios, speed)) {
-    TRACE(TRACE_ERROR,"setting term speed (%s)\n", strerror(errno));
+    TRACE(TRACE_ERROR,"%s, set term speed failed: %s (%d)\n", device, 
strerror(errno), errno);
+    close(me->fd);
     return -1;
   }
   if (tcsetattr(me->fd, TCSADRAIN, &me->cur_termios)) {
-    TRACE(TRACE_ERROR,"setting term attributes (%s)\n", strerror(errno));
+    TRACE(TRACE_ERROR,"%s, set term attr failed: %s (%d)\n", device, 
strerror(errno), errno);
+    close(me->fd);
     return -1;
   }
   return 0;
@@ -46,16 +53,21 @@
 
 void serial_port_close(struct FmsSerialPort* me) {
 
+  /* if null pointer or file descriptor indicates error just bail */
+  if (!me || me->fd < 0)
+    return;
   if (tcflush(me->fd, TCIOFLUSH)) {
-    TRACE(TRACE_ERROR,"flushing (%s)\n", strerror(errno));
+    TRACE(TRACE_ERROR,"flushing (%s) (%d)\n", strerror(errno), errno);
+    close(me->fd);
     return; 
   }
   if (tcsetattr(me->fd, TCSADRAIN, &me->orig_termios)) {        // Restore 
modes.
-    TRACE(TRACE_ERROR,"restoring term attributes (%s)\n", strerror(errno));
+    TRACE(TRACE_ERROR,"restoring term attributes (%s) (%d)\n", 
strerror(errno), errno);
+    close(me->fd);
     return; 
   }
   if (close(me->fd)) {
-    TRACE(TRACE_ERROR,"closing (%s)\n", strerror(errno));
+    TRACE(TRACE_ERROR,"closing %s (%d)\n", strerror(errno), errno);
     return; 
   }
   return;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]