def scantable(): #make queue for 3b table scan_q = brybus.writequeue() print "Building Queue" #table 3c isn't complete so use this array of valid rows table_3c = ( '200130010300000B003C01', '200130010300000B003C03', '200130010300000B003C04', '200130010300000B003C05', '200130010300000B003C06', '200130010300000B003C08', '200130010300000B003C09', '200130010300000B003C0A', '200130010300000B003C0B', '200130010300000B003C0C', '200130010300000B003C0D', '200130010300000B003C0E', '200130010300000B003C0F', '200130010300000B003C10', '200130010300000B003C11', '200130010300000B003C12', '200130010300000B003C13', '200130010300000B003C14', '200130010300000B003C1E', '200130010300000B003C1F', '200130010300000B003C28', '200130010300000B003C29' ) for r in range(1,16): reg = '00' + '3B' + "{0:02X}".format(r) f = brybus.frame(reg,'C','2001','3001','0B') scan_q.pushframe(f) #use the list above for r in table_3c: f = brybus.frame(r,'S') scan_q.pushframe(f) for r in range(1,4): reg = '00' + '3D' + "{0:02X}".format(r) f = brybus.frame(reg,'C','2001','3001','0B') scan_q.pushframe(f) return scan_q
def main(): # load CSV into memory data = [] tfin = csv.reader(open(scan_data, "rb"), delimiter=" ") for row in tfin: f = brybus.frame(row[2], "S") s = printable(f.data.decode("hex")) if s != "": print f.src, f.data[:6], s
def scantable(): # load data from csv print "Loading table information" # load CSV into memory registers = [] tfin = csv.reader(open(scan_registers, "rb")) for row in tfin: registers.append(row) scan_q = brybus.writequeue() print "Building Queue" for r in registers: reg = "00" + r[1] + r[6] f = brybus.frame(reg, "C", r[0], "3001", "0B") scan_q.pushframe(f) return scan_q
def __init__(self,f): self.frame = f self.response = brybus.frame('000130010100000B000000','S') self.done = False
#!/usr/bin/python #an example program to use brybus and bryqueue #writes to frames constructed differently and reads #frames from the bus import time import brybus import ConfigParser cfg = ConfigParser.ConfigParser() cfg.read('brybus.cfg') serialport = cfg.get('brybus','serialport') #build a frame if you already know it f1 = brybus.frame('400130010300000B000101',"S") print "Frame Built: ",f1.print_str() #build a frame from parts: data, C for Create, dst, src, function f2 = brybus.frame('000101','C','5001','3001','0B') print "Frame Built: ",f2.print_str() #build the queue and put the items in it q = brybus.writequeue() q.pushframe(f1) q.pushframe(f2) q.printqueue() #setup the stream and bus s = brybus.stream('S',serialport) b = brybus.bus(s)
if phase==0: #scan devices for X seconds - exit loop by setting phase=1 if 'ph1_time' in locals(): if time.time() - ph1_time > 10: phase=1 #uncomment the next line to force items into the device list #devices.append("XXXX") print "ending phase 0" print "Devices:",devices #if variables are not setup do some init stuff one time else: ph1_time = time.time() print "starting phase 0" devices=[] #loop to read a frame and build a list of devices f = brybus.frame(b.read(),"B") if f.src not in devices: devices.append(f.src) #use device list to build a queue of all possible tables, scan them all if phase==1: #if the initial setup is done, scan it (normal write/read loop) if 'ph1_q' in locals(): #write w = b.write(ph1_q.writeframe()) if w==1: print "write", ph1_q.printstatus(), ByteToHex(ph1_q.writeframe()) if w==2: print "pause" #read and check frame f = brybus.frame(b.read(),"B")
return scan_q # =======main======== q = scantable() q.printqueue() # setup the stream and bus s = brybus.stream("S", serialport) b = brybus.bus(s) while 1: # write wf_raw = q.writeframe() wf = brybus.frame(wf_raw, "B") w = b.write(wf_raw) f = brybus.frame(b.read(), "B") if w == 1: print "write", q.printstatus() print wf.dst, wf.src, wf.len, wf.func, wf.data, wf.crc print f.dst, f.src, f.len, f.func, f.data, f.crc q.checkframe(f) # test for end of queue if q.writeframe() == "": q.printqueue() f = open(scan_data, "w") f.write(q.print_str())
#setup the stream and bus s = brybus.stream('S',serialport) b = brybus.bus(s) table=[] db_insert("START","START") while(1): #get write frame and write it #write blocks, writes if the timeout passes, but returns without writing if data is received on the serial port wf_raw = q.writeframe() w = b.write(wf_raw) f = brybus.frame(b.read(),"B") #if w==1: #print "write", q.printstatus() #print wf.dst,wf.src,wf.len,wf.func,wf.data,wf.crc #print f.dst,f.src,f.len,f.func,f.data,f.crc #check the frame that was read against the queue to match the response with the request q.checkframe(f) #test for end of queue, then restart the queue if q.writeframe() == '': print "Write Queue Done. Seconds Elapsed:",(time.time()-writestart) writestart = time.time() for k,v in q.queue.iteritems(): v.done = False