Exemplo n.º 1
0
    def start(self, callback=None):
        callback = callback or self._callback
        if callback and hasattr(callback, "on_start"):
            callback.on_start(self)

        self._node = Node(self._vendor_id, self._product_id)
        _logger.debug("Manager: Node initialized")

        self._status_msg("Request basic information...")
        m = self._node.request_message(Message.ID.RESPONSE_VERSION)
        self._status_msg("  ANT version:   {}",
                         struct.unpack("<10sx", m[2])[0])
        m = self._node.request_message(Message.ID.RESPONSE_CAPABILITIES)
        self._status_msg("  Capabilities:  {}", m[2])
        m = self._node.request_message(Message.ID.RESPONSE_SERIAL_NUMBER)
        self._status_msg("  Serial number: {}", struct.unpack("<I", m[2])[0])
        _logger.debug("Application: retrieved basic info")

        self._status_msg("Starting system...")

        NETWORK_KEY = [0xa8, 0xa4, 0x23, 0xb9, 0xf5, 0x5e, 0x63, 0xc1]

        self._node.reset_system()
        self._node.set_network_key(0x00, NETWORK_KEY)

        self._channel = self._node.new_channel(
            Channel.Type.BIDIRECTIONAL_RECEIVE)
        self._channel.on_broadcast_data = self._on_data
        self._channel.on_burst_data = self._on_data
        self._setup_channel()

        self._worker_thread = threading.Thread(target=self._node.start,
                                               name="ant.fs")
        self._worker_thread.start()

        if callback and hasattr(callback, "started"):
            callback.started(self)