
import serial
import time
import platform
import csv

import zephyr.protocol

def main():
    serial_port_dict = {"Darwin": "/dev/cu.BHBHT001931-iSerialPort1",
                        "Windows": 23}
    
    serial_port = serial_port_dict[platform.system()]
    ser = serial.Serial(serial_port)
    
    callback = lambda x: None
    protocol = zephyr.protocol.BioHarnessProtocol(ser, callback, "../test_data/120-second-bt-stream")
    protocol.enable_periodic_packets()
    
    start_time = time.time()
    while time.time() < start_time + 120:
        protocol.read_and_handle_bytes(1)


if __name__ == "__main__":
    main()


import serial
import time
import platform
import csv
import threading

import zephyr.protocol
import zephyr.message


def callback(x):
    print x


def reading_thread(protocol):
    start_time = time.time()
    
    while time.time() < start_time + 120:
        protocol.read_and_handle_bytes(1)


def create_data_files(input_definitions):
    threads = []
    
    try:
        for serial_i, (serial_port, enable_channels) in enumerate(input_definitions):
            payload_parser = zephyr.message.MessagePayloadParser(callback)
            
            ser = serial.Serial(serial_port)
            protocol = zephyr.protocol.BioHarnessProtocol(ser, payload_parser.handle_message, "../test_data/120-second-bt-stream-%d" % serial_i)
            
            if enable_channels:
                protocol.enable_periodic_packets()
            
            thread = threading.Thread(target=reading_thread, args=(protocol,))
            threads.append(thread)
            thread.start()
    
    finally:
        for thread in threads:
            thread.join()


def main():
    create_data_files([(29, False), (30, True)])


if __name__ == "__main__":
    main()

Refactor to support multiple devices for test data generation
Refactor to support multiple devices for test data generation