Exemplo n.º 1
0
    def _handle_ui_device_connected(self, msg):
        if msg.connectionType != _clad_to_engine_cozmo.UiConnectionType.SdkOverTcp:
            # This isn't for us
            return

        if msg.deviceID != 1:
            logger.error('Unexpected Device Id %s', msg.deviceID)
            return

        # Verify that engine and SDK are compatible
        clad_hashes_match = False
        try:
            cozmoclad.assert_clad_match(msg.toGameCLADHash, msg.toEngineCLADHash)
            clad_hashes_match = True
        except cozmoclad.CLADHashMismatch as exc:
            logger.error(exc)

        build_versions_match = (cozmoclad.__build_version__ == '00000.00000.00000'
            or cozmoclad.__build_version__ == msg.buildVersion)

        if clad_hashes_match and not build_versions_match:
            # If CLAD hashes match, and this is only a minor version change,
            # then still allow connection (it's just an app hotfix
            # that didn't require CLAD or SDK changes)
            sdk_major_version = cozmoclad.__build_version__.split(".")[0:2]
            build_major_version = msg.buildVersion.split(".")[0:2]
            build_versions_match = (sdk_major_version == build_major_version)

        if clad_hashes_match and build_versions_match:
            connection_success_msg = _clad_to_engine_iface.UiDeviceConnectionSuccess(
                connectionType=msg.connectionType,
                deviceID=msg.deviceID,
                buildVersion = cozmoclad.__version__,
                sdkModuleVersion = version.__version__,
                pythonVersion = platform.python_version(),
                pythonImplementation = platform.python_implementation(),
                osVersion = platform.platform(),
                cpuVersion = platform.machine())

            self.send_msg(connection_success_msg)

        else:
            try:
                wrong_version_msg = _clad_to_engine_iface.UiDeviceConnectionWrongVersion(
                    reserved=0,
                    connectionType=msg.connectionType,
                    deviceID = msg.deviceID,
                    buildVersion = cozmoclad.__version__)

                self.send_msg(wrong_version_msg)
            except AttributeError:
                pass

            line_separator = "=" * 80
            error_message = "\n" + line_separator + "\n"

            if not build_versions_match:

                def _trimmed_version(ver_string):
                    # Trim leading zeros from the version string.
                    trimmed_string = ""
                    for i in ver_string.split("."):
                        trimmed_string += str(int(i)) + "."
                    return trimmed_string[:-1]  # remove trailing "."

                error_message += ("App and SDK versions do not match!\n"
                                  "----------------------------------\n"
                                  "SDK's cozmoclad version: %s\n"
                                  "         != app version: %s\n\n"
                                  % (cozmoclad.__version__, _trimmed_version(msg.buildVersion)))

                if cozmoclad.__build_version__ < msg.buildVersion:
                    # App is newer
                    error_message += ('Please update your SDK to the newest version by calling command:\n'
                                      '"pip3 install --user --upgrade cozmo"\n'
                                      'and downloading the latest examples from:\n'
                                      'http://cozmosdk.anki.com/docs/downloads.html\n')
                else:
                    # SDK is newer
                    error_message += ('Please either:\n\n'
                                      '1) Update your app to the most recent version on the app store.\n'
                                      '2) Or, if you prefer, please determine which SDK version matches\n'
                                      '   your app version at: http://go.anki.com/cozmo-sdk-version\n'
                                      '   Then downgrade your SDK by calling the following command,\n'
                                      '   replacing SDK_VERSION with the version listed at that page:\n'
                                      '   "pip3 install --ignore-installed cozmo==SDK_VERSION"\n')

            else:
                # CLAD version mismatch
                error_message += ('CLAD Hashes do not match!\n'
                                  '-------------------------\n'
                                  'Your Python and C++ CLAD versions do not match - connection refused.\n'
                                  'Please check that you have the most recent versions of both the SDK and the\n'
                                  'Cozmo app. You may update your SDK by calling:\n'
                                  '"pip3 install --user --ignore-installed cozmo".\n'
                                  'Please also check the app store for a Cozmo app update.\n')

            error_message += line_separator
            logger.error(error_message)

            exc = exceptions.SDKVersionMismatch("SDK library does not match software running on device")
            self.abort(exc)
            return

        self._is_ui_connected = True
        self.dispatch_event(EvtConnected, conn=self)

        logger.info('App connection established. sdk_version=%s '
                'cozmoclad_version=%s app_build_version=%s',
                version.__version__, cozmoclad.__version__, msg.buildVersion)

        # We send RequestConnectedObjects and RequestLocatedObjectStates before
        # refreshing the animation names as this ensures that we will receive
        # the responses before we mark the robot as ready.
        self._request_connected_objects()
        self._request_located_objects()

        self.anim_names.refresh()
