def do_packetiser(ser, state, out, info): while ser.inWaiting(): chr = ser.read(1) state, info = do_packetise_byte(ord(chr), state, info) if (is_packet_ready(state)): state = store_packet(out, state) elif (is_packet_damaged(state)): state = drop_packet(state) if (is_packet_at_finish(state)): break return state, info
def do_read_packets(ser, state, info): out = ListFormatter() num_bytes = ser.in_waiting while (num_bytes > 0): # The read() function in Python is ridiculously slow; instead of using it # many times to read one byte, let's call it once for considerable buffer btarr = ser.read(min(num_bytes, 4096)) for bt in btarr: state, info = do_packetise_byte(bt, state, info) if (is_packet_ready(state)): state = store_packet(out, state) elif (is_packet_damaged(state)): state = drop_packet(state) if (is_packet_at_finish(state)): break num_bytes = ser.in_waiting return state, out.pktlist, info
def do_read_packets(ser, state, info): out = ListFormatter() num_bytes = ser.in_waiting while (num_bytes > 0): # The read() function in Python is ridiculously slow; instead of using it # many times to read one byte, let's call it once for considerable buffer btarr = ser.read(min(num_bytes,4096)) for bt in btarr: state, info = do_packetise_byte(bt, state, info) if (is_packet_ready(state)): state = store_packet(out, state) elif (is_packet_damaged(state)): state = drop_packet(state) if (is_packet_at_finish(state)): break; num_bytes = ser.in_waiting return state, out.pktlist, info
def do_packetiser(ser, state, out, info): num_bytes = ser.inWaiting() while (num_bytes > 0): # The read() function in Python is ridiculously slow; instead of using it # many times to read one byte, let's call it once for considerable buffer btarr = ser.read(min(num_bytes,4096)) for bt in btarr: state, info = do_packetise_byte(bt, state, info) if (is_packet_ready(state)): state = store_packet(out, state) elif (is_packet_damaged(state)): if (out.storebad): state = store_packet(out, state) else: state = drop_packet(state) if (is_packet_at_finish(state)): break; num_bytes = ser.inWaiting() return state, info