Beispiel #1
0
	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("fs20","tx","bad_length",len=len(data),data=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("fs20","tx","checksum",checksum=qs,checksum_wanted=qsum,data=data)
			#return
		data = data[1:-1]
		try:
			g = tx_procs[data[0]]
			if not g:
				raise IndexError(data[0])
		except IndexError:
			simple_event("fs20","unknown","tx",code=data[0],data=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("fs20","unknown","tx","unregistered",type=g.tx_name,adr=adr,**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("fs20","conflict","tx","untimed",type=g.tx_name,adr=adr, **r)
				elif hn:
					hn[0].event(ctx,r)
				elif hdl:
					simple_event("fs20","unknown","tx","untimed",type=g.tx_name,adr=adr, **r)
				else:
					simple_event("fs20","unknown","tx","unregistered",type=g.tx_name,adr=adr, **r)
Beispiel #2
0
	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)
Beispiel #3
0
	def dataReceived(self, ctx, data, handler=None, timedelta=None):
		if len(data) != 10:
			simple_event(ctx, "fs20","en","bad_length","counter",len=len(data),data=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("fs20","en","checksum",checksum=xs,checksum_wanted=xsum,data=data)
			return
		try:
			g = en_procs[data[0]]
			if not g:
				raise IndexError(data[0])
		except IndexError:
			simple_event("fs20","unknown","en",type=data[0],data=data[1:])
		else:
			r = g(ctx, data[3:9])
			if r is None:
				return
			try:
				hdl = encodes[data[0]][data[1]]
			except KeyError:
				simple_event("fs20","unknown","en","unregistered",type=g.en_name,code=data[1],**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","en","sync",type=g.en_name,code=data[1], **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","en","unsync",type=g.en_name,code=data[1], **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","en","untimed",type=g.en_name,code=data[1], **r)
					else:
						# no timeslot here
						hn[0].event(ctx,r)
				elif hdl:
					simple_event("fs20","unknown","en","untimed",type=g.en_name,code=data[1], **r)
				else:
					simple_event("fs20","unknown","en","unregistered",type=g.en_name,code=data[1], **r)
Beispiel #4
0
    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("fs20", "tx", "bad_length", len=len(data), data=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("fs20",
                         "tx",
                         "checksum",
                         checksum=qs,
                         checksum_wanted=qsum,
                         data=data)
            #return
        data = data[1:-1]
        try:
            g = tx_procs[data[0]]
            if not g:
                raise IndexError(data[0])
        except IndexError:
            simple_event("fs20", "unknown", "tx", code=data[0], data=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("fs20",
                             "unknown",
                             "tx",
                             "unregistered",
                             type=g.tx_name,
                             adr=adr,
                             **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("fs20",
                                 "conflict",
                                 "tx",
                                 "untimed",
                                 type=g.tx_name,
                                 adr=adr,
                                 **r)
                elif hn:
                    hn[0].event(ctx, r)
                elif hdl:
                    simple_event("fs20",
                                 "unknown",
                                 "tx",
                                 "untimed",
                                 type=g.tx_name,
                                 adr=adr,
                                 **r)
                else:
                    simple_event("fs20",
                                 "unknown",
                                 "tx",
                                 "unregistered",
                                 type=g.tx_name,
                                 adr=adr,
                                 **r)