All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful
69 lines
1.8 KiB
Python
69 lines
1.8 KiB
Python
from loguru import logger
|
|
import argparse
|
|
import configparser
|
|
import threading
|
|
|
|
from ProcessImage import ProcessImage
|
|
from ModbusHandler import ModbusHandler
|
|
from MqttEventPublisher import MqttEventPublisher, mqttEventPublisherStart
|
|
from MqttPeriodPublisher import MqttPeriodPublisher
|
|
from MqttCoilSubscriber import MqttCoilSubscriber
|
|
from config import Config
|
|
|
|
deathBell = threading.Event()
|
|
|
|
def exceptHook(args):
|
|
global deathBell
|
|
logger.error("Exception in thread caught: {}".format(args))
|
|
deathBell.set()
|
|
logger.error("rang the death bell")
|
|
|
|
|
|
logger.info("DigitalTwin1 starting")
|
|
|
|
config = Config()
|
|
|
|
processImage = ProcessImage()
|
|
|
|
modbusHandlerThread = ModbusHandler(config, processImage)
|
|
modbusHandlerThread.start()
|
|
logger.info("Modbus handler running")
|
|
|
|
mqttEventPublisherThread = MqttEventPublisher(config, processImage)
|
|
mqttEventPublisherThread.start()
|
|
logger.info("MQTT event publisher running")
|
|
|
|
mqttPeriodPublisherThread = MqttPeriodPublisher(config, processImage)
|
|
mqttPeriodPublisherThread.start()
|
|
logger.info("MQTT period publisher running")
|
|
|
|
mqttCoilSubscriberThread = MqttCoilSubscriber(config, processImage)
|
|
mqttCoilSubscriberThread.start()
|
|
logger.info("MQTT coil subscriber running")
|
|
|
|
threading.excepthook = exceptHook
|
|
logger.info("Threading excepthook set")
|
|
|
|
logger.info("DigitalTwin1 running")
|
|
|
|
|
|
deathBell.wait()
|
|
logger.error("DigitalTwin1 is dying")
|
|
|
|
modbusHandlerThread.stop()
|
|
mqttEventPublisherThread.stop()
|
|
mqttPeriodPublisherThread.stop()
|
|
mqttCoilSubscriberThread.stop()
|
|
|
|
modbusHandlerThread.join()
|
|
logger.error("modbusHandlerThread joined")
|
|
mqttEventPublisherThread.join()
|
|
logger.error("mqttEventPublisherThread joined")
|
|
mqttPeriodPublisherThread.join()
|
|
logger.error("mqttPeriodPublisherThread joined")
|
|
mqttCoilSubscriberThread.join()
|
|
logger.error("mqttCoilSubscriberThread joined")
|
|
|
|
logger.error("DigitalTwin1 to terminate")
|
|
|