Changes to GoodFETMCPCANCommunication.py. Added file management capabilities back...
authorchrishoder <chrishoder@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 22 Jan 2013 20:22:34 +0000 (20:22 +0000)
committerchrishoder <chrishoder@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Tue, 22 Jan 2013 20:22:34 +0000 (20:22 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1401 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFETMCPCANCommunication.py
client/goodfet.mcpcan

index 8fbec7e..d0c86c5 100644 (file)
@@ -15,6 +15,8 @@ import sys;
 import binascii;
 import array;
 import csv, time, argparse;
 import binascii;
 import array;
 import csv, time, argparse;
+import datetime
+import os
 
 from GoodFETMCPCAN import GoodFETMCPCAN;
 from intelhex import IntelHex;
 
 from GoodFETMCPCAN import GoodFETMCPCAN;
 from intelhex import IntelHex;
@@ -25,7 +27,9 @@ class GoodFETMCPCANCommunication:
        self.client=GoodFETMCPCAN();
        self.client.serInit()
        self.client.MCPsetup();
        self.client=GoodFETMCPCAN();
        self.client.serInit()
        self.client.MCPsetup();
+       self.DATALOCATION = "../../contrib/ThayerData/"
        
        
+
     
     def printInfo(self):
         
     
     def printInfo(self):
         
@@ -67,7 +71,7 @@ class GoodFETMCPCANCommunication:
     #   SNIFF
     ##########################
          
     #   SNIFF
     ##########################
          
-    def sniff(self,freq,duration,filename,description, verbose=True, comment=None, standardid=None):
+    def sniff(self,freq,duration,description, verbose=True, comment=None, filename=None, standardid=None, debug = False):
         
         #### ON-CHIP FILTERING
         if(standardid != None):
         
         #### ON-CHIP FILTERING
         if(standardid != None):
@@ -112,12 +116,21 @@ class GoodFETMCPCANCommunication:
                self.client.poke8(RXFSIDL, SIDlow);
         
                if (verbose == True):
                self.client.poke8(RXFSIDL, SIDlow);
         
                if (verbose == True):
-                   print "Filtering for SID %d (0x%02xh) with filter #%d"%(ID, ID, filter);
-                comment = comment + "%d " %(ID);
+                print "Filtering for SID %d (0x%02xh) with filter #%d"%(ID, ID, filter);
+            comment = comment + ("%d " %(ID))
         
         
         self.client.MCPsetrate(freq);
         
         
         
         self.client.MCPsetrate(freq);
         
+        # This will handle the files so that we do not loose them. each day we will create a new csv file
+        if( filename==None):
+            #get folder information (based on today's date)
+            now = datetime.datetime.now()
+            datestr = now.strftime("%Y%m%d")
+            path = self.DATALOCATION+datestr+".csv"
+            filename = path
+            
+        
         outfile = open(filename,'a');
         dataWriter = csv.writer(outfile,delimiter=',');
         dataWriter.writerow(['# Time     Error        Bytes 1-13']);
         outfile = open(filename,'a');
         dataWriter = csv.writer(outfile,delimiter=',');
         dataWriter.writerow(['# Time     Error        Bytes 1-13']);
@@ -346,7 +359,7 @@ if __name__ == "__main__":
     parser.add_argument('verb', choices=['info', 'test','peek', 'reset', 'sniff', 'freqtest','snifftest', 'spit']);
     parser.add_argument('-f', '--freq', type=int, default=500, help='The desired frequency (kHz)', choices=[100, 125, 250, 500, 1000]);
     parser.add_argument('-t','--time', type=int, default=15, help='The duration to run the command (s)');
     parser.add_argument('verb', choices=['info', 'test','peek', 'reset', 'sniff', 'freqtest','snifftest', 'spit']);
     parser.add_argument('-f', '--freq', type=int, default=500, help='The desired frequency (kHz)', choices=[100, 125, 250, 500, 1000]);
     parser.add_argument('-t','--time', type=int, default=15, help='The duration to run the command (s)');
-    parser.add_argument('-o', '--output', default="../../contrib/ted/sniff_out.csv",help='Output file');
+    parser.add_argument('-o', '--output', default=None,help='Output file');
     parser.add_argument("-d", "--description", help='Description of experiment (included in the output file)', default="");
     parser.add_argument('-v',"--verbose",action='store_false',help='-v will stop packet output to terminal', default=True);
     parser.add_argument('-c','--comment', help='Comment attached to ech packet uploaded',default=None);
     parser.add_argument("-d", "--description", help='Description of experiment (included in the output file)', default="");
     parser.add_argument('-v',"--verbose",action='store_false',help='-v will stop packet output to terminal', default=True);
     parser.add_argument('-c','--comment', help='Comment attached to ech packet uploaded',default=None);
@@ -394,7 +407,7 @@ if __name__ == "__main__":
     #
     
     if(args.verb=="sniff"):
     #
     
     if(args.verb=="sniff"):
-        comm.sniff(freq=freq,duration=duration,filename=filename,description=description,verbose=verbose,comment=comments, standardid=standardid)    
+        comm.sniff(freq=freq,duration=duration,description=description,verbose=verbose,comment=comments,filename=filename, standardid=standardid)    
                     
     ##########################
     #   SNIFF TEST
                     
     ##########################
     #   SNIFF TEST
index a5aa968..77bc082 100755 (executable)
@@ -176,9 +176,6 @@ if(sys.argv[1]=="peek"):
     while start<=stop:
         print "%04x: %02x" % (start,client.peek8(start));
         start=start+1;
     while start<=stop:
         print "%04x: %02x" % (start,client.peek8(start));
         start=start+1;
-        
-# AWWW YEAAAA CODIN THAT SHIT
-# as written, this should
 
 if(sys.argv[1]=="spit"):
 
 
 if(sys.argv[1]=="spit"):