メインコンテンツまでスキップ

カメラファームウェア更新

Camera OTA は、対応デバイスのカメラモジュールで動作するファームウェアを更新します。デバイスのメインファームウェア更新とは別の処理です。

ホストアプリは互換性のあるローカルカメラファームウェアパッケージを渡します。SDK は、デバイスホットスポットの設定、Camera OTA モードへの移行、ローカル HTTP サーバーの起動、ファームウェア URL の送信、パッケージ転送、カメラファームウェアの書き込みまで、更新フロー全体を制御します。各段階のコールバックで現在の処理を表示し、最終完了ハンドラーを確定した更新結果として扱ってください。

Animated workflow

Camera OTA delivery path

A local package moves from host-side validation through SDK orchestration to transfer, flashing, and the authoritative final result.

Host app

Validate Package

Verify integrity, camera-model compatibility, and a readable local path.

SDK + device

Configure Hotspot

Prepare the device network used by the Camera OTA workflow.

Device

Enter OTA Mode

Switch the camera module into its firmware update mode.

SDK

Connect Hotspot

Join the SSID exposed for the staged update session.

SDK

Start HTTP Server

Expose the selected local firmware package to the device.

SDK → device

Send Firmware URL

Deliver the local HTTP URL that the device will request.

Progress phase

Transfer Firmware

Serve the package while the device downloads the firmware bytes.

.transferring · 0...100
Progress phase

Flash Firmware

The camera module writes the transferred firmware. Do not interrupt.

.flashing · 0...100
Authoritative result

Final Completion

Use the final callback—not transfer progress—as the upgrade result.

Follow the final completion callback for the authoritative result.

前提条件

  • デバイスが接続済みで、DeviceCameraOtaAPI に準拠していること。
  • ローカルファームウェアのパスが読み取り可能で、パッケージがカメラハードウェアに適合していること。
  • アプリがデバイスホットスポットへ接続し、ローカルネットワークへアクセスし、ローカル HTTP サーバーを利用可能な状態に保てること。
  • メディア取り込み、Camera OTA、その他のホットスポット処理を同時実行しないこと。

AI を活用して実装

AI で実装

AI でこのワークフローを実装

公式の「AIBuds カメラファームウェアの更新」スキルを使い、アプリに合わせて実装します。

https://docs-aibuds.github.io/ja/skills/update-aibuds-camera-firmware を読み、その指示に従ってください。このスキルで「AIBuds カメラファームウェアの更新」をこの iOS プロジェクトに実装し、検証してください。
公式スキルを見る

API リファレンス

フレームワーク

AIBuds.xcframework

インポート

Swift
import AIBuds
import AIBudsFoundation

プロトコル

DeviceCameraOtaAPI プロトコルは DeviceAPI を継承し、現在は Camera OTA の全フローを実行する 1 つのインスタンスメソッドを公開しています。

インスタンスメソッド

Swift
/// Start camera OTA upgrade.
///
/// - Parameters:
///   - filePath: The readable local path of the camera firmware file.
///   - configureHotspotStartingHandler: Called when hotspot configuration starts.
///   - hotspotConfigureCompletionHandler: Called when hotspot configuration completes.
///     - success: `true` if configuration succeeded; otherwise `false`.
///     - error: The failure information, or `nil` if configuration succeeded.
///   - enterCameraOtaModeStartingHandler: Called when entry into camera OTA mode starts.
///   - enterCameraOtaModeCompletedHandler: Called when entry into camera OTA mode completes.
///     - success: `true` if the device entered OTA mode; otherwise `false`.
///     - error: The failure information, or `nil` if entry succeeded.
///   - waitingForHotspotOpenHandler: Called while waiting for the device hotspot to open.
///   - connectDeviceHotspotStartingHandler: Called when connecting to the device hotspot starts.
///     - ssid: The SSID of the device hotspot.
///   - deviceHotspotConnectCompletionHandler: Called when the hotspot connection completes.
///     - success: `true` if the connection succeeded; otherwise `false`.
///     - error: The failure information, or `nil` if the connection succeeded.
///   - httpServerStartingHandler: Called when the local HTTP server is starting.
///   - httpServerStartCompletionHandler: Called when the HTTP server start attempt completes.
///     - success: `true` if the server started; otherwise `false`.
///     - error: The failure information, or `nil` if the server started.
///   - sendingFirmwareUrlHandler: Called before sending the firmware URL to the device.
///     - firmwareUrl: The local HTTP URL that will be sent.
///   - firmwareUrlSendCompletionHandler: Called when firmware URL delivery completes.
///     - success: `true` if the URL was sent; otherwise `false`.
///     - error: The failure information, or `nil` if delivery succeeded.
///   - startCompletionHandler: Called when the Camera OTA start command completes.
///     - success: `true` if the update started; otherwise `false`.
///     - error: The failure information, or `nil` if the update started.
///   - fileTransferStartedHandler: Called when firmware transfer starts.
///   - fileTransferCompletedHandler: Called when firmware transfer completes.
///   - waitingForFlashingHandler: Called while the device is preparing to flash.
///   - flashingStartedHandler: Called when firmware flashing starts.
///   - flashingCompletedHandler: Called when firmware flashing completes.
///   - phaseProgressHandler: Reports progress for transfer and flashing.
///     - phase: `.transferring` or `.flashing`.
///     - progress: The phase progress in the range `0...100`.
///   - completionHandler: Called when the complete Camera OTA workflow finishes.
///     - success: `true` if the upgrade succeeded; otherwise `false`.
///     - error: The failure information, or `nil` if the upgrade succeeded.
func startCameraOta(
    withFilePath filePath: String,
    configureHotspotStartingHandler: AIBudsCameraOtaConfigureHotspotStartingHandler?,
    hotspotConfigureCompletionHandler: AIBudsCameraOtaHotspotConfigureCompletionHandler?,
    enterCameraOtaModeStartingHandler: AIBudsEnterCameraOtaModeStartingHandler?,
    enterCameraOtaModeCompletedHandler: AIBudsEnterCameraOtaModeCompletionHandler?,
    waitingForHotspotOpenHandler: AIBudsCameraOtaStartingToWaitForHotspotOpenHandler?,
    connectDeviceHotspotStartingHandler: AIBudsCameraOtaConnectDeviceHotspotStartingHandler?,
    deviceHotspotConnectCompletionHandler: AIBudsCameraOtaDeviceHotspotConnectCompletionHandler?,
    httpServerStartingHandler: AIBudsCameraOtaHttpServerStartingHandler?,
    httpServerStartCompletionHandler: AIBudsCameraOtaHttpServerStartCompletionHandler?,
    sendingFirmwareUrlHandler: AIBudsCameraOtaSendingFirmwareUrlHandler?,
    firmwareUrlSendCompletionHandler: AIBudsCameraOtaFirmwareUrlSendCompletionHandler?,
    startCompletionHandler: AIBudsCameraOtaStartCompletionHandler?,
    fileTransferStartedHandler: AIBudsCameraOtaFileTransferStartedHandler?,
    fileTransferCompletedHandler: AIBudsCameraOtaFileTransferCompletedHandler?,
    waitingForFlashingHandler: AIBudsCameraOtaWaitingForFlashingHandler?,
    flashingStartedHandler: AIBudsCameraOtaFlashingStartedHandler?,
    flashingCompletedHandler: AIBudsCameraOtaFlashingCompletedHandler?,
    phaseProgressHandler: AIBudsCameraOtaPhaseProgressHandler?,
    completionHandler: AIBudsCameraOtaCompletionHandler?
)

API リファレンスの startCameraOta を参照してください。

戻り値

このメソッドは値を直接返しません。開始、段階遷移、進捗、最終結果は指定したハンドラーへ通知されます。

ワークフローの段階

次は Camera OTA のコールバック段階であり、CameraOtaProgressPhase の値ではありません。

段階関連ハンドラー
ホットスポット設定configureHotspotStartingHandler, hotspotConfigureCompletionHandler
Camera OTA モードへ移行enterCameraOtaModeStartingHandler, enterCameraOtaModeCompletedHandler
デバイスホットスポットへ接続waitingForHotspotOpenHandler, connectDeviceHotspotStartingHandler, deviceHotspotConnectCompletionHandler
ローカル HTTP サーバーを起動httpServerStartingHandler, httpServerStartCompletionHandler
ファームウェア URL を送信sendingFirmwareUrlHandler, firmwareUrlSendCompletionHandler
更新を開始startCompletionHandler
ファームウェアを転送fileTransferStartedHandler, fileTransferCompletedHandler
書き込み準備と実行waitingForFlashingHandler, flashingStartedHandler, flashingCompletedHandler
完了completionHandler

進捗フェーズ

CameraOtaProgressPhase には公開値が 2 つだけあります。progress は通知されたフェーズに対する 0100 の整数です。

SwiftObjective-Craw value意味
.transferringAIBudsCameraOtaProgressPhaseTransferring1ファームウェアファイルの転送進捗。
.flashingAIBudsCameraOtaProgressPhaseFlashing2カメラファームウェアの書き込み進捗。

使用例

例では SDK Demo が公開するすべてのコールバックを保持しています。本番コードではメインキューで UI を更新してください。

Swift
guard let cameraOtaDevice = device as? DeviceCameraOtaAPI else {
    print("Camera OTA is not supported")
    return
}

cameraOtaDevice.startCameraOta(
    withFilePath: filePath,
    configureHotspotStartingHandler: {
        print("Configuring device hotspot")
    },
    hotspotConfigureCompletionHandler: { success, error in
        print(
            success
                ? "Hotspot configured"
                : "Hotspot configuration failed: \(error?.localizedDescription ?? "Unknown error")")
    },
    enterCameraOtaModeStartingHandler: {
        print("Entering Camera OTA mode")
    },
    enterCameraOtaModeCompletedHandler: { success, error in
        print(
            success
                ? "Camera OTA mode ready"
                : "Could not enter Camera OTA mode: \(error?.localizedDescription ?? "Unknown error")"
        )
    },
    waitingForHotspotOpenHandler: {
        print("Waiting for device hotspot")
    },
    connectDeviceHotspotStartingHandler: { ssid in
        print("Connecting to \(ssid)")
    },
    deviceHotspotConnectCompletionHandler: { success, error in
        print(
            success
                ? "Device hotspot connected"
                : "Hotspot connection failed: \(error?.localizedDescription ?? "Unknown error")")
    },
    httpServerStartingHandler: {
        print("Starting local HTTP server")
    },
    httpServerStartCompletionHandler: { success, error in
        print(
            success
                ? "HTTP server ready"
                : "HTTP server failed: \(error?.localizedDescription ?? "Unknown error")")
    },
    sendingFirmwareUrlHandler: { firmwareURL in
        print("Sending firmware URL: \(firmwareURL)")
    },
    firmwareUrlSendCompletionHandler: { success, error in
        print(
            success
                ? "Firmware URL sent"
                : "URL delivery failed: \(error?.localizedDescription ?? "Unknown error")")
    },
    startCompletionHandler: { success, error in
        print(
            success
                ? "Camera OTA started"
                : "Camera OTA could not start: \(error?.localizedDescription ?? "Unknown error")")
    },
    fileTransferStartedHandler: {
        print("Firmware transfer started")
    },
    fileTransferCompletedHandler: {
        print("Firmware transfer completed")
    },
    waitingForFlashingHandler: {
        print("Waiting for flashing")
    },
    flashingStartedHandler: {
        print("Firmware flashing started")
    },
    flashingCompletedHandler: {
        print("Firmware flashing completed")
    },
    phaseProgressHandler: { phase, progress in
        switch phase {
        case .transferring:
            print("Transfer: \(progress)%")
        case .flashing:
            print("Flashing: \(progress)%")
        }
    },
    completionHandler: { success, error in
        if success {
            print("Camera OTA completed successfully")
        } else {
            print("Camera OTA failed: \(error?.localizedDescription ?? "Unknown error")")
        }
    }
)

エラー処理

Camera OTA エラーには AIBudsSDK.CameraOtaErrorDomainSdkCameraOtaErrorCode を使用します。公開列挙型は、ローカルファイル検証、ネットワーク/ホットスポット、タスクライフサイクル、OTA モード移行、ファームウェア URL 送信の失敗を扱います。

コード主な状況
unknown, networkRequestFailed, networkTimeoutSDK がエラーをこれ以上分類できないか、ネットワーク処理に失敗しました。
cameraOtaFileNotFound, invalidCameraOtaFile, cameraOtaTaskCreateFailedDueToFileNotFound選択したローカルファームウェアのパスがないか、パッケージが無効です。
hotspotDisconnectedDuringTransfer, invalidHotspotConfigデバイスホットスポットを安定して使用できません。
stageTwoTimeout, interruptedByShutdownOrLowBattery書き込みが完了直前で停止したか、デバイスが更新を中断しました。
cameraOtaTaskAlreadyRunning別の Camera OTA タスクが実行中です。
4003...4009デバイス接続、タイムアウト、ホットスポット設定、OTA モード移行、HTTP 配信、URL 送信のいずれかで失敗しました。
5001...5010コマンド、ストレージ、権限、チャンネル、状態の条件により、デバイスが OTA モード移行または URL 送信を拒否しました。

一般的な更新エラーではなく、失敗したワークフロー段階を表示します。書き込み開始後は、自動再試行、切断、電源オフ、別のホットスポット処理の開始を行わないでください。SDK は現在、確定した再試行境界を定義していません。別パッケージを提示する前に、デバイスの復旧状態とカメラファームウェアバージョンを確認します。

ベストプラクティス

  1. API 呼び出し前にローカルファイルの存在を確認します。パッケージの真正性とカメラモデル互換性はホスト製品側の責任です。
  2. メディアファイル取り込み、Camera OTA、その他のホットスポット処理を同時実行しないでください。
  3. 最終完了までアプリをアクティブに保ち、ローカル HTTP サーバーへ到達できる状態を維持します。
  4. コールバックは別のキューで届く場合があるため、UI 更新をメインキューへ切り替えます。
  5. startCompletionHandler は OTA 処理の開始結果として扱い、最終的な更新成功とはみなさないでください。
  6. completionHandler を最終結果として使用し、再接続後にカメラファームウェアの状態を確認します。

注意事項

  • Camera OTA はローカルファームウェアパスを使用します。SDK はリモート更新サービスへの問い合わせやパッケージのダウンロードを行いません。
  • phaseProgressHandler が通知するのは転送と書き込みの進捗だけです。その他の段階には専用コールバックを使用します。
  • 転送進捗が 100 になっても Camera OTA の最終結果ではありません。その後に書き込みと最終完了が続きます。
  • 安全な自動再試行の動作は、現在の公開 SDK 仕様では定義されていません。