Commit f5e9fb7b authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Updates the welcome message

Showing with 45 additions and 34 deletions
+45 -34
...@@ -33,27 +33,12 @@ try: ...@@ -33,27 +33,12 @@ try:
from digitalio import Direction from digitalio import Direction
from gpiozero import CPUTemperature from gpiozero import CPUTemperature
arm64_imports = True arm64_imports = True
except ImportError as e: except ImportError as error:
print(f'Warning: {e}') print(colored(f'Import error: {error}', 'yellow'))
arm64_imports = False arm64_imports = False
except Exception as error:
msg_logger, msg_log_filename, data_logger, data_log_filename, logging_level = setup_loggers() print(colored(f'Unexpected error: {error}', 'red'))
# mqtt_client, measurement_topic = mqtt_client_setup() exit()
# msg_logger.info(f'publishing mqtt to topic {measurement_topic}')
VERSION = '2.0.1'
print('\033[1m'+'\033[31m'+' ________________________________')
print(r'| _ | | | || \/ || ___ \_ _|')
print(r'| | | | |_| || . . || |_/ / | |')
print(r'| | | | _ || |\/| || __/ | |')
print(r'\ \_/ / | | || | | || | _| |_')
print(r' \___/\_| |_/\_| |_/\_| \___/ ')
print('\033[0m')
print('OhmPi start')
print('Version:', VERSION)
current_time = datetime.now()
print(current_time.strftime("%Y-%m-%d %H:%M:%S"))
class OhmPi(object): class OhmPi(object):
...@@ -70,9 +55,12 @@ class OhmPi(object): ...@@ -70,9 +55,12 @@ class OhmPi(object):
Either 'print' for a console output or 'mqtt' for publication onto Either 'print' for a console output or 'mqtt' for publication onto
MQTT broker. MQTT broker.
""" """
def __init__(self, config=None, sequence=None, output='print', data_logger=None, msg_logger=None, soh_logger=None): def __init__(self, config=None, sequence=None, output='print', data_logger=None, msg_logger=None, soh_logger=None,
on_pi=None):
# flags and attributes # flags and attributes
# self.on_pi = on_pi # True if run from the RaspberryPi with the hardware, otherwise False for random data if on_pi is None:
_, on_pi = OhmPi.get_platform()
self.on_pi = on_pi # True if run from the RaspberryPi with the hardware, otherwise False for random data
self.output = output # type of output print self.output = output # type of output print
self.status = 'idle' # either running or idle self.status = 'idle' # either running or idle
self.run = False # flag is True when measuring self.run = False # flag is True when measuring
...@@ -82,11 +70,6 @@ class OhmPi(object): ...@@ -82,11 +70,6 @@ class OhmPi(object):
self.msg_logger = msg_logger self.msg_logger = msg_logger
self.soh_logger = soh_logger self.soh_logger = soh_logger
if not arm64_imports:
self.log_msg(f'Warning: {e}\n Some libraries only available on arm64 platform could not be imported.\n'
f'The Ohmpi class will fake operations for testing purposes.', 'warning')
# read in hardware parameters (settings.py) # read in hardware parameters (settings.py)
self._read_hardware_parameters() self._read_hardware_parameters()
...@@ -231,17 +214,20 @@ class OhmPi(object): ...@@ -231,17 +214,20 @@ class OhmPi(object):
# output.append(i) # output.append(i)
return output return output
@property @staticmethod
def on_pi(self): def get_platform():
"""Returns True if code is running on a raspberry pi and required arm64 libs have been imported""" """Get platform name and check if it is a raspberry pi"""
running_on_pi = False
platform = 'unknown'
on_pi = False
try: try:
with io.open('/sys/firmware/devicetree/base/model', 'r') as f: with io.open('/sys/firmware/devicetree/base/model', 'r') as f:
if 'raspberry pi' in f.read().lower(): platform = f.read().lower()
running_on_pi = True if 'raspberry pi' in platform:
on_pi = True
except FileNotFoundError: except FileNotFoundError:
pass pass
return running_on_pi and arm64_imports return platform, on_pi
def read_quad(self, filename): def read_quad(self, filename):
"""Read quadrupole sequence from file. """Read quadrupole sequence from file.
...@@ -620,6 +606,31 @@ class OhmPi(object): ...@@ -620,6 +606,31 @@ class OhmPi(object):
self.log_msg('status = ' + self.status) self.log_msg('status = ' + self.status)
msg_logger, msg_log_filename, data_logger, data_log_filename, logging_level = setup_loggers()
# mqtt_client, measurement_topic = mqtt_client_setup()
# msg_logger.info(f'publishing mqtt to topic {measurement_topic}')
VERSION = '2.0.1'
print(colored(r' ________________________________' + '\n' +
r'| _ | | | || \/ || ___ \_ _|' + '\n' +
r'| | | | |_| || . . || |_/ / | |' + '\n' +
r'| | | | _ || |\/| || __/ | |' + '\n' +
r'\ \_/ / | | || | | || | _| |_' + '\n' +
r' \___/\_| |_/\_| |_/\_| \___/ ', 'red'))
print('OhmPi start')
print('Version:', VERSION)
platform, on_pi = OhmPi.get_platform()
if on_pi:
print(colored(f'Running on {platform} platform', 'green'))
if not arm64_imports:
print(colored(f'Warning: Required packages are missing.\n'
f'Please run . env.sh at command prompt to update your virtual environment\n', 'yellow'))
else:
print(colored(f'Not running on the Raspberry Pi platform.\nFor simulation purposes only...', 'yellow'))
current_time = datetime.now()
print(current_time.strftime("%Y-%m-%d %H:%M:%S"))
# for testing # for testing
if __name__ == "__main__": if __name__ == "__main__":
ohmpi = OhmPi(config='ohmpi_param.json') ohmpi = OhmPi(config='ohmpi_param.json')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment