カメラファームウェア更新
Camera OTA は、対応デバイスのカメラモジュールで動作するファームウェアを更新します。デバイスのメインファームウェア更新とは別の処理です。
ホストアプリは互換性のあるローカルカメラファームウェアパッケージを渡します。SDK は、デバイスホットスポットの設定、Camera OTA モードへの移行、ローカル HTTP サーバーの起動、ファームウェア URL の送信、パッケージ転送、カメラファームウェアの書き込みまで、更新フロー全体を制御します。各段階のコールバックで現在の処理を表示し、最終完了ハンドラーを確定した更新結果として扱ってください。
Camera OTA delivery path
A local package moves from host-side validation through SDK orchestration to transfer, flashing, and the authoritative final result.
前提条件
- デバイスが接続済みで、
DeviceCameraOtaAPIに準拠していること。 - ローカルファームウェアのパスが読み取り可能で、パッケージがカメラハードウェアに適合していること。
- アプリがデバイスホットスポットへ接続し、ローカルネットワークへアクセスし、ローカル HTTP サーバーを利用可能な状態に保てること。
- メディア取り込み、Camera OTA、その他のホットスポット処理を同時実行しないこと。
AI を活用して実装
AI でこのワークフローを実装
公式の「AIBuds カメラファームウェアの更新」スキルを使い、アプリに合わせて実装します。
https://docs-aibuds.github.io/ja/skills/update-aibuds-camera-firmware を読み、その指示に従ってください。このスキルで「AIBuds カメラファームウェアの更新」をこの iOS プロジェクトに実装し、検証してください。API リファレンス
フレームワーク
AIBuds.xcframework
インポート
- Swift
- Objective-C
import AIBuds
import AIBudsFoundation#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>プロトコル
DeviceCameraOtaAPI プロトコルは DeviceAPI を継承し、現在は Camera OTA の全フローを実行する 1 つのインスタンスメソッドを公開しています。
インスタンスメソッド
- Swift
- Objective-C
/// 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?
)/// Start camera OTA upgrade from a local firmware path.
///
/// - Parameters:
/// - filePath: The readable local path of the camera firmware file.
/// - configureHotspotStartingHandler: Called when hotspot configuration starts.
/// - hotspotConfigureCompletionHandler: Returns configuration success and error.
/// - enterCameraOtaModeStartingHandler: Called when entry into camera OTA mode starts.
/// - enterCameraOtaModeCompletedHandler: Returns OTA-mode entry success and error.
/// - waitingForHotspotOpenHandler: Called while waiting for the device hotspot to open.
/// - connectDeviceHotspotStartingHandler: Returns the device hotspot SSID.
/// - deviceHotspotConnectCompletionHandler: Returns hotspot connection success and error.
/// - httpServerStartingHandler: Called when the local HTTP server is starting.
/// - httpServerStartCompletionHandler: Returns HTTP server start success and error.
/// - sendingFirmwareUrlHandler: Returns the local firmware URL before it is sent.
/// - firmwareUrlSendCompletionHandler: Returns URL delivery success and error.
/// - startCompletionHandler: Returns Camera OTA start success and error.
/// - fileTransferStartedHandler: Called when firmware transfer starts.
/// - fileTransferCompletedHandler: Called when firmware transfer completes.
/// - waitingForFlashingHandler: Called while the device prepares to flash.
/// - flashingStartedHandler: Called when firmware flashing starts.
/// - flashingCompletedHandler: Called when firmware flashing completes.
/// - phaseProgressHandler: Returns `Transferring` or `Flashing` and progress from `0` to `100`.
/// - completionHandler: Returns final upgrade success and error.
- (void)startCameraOtaWithFilePath:(NSString *_Nonnull)filePath
configureHotspotStartingHandler:(AIBudsCameraOtaConfigureHotspotStartingHandler _Nullable)
configureHotspotStartingHandler
hotspotConfigureCompletionHandler:
(AIBudsCameraOtaHotspotConfigureCompletionHandler _Nullable)
hotspotConfigureCompletionHandler
enterCameraOtaModeStartingHandler:
(AIBudsEnterCameraOtaModeStartingHandler _Nullable)enterCameraOtaModeStartingHandler
enterCameraOtaModeCompletedHandler:
(AIBudsEnterCameraOtaModeCompletionHandler _Nullable)enterCameraOtaModeCompletedHandler
waitingForHotspotOpenHandler:
(AIBudsCameraOtaStartingToWaitForHotspotOpenHandler _Nullable)
waitingForHotspotOpenHandler
connectDeviceHotspotStartingHandler:
(AIBudsCameraOtaConnectDeviceHotspotStartingHandler _Nullable)
connectDeviceHotspotStartingHandler
deviceHotspotConnectCompletionHandler:
(AIBudsCameraOtaDeviceHotspotConnectCompletionHandler _Nullable)
deviceHotspotConnectCompletionHandler
httpServerStartingHandler:
(AIBudsCameraOtaHttpServerStartingHandler _Nullable)httpServerStartingHandler
httpServerStartCompletionHandler:
(AIBudsCameraOtaHttpServerStartCompletionHandler _Nullable)
httpServerStartCompletionHandler
sendingFirmwareUrlHandler:
(AIBudsCameraOtaSendingFirmwareUrlHandler _Nullable)sendingFirmwareUrlHandler
firmwareUrlSendCompletionHandler:
(AIBudsCameraOtaFirmwareUrlSendCompletionHandler _Nullable)
firmwareUrlSendCompletionHandler
startCompletionHandler:
(AIBudsCameraOtaStartCompletionHandler _Nullable)startCompletionHandler
fileTransferStartedHandler:
(AIBudsCameraOtaFileTransferStartedHandler _Nullable)fileTransferStartedHandler
fileTransferCompletedHandler:
(AIBudsCameraOtaFileTransferCompletedHandler _Nullable)fileTransferCompletedHandler
waitingForFlashingHandler:
(AIBudsCameraOtaWaitingForFlashingHandler _Nullable)waitingForFlashingHandler
flashingStartedHandler:
(AIBudsCameraOtaFlashingStartedHandler _Nullable)flashingStartedHandler
flashingCompletedHandler:
(AIBudsCameraOtaFlashingCompletedHandler _Nullable)flashingCompletedHandler
phaseProgressHandler:
(AIBudsCameraOtaPhaseProgressHandler _Nullable)phaseProgressHandler
completionHandler:
(AIBudsCameraOtaCompletionHandler _Nullable)completionHandler;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 は通知されたフェーズに対する 0〜100 の整数です。
| Swift | Objective-C | raw value | 意味 |
|---|---|---|---|
.transferring | AIBudsCameraOtaProgressPhaseTransferring | 1 | ファームウェアファイルの転送進捗。 |
.flashing | AIBudsCameraOtaProgressPhaseFlashing | 2 | カメラファームウェアの書き込み進捗。 |
使用例
例では SDK Demo が公開するすべてのコールバックを保持しています。本番コードではメインキューで UI を更新してください。
- Swift
- Objective-C
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")")
}
}
)id<AIBudsDeviceCameraOtaAPI> cameraOtaDevice = (id<AIBudsDeviceCameraOtaAPI>)self.device;
if (![cameraOtaDevice conformsToProtocol:@protocol(AIBudsDeviceCameraOtaAPI)]) {
NSLog(@"Camera OTA is not supported");
return;
}
[cameraOtaDevice startCameraOtaWithFilePath:filePath
configureHotspotStartingHandler:^{
NSLog(@"Configuring device hotspot");
}
hotspotConfigureCompletionHandler:^(BOOL success, NSError *_Nullable error) {
NSLog(@"%@", success ? @"Hotspot configured" : error.localizedDescription);
}
enterCameraOtaModeStartingHandler:^{
NSLog(@"Entering Camera OTA mode");
}
enterCameraOtaModeCompletedHandler:^(BOOL success, NSError *_Nullable error) {
NSLog(@"%@", success ? @"Camera OTA mode ready" : error.localizedDescription);
}
waitingForHotspotOpenHandler:^{
NSLog(@"Waiting for device hotspot");
}
connectDeviceHotspotStartingHandler:^(NSString *_Nonnull ssid) {
NSLog(@"Connecting to %@", ssid);
}
deviceHotspotConnectCompletionHandler:^(BOOL success, NSError *_Nullable error) {
NSLog(@"%@", success ? @"Device hotspot connected" : error.localizedDescription);
}
httpServerStartingHandler:^{
NSLog(@"Starting local HTTP server");
}
httpServerStartCompletionHandler:^(BOOL success, NSError *_Nullable error) {
NSLog(@"%@", success ? @"HTTP server ready" : error.localizedDescription);
}
sendingFirmwareUrlHandler:^(NSString *_Nonnull firmwareUrl) {
NSLog(@"Sending firmware URL: %@", firmwareUrl);
}
firmwareUrlSendCompletionHandler:^(BOOL success, NSError *_Nullable error) {
NSLog(@"%@", success ? @"Firmware URL sent" : error.localizedDescription);
}
startCompletionHandler:^(BOOL success, NSError *_Nullable error) {
NSLog(@"%@", success ? @"Camera OTA started" : error.localizedDescription);
}
fileTransferStartedHandler:^{
NSLog(@"Firmware transfer started");
}
fileTransferCompletedHandler:^{
NSLog(@"Firmware transfer completed");
}
waitingForFlashingHandler:^{
NSLog(@"Waiting for flashing");
}
flashingStartedHandler:^{
NSLog(@"Firmware flashing started");
}
flashingCompletedHandler:^{
NSLog(@"Firmware flashing completed");
}
phaseProgressHandler:^(AIBudsCameraOtaProgressPhase phase, NSInteger progress) {
if (phase == AIBudsCameraOtaProgressPhaseTransferring) {
NSLog(@"Transfer: %ld%%", (long)progress);
} else if (phase == AIBudsCameraOtaProgressPhaseFlashing) {
NSLog(@"Flashing: %ld%%", (long)progress);
}
}
completionHandler:^(BOOL success, NSError *_Nullable error) {
NSLog(@"%@", success ? @"Camera OTA completed successfully" : error.localizedDescription);
}];エラー処理
Camera OTA エラーには AIBudsSDK.CameraOtaErrorDomain と SdkCameraOtaErrorCode を使用します。公開列挙型は、ローカルファイル検証、ネットワーク/ホットスポット、タスクライフサイクル、OTA モード移行、ファームウェア URL 送信の失敗を扱います。
| コード | 主な状況 |
|---|---|
unknown, networkRequestFailed, networkTimeout | SDK がエラーをこれ以上分類できないか、ネットワーク処理に失敗しました。 |
cameraOtaFileNotFound, invalidCameraOtaFile, cameraOtaTaskCreateFailedDueToFileNotFound | 選択したローカルファームウェアのパスがないか、パッケージが無効です。 |
hotspotDisconnectedDuringTransfer, invalidHotspotConfig | デバイスホットスポットを安定して使用できません。 |
stageTwoTimeout, interruptedByShutdownOrLowBattery | 書き込みが完了直前で停止したか、デバイスが更新を中断しました。 |
cameraOtaTaskAlreadyRunning | 別の Camera OTA タスクが実行中です。 |
4003...4009 | デバイス接続、タイムアウト、ホットスポット設定、OTA モード移行、HTTP 配信、URL 送信のいずれかで失敗しました。 |
5001...5010 | コマンド、ストレージ、権限、チャンネル、状態の条件により、デバイスが OTA モード移行または URL 送信を拒否しました。 |
一般的な更新エラーではなく、失敗したワークフロー段階を表示します。書き込み開始後は、自動再試行、切断、電源オフ、別のホットスポット処理の開始を行わないでください。SDK は現在、確定した再試行境界を定義していません。別パッケージを提示する前に、デバイスの復旧状態とカメラファームウェアバージョンを確認します。
ベストプラクティス
- API 呼び出し前にローカルファイルの存在を確認します。パッケージの真正性とカメラモデル互換性はホスト製品側の責任です。
- メディアファイル取り込み、Camera OTA、その他のホットスポット処理を同時実行しないでください。
- 最終完了までアプリをアクティブに保ち、ローカル HTTP サーバーへ到達できる状態を維持します。
- コールバックは別のキューで届く場合があるため、UI 更新をメインキューへ切り替えます。
startCompletionHandlerは OTA 処理の開始結果として扱い、最終的な更新成功とはみなさないでください。completionHandlerを最終結果として使用し、再接続後にカメラファームウェアの状態を確認します。
注意事項
- Camera OTA はローカルファームウェアパスを使用します。SDK はリモート更新サービスへの問い合わせやパッケージのダウンロードを行いません。
phaseProgressHandlerが通知するのは転送と書き込みの進捗だけです。その他の段階には専用コールバックを使用します。- 転送進捗が
100になっても Camera OTA の最終結果ではありません。その後に書き込みと最終完了が続きます。 - 安全な自動再試行の動作は、現在の公開 SDK 仕様では定義されていません。