radios/ccspi firmware fixed off-by-one error on packet rx; GoodFET.py added serInit...
[goodfet] / client / GoodFET.py
index ef21833..673ffde 100755 (executable)
@@ -72,7 +72,7 @@ class GoodFET:
         return self.symbols.get(name);
     def timeout(self):
         print "timeout\n";
-    def serInit(self, port=None, timeout=2):
+    def serInit(self, port=None, timeout=2, attemptlimit=None):
         """Open the serial port"""
         # Make timeout None to wait forever, 0 for non-blocking mode.
         
@@ -90,6 +90,10 @@ class GoodFET:
             glob_list = glob.glob("/dev/ttyUSB*");
             if len(glob_list) > 0:
                 port = glob_list[0];
+        if port is None:
+            glob_list = glob.glob("/dev/ttyU0");
+            if len(glob_list) > 0:
+                port = glob_list[0];
         if os.name=='nt':
             from scanwin32 import winScan;
             scan=winScan();
@@ -115,7 +119,10 @@ class GoodFET:
         connected=0;
         while connected==0:
             while self.verb!=0x7F or self.data!="http://goodfet.sf.net/":
-                #print "Resyncing.";
+                if attemptlimit is not None and attempts >= attemptlimit:
+                    return
+                elif attempts>2:
+                    print "Resyncing.";
                 self.serialport.flushInput()
                 self.serialport.flushOutput()
                 #Explicitly set RTS and DTR to halt board.
@@ -126,6 +133,7 @@ class GoodFET:
                 
                 #TelosB reset, prefer software to I2C SPST Switch.
                 if(os.environ.get("platform")=='telosb'):
+                    #print "TelosB Reset";
                     self.telosBReset();
                 #self.serialport.write(chr(0x80));
                 #self.serialport.write(chr(0x80));
@@ -151,6 +159,8 @@ class GoodFET:
         if self.verbose: print "Connected after %02i attempts." % attempts;
         self.mon_connected();
         self.serialport.setTimeout(12);
+    def serClose(self):
+        self.serialport.close();
     def telosSetSCL(self, level):
         self.serialport.setRTS(not level)
     def telosSetSDA(self, level):