def main():
    zephyr.configure_root_logger()
    
    collector = MeasurementCollector()
    rr_signal_analysis = BioHarnessSignalAnalysis([], [collector.handle_event])
    signal_packet_handlers = [collector.handle_signal, rr_signal_analysis.handle_signal]
    
    signal_packet_handler = BioHarnessPacketHandler(signal_packet_handlers, [collector.handle_event])
    
    payload_parser = MessagePayloadParser(signal_packet_handler.handle_packet)
    
    delayed_stream_thread = DelayedRealTimeStream(collector, callback)
    
    simulation_thread = FilePacketSimulator(test_data_dir + "/120-second-bt-stream.dat",
                                            test_data_dir + "/120-second-bt-stream-timing.csv",
                                            payload_parser.handle_message)
    
    delayed_stream_thread.start()
    simulation_thread.start()
    
    visualization = VisualizationWindow(collector)
    visualization.show()
    
    simulation_thread.terminate()
    simulation_thread.join()
    
    delayed_stream_thread.terminate()
    delayed_stream_thread.join()
示例#2
0
def main():
    zephyr.util.DISABLE_CLOCK_DIFFERENCE_ESTIMATION = True

    collector = MeasurementCollector()
    rr_signal_analysis = BioHarnessSignalAnalysis([], [collector.handle_event])
    signal_packet_handlers = [
        collector.handle_signal, rr_signal_analysis.handle_signal
    ]

    signal_packet_handler = BioHarnessPacketHandler(signal_packet_handlers,
                                                    [collector.handle_event])

    payload_parser = MessagePayloadParser(
        [signal_packet_handler.handle_packet])

    message_parser = MessageFrameParser(payload_parser.handle_message)

    ser = VirtualSerial(test_data_dir + "/120-second-bt-stream.dat")

    protocol = Protocol(ser, [message_parser.parse_data])

    try:
        protocol.run()
    except EOFError:
        pass

    visualize_measurements(collector)
示例#3
0
    def initialize_device(self):

        collector = MeasurementCollector()

        rr_signal_analysis = BioHarnessSignalAnalysis([], [collector.handle_event])

        signal_packet_handler_bh = BioHarnessPacketHandler([collector.handle_signal, rr_signal_analysis.handle_signal],
                                                           [collector.handle_event])

        # Handle the payload of the message.
        # We don't treat the message payload at this time. The MessagePayloadParser class, when its method
        # handle_message() is executed (after the MessageFrameParser has verified the frame), will callbacks
        # the function specified in the list below with a correct message format.
        payload_parser = MessagePayloadParser([signal_packet_handler_bh.handle_packet, self.anyotherpackets])

        # handle the frame: verify STX, DLC, CRC and execute callback with the message in parameter
        message_parser = MessageFrameParser([payload_parser.handle_message])

        # The delayed stream is useful to synchronize the data coming from the device
        # and provides an easy reading by sending tuples like (signal name, sample value)
        self.delayed_stream_thread = DelayedRealTimeStream(collector, [self.callback], 1)

        self.protocol = BioHarnessProtocol(self.ser, [message_parser.parse_data, self.create_test_data_function])

        if self.virtual_serial is False :
            self.protocol.add_initilization_message( 0x0B, []) # get Serial Number
            self.connect( self, SIGNAL( 'Message' ), self._callback_serial_test )
            # by default disable every packet:
            self.protocol.add_initilization_message(self.PacketType['SUMMARY'], [0]) # disable summary packet
            self.protocol.add_initilization_message(self.PacketType['BREATHING'], [0]) # disable breathing waveform
            self.protocol.add_initilization_message(self.PacketType['ECG'], [0]) # disable ecg waveform
            self.protocol.add_initilization_message(self.PacketType['RRDATA'], [0]) # disable rr data
            self.protocol.add_initilization_message(self.PacketType['ACC'], [0]) # disable accelerometer waveform