Exemplo n.º 2
0
    def _handle_ui_device_connected(self, msg):
        if msg.connectionType != _clad_to_engine_cozmo.UiConnectionType.SdkOverTcp:
            # This isn't for us
            return

        if msg.deviceID != 1:
            logger.error('Unexpected Device Id %s', msg.deviceID)
            return

        # Verify that engine and SDK are compatible
        clad_hashes_match = False
        try:
            cozmoclad.assert_clad_match(msg.toGameCLADHash,
                                        msg.toEngineCLADHash)
            clad_hashes_match = True
        except cozmoclad.CLADHashMismatch as exc:
            logger.error(exc)

        build_versions_match = (
            cozmoclad.__build_version__ == '00000.00000.00000'
            or cozmoclad.__build_version__ == msg.buildVersion)

        if clad_hashes_match and not build_versions_match:
            # If CLAD hashes match, and this is only a minor version change,
            # then still allow connection (it's just an app hotfix
            # that didn't require CLAD or SDK changes)
            sdk_major_version = cozmoclad.__build_version__.split(".")[0:2]
            build_major_version = msg.buildVersion.split(".")[0:2]
            build_versions_match = (sdk_major_version == build_major_version)

        if clad_hashes_match and build_versions_match:
            connection_success_msg = _clad_to_engine_iface.UiDeviceConnectionSuccess(
                connectionType=msg.connectionType,
                deviceID=msg.deviceID,
                buildVersion=cozmoclad.__version__,
                sdkModuleVersion=version.__version__,
                pythonVersion=platform.python_version(),
                pythonImplementation=platform.python_implementation(),
                osVersion=platform.platform(),
                cpuVersion=platform.machine())

            self.send_msg(connection_success_msg)

        else:
            try:
                wrong_version_msg = _clad_to_engine_iface.UiDeviceConnectionWrongVersion(
                    reserved=0,
                    connectionType=msg.connectionType,
                    deviceID=msg.deviceID,
                    buildVersion=cozmoclad.__version__)

                self.send_msg(wrong_version_msg)
            except AttributeError:
                pass

            if not build_versions_match:
                logger.warning(
                    'Build versions do not match (cozmoclad version %s != app version %s) - connection refused',
                    cozmoclad.__build_version__, msg.buildVersion)

                if cozmoclad.__build_version__ < msg.buildVersion:
                    # App is newer
                    logger.error(
                        'Please update your SDK to the newest version by calling command: '
                        '"pip3 install --user --upgrade cozmo" '
                        'and downloading the latest examples from http://cozmosdk.anki.com/docs/downloads.html'
                    )
                else:
                    # SDK is newer
                    logger.error(
                        "Please update your app to the most recent version on the app store."
                    )
                    logger.error(
                        "Or, if you prefer, please determine which SDK version matches your app version at:"
                    )
                    logger.error("http://go.anki.com/cozmo-sdk-version")
                    logger.error(
                        "Then downgrade your SDK by calling the following command, replacing"
                    )
                    logger.error(
                        "SDK_VERSION with the version listed at that page:")
                    logger.error(
                        "'pip3 install --ignore-installed cozmo==SDK_VERSION'")

            else:
                # CLAD version mismatch
                logger.error(
                    'Your Python and C++ CLAD versions do not match - connection refused.'
                )
                logger.error(
                    'Please check that you have the most recent versions of both the SDK and the Cozmo app.'
                )
                logger.error(
                    "You may update your SDK by calling: 'pip3 install --user --ignore-installed cozmo'."
                )
                logger.error(
                    "Please also check the app store for a Cozmo app update.")

            exc = exceptions.SDKVersionMismatch(
                "SDK library does not match software running on device")
            self.abort(exc)
            return

        self._is_ui_connected = True
        self.dispatch_event(EvtConnected, conn=self)

        logger.info(
            'App connection established. sdk_version=%s '
            'cozmoclad_version=%s app_build_version=%s', version.__version__,
            cozmoclad.__version__, msg.buildVersion)

        # We send RequestObjectStates before refreshing the animation names
        # as this ensures that we will receive the responses before we mark the
        # robot as ready
        msg = _clad_to_engine_iface.RequestObjectStates()
        self.send_msg(msg)

        self.anim_names.refresh()
Exemplo n.º 3
0
    def _handle_ui_device_connected(self, msg):
        if msg.connectionType != _clad_to_engine_cozmo.UiConnectionType.SdkOverTcp:
            # This isn't for us
            return

        if msg.deviceID != 1:
            logger.error('Unexpected Device Id %s' % msg.deviceID)
            return

        # Verify that engine and SDK are compatible
        clad_hashes_match = False
        try:
            cozmoclad.assert_clad_match(msg.toGameCLADHash,
                                        msg.toEngineCLADHash)
            clad_hashes_match = True
        except cozmoclad.CLADHashMismatch as exc:
            logger.error(exc)

        build_versions_match = (
            cozmoclad.__build_version__ == '00000.00000.00000'
            or cozmoclad.__build_version__ == msg.buildVersion)

        if clad_hashes_match and build_versions_match:
            connection_success_msg = _clad_to_engine_iface.UiDeviceConnectionSuccess(
                connectionType=msg.connectionType,
                deviceID=msg.deviceID,
                buildVersion=cozmoclad.__version__,
                sdkModuleVersion=version.__version__,
                pythonVersion=platform.python_version(),
                pythonImplementation=platform.python_implementation(),
                osVersion=platform.platform(),
                cpuVersion=platform.machine())

            self.send_msg(connection_success_msg)

        else:
            try:
                wrong_version_msg = _clad_to_engine_iface.UiDeviceConnectionWrongVersion(
                    reserved=0,
                    connectionType=msg.connectionType,
                    deviceID=msg.deviceID,
                    buildVersion=cozmoclad.__version__)

                self.send_msg(wrong_version_msg)
            except AttributeError:
                pass

            if not build_versions_match:
                logger.warning(
                    'Build versions do not match (SDK version %s != App version %s) - connection refused'
                    % (cozmoclad.__build_version__, msg.buildVersion))

                if cozmoclad.__build_version__ < msg.buildVersion:
                    # App is newer
                    logger.error(
                        'Please update your SDK to the newest version by calling command: '
                        '"pip3 install --user --ignore-installed cozmo"')
                else:
                    # SDK is newer
                    logger.error(
                        "Please update your app to the most recent version on the app store."
                    )
                    logger.error(
                        "Or, if you prefer, please determine which SDK version matches your app version at:"
                    )
                    logger.error("http://go.anki.com/cozmo-sdk-version")
                    logger.error(
                        "Then downgrade your SDK by calling the following command, replacing"
                    )
                    logger.error(
                        "SDK_VERSION with the version listed at that page:")
                    logger.error(
                        "'pip3 install --ignore-installed cozmo==SDK_VERSION'")

            else:
                # CLAD version mismatch
                logger.error(
                    'Your Python and C++ CLAD versions do not match - connection refused.'
                )
                logger.error(
                    'Please check that you have the most recent versions of both the SDK and the Cozmo app.'
                )
                logger.error(
                    "You may update your SDK by calling: 'pip3 install --user --ignore-installed cozmo'."
                )
                logger.error(
                    "Please also check the app store for a Cozmo app update.")

            exc = exceptions.SDKVersionMismatch(
                "SDK library does not match software running on device")
            self.abort(exc)
            return

        self._is_ui_connected = True
        self.dispatch_event(EvtConnected, conn=self)
        self.anim_names.refresh()
        logger.info("UI device connected")