def receiver(): data = yield b.framer.recv() print 'bytes recv by {}: {}'.format(b, fmt(data, 'hex')) data = yield b.framer.recv() print 'bytes recv by {}: {}'.format(b, fmt(data, 'hex')) print 'bits ever received at {}: {}'.format( b.port, fmt(utils.unbitify(b.port.bits_received), 'bin')) print 'bits ever received at {} (shifted): {}'.format( b.port, fmt(utils.unbitify(b.port.bits_received[3:]), 'hex')) raise mint.Stop yield mint.end
def recv(self): data = '' flag = utils.bitify(self.flag) escape_byte = utils.bitify(self.escape_byte) # detect start flag while True: yield self.port.bit_arrive.event data += self.port.get(1) if data.endswith(flag): data = '' break # receive data until end flag while True: # receive 8 bits for _ in range(8): yield self.port.bit_arrive.event data += self.port.get(1) # check if is escaping if data.endswith(escape_byte): # delete the escaper byte data = data[:-8] # get the escapee byte for _ in range(8): yield self.port.bit_arrive.event data += self.port.get(1) continue # end flag detected if data.endswith(flag): data = data[:-8] break mint.ret(utils.unbitify(data))
def collect_bits(self, port): # TODO # self.data += ibuffer.take_bytes() # # collect bits at multiples of 8 bits, port.ibuffer = utils.split_at(port.ibuffer, len(port.ibuffer) // 8 * 8) if bits: self.data += utils.unbitify(bits)
def collect_bits(self, port): # TODO # self.data += ibuffer.take_bytes() # # collect bits at multiples of 8 bits, port.ibuffer = utils.split_at(port.ibuffer, len(port.ibuffer) // 8 * 8) if bits: self.data += utils.unbitify(bits) print '{} Collected: {}'.format(self, utils.format_bytes(self.data)) raw_input()
def __init__(self, endpoint): self.endpoint = endpoint self.port = self.endpoint.port self.group_size = 3 self.flag = utils.unbitify('11111111') self.escape_byte = utils.unbitify('00000000')