diff --git a/config.py b/config.py index c0ee048cce3410946cea8ccfe7007c5d3c0e0623..f92ef7e6481f4abeda78b5b81a7e4d06b3257a09 100644 --- a/config.py +++ b/config.py @@ -15,7 +15,8 @@ OHMPI_CONFIG = { 'version': 2, 'max_elec': 64, 'board_address': {'A': 0x70, 'B': 0x71, 'M': 0x72, 'N': 0x73}, # def. {'A': 0x76, 'B': 0x71, 'M': 0x74, 'N': 0x70} -} + 'settings': 'ohmpi_settings.json' +} # TODO: add a dictionary with INA models and associated gain values CONTROL_CONFIG = { 'tcp_port': 5555, diff --git a/mqtt_controller.py b/mqtt_controller.py index df30e2a045c29bded19790a1ec5872722748c20d..93abf662492cb34d58fc86b3ad1746fb24529a94 100644 --- a/mqtt_controller.py +++ b/mqtt_controller.py @@ -15,7 +15,7 @@ publisher_config['topic'] = MQTT_CONTROL_CONFIG['ctrl_topic'] publisher_config.pop('ctrl_topic') settings = { 'injection_duration': 0.2, - 'nbr_meas': 100, + 'nbr_meas': 1, 'sequence_delay': 1, 'nb_stack': 1, 'export_path': 'data/measurement.csv' diff --git a/ohmpi.py b/ohmpi.py index 64a8f4655f9a1c5bb98ab1133d34e7f771431101..a07fc22c25040ad5ed3e526ab28a676e88148c12 100644 --- a/ohmpi.py +++ b/ohmpi.py @@ -20,7 +20,7 @@ from datetime import datetime from termcolor import colored import threading from logging_setup import setup_loggers -from config import CONTROL_CONFIG +from config import CONTROL_CONFIG, OHMPI_CONFIG from subprocess import Popen # finish import (done only when class is instantiated as some libs are only available on arm64 platform) @@ -118,6 +118,7 @@ class OhmPi(object): self.ads_voltage = ads.ADS1115(self.i2c, gain=2 / 3, data_rate=860, address=0x49) # Starts the command processing thread + self.cmd_listen = True self.cmd_thread = threading.Thread(target=self.process_commands) self.cmd_thread.start() @@ -650,7 +651,7 @@ class OhmPi(object): print(colored(f'Listening to commands on tcp port {tcp_port}.' f' Make sure your client interface is running and bound to this port...', 'blue')) self.exec_logger.debug(f'Start listening for commands on port {tcp_port}') - while True: + while self.cmd_listen: message = socket.recv() self.exec_logger.debug(f'Received command: {message}') e = None @@ -780,6 +781,15 @@ class OhmPi(object): if self.thread is not None: self.thread.join() self.exec_logger.debug(f'Status: {self.status}') + + def quit(self): + """Quit OhmPi. + """ + self.cmd_listen = False + if self.cmd_thread is not None: + self.cmd_thread.join() + self.exec_logger.debug(f'Stopped listening to tcp port.') + exit() @@ -812,6 +822,6 @@ if __name__ == "__main__": # start interface Popen(['python', CONTROL_CONFIG['interface']]) - ohmpi = OhmPi(settings='ohmpi_settings.json') + ohmpi = OhmPi(settings=OHMPI_CONFIG['settings']) diff --git a/ohmpi_settings.json b/ohmpi_settings.json index eea474050b8be42722a4e2f54488cfc901cb954e..273f22904d72553ed4c5140379992cd9672d0462 100644 --- a/ohmpi_settings.json +++ b/ohmpi_settings.json @@ -1,7 +1,7 @@ { "nb_electrodes": 64, "injection_duration":0.2, - "nbr_meas": 100, + "nbr_meas": 1, "sequence_delay": 1, "nb_stack": 1, "export_path": "data/measurement.csv"