Example #1
0
def restart_app_on_watch(pebble, appUUID):
    current_app_uuid = pebble.send_and_read(
        AppRunState(data=AppRunStateRequest()), AppRunState).data.uuid
    # Re-start the watchapp
    pebble.send_packet(
        AppRunState(command=0x01,
                    data=AppRunStateStop(uuid=uuid.UUID(appUUID))))
    print("Restart Pebble App!")
    time.sleep(1)
    pebble.send_packet(
        AppRunState(command=0x01,
                    data=AppRunStateStart(uuid=uuid.UUID(appUUID))))
    time.sleep(1)
    #print(current_app_uuid)
    if current_app_uuid != uuid.UUID(appUUID):
        # Re-start the watchapp
        pebble.send_packet(
            AppRunState(command=0x01,
                        data=AppRunStateStop(uuid=uuid.UUID(appUUID))))
        print("Pebble App Closed!")
        time.sleep(5)
        pebble.send_packet(
            AppRunState(command=0x01,
                        data=AppRunStateStart(uuid=uuid.UUID(appUUID))))
        time.sleep(2)
    return
Example #2
0
def is_app_on(pebble,appUUID):
	try:
		current_app_uuid = pebble.send_and_read(AppRunState(data=AppRunStateRequest()), AppRunState).data.uuid
		#print(current_app_uuid)
		if current_app_uuid != uuid.UUID(appUUID):
			# Re-start the watchapp
			pebble.send_packet(AppRunState(command = 0x01, data=AppRunStateStop(uuid = uuid.UUID(appUUID))))
			print("Pebble App Closed!")
			time.sleep(5)
			pebble.send_packet(AppRunState(command = 0x01, data=AppRunStateStart(uuid = uuid.UUID(appUUID))))
			time.sleep(2)
		return
	except :
		print "Pebble Disconnected"
		return
def main(settings):
    """ Main function for the communicatior, loops here """

    if settings.transport == "websocket":
        pebble = PebbleConnection(WebsocketTransport(settings.device), log_packet_level=logging.DEBUG)
    else: # No elif, for compatibility with older configs
        pebble = PebbleConnection(SerialTransport(settings.device), log_packet_level=logging.DEBUG)
    pebble.connect()

    # For some reason it seems to timeout for the first time, with "somebody is eating our input" error,
    # replying seems to help.
    for loop in range(5):
        try:
            pebble.run_async()
            break
        except libpebble2.exceptions.TimeoutError:
            logging.info("Pebble timeouted, retrying..")
            continue

    # Register service for app messages
    appservice = AppMessageService(pebble)
    handler = CommandHandler(settings)

    commwatch = CommunicationKeeper(settings, appservice)
    appservice.register_handler("nack", commwatch.nack_received)
    appservice.register_handler("ack", commwatch.ack_received)

    # Start the watchapp
    pebble.send_packet(AppRunState(command = 0x01, data=AppRunStateStart(uuid = uuid.UUID(settings.uuid))))

    # Send our current config
    for (id_key, id_type) in get_button_ids():
        id_full = id_key[0] + "," + id_type[0]
        if id_full in settings.key_mappings:
            status = "T"
        else:
            status = "F"

        data = id_key[0] + id_type[0] + status
        commwatch.send_message({COMMUNICATION_KEY_CONFIG: CString(data)})

        # Wait for all
        for loop in range(10):
            if len(commwatch.pending) == 0:
                break
            if commwatch.error:
                raise PebbleConnectionException("Commwatch:" + commwatch.error)
            time.sleep(0.1)
        else:
            raise PebbleConnectionException("Pebble not respoding to config")

    logging.info("Connection ok, entering to active state..")
    appservice.register_handler("appmessage", handler.message_received_event)

    while True:
        commwatch.send_message({COMMUNICATION_KEY_PING: Uint8(0)})
        time.sleep(10)
