changes to the GUI to allow for better loading and writing as well as tested our...
[goodfet] / client / GoodFETMCPCANCommunication.py
index 107b6ea..676d018 100644 (file)
@@ -20,6 +20,7 @@ import os
 from random import randrange
 from GoodFETMCPCAN import GoodFETMCPCAN;
 from intelhex import IntelHex;
+import Queue
 
 class GoodFETMCPCANCommunication:
     
@@ -154,9 +155,11 @@ class GoodFETMCPCANCommunication:
                 packet=self.client.rxpacket();
                 
             #add the data to list if the pointer was included
-            if(data != None):
-                data.append(packet)
-            
+            if(data != None and packet != None):
+                #data.append(self.client.packet2parsedstr(packet))
+                packetParsed = self.client.packet2parsed(packet)
+                packetParsed["time"] =time.time()
+                data.put(packetParsed)
             if(debug == True):
                 #check packet status
                 MCPstatusReg = self.client.MCPrxstatus();
@@ -180,19 +183,19 @@ class GoodFETMCPCANCommunication:
                 if( verbose==True):
                     #if we want to print a parsed message
                     if( parsed == True):
-#                        packetParsed = self.client.packet2parsed(packet)
-#                        sId = packetParsed.get('sID')
-#                        msg = "sID: %04d" %sId
-#                        if( packetParsed.get('eID')):
-#                            msg += " eID: %d" %packetParsed.get('eID')
-#                        msg += " rtr: %d"%packetParsed['rtr']
-#                        length = packetParsed['length']
-#                        msg += " length: %d"%length
-#                        msg += " data:"
-#                        for i in range(0,length):
-#                            dbidx = 'db%d'%i
-#                            msg +=" %03d"% ord(packetParsed[dbidx])
-                        msg = self.client.packet2parsedstr(packet)
+                        packetParsed = self.client.packet2parsed(packet)
+                        sId = packetParsed.get('sID')
+                        msg = "sID: %04d" %sId
+                        if( packetParsed.get('eID')):
+                            msg += " eID: %d" %packetParsed.get('eID')
+                        msg += " rtr: %d"%packetParsed['rtr']
+                        length = packetParsed['length']
+                        msg += " length: %d"%length
+                        msg += " data:"
+                        for i in range(0,length):
+                            dbidx = 'db%d'%i
+                            msg +=" %03d"% ord(packetParsed[dbidx])
+                        #msg = self.client.packet2parsedstr(packet)
                         print msg
                     # if we want to print just the message as it is read off the chip
                     else:
@@ -553,7 +556,7 @@ class GoodFETMCPCANCommunication:
         self.spitSetup(freq);
         spit(self,freq, standardid, repeat, duration = None, debug = False, packet = None)
 
-    def spit(self,freq, standardid, repeat, duration = None, debug = False, packet = None):
+    def spit(self,freq, standardid, repeat,writes, period = None, debug = False, packet = None):
     
 
         #### split SID into different regs
@@ -596,19 +599,24 @@ class GoodFETMCPCANCommunication:
         
                 
         print "Transmitting packet: "
-        print self.client.packet2str(packet)
+        #print self.client.packet2str(packet)
                 
         self.client.txpacket(packet);
             
         if repeat:
             print "\nNow looping on transmit. "
-            if duration!= None:
-                starttime = time.time();
-                while((time.time()-starttime < duration)):
+            if period != None:
+                for i in range(0,writes):
                     self.client.MCPrts(TXB0=True);
-                    print "MSG printed"
+                    tic = time.time()
+                    time.sleep(period/1000) # pause for period ms before sending again
+                    print time.time()-tic
+                #starttime = time.time();
+                #while((time.time()-starttime < duration)):
+                #    self.client.MCPrts(TXB0=True);
+                #    print "MSG printed"
             else:
-                while(1): 
+                for i in range(0,writes): 
                     self.client.MCPrts(TXB0=True);
         print "messages injected"