コード例 #1
0
    def __init__(
        self,
        shared_state,
        tx_queue,
        rx_queue,
        settings,
        data_queue=None,
        event_queue=None,
        timeout=10,
        histfile_size=1000,
        exit_signal=None,
        logger=None,
    ):

        self._prompt_base = "cli"
        self._prompt_format = "{} | {} > "
        self._reply_greeting = "<< message from"

        self._bstr_as_hex = True
        self._pretty_prints = False
        self._minimal_prints = False
        self._silent_loop = False
        self._max_queue_size = 1000
        self._max_data_queue_size = 1  # Data queues contains list messges

        self._file = None
        self._histfile = os.path.expanduser("~/.wm-shell-history")
        self._histfile_size = histfile_size

        self._tracking_loop_timeout = 1
        self._tracking_loop_iterations = float("Inf")
        self._raise_errors = False
        self._skip_replies = True

        super().__init__()

        self.settings = settings
        self.intro = self.intro.format(**self.settings.to_dict())
        self.prompt = self._prompt_format.format(
            datetime.datetime.now().strftime("%H:%M.%S"), self._prompt_base)

        self.request_queue = tx_queue
        self.response_queue = rx_queue
        self.data_queue = data_queue
        self.event_queue = event_queue

        self.wait_api_lock = Lock()
        self.mqtt_topics = Topics()
        self.exit_signal = exit_signal
        self.timeout = timeout
        self.logger = logger or logging.getLogger(__name__)

        self.device_manager = shared_state["devices"]
        self._shared_state = shared_state
        self._flush_lock = threading.Lock()

        self.start_data_event_queue_peroidic_flush_timer()
コード例 #2
0
ファイル: http.py プロジェクト: jouker2k/backend-client
    def __init__(self, request, client_address, server):
        #
        self.logger = server.logger or logging.getLogger(__name__)
        self.http_tx_queue = server.http_tx_queue
        self.status_observer = server.status_observer
        self.mqtt_topics = Topics()

        self.debug_comms = False  # if true communication details are logged
        self.http_api_test_mode = False  # When on, does not send MQTT messages

        super(wbcHTTPRequestHandler, self).__init__(request, client_address,
                                                    server)
コード例 #3
0
 def __init__(self, deviceManager: MeshManagement):
     self._processingActive: bool = True
     self._networkIdToUse: int = 0
     self._diagnosticIntervalSecs: SetDiagnosticsIntervals = SetDiagnosticsIntervals.intervalOff
     self._deviceManager: MeshManagement = deviceManager
     self._mqttSendFn = None
     self._diagnosticActivationStatuses = dict()
     self.mqtt_topics = Topics()
     self._defaultPollTimeSec = 0.1
     self._operationStart = None
     self._sinksAddressInfo = None
     self._messageTxList = list()
     self._defaultOperationTimeOutSec = 30
コード例 #4
0
ファイル: mqtt.py プロジェクト: namtung-git/backend-client
    def __init__(
        self,
        mqtt_settings,
        shared_state=None,
        data_queue=None,
        event_queue=None,
        gateway_id: str = "+",
        sink_id: str = "+",
        network_id: str = "+",
        source_endpoint: str = "+",
        destination_endpoint: str = "+",
        message_subscribe_handlers=None,
        publish_cb=None,
        network_parameters=None,
        **kwargs,
    ):

        try:
            tx_queue = kwargs["tx_queue"]
        except KeyError:
            tx_queue = None

        try:
            rx_queue = kwargs["rx_queue"]
        except KeyError:
            rx_queue = None

        try:
            logger = kwargs["logger"]
        except KeyError:
            logger = logging.getLogger(__name__)

        try:
            exit_signal = kwargs["exit_signal"]
        except KeyError:
            exit_signal = Signal(False)

        try:
            start_signal = kwargs["start_signal"]
        except KeyError:
            start_signal = Signal(True)

        try:
            allowed_endpoints = kwargs["allowed_endpoints"]
        except KeyError:
            allowed_endpoints = None

        # create subscription list for MQTT API
        self.mqtt_settings = mqtt_settings
        self.mqtt_topics = Topics()

        if network_parameters:
            self.network_parameters = network_parameters
        else:
            self.network_parameters = dict(
                gw_id=str(gateway_id),
                sink_id=str(sink_id),
                network_id=str(network_id),
                src_ep=str(source_endpoint),
                dst_ep=str(destination_endpoint),
            )

        if message_subscribe_handlers:
            self.message_subscribe_handlers = message_subscribe_handlers
        else:
            self.message_subscribe_handlers = self.build_subscription()

        super(NetworkDiscovery, self).__init__(
            mqtt_settings=mqtt_settings,
            start_signal=start_signal,
            exit_signal=exit_signal,
            tx_queue=tx_queue,
            rx_queue=rx_queue,
            allowed_endpoints=allowed_endpoints,
            message_subscribe_handlers=self.message_subscribe_handlers,
            publish_cb=publish_cb,
            logger=logger,
        )

        # This is to mimic the API style in terms of having a data, event
        # and request response path
        self.response_queue = self.tx_queue
        self.request_queue = self.rx_queue
        self.data_queue = data_queue
        self.event_queue = event_queue

        self.shared_state = shared_state
        self.device_manager = MeshManagement()
        self._debug_comms = False
        self._perioidicTimer = None  # Set on notify where context is right
        self._timerRunning: bool = False  # picklable
        self.data_event_flush_timer_interval_sec: float = 1.0

        self._data_event_tx_queue = Queue()