def simulation_workflow(callbacks, ser):
    zephyr.configure_root_logger()

    collector = MeasurementCollector()

    rr_signal_analysis = BioHarnessSignalAnalysis([], [collector.handle_event])

    signal_packet_handler_bh = BioHarnessPacketHandler(
        [collector.handle_signal, rr_signal_analysis.handle_signal],
        [collector.handle_event])
    signal_packet_handler_hxm = HxMPacketAnalysis([collector.handle_event])

    payload_parser = MessagePayloadParser([
        signal_packet_handler_bh.handle_packet,
        signal_packet_handler_hxm.handle_packet
    ])

    message_parser = MessageFrameParser(payload_parser.handle_message)

    delayed_stream_thread = DelayedRealTimeStream(collector, callbacks, 1.2)

    protocol = BioHarnessProtocol(ser, [message_parser.parse_data])
    print "Enabling packets"
    protocol.enable_periodic_packets()

    delayed_stream_thread.start()

    try:
        protocol.run()
    except EOFError:
        pass

    delayed_stream_thread.terminate()
    delayed_stream_thread.join()
    def connectionMade(self):
        # Setting the protocol to handle raw data rather than just lines
        self.setRawMode()

        # Sending commands to enable relevant streams and summary messages
        self.send_initialization_commands()

        self.signal_packet_handler_bh = BioHarnessPacketHandler(
            self.waveform_callbacks, self.event_callbacks)
        self.payload_parser = MessagePayloadParser(
            [self.signal_packet_handler_bh.handle_packet])
        self.message_parser = MessageFrameParser(
            self.payload_parser.handle_message)
示例#6
0
def main():
    zephyr.configure_root_logger()
    
    analysis = HxMPacketAnalysis([callback])
    
    hxm_handler = MessagePayloadParser(analysis.handle_packet)
    
    simulation_thread = FilePacketSimulator(test_data_dir + "/120-second-bt-stream-hxm.dat",
                                            test_data_dir + "/120-second-bt-stream-hxm-timing.csv",
                                            hxm_handler.handle_message)
    
    simulation_thread.start()
    simulation_thread.join()
示例#7
0
def main():
    zephyr.util.DISABLE_CLOCK_DIFFERENCE_ESTIMATION = True

    collector = MeasurementCollector()
    rr_signal_analysis = BioHarnessSignalAnalysis([], [collector.handle_event])
    signal_packet_handlers = [
        collector.handle_signal, rr_signal_analysis.handle_signal
    ]

    signal_packet_handler = BioHarnessPacketHandler(signal_packet_handlers,
                                                    [collector.handle_event])

    payload_parser = MessagePayloadParser(signal_packet_handler.handle_packet)

    simulation_thread = FilePacketSimulator(
        "../test_data/120-second-bt-stream.dat",
        "../test_data/120-second-bt-stream-timing.csv",
        payload_parser.handle_message, False)
    simulation_thread.start()
    simulation_thread.join()

    visualize_measurements(collector)
def main():
    zephyr.util.DISABLE_CLOCK_DIFFERENCE_ESTIMATION = True

    collector = MeasurementCollector()
    rr_signal_analysis = BioHarnessSignalAnalysis([], [collector.handle_event])
    signal_packet_handlers = [
        collector.handle_signal, rr_signal_analysis.handle_signal
    ]

    signal_packet_handler = BioHarnessPacketHandler(signal_packet_handlers,
                                                    [collector.handle_event])

    payload_parser = MessagePayloadParser(
        [signal_packet_handler.handle_packet])

    message_parser = MessageFrameParser(payload_parser.handle_message)

    serial_port_dict = {
        "Darwin": "/dev/tty.BHBHT022509-iSerialPort1",
        "Windows": 23
    }

    serial_port = serial_port_dict[platform.system()]
    ser = serial.Serial(serial_port, 0)
    ser = VirtualSerial(
        "/Users/kaandonbekci/dev/pervasivetech/Room/monitor/test_data/120-second-bt-stream.dat"
    )

    protocol = Protocol(ser, [message_parser.parse_data])

    try:
        protocol.run()
    except EOFError:
        pass

    visualize_measurements(collector)