heart_sync

Heart Sync

class heart_sync.heart_sync.UDPHandler(request, client_address, server)[source]

Bases: DatagramRequestHandler

handle()[source]
finish()
setup()
class heart_sync.heart_sync.EcgProducer(polar_sn, polar_id)[source]

Bases: object

Add ECG data from one polar h10 device to a queue. Based on producer/consumer design pattern.

udp_handler(loop=None, port=5354)[source]

UDP socket listening on port for signal to stop ECG stream.

disconnected_callback(client)[source]

Called by BleakClient if the sensor disconnects

async connect_to_sn(devices)[source]

Scan bluetooth devices and find polar devices by their Serial Numbers

async run_ble_client(device, polar_id, ecg_queue, acc_queue, port, dongle_name)[source]

This task connects to the BLE server (the heart rate sensor) identified by device, starts ECG notification and pushes the ECG data to the queue. The tasks terminates when the sensor disconnects or the user hits enter.

async heart_sync.heart_sync.run_consumer_task(polar_id, ecg_queue, acc_queue, stream_ended, output, stream_not_started, trigger_port=5355)[source]

This task retrieves ECG data from the queue and does all the processing. You should ensure it returns control before the next frame is received from the sensor.

In this example, we simply prints decoded ECG data as it is received

heart_sync.heart_sync.read_config(polar_id, config)[source]

Read configuration file and output config data. Expected format for the configuration file is:

POLAR_ID,POLAR_SERIALNUMBER,QUIT_PORT,TRIGGER_PORT,OUTPUT_FILE,DONGLE_MAC

Returns:

  • sn (string) – the polar device serial number to which we connect

  • port (int) – the port which is used to stop the stream

  • trigger_port (int) – the port which is used to write a trigger

  • output (string) – the name used for the output file

  • dongle_mac (string) – the mac address of the dongle to use for connection

async heart_sync.heart_sync.main()[source]