Bug fixes and new features added to zigduino firmware and client.
[goodfet] / client / goodfet.zigduino
index 2a84888..ca5ed35 100755 (executable)
@@ -2,7 +2,7 @@
 #GoodFET zigduino client
 #forked from code by neighbor Travis Goodspeed by bx
 
-import sys, binascii, os, array, time, glob
+import sys, binascii, os, array, time, glob, argparse
 
 from GoodFETatmel128 import GoodFETatmel128rfa1
 from intelhex import IntelHex;
@@ -18,55 +18,60 @@ def printpacket(packet):
     print "%s" % s;
 
 
-mskbstring="";
-oldseq=-1;
+commands=["sniff", "beaconreq"]
+parser = argparse.ArgumentParser(description="Simple GoodFET running on Zigduino tools.")
+subparsers = parser.add_subparsers(help='sub-command help')
+p_sniff = subparsers.add_parser('sniff', help='Sniff for packets')
+p_sniff.add_argument("-f", action="store", dest="channel", help="channel")
+p_sniff.add_argument("-i", action="store", dest="interface", 
+                    default="/dev/ttyUSB0", help="interface (ie. /dev/ttyUSB0")
+p_sniff.set_defaults(name="sniff")
+p_br = subparsers.add_parser('beaconreq', help= 'Send out beacon requests')
+p_br.add_argument("-f", action="store", dest="channel", help="channel")
+p_br.add_argument("-c", action="store_true", dest="autocrc", help="Sends beacon requests with autocrc enabled.")
+p_br.add_argument("-i", action="store", dest="interface", 
+                    default="/dev/ttyUSB0", help="interface (ie. /dev/ttyUSB0")
 
-#def printconfig():
-#    print "Encoding %s" % client.RF_getenc();
-#    print "Freq    %10i MHz" % (client.RF_getfreq()/10**6);
-#    print "Rate    %10i kbps" % (client.RF_getrate()/1000);
-#    print "PacketLen %02i bytes" % client.RF_getpacketlen();
-#    #print "MacLen    %2i bytes" % client.RF_getmaclen();
-#    print "SMAC  0x%010x" % client.RF_getsmac();
-#    print "TMAC  0x%010x" % client.RF_gettmac();
+p_br.set_defaults(name="beaconreq")
 
-
-if(len(sys.argv)==1):
-    print "Usage: %s verb [objects]\n" % sys.argv[0];
-    #print "%s info" % sys.argv[0];
-    print "%s sniff [channel]\n\tSniffs packets." % sys.argv[0];
-    print "%s beaconreq [channel]\n\tSends out beacons requests" % sys.argv[0];
-    sys.exit();
+args = parser.parse_args()
 
 #Initialize FET and set baud rate
 client=GoodFETatmel128rfa1()
 #client.verbose = True
-client.serInit()
+client.serInit(args.interface)
 
 #if(sys.argv[1ce]=="info"):
 #    printconfig();
 
-if(sys.argv[1]=="sniff"):
+if(args.name=="sniff"):
     client.RF_setup()
-    if len(sys.argv)>2:
-        print "Set channel to %s" % sys.argv[2];
-        client.RF_setchannel(int(sys.argv[2]));
+    if args.channel:
+        print "Set channel to %s" % args.channel
+        client.RF_setchannel(int(args.channel))
     #Now we're ready to get packets.
-
     while 1:
         packet=None;
         while packet==None:
             packet=client.RF_rxpacket();
-            time.sleep(0.4)
+            time.sleep(.5)
         printpacket(packet);
         sys.stdout.flush();
 
-if (sys.argv[1]=="beaconreq"):
+if (args.name=="beaconreq"):
+    if (args.autocrc):
+        autocrc = 1
+    else:
+        autocrc = 0
     client.RF_setup()
-    if len(sys.argv)>2:
-        print "Set channel to %s" % sys.argv[2];
-        client.RF_setchannel(int(sys.argv[2]));
-    packet="\x03\x08\x46\xff\xff\xff\xff\x07\x13\x33"
+    if args.channel:
+        print "Set channel to %s" % args.channel
+        client.RF_setchannel(int(args.channel))
+    client.RF_autocrc(autocrc)
+    if autocrc:
+        packet="\x03\x08\x46\xff\xff\xff\xff\x07\x00\x00"        
+    else:
+        packet="\x03\x08\x46\xff\xff\xff\xff\x07\x13\x33"
     while 1:
-        client.RX_txpacket(packet)
+        client.RF_txpacket(chr(len(packet))+packet)
         time.sleep(1)