From: MRSa Date: Thu, 23 Sep 2021 12:54:24 +0000 (+0900) Subject: OMDS機の設定表示と変更の一部実装。(要変更だけど) X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=cf3ff43c9169640363375fae82deca7912423cb0;p=gokigen%2Fmangle.git OMDS機の設定表示と変更の一部実装。(要変更だけど) --- diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index f38ec99..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/console/ConsolePanelControl.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/console/ConsolePanelControl.kt index 8a0a2c3..ab59644 100644 --- a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/console/ConsolePanelControl.kt +++ b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/console/ConsolePanelControl.kt @@ -21,8 +21,10 @@ import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.B import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.CAPTURE_MODE import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.EFFECT import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.EXPREV +import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.FOCAL_LENGTH import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.FOCUS_STATUS import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.ISO_SENSITIVITY +import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.REMAIN_SHOTS import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.SHUTTER_SPEED import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.TAKE_MODE import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus.Companion.TORCH_MODE @@ -330,6 +332,8 @@ class ConsolePanelControl (private val context: AppCompatActivity, private val v drawPictureEffect(canvas, currentCameraStatus) drawFocusStatus(canvas, currentCameraStatus) drawTorchMode(canvas, currentCameraStatus) + drawFocalLength(canvas, currentCameraStatus) + drawRemainShotNumber(canvas, currentCameraStatus) drawBatteryLevel(canvas, currentCameraStatus) } drawFramingGrid(canvas) @@ -543,6 +547,22 @@ class ConsolePanelControl (private val context: AppCompatActivity, private val v } } + private fun drawFocalLength(canvas: Canvas, currentCameraStatus : ICameraStatus) + { + try + { + // area : bottom-left UP + val rect = RectF(canvasWidth * 0.0f, canvasHeight * 7.0f, canvasWidth * 1.0f, canvasHeight * 8.0f) + val msg = currentCameraStatus.getStatus(FOCAL_LENGTH) + val color = currentCameraStatus.getStatusColor(FOCAL_LENGTH) + drawString(canvas, rect, msg, color) + } + catch (e : Exception) + { + e.printStackTrace() + } + } + private fun drawTorchMode(canvas: Canvas, currentCameraStatus : ICameraStatus) { try @@ -550,7 +570,8 @@ class ConsolePanelControl (private val context: AppCompatActivity, private val v // area : bottom-right UP val rect = RectF(canvasWidth * 2.0f, canvasHeight * 6.0f, canvas.width.toFloat(), canvasHeight * 7.0f) val msg = currentCameraStatus.getStatus(TORCH_MODE) - drawString(canvas, rect, msg, Color.WHITE) + val color = currentCameraStatus.getStatusColor(TORCH_MODE) + drawString(canvas, rect, msg, color) } catch (e : Exception) { @@ -558,6 +579,21 @@ class ConsolePanelControl (private val context: AppCompatActivity, private val v } } + private fun drawRemainShotNumber(canvas: Canvas, currentCameraStatus : ICameraStatus) + { + try + { + // area : bottom-right UP + val rect = RectF(canvasWidth * 2.0f, canvasHeight * 7.0f, canvas.width.toFloat(), canvasHeight * 8.0f) + val msg = currentCameraStatus.getStatus(REMAIN_SHOTS) + val color = currentCameraStatus.getStatusColor(FOCUS_STATUS) + drawString(canvas, rect, msg, color) + } + catch (e : Exception) + { + e.printStackTrace() + } + } private fun drawBatteryLevel(canvas: Canvas, currentCameraStatus : ICameraStatus) { diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/interfaces/ICameraStatus.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/interfaces/ICameraStatus.kt index 6ff94c4..45349cb 100644 --- a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/interfaces/ICameraStatus.kt +++ b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/interfaces/ICameraStatus.kt @@ -13,21 +13,23 @@ interface ICameraStatus companion object { - var TAKE_MODE = "exposureMode" // プログラムモード(P/A/S/M) - var SHUTTER_SPEED = "tv" // シャッタースピード - var APERTURE = "av" // 絞り値 - var EXPREV = "xv" // 露出補正値 - var CAPTURE_MODE = "captureMode" // キャプチャーモード - var ISO_SENSITIVITY = "sv" // ISO感度 - var WHITE_BALANCE = "WBMode" // ホワイトバランス - var AE = "meteringMode" // 測光モード - var EFFECT = "effect" // ピクチャーエフェクトモード (フォトスタイルモード) - var BATTERY = "battery" // バッテリ残量 - var TORCH_MODE = "torch" // 明かり(トーチ)の設定 - var FOCUS_STATUS = "focusStatus" // フォーカス状態(合焦かどうか) - - var IMAGE_SIZE = "stillSize" // 撮影画像サイズ - var MOVIE_SIZE = "movieSize" // 動画画像サイズ + const val TAKE_MODE = "exposureMode" // プログラムモード(P/A/S/M) + const val SHUTTER_SPEED = "tv" // シャッタースピード + const val APERTURE = "av" // 絞り値 + const val EXPREV = "xv" // 露出補正値 + const val CAPTURE_MODE = "captureMode" // キャプチャーモード + const val ISO_SENSITIVITY = "sv" // ISO感度 + const val WHITE_BALANCE = "WBMode" // ホワイトバランス + const val AE = "meteringMode" // 測光モード + const val EFFECT = "effect" // ピクチャーエフェクトモード (フォトスタイルモード) + const val BATTERY = "battery" // バッテリ残量 + const val TORCH_MODE = "torch" // 明かり(トーチ)の設定 + const val FOCUS_STATUS = "focusStatus" // フォーカス状態(合焦かどうか) + const val FOCAL_LENGTH = "focalLength" // 焦点距離 (ズーム状態) + const val REMAIN_SHOTS = "remainShots" // 残り撮影枚数 + + const val IMAGE_SIZE = "stillSize" // 撮影画像サイズ + const val MOVIE_SIZE = "movieSize" // 動画画像サイズ //var STATE = "state" //var FOCUS_MODE = "focusMode" diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/OmdsCameraControl.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/OmdsCameraControl.kt index d0fe99e..0a2424a 100644 --- a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/OmdsCameraControl.kt +++ b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/OmdsCameraControl.kt @@ -90,7 +90,7 @@ class OmdsCameraControl(private val context: AppCompatActivity, private val vibr liveViewControl.stopLiveView() statusChecker.stopStatusWatch() cameraConnection.disconnect(true) - cameraConnection.stopWatchWifiStatus(context) + } catch (e: Exception) { @@ -258,6 +258,7 @@ class OmdsCameraControl(private val context: AppCompatActivity, private val vibr zoomLensControl.detectedOpcProtocol(opcProtocol) focusControl.detectedOpcProtocol(opcProtocol) captureControl.detectedOpcProtocol(opcProtocol) + statusChecker.detectedOpcProtocol(opcProtocol) } companion object diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/connection/OmdsCameraConnectSequence.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/connection/OmdsCameraConnectSequence.kt index 4914dcf..2977f1f 100644 --- a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/connection/OmdsCameraConnectSequence.kt +++ b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/connection/OmdsCameraConnectSequence.kt @@ -26,7 +26,6 @@ class OmdsCameraConnectSequence(private val context: AppCompatActivity, private val getConnectModeUrl = "$executeUrl/get_connectmode.cgi" val switchCameraModeUrl = "$executeUrl/switch_cammode.cgi" val switchOpcCameraModeUrl = "$executeUrl/switch_cameramode.cgi" - //val getCameraStatusUrl = "$executeUrl/get_activate.cgi" val response: String = http.httpGetWithHeader(getConnectModeUrl, headerMap, null, TIMEOUT_MS) ?: "" Log.v(TAG, " $getConnectModeUrl $response") @@ -55,9 +54,27 @@ class OmdsCameraConnectSequence(private val context: AppCompatActivity, private } } - //// カメラのステータス取得 - //String response5 = SimpleHttpClient.httpGetWithHeader(getCameraStatusUrl, headerMap, null, TIMEOUT_MS); - //Log.v(TAG, " " + getCameraStatusUrl + " " + response5); + //////////////// for TEST //////////////// + if (checkStatusDump) + { + //val testUrl = "$executeUrl/get_proplist.cgi" // プロパティ一覧 (OPC) + val testUrl = "$executeUrl/get_camprop.cgi?com=desc&propname=desclist" // コマンド一覧 + val testResponse: String = http.httpGetWithHeader(testUrl, headerMap, null, TIMEOUT_MS) ?: "" + Log.v(TAG, " ------------------------------------------ ") + for (pos in 0..testResponse.length step 768) + { + val lastIndex = if ((pos + 768) > testResponse.length) { testResponse.length } else { pos + 768 } + Log.v(TAG, " $testUrl ($pos/${testResponse.length}) ${testResponse.substring(pos, lastIndex)}") + } + Log.v(TAG, " ------------------------------------------ ") + + //// カメラのステータス取得 + val getCameraStatusUrl = "$executeUrl/get_activate.cgi" + val response5 : String = http.httpGetWithHeader(getCameraStatusUrl, headerMap, null, TIMEOUT_MS) ?: "" + Log.v(TAG, " $getCameraStatusUrl $response5") + } + //////////////// for TEST //////////////// + onConnectNotify() } else @@ -100,5 +117,6 @@ class OmdsCameraConnectSequence(private val context: AppCompatActivity, private { private val TAG = OmdsCameraConnectSequence::class.java.simpleName private const val TIMEOUT_MS = 5000 + private const val checkStatusDump = false } } diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/status/OmdsCameraStatusWatcher.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/status/OmdsCameraStatusWatcher.kt index dfdaa43..be54ce5 100644 --- a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/status/OmdsCameraStatusWatcher.kt +++ b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/status/OmdsCameraStatusWatcher.kt @@ -5,33 +5,58 @@ import android.util.Log import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusUpdateNotify import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatusWatcher +import jp.osdn.gokigen.gokigenassets.camera.vendor.omds.IOmdsProtocolNotify import jp.osdn.gokigen.gokigenassets.liveview.message.IMessageDrawer +import jp.osdn.gokigen.gokigenassets.utils.communication.SimpleHttpClient +import jp.osdn.gokigen.gokigenassets.utils.communication.SimpleLogDumper import java.lang.Exception +import java.util.* import kotlin.collections.ArrayList -class OmdsCameraStatusWatcher : ICameraStatusWatcher, ICameraStatus, IOmdsCommunicationInfo +class OmdsCameraStatusWatcher(userAgent: String = "OlympusCameraKit", private val executeUrl : String = "http://192.168.0.10") : ICameraStatusWatcher, ICameraStatus, IOmdsCommunicationInfo, IOmdsProtocolNotify { + private val headerMap: MutableMap = HashMap() + private val http = SimpleHttpClient() + private var useOpcProtocol = false + private var buffer: ByteArray? = null private var isWatching = false + private var isWatchingEvent = false private var statusReceived = false private var notifier: ICameraStatusUpdateNotify? = null private var focusingStatus = 0 private var omdsCommandList : String = "" + private var latestEventResponse : String = "" + + private var currentTakeMode = "" + private var currentShutterSpeed = "" + private var currentAperture = "" + private var currentExpRev = "" + private var currentCaptureMode = "" + private var currentIsoSensitivity = "" + private var currentWhiteBalance = "" + private var currentMeteringMode = "" + private var currentPictureEffect = "" + private var currentTorchMode = "" + private var currentRemainBattery = "" + private var currentFocusStatus = "" + private var currentFocalLength = "" + private var currentRemainShots = "" override fun setOmdsCommandList(commandList: String) { - //Log.v(TAG, " setOmdsCommandList() : $commandList") omdsCommandList = commandList val commandListParser = OmdsCommandListParser() commandListParser.startParse(omdsCommandList) + + startStatusWatch(null, null) } fun setRtpHeader(byteBuffer: ByteArray?) { try { - //buffer = byteBuffer?.copyOf() if (byteBuffer != null) { buffer = byteBuffer @@ -53,9 +78,23 @@ class OmdsCameraStatusWatcher : ICameraStatusWatcher, ICameraStatus, IOmdsCommun { try { + startRtpStatusWatch(notifier) + startEventStatusWatch() + + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + private fun startRtpStatusWatch(notifier: ICameraStatusUpdateNotify?) + { + try + { + Log.v(TAG, " startStatusWatch()") this.notifier = notifier val thread = Thread { - val waitMs = SLEEP_TIME_MS isWatching = true while (isWatching) { @@ -65,7 +104,36 @@ class OmdsCameraStatusWatcher : ICameraStatusWatcher, ICameraStatus, IOmdsCommun parseRtpHeader() statusReceived = false } - sleep(waitMs) + sleep(SLEEP_TIME_MS) + } + } + thread.start() + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + private fun startEventStatusWatch() + { + try + { + Log.v(TAG, " startEventStatusWatch()") + val thread = Thread { + isWatchingEvent = true + while (isWatchingEvent) + { + // ----- EVENT POLLING + if (useOpcProtocol) + { + watchOpcStatus() + } + else + { + watchOmdsStatus() + } + sleep(SLEEP_EVENT_TIME_MS) } } thread.start() @@ -76,6 +144,154 @@ class OmdsCameraStatusWatcher : ICameraStatusWatcher, ICameraStatus, IOmdsCommun } } + private fun watchOmdsStatus() + { + try + { + // OMDS機のイベント受信 + val omdsEventUrl = "$executeUrl/get_camprop.cgi?com=desc&propname=desclist" + latestEventResponse = http.httpGetWithHeader(omdsEventUrl, headerMap, null, TIMEOUT_MS) ?: "" + dumpLog(omdsEventUrl, latestEventResponse) + parseOmdsProperties(latestEventResponse) + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + private fun watchOpcStatus() + { + try + { + // OPC機のイベント受信 + val opcEventUrl = "$executeUrl/get_camprop.cgi?com=getlist" + val postData = "takemode") + currentShutterSpeed = getPropertyValue(eventResponse, "shutspeedvalue") + currentAperture = "F" + getPropertyValue(eventResponse, "focalvalue") + + currentIsoSensitivity = "ISO " + getPropertyValue(eventResponse, "isospeedvalue") + currentExpRev = getPropertyValue(eventResponse, "expcomp") + + currentWhiteBalance = decideWhiteBalance(getPropertyValue(eventResponse, "wbvalue")) + currentPictureEffect = getPropertyValue(eventResponse, "colortone") + currentCaptureMode = " DRIVE: " + getPropertyValue(eventResponse, "drivemode") + + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + private fun decideWhiteBalance(wbValue: String) : String + { + + return ("WB: ($wbValue)") + } + + + private fun getPropertySelectionList(responseString: String, propertyString: String) : List + { + try + { + if (responseString.isNotEmpty()) + { + val propertyIndex = responseString.indexOf(propertyString) + if (propertyIndex > 0) + { + val propertyValueIndex = + responseString.indexOf("", propertyIndex) + "".length + val propertyValueLastIndex = responseString.indexOf("", propertyIndex) + val propertyListString = + responseString.substring(propertyValueIndex, propertyValueLastIndex) + if (propertyListString.isNotEmpty()) + { + val propertyList = propertyListString.split(" ") + val selectionList: ArrayList = ArrayList() + selectionList.addAll(propertyList) + return (selectionList) + } + } + } + Log.v(TAG, "getPropertySelectionList($propertyString) $responseString ..." ) + } + catch (e: Exception) + { + e.printStackTrace() + } + return (ArrayList()) + } + + + private fun getPropertyValue(responseString: String, propertyString: String) : String + { + try + { + val propertyIndex = responseString.indexOf(propertyString) + if (propertyIndex > 0) + { + val propertyValueIndex = responseString.indexOf("", propertyIndex) + "".length + val propertyValueLastIndex = responseString.indexOf("", propertyIndex) + return (responseString.substring(propertyValueIndex, propertyValueLastIndex)) + } + } + catch (e: Exception) + { + e.printStackTrace() + } + return ("") + } + + private fun parseOpcProperties(eventResponse: String) + { + try + { + + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + private fun dumpLog(header: String, data: String) + { + if (isDumpLog) + { + val dataStep = 1536 + Log.v(TAG, " ------------------------------------------ ") + for (pos in 0..data.length step dataStep) { + val lastIndex = if ((pos + dataStep) > data.length) + { + data.length + } + else + { + pos + dataStep + } + Log.v(TAG, " $header ($pos/${data.length}) ${data.substring(pos, lastIndex)}") + } + Log.v(TAG, " ------------------------------------------ ") + } + } + + private fun sleep(waitMs: Int) { try @@ -99,17 +315,55 @@ class OmdsCameraStatusWatcher : ICameraStatusWatcher, ICameraStatus, IOmdsCommun } var position = 16 val maxLength = buffer?.size ?: 0 + if (maxLength <= 0) + { + // データがないので何もしない + return + } + + if (isDumpLog) + { + // 受信データのバッファをダンプする + Log.v(TAG," parseRtpHeader size: $maxLength") + SimpleLogDumper.dumpBytes("EVT[$maxLength]", buffer) + } + while (position + 4 < maxLength) { - val id: Int = ((buffer?.get(position) ?: 0).toInt() and 0xff) * 256 + ((buffer?.get(position + 1) ?: 0).toInt() and 0xff) + val commandId: Int = ((buffer?.get(position) ?: 0).toInt() and 0xff) * 256 + ((buffer?.get(position + 1) ?: 0).toInt() and 0xff) val length: Int = ((buffer?.get(position + 2) ?: 0).toInt() and 0xff) * 256 + ((buffer?.get(position + 3) ?: 0).toInt() and 0xff) - when (id) + when (commandId) { ID_AF_FRAME_INFO -> { checkFocused(buffer, position, length) } - ID_ZOOM_LENS_INFO, ID_FRAME_SIZE -> { } + ID_FRAME_SIZE -> { } + ID_MEDIA_INFO -> { } + ID_ROTATION_INFO -> { } + ID_AVAILABLE_SHOTS -> { } + ID_OMDS_UNKNOWN_01 -> { } + ID_OMDS_UNKNOWN_02 -> { } + ID_SHUTTER_SPEED -> { } + ID_APERTURE -> { } + ID_EXPOSURE_COMPENSATION -> { } + ID_OMDS_UNKNOWN_03 -> { } + ID_ISO_SENSITIVITY -> { } + ID_OMDS_UNKNOWN_04 -> { } + ID_OMDS_UNKNOWN_05 -> { } + ID_OMDS_UNKNOWN_06 -> { } + ID_OPTICAL_WARNING -> { } + ID_FOCUS_TYPE -> { } + ID_ZOOM_LENS_INFO -> { } + ID_REMAIN_VIDEO_TIME -> { } + ID_POSITION_LEVEL_INFO -> { } + ID_FACE_DETECT_1 -> { } + ID_FACE_DETECT_2 -> { } + ID_FACE_DETECT_3 -> { } + ID_FACE_DETECT_4 -> { } + ID_FACE_DETECT_5 -> { } + ID_FACE_DETECT_6 -> { } + ID_FACE_DETECT_7 -> { } else -> { } } - position += 4 + length * 4 // header : 4bytes , data : length * 4 bytes + position += 4 + length * 4 // header : 4bytes , data : length * 4 bytes } } catch (e: Exception) @@ -142,15 +396,70 @@ class OmdsCameraStatusWatcher : ICameraStatusWatcher, ICameraStatus, IOmdsCommun override fun stopStatusWatch() { isWatching = false + isWatchingEvent = false + } override fun getStatusList(key: String): List { +/**/ + try + { + Log.v(TAG, " getStatusList($key)") + return (when (key) { + ICameraStatus.TAKE_MODE -> getPropertySelectionList(latestEventResponse, "takemode") + ICameraStatus.SHUTTER_SPEED -> getPropertySelectionList(latestEventResponse, "shutspeedvalue") + ICameraStatus.APERTURE -> getPropertySelectionList(latestEventResponse, "focalvalue") + ICameraStatus.EXPREV -> getPropertySelectionList(latestEventResponse, "expcomp") + ICameraStatus.ISO_SENSITIVITY -> getPropertySelectionList(latestEventResponse, "isospeedvalue") +/* + ICameraStatus.CAPTURE_MODE -> getAvailableCaptureMode() + ICameraStatus.WHITE_BALANCE -> getAvailableWhiteBalance() + ICameraStatus.AE -> getAvailableMeteringMode() + ICameraStatus.EFFECT -> getAvailablePictureEffect() + ICameraStatus.TORCH_MODE -> getAvailableTorchMode() + ICameraStatus.BATTERY -> getAvailableRemainBattery() + ICameraStatus.FOCUS_STATUS -> getAvailableFocusStatus() + ICameraStatus.FOCAL_LENGTH -> getAvailableFocalLength() + ICameraStatus.REMAIN_SHOTS -> getAvailableRemainShots() +*/ + else -> java.util.ArrayList() + }) + } + catch (e: Exception) + { + e.printStackTrace() + } +/**/ return (ArrayList()) } override fun getStatus(key: String): String { + try + { + return (when (key) { + ICameraStatus.TAKE_MODE -> currentTakeMode + ICameraStatus.SHUTTER_SPEED -> currentShutterSpeed + ICameraStatus.APERTURE -> currentAperture + ICameraStatus.EXPREV -> currentExpRev + ICameraStatus.CAPTURE_MODE -> currentCaptureMode + ICameraStatus.ISO_SENSITIVITY -> currentIsoSensitivity + ICameraStatus.WHITE_BALANCE -> currentWhiteBalance + ICameraStatus.AE -> currentMeteringMode + ICameraStatus.EFFECT -> currentPictureEffect + ICameraStatus.TORCH_MODE -> currentTorchMode + ICameraStatus.BATTERY -> currentRemainBattery + ICameraStatus.FOCUS_STATUS -> currentFocusStatus + ICameraStatus.FOCAL_LENGTH -> currentFocalLength + ICameraStatus.REMAIN_SHOTS -> currentRemainShots + else -> "" + }) + } + catch (e: Exception) + { + e.printStackTrace() + } return ("") } @@ -161,7 +470,99 @@ class OmdsCameraStatusWatcher : ICameraStatusWatcher, ICameraStatus, IOmdsCommun override fun setStatus(key: String, value: String) { + try + { + if (useOpcProtocol) + { + setStatusOpc(key, value) + } + else + { + setStatusOmds(key, value) + } + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + private fun setStatusOmds(key: String, value: String) + { + try + { + when (key) + { + ICameraStatus.TAKE_MODE -> sendStatusRequestOmds("takemode", value) + ICameraStatus.SHUTTER_SPEED -> sendStatusRequestOmds("shutspeedvalue", value) + ICameraStatus.APERTURE -> sendStatusRequestOmds("focalvalue", value) + ICameraStatus.EXPREV -> sendStatusRequestOmds("expcomp", value) + ICameraStatus.ISO_SENSITIVITY -> sendStatusRequestOmds("isospeedvalue", value) + ICameraStatus.CAPTURE_MODE -> { } + ICameraStatus.WHITE_BALANCE -> { } + ICameraStatus.AE -> { } + ICameraStatus.EFFECT -> { } + ICameraStatus.TORCH_MODE -> { } + ICameraStatus.BATTERY -> { } + ICameraStatus.FOCUS_STATUS -> { } + ICameraStatus.FOCAL_LENGTH -> { } + ICameraStatus.REMAIN_SHOTS -> { } + else -> { } + } + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + private fun sendStatusRequestOmds(property: String, value: String) + { + val requestUrl = "$executeUrl/set_camprop.cgi?com=set&propname=$property" + val postData = "$value" + val response: String = http.httpPostWithHeader(requestUrl, postData, headerMap, null, TIMEOUT_MS) ?: "" + dumpLog(requestUrl, response) + } + + private fun setStatusOpc(key: String, value: String) + { + try + { + when (key) + { + ICameraStatus.TAKE_MODE -> { } + ICameraStatus.SHUTTER_SPEED -> { } + ICameraStatus.APERTURE -> { } + ICameraStatus.EXPREV -> { } + ICameraStatus.CAPTURE_MODE -> { } + ICameraStatus.ISO_SENSITIVITY -> { } + ICameraStatus.WHITE_BALANCE -> { } + ICameraStatus.AE -> { } + ICameraStatus.EFFECT -> { } + ICameraStatus.TORCH_MODE -> { } + ICameraStatus.BATTERY -> { } + ICameraStatus.FOCUS_STATUS -> { } + ICameraStatus.FOCAL_LENGTH -> { } + ICameraStatus.REMAIN_SHOTS -> { } + else -> { } + } + } + catch (e: Exception) + { + e.printStackTrace() + } + } + + override fun detectedOpcProtocol(opcProtocol: Boolean) + { + Log.v(TAG, " --- detectedOpcProtocol($opcProtocol)") + useOpcProtocol = opcProtocol + } + init + { + headerMap["User-Agent"] = userAgent // "OlympusCameraKit" // "OI.Share" + headerMap["X-Protocol"] = userAgent // "OlympusCameraKit" // "OI.Share" } companion object @@ -169,9 +570,39 @@ class OmdsCameraStatusWatcher : ICameraStatusWatcher, ICameraStatus, IOmdsCommun private val TAG = OmdsCameraStatusWatcher::class.java.simpleName private const val SLEEP_TIME_MS = 250 - private const val ID_FRAME_SIZE = 1 - private const val ID_AF_FRAME_INFO = 2 - private const val ID_ZOOM_LENS_INFO = 18 + private const val SLEEP_EVENT_TIME_MS = 350 + private const val TIMEOUT_MS = 4000 + + // RTP HEADER IDs + private const val ID_FRAME_SIZE = 0x01 + private const val ID_AF_FRAME_INFO = 0x02 + private const val ID_MEDIA_INFO = 0x03 + private const val ID_ROTATION_INFO = 0x04 + private const val ID_AVAILABLE_SHOTS = 0x05 + private const val ID_OMDS_UNKNOWN_01 = 0x06 + private const val ID_OMDS_UNKNOWN_02 = 0x07 + private const val ID_SHUTTER_SPEED = 0x08 + private const val ID_APERTURE = 0x09 + private const val ID_EXPOSURE_COMPENSATION = 0x0a + private const val ID_OMDS_UNKNOWN_03 = 0x0b + private const val ID_ISO_SENSITIVITY = 0x0c + private const val ID_OMDS_UNKNOWN_04 = 0x0d + private const val ID_OMDS_UNKNOWN_05 = 0x0e + private const val ID_OMDS_UNKNOWN_06 = 0x0f + private const val ID_OPTICAL_WARNING = 0x10 + private const val ID_FOCUS_TYPE = 0x11 + private const val ID_ZOOM_LENS_INFO = 0x12 + private const val ID_REMAIN_VIDEO_TIME = 0x6a + private const val ID_POSITION_LEVEL_INFO = 0x6b + private const val ID_FACE_DETECT_1 = 0x6c + private const val ID_FACE_DETECT_2 = 0x6d + private const val ID_FACE_DETECT_3 = 0x6e + private const val ID_FACE_DETECT_4 = 0x6f + private const val ID_FACE_DETECT_5 = 0x70 + private const val ID_FACE_DETECT_6 = 0x71 + private const val ID_FACE_DETECT_7 = 0x72 + + private const val isDumpLog = false } } diff --git a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/status/OmdsCommandListParser.kt b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/status/OmdsCommandListParser.kt index 1378984..df8f99c 100644 --- a/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/status/OmdsCommandListParser.kt +++ b/app/src/main/java/jp/osdn/gokigen/gokigenassets/camera/vendor/omds/status/OmdsCommandListParser.kt @@ -1,9 +1,6 @@ package jp.osdn.gokigen.gokigenassets.camera.vendor.omds.status import android.util.Log -import android.util.Xml -import org.xmlpull.v1.XmlPullParser -import java.io.StringReader class OmdsCommandListParser { @@ -11,7 +8,9 @@ class OmdsCommandListParser { try { - var parsedData = "" +/* + + var parsedData = targetData val parser: XmlPullParser = Xml.newPullParser() parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false) parser.setInput(StringReader(targetData)) @@ -33,8 +32,26 @@ class OmdsCommandListParser } eventType = parser.next() } - Log.v(TAG, " <<< COMMAND LIST >>>") - Log.v(TAG, parsedData) +*/ + if (isDumpLog) + { + val parsedData = targetData + Log.v(TAG, " ------------------------------------------ ") + Log.v(TAG, " <<< COMMAND LIST >>>") + for (pos in 0..parsedData.length step 768) + { + val lastIndex = if ((pos + 768) > parsedData.length) + { + parsedData.length + } + else + { + pos + 768 + } + Log.v(TAG, " ${parsedData.substring(pos, lastIndex)}") + } + Log.v(TAG, " ------------------------------------------ ") + } } catch (e: Exception) { @@ -46,6 +63,7 @@ class OmdsCommandListParser companion object { private val TAG = OmdsCommandListParser::class.java.simpleName + private const val isDumpLog = false } } \ No newline at end of file