1 package jp.sfjp.gokigen.a01c.thetacamerawrapper.operation
3 import android.util.Log
5 import jp.sfjp.gokigen.a01c.thetacamerawrapper.IThetaSessionIdProvider
6 import jp.sfjp.gokigen.a01c.utils.SimpleHttpClient
8 class ThetaOptionUpdateControl(private val sessionIdProvider: IThetaSessionIdProvider)
10 private val httpClient = SimpleHttpClient()
16 fun setOptions(options: String, useOSCv2: Boolean, callBack: IOperationCallback? = null)
18 Log.v(TAG, "setOptions() useOSCv2 : $useOSCv2 MSG : $options")
24 val setOptionsUrl = "http://192.168.1.1/osc/commands/execute"
25 val postData = if (useOSCv2) "{\"name\":\"camera.setOptions\",\"parameters\":{\"timeout\":0, \"options\": {\"$options\"}}}" else "{\"name\":\"camera.setOptions\",\"parameters\":{\"sessionId\": \"" + sessionIdProvider.sessionId + "\", \"options\": { $options }}}"
26 Log.v(TAG, " OPTIONS : $postData")
27 val result: String? = httpClient.httpPostWithHeader(setOptionsUrl, postData, null, "application/json;charset=utf-8", timeoutMs)
28 if ((result != null) && (result.isNotEmpty()))
30 Log.v(TAG, " setOptions() : $result")
31 callBack?.operationExecuted(0, result)
35 Log.v(TAG, "setOptions() reply is null or empty.")
36 callBack?.operationExecuted(-1, "")
42 callBack?.operationExecuted(-1, e.localizedMessage)
50 callBack?.operationExecuted(-1, e.localizedMessage)
56 private val TAG = ThetaOptionUpdateControl::class.java.simpleName
57 private const val timeoutMs = 1500