Example #4
0
    def _ensure_correct_app(self, try_install=True):
        project = PebbleProject()
        if project.project_type != 'native':
            raise ToolError("Only native apps can be debugged using gdb.")

        current_app_uuid = self.pebble.send_and_read(
            AppRunState(data=AppRunStateRequest()), AppRunState).data.uuid
        if current_app_uuid != project.uuid:
            print("Launching {}...".format(project.long_name))
            # Try launching the app we want. This just does nothing if the app doesn't exist.
            # Edge case: the app exists in blobdb but isn't installed. This shouldn't come up with the pebble tool.
            queue = self.pebble.get_endpoint_queue(AppRunState)
            try:
                self.pebble.send_packet(
                    AppRunState(data=AppRunStateStart(uuid=project.uuid)))
                while True:
                    packet = queue.get(timeout=0.5)
                    if isinstance(packet.data, AppRunStateStart
                                  ) and packet.data.uuid == project.uuid:
                        break
            except TimeoutError:
                if try_install:
                    print("App did not launch. Trying to install it...")
                    try:
                        ToolAppInstaller(self.pebble).install()
                    except IOError:
                        raise ToolError(
                            "The app to debug must be built and installed on the watch."
                        )
                    self._ensure_correct_app(try_install=False)
                else:
                    raise ToolError(
                        "The app to debug must be running on the watch to start gdb."
                    )
            finally:
                queue.close()
Example #5
0
    def _install_modern(self):
        metadata = self._bundle.get_app_metadata()
        app_uuid = metadata['uuid']
        blob_packet = AppMetadata(
            uuid=app_uuid,
            flags=metadata['flags'],
            icon=metadata['icon_resource_id'],
            app_version_major=metadata['app_version_major'],
            app_version_minor=metadata['app_version_minor'],
            sdk_version_major=metadata['sdk_version_major'],
            sdk_version_minor=metadata['sdk_version_minor'],
            app_face_bg_color=0,
            app_face_template_id=0,
            app_name=metadata['app_name'])

        result = SyncWrapper(self._blobdb.insert, BlobDatabaseID.App, app_uuid,
                             blob_packet.serialise()).wait()
        if result != BlobStatus.Success:
            raise AppInstallError("BlobDB error: {!s}".format(result))

        # Start the app.
        app_fetch = self._pebble.send_and_read(
            AppRunState(data=AppRunStateStart(uuid=app_uuid)), AppFetchRequest)
        if app_fetch.uuid != app_uuid:
            self._pebble.send_packet(
                AppFetchResponse(response=AppFetchStatus.InvalidUUID))
            raise AppInstallError(
                "App requested the wrong UUID! Asked for {}; expected {}".
                format(app_fetch.uuid, app_uuid))
        self._broadcast_event('progress', 0, self.total_sent, self.total_size)

        # Send the app over
        binary = self._bundle.zip.read(self._bundle.get_app_path())
        self._send_part(PutBytesType.Binary, binary, app_fetch.app_id)

        if self._bundle.has_resources:
            resources = self._bundle.zip.read(self._bundle.get_resource_path())
            self._send_part(PutBytesType.Resources, resources,
                            app_fetch.app_id)

        if self._bundle.has_worker:
            worker = self._bundle.zip.read(self._bundle.get_worker_path())
            self._send_part(PutBytesType.Worker, worker, app_fetch.app_id)
Example #6
0
def main(settings):
    """ Main function for the communicator, loops here """

    if settings.transport == "websocket":
        pebble = PebbleConnection(WebsocketTransport(settings.device),
                                  log_packet_level=logging.DEBUG)
    else:  # No elif, for compatibility with older configs
        pebble = PebbleConnection(SerialTransport(settings.device),
                                  log_packet_level=logging.DEBUG)
    pebble.connect()

    if (pebble.connected):
        print("Pebble successfully connected.")

    try:
        pebble.run_async()
    except libpebble2.exceptions.TimeoutError:
        print("Pebble timeouted")
        logging.info("Pebble timeouted")

    # Install app
    AppInstaller(pebble, "../hotpebble.pbw").install()

    # Register service for app messages
    appservice = AppMessageService(pebble)
    handler = CommandHandler(settings)

    commwatch = CommunicationKeeper(settings, appservice)
    appservice.register_handler("nack", commwatch.nack_received)
    appservice.register_handler("ack", commwatch.ack_received)

    # Start the watchapp
    pebble.send_packet(
        AppRunState(command=0x01,
                    data=AppRunStateStart(uuid=uuid.UUID(settings.uuid))))

    logging.info("Connection ok, entering to active state...")
    appservice.register_handler("appmessage", handler.message_received_event)

    while True:
        commwatch.send_message({COMMUNICATION_KEY_PING: Uint8(0)})
        time.sleep(10)