debugged the demonstration
[goodfet] / client / experiments.py
index 9c07643..0cffedb 100644 (file)
@@ -22,11 +22,11 @@ class experiments(GoodFETMCPCANCommunication):
     
     """
     
     
     """
     
-    def __init__(self, data_location):
+    def __init__(self, data_location = "../../contrib/ThayerData/"):
         """ 
         Constructor
         """ 
         Constructor
-        @type datalocation: string
-        @param datalocation: path to the folder where data will be stored
+        @type data_location: string
+        @param data_location: path to the folder where data will be stored
         """
         GoodFETMCPCANCommunication.__init__(self, data_location)
         #super(experiments,self).__init(self)
         """
         GoodFETMCPCANCommunication.__init__(self, data_location)
         #super(experiments,self).__init(self)
@@ -38,8 +38,8 @@ class experiments(GoodFETMCPCANCommunication):
         This method will sweep through the range of standard ids given from low to high.
         This will actively filter for 6 ids at a time and sniff for the given amount of
         time in seconds. If at least one message is read in then it will go individually
         This method will sweep through the range of standard ids given from low to high.
         This will actively filter for 6 ids at a time and sniff for the given amount of
         time in seconds. If at least one message is read in then it will go individually
-        through the 6 ids and sniff only for that id for the given amount of time. All the
-        data gathered will be saved.  This does not save any sniffed packets.
+        through the 6 ids and sniff only for that id for the given amount of time.
+        This does not save any sniffed packets.
         
         @type  freq: number
         @param freq: The frequency at which the bus is communicating
         
         @type  freq: number
         @param freq: The frequency at which the bus is communicating
@@ -278,19 +278,9 @@ class experiments(GoodFETMCPCANCommunication):
         #print "Fuzzing on standard ID: %d" %standardId
         self.client.serInit()
         self.spitSetup(freq)
         #print "Fuzzing on standard ID: %d" %standardId
         self.client.serInit()
         self.spitSetup(freq)
-        packet = [0,0,0x00,0x00,0x08,0,0,0,0,0,0,0,0] #empty template
-        #form a basic packet
-        
-#        #### split SID into different regs
-#        SIDlow = (standardIds[0] & 0x07) << 5;  # get SID bits 2:0, rotate them to bits 7:5
-#        SIDhigh = (standardIds[0] >> 3) & 0xFF; # get SID bits 10:3, rotate them to bits 7:0
-#        
-#        packet = [SIDhigh, SIDlow, 0x00,0x00, # pad out EID regs
-#                  0x08, # bit 6 must be set to 0 for data frame (1 for RTR) 
-#                  # lower nibble is DLC                   
-#                 packetTemp[0],packetTemp[1],packetTemp[2],packetTemp[3],packetTemp[4],packetTemp[5],packetTemp[6],packetTemp[7]]
-#        
-        
+        packet = [0,0,0x00,0x00,0x08,0,0,0,0,0,0,0,0] #empty packet template
+    
+
         #get folder information (based on today's date)
         now = datetime.datetime.now()
         datestr = now.strftime("%Y%m%d")
         #get folder information (based on today's date)
         now = datetime.datetime.now()
         datestr = now.strftime("%Y%m%d")
@@ -320,7 +310,7 @@ class experiments(GoodFETMCPCANCommunication):
                 packet[i+5] = value
             print packet
             #put a rough time stamp on the data and get all the data bytes    
                 packet[i+5] = value
             print packet
             #put a rough time stamp on the data and get all the data bytes    
-            row = [time.tT(), id_new,8] # could make this 8 a variable 
+            row = [tT.time(), id_new,8] # could make this 8 a variable 
             msg = "Injecting: "
             for i in range(5,13):
                 row.append(packet[i])
             msg = "Injecting: "
             for i in range(5,13):
                 row.append(packet[i])
@@ -394,7 +384,7 @@ class experiments(GoodFETMCPCANCommunication):
                 
                 value = random.randint(0, 255) #generate pseudo-random integer value
                 packet[i+5] = value
                 
                 value = random.randint(0, 255) #generate pseudo-random integer value
                 packet[i+5] = value
-            print packet
+            #print packet
             #put a rough time stamp on the data and get all the data bytes    
             row = [time.time(), id_new,8] 
             """@todo: allow for varied packet lengths"""
             #put a rough time stamp on the data and get all the data bytes    
             row = [time.time(), id_new,8] 
             """@todo: allow for varied packet lengths"""
@@ -478,17 +468,21 @@ class experiments(GoodFETMCPCANCommunication):
                         self.client.MCPrts(TXB0=True)
                         tT.sleep(period/1000)
                 else: #compare packets
                         self.client.MCPrts(TXB0=True)
                         tT.sleep(period/1000)
                 else: #compare packets
-                    sid =  ord(packet[0])<< | ord(packet[1])>>5
+                    sid =  ord(packet[0])<<3 | ord(packet[1])>>5
                     print "standard id of packet recieved: ", sid #standard ID
                     print "standard id of packet recieved: ", sid #standard ID
+                    msg = ""
                     for i in range(0,8):
                         idx = 5 + i
                         byteIn = ord(packet[idx])
                     for i in range(0,8):
                         idx = 5 + i
                         byteIn = ord(packet[idx])
-                        compareIn = respondPacket[i]
+                        msg += " %d" %byteIn
+                        compareIn = listenPacket[i]
+                        print byteIn, compareIn
                         if( byteIn != compareIn):
                             packet == None
                             print "packet did not match"
                             break
                         if( byteIn != compareIn):
                             packet == None
                             print "packet did not match"
                             break
-                    if( packet ):
+                    print msg
+                    if( packet != None ):
                         self.client.MCPrts(TXB0=True)
                         tT.sleep(period/1000)
         print "Response Listening Terminated."
                         self.client.MCPrts(TXB0=True)
                         tT.sleep(period/1000)
         print "Response Listening Terminated."