2022-06-19 14:16:45 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import json
|
2022-07-02 03:19:32 +02:00
|
|
|
import logging
|
2022-06-19 14:16:45 +02:00
|
|
|
import pathlib
|
2022-06-25 18:51:11 +02:00
|
|
|
import queue
|
2022-06-19 14:16:45 +02:00
|
|
|
import threading
|
|
|
|
|
|
|
|
from . import config
|
2022-06-25 17:03:13 +02:00
|
|
|
from . import controller
|
2022-06-19 14:16:45 +02:00
|
|
|
from . import dect
|
2022-07-06 13:15:31 +02:00
|
|
|
from . import routing
|
2022-07-06 13:05:06 +02:00
|
|
|
from . import ywsd
|
2022-06-19 14:16:45 +02:00
|
|
|
|
2022-07-02 03:19:32 +02:00
|
|
|
logger = logging.getLogger("fieldpoc.fieldpoc")
|
|
|
|
|
2022-06-19 14:16:45 +02:00
|
|
|
class FieldPOC:
|
|
|
|
config = None
|
|
|
|
extensions = None
|
2022-07-20 15:44:11 +02:00
|
|
|
temp_extensions = {}
|
2022-06-19 14:16:45 +02:00
|
|
|
|
|
|
|
def __init__(self, config_file_path, extensions_file_path):
|
2022-07-02 03:19:32 +02:00
|
|
|
logger.info("loading configuration")
|
2022-06-19 14:16:45 +02:00
|
|
|
self.config_file_path = pathlib.Path(config_file_path)
|
|
|
|
self._load_config()
|
|
|
|
self.extensions_file_path = pathlib.Path(extensions_file_path)
|
|
|
|
self._load_extensions()
|
|
|
|
|
2022-07-02 03:19:32 +02:00
|
|
|
logger.info("initialising queues")
|
2022-06-25 18:51:11 +02:00
|
|
|
self.queues = {
|
|
|
|
"controller": queue.Queue(),
|
|
|
|
"dect": queue.Queue(),
|
2022-07-06 13:15:31 +02:00
|
|
|
"routing": queue.Queue(),
|
2022-06-25 18:51:11 +02:00
|
|
|
}
|
2022-06-25 17:03:13 +02:00
|
|
|
|
2022-07-02 03:19:32 +02:00
|
|
|
logger.info("initialising components")
|
2022-06-25 17:03:13 +02:00
|
|
|
self._controller = controller.Controller(self)
|
2022-06-19 14:16:45 +02:00
|
|
|
self._dect = dect.Dect(self)
|
2022-07-06 13:15:31 +02:00
|
|
|
self._routing = routing.Routing(self)
|
2022-07-06 13:05:06 +02:00
|
|
|
self._ywsd = ywsd.Ywsd(self)
|
2022-06-19 14:16:45 +02:00
|
|
|
|
2022-06-25 18:51:11 +02:00
|
|
|
def queue_all(self, msg):
|
|
|
|
"""
|
|
|
|
Send message to every queue
|
|
|
|
"""
|
|
|
|
|
|
|
|
for queue in self.queues.values():
|
|
|
|
queue.put(msg)
|
|
|
|
|
2022-07-06 13:05:06 +02:00
|
|
|
def init(self):
|
|
|
|
"""
|
|
|
|
Prepare some data structures.
|
|
|
|
Run this once before using FieldPOC.
|
|
|
|
"""
|
|
|
|
|
|
|
|
logger.info("initialize datastructures")
|
|
|
|
|
|
|
|
self._ywsd.init()
|
|
|
|
|
|
|
|
logger.info("initialization complete")
|
|
|
|
|
2022-06-19 14:16:45 +02:00
|
|
|
def run(self):
|
2022-07-06 13:05:06 +02:00
|
|
|
logger.info("starting components")
|
2022-07-02 03:19:32 +02:00
|
|
|
|
2022-06-25 17:03:13 +02:00
|
|
|
self._controller_thread = threading.Thread(target=self._controller.run)
|
|
|
|
self._controller_thread.start()
|
|
|
|
|
2022-06-19 14:16:45 +02:00
|
|
|
self._dect_thread = threading.Thread(target=self._dect.run)
|
|
|
|
self._dect_thread.start()
|
|
|
|
|
2022-07-06 13:15:31 +02:00
|
|
|
self._routing_thread = threading.Thread(target=self._routing.run)
|
|
|
|
self._routing_thread.start()
|
|
|
|
|
2022-07-06 13:05:06 +02:00
|
|
|
self._ywsd_thread = threading.Thread(target=self._ywsd.run, daemon=True)
|
|
|
|
self._ywsd_thread.start()
|
|
|
|
|
2022-07-02 03:19:32 +02:00
|
|
|
logger.info("started components")
|
|
|
|
|
2022-06-19 14:16:45 +02:00
|
|
|
def _load_config(self):
|
|
|
|
self.config = config.Config(json.loads(self.config_file_path.read_text()))
|
|
|
|
|
|
|
|
def _load_extensions(self):
|
2022-06-19 16:33:44 +02:00
|
|
|
self.extensions = config.Extensions(json.loads(self.extensions_file_path.read_text()))
|