def dataReceived(self, ctx, data, handler=None, timedelta=None): dat = [] for d in data: d=ord(d) dat.append(d>>4) dat.append(d&0xF) data=dat if len(data) < 4: return if data[0]&1: data.pop() # last nibble is missing if data[0] != len(data): simple_event(ctx, "fs20","tx","bad_length",len(data),"".join("%x"%x for x in data)) return None qsum = data[-1] qs=0 for d in data[:-1]: qs += d if qs&0xF != qsum: # fs20¦tx¦checksum¦65¦0¦a0ca791790 # obviously wrong simple_event(ctx, "fs20","tx","checksum",qs,qsum,"".join("%x" % x for x in data)) #return data = data[1:-1] try: g = tx_procs[data[0]] if not g: raise IndexError(data[0]) except IndexError: simple_event(ctx, "fs20","unknown","tx",data[0],"".join("%x"%x for x in data[1:])) else: r = g(ctx, data[1:]) if r is None: return adr = (data[1]<<3) + (data[2]>>1) try: hdl = TXcodes[data[0]][adr] except KeyError: simple_event(ctx, "fs20","unknown","tx","unregistered",g.tx_name,adr,*tuple(flat(r))) else: # If there is more than one device on the same # address, this code tries to find the one that's # most likely to be the one responsible. hn = collision_filter(r,hdl) if len(hn) > 1: simple_event(ctx, "fs20","conflict","tx","untimed",g.tx_name,adr, *tuple(flat(r))) elif hn: hn[0].event(ctx,r) elif hdl: simple_event(ctx, "fs20","unknown","tx","untimed",g.tx_name,adr, *tuple(flat(r))) else: simple_event(ctx, "fs20","unknown","tx","unregistered",g.tx_name,adr, *tuple(flat(r)))
def dataReceived(self, ctx, data, handler=None, timedelta=None): if len(data) < 4: return xsum = ord(data[-2]) qsum = ord(data[-1]) data = tuple(ord(d) for d in data[:-2]) xs=0; qs=xsum for d in data: xs ^= d qs += d if xs != xsum: simple_event("fs20","em","checksum1",checksum=xs,checksum_wanted=xsum,data=data) return if (qs+5)&15 != qsum: simple_event("fs20","em","checksum2",checksum=(qs+5)&15,checksum_wanted=qsum,data=data) return try: g = em_procs[data[0]] if not g: raise IndexError(data[0]) except IndexError: simple_event("fs20","unknown","em",type=data[0],data=data[1:]) else: r = g(ctx, data[1:]) if r is None: return try: hdl = EMcodes[data[0]][data[1]&7] except KeyError: simple_event("fs20","unknown","em","unregistered",type=g.em_name,code=data[1]&7,info=r) else: # If there is more than one device on the same # address, this code tries to find the one that's # most likely to be the one responsible. hi = [] # in slot hr = [] # slot not running hn = [] # device without slot for h in hdl: if h.slot is None: hn.append(h) elif h.slot.is_in(): hi.append(h) elif not h.slot.is_out(): hr.append(h) if hi: hi = collision_filter(r,hi) if len(hi) > 1: simple_event("fs20","conflict","em","sync",type=g.em_name,code=data[1]&7, **r) else: hi[0].slot.do_sync() hi[0].event(ctx,r) elif hr: hr = collision_filter(r,hr) if len(hr) > 1: simple_event("fs20","conflict","em","unsync",type=g.em_name,code=data[1]&7, **r) else: hr[0].slot.up(True) hr[0].event(ctx,r) elif hn: hn = collision_filter(r,hn) if len(hn) > 1: simple_event("fs20","conflict","em","untimed",type=g.em_name,code=data[1]&7, **r) else: # no timeslot here hn[0].event(ctx,r) elif hdl: simple_event("fs20","unknown","em","untimed",type=g.em_name,code=data[1]&7, **r) else: simple_event("fs20","unknown","em","unregistered",type=g.em_name,code=data[1]&7, **r)
def dataReceived(self, ctx, data, handler=None, timedelta=None): if len(data) != 10: simple_event(ctx, "fs20","en","bad_length","counter",len(data),"".join("%x"%ord(x) for x in data)) return xsum = ord(data[-1]) data = tuple(ord(d) for d in data[:-1]) xs=0 for d in data: xs ^= d if xs != xsum: simple_event(ctx, "fs20","en","checksum",xs,xsum,"".join("%x"%x for x in data)) return try: g = en_procs[data[0]] if not g: raise IndexError(data[0]) except IndexError: simple_event(ctx, "fs20","unknown","en",data[0],"".join("%x"%x for x in data)) else: r = g(ctx, data[3:9]) if r is None: return try: hdl = encodes[data[0]][data[1]] except KeyError: simple_event(ctx, "fs20","unknown","en","unregistered",g.en_name,data[1],*tuple(flat(r))) else: # If there is more than one device on the same # address, this code tries to find the one that's # most likely to be the one responsible. hi = [] # in slot hr = [] # slot not running hn = [] # device without slot for h in hdl: if h.slot is None: hn.append(h) elif h.slot.is_in(): hi.append(h) elif not h.slot.is_out(): hr.append(h) if hi: hi = collision_filter(r,hi) if len(hi) > 1: simple_event(ctx, "fs20","conflict","en","sync",g.en_name,data[1], *tuple(flat(r))) else: hi[0].slot.do_sync() hi[0].event(ctx,r) elif hr: hr = collision_filter(r,hr) if len(hr) > 1: simple_event(ctx, "fs20","conflict","en","unsync",g.en_name,data[1], *tuple(flat(r))) else: hr[0].slot.up(True) hr[0].event(ctx,r) elif hn: hn = collision_filter(r,hn) if len(hn) > 1: simple_event(ctx, "fs20","conflict","en","untimed",g.en_name,data[1], *tuple(flat(r))) else: # no timeslot here hn[0].event(ctx,r) elif hdl: simple_event(ctx, "fs20","unknown","en","untimed",g.en_name,data[1], *tuple(flat(r))) else: simple_event(ctx, "fs20","unknown","en","unregistered",g.en_name,data[1], *tuple(flat(r)))