import java.net.SocketException
import java.util.*
-class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private val notifier: IPixproCommunicationNotify) : IPixproCommandPublisher, IPixproCommunication
+class PixproCommandCommunicator(private val pixproCamera: IPixproCamera, private val notifier: IPixproCommunicationNotify, private val statusChecker: IPixproCommandCallback) : IPixproCommandPublisher, IPixproCommunication
{
private var isStart = false
private var isConnected = false
{
private val TAG = PixproCommandCommunicator::class.java.simpleName
private const val BUFFER_SIZE = 1024 * 1024 + 16 // 受信バッファは 1MB
- private const val COMMAND_SEND_RECEIVE_DURATION_MS = 5
+ private const val COMMAND_SEND_RECEIVE_DURATION_MS = 30
private const val COMMAND_SEND_RECEIVE_DURATION_MAX = 3000
- private const val COMMAND_POLL_QUEUE_MS = 5
+ private const val COMMAND_POLL_QUEUE_MS = 15
}
override fun connect(): Boolean
}
try
{
- Log.v(TAG, " connect()")
+ val tcpNoDelay = pixproCamera.getTcpNoDelay()
+ Log.v(TAG, " connect() $tcpNoDelay")
socket = Socket()
- if (pixproCamera.getTcpNoDelay())
+ socket?.reuseAddress = true
+ socket?.keepAlive = true
+ socket?.tcpNoDelay = tcpNoDelay
+ if (tcpNoDelay)
{
socket?.keepAlive = false
socket?.setPerformancePreferences(0, 2, 0)
socket?.reuseAddress = false
socket?.trafficClass = 0x80
}
- socket?.tcpNoDelay = pixproCamera.getTcpNoDelay()
socket?.connect(InetSocketAddress(pixproCamera.getIpAddress(), pixproCamera.getPortNumber()), 0)
isConnected = true
return (true)
if (command != null)
{
issueCommand(command)
+
+ Thread.sleep(COMMAND_POLL_QUEUE_MS.toLong())
+ Log.v(TAG, " --- RECEIVE FOR REPLY --- ")
+ receiveFromCamera(command)
}
Thread.sleep(COMMAND_POLL_QUEUE_MS.toLong())
+
if (inputStream != null && inputStream.available() > 0)
{
- Log.v(TAG, " --- RECEIVE MSG --- ")
+ Log.v(TAG, " --- RECEIVE FOR (PRIMARY) MSG --- ")
receiveFromCamera(PixproCommandReceiveOnly(SEQ_RECEIVE_ONLY, PixproCommandOnlyCallback()))
}
}
e.printStackTrace()
}
}
- try {
+ try
+ {
thread.start()
- } catch (e: Exception) {
+ }
+ catch (e: Exception)
+ {
e.printStackTrace()
}
}
{
try
{
+/*
var retryOver = true
while (retryOver)
{
+*/
//Log.v(TAG, "issueCommand : " + command.getId());
val commandBody: ByteArray = command.commandBody()
// コマンドボディが入っていた場合には、コマンド送信(入っていない場合は受信待ち)
// コマンドボディの2つめが入っていた場合には、コマンドを連続送信する
sendToCamera(command.dumpLog(), commandBody2)
}
+/*
retryOver = receiveFromCamera(command)
if (retryOver)
{
retryOver = command.sendRetry()
}
}
+*/
}
catch (e: Exception)
{
try
{
var messageToSend: ByteArray? = null
- if (received_body[8] == 0xd2.toByte() && received_body[9] == 0xd7.toByte())
+ if (received_body[8] == 0xd2.toByte() && received_body[9] == 0x07.toByte())
{
messageToSend = byteArrayOf(
0x2e.toByte(),
0xff.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte()
)
}
+ if (received_body[8] == 0xd2.toByte() && received_body[9] == 0xd7.toByte())
+ {
+ messageToSend = byteArrayOf(
+ 0x2e.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0xd2.toByte(),
+ 0xd7.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x01.toByte(),
+ 0x10.toByte(),
+ 0x00.toByte(),
+ 0x80.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x01.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0x00.toByte(),
+ 0xff.toByte(),
+ 0xff.toByte(),
+ 0xff.toByte(),
+ 0xff.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte()
+ )
+ }
if (received_body[8] == 0xb9.toByte() && received_body[9] == 0x0b.toByte()) {
messageToSend = byteArrayOf(
0x2e.toByte(),
return false
}
if (receive_body[8] == 0xd2.toByte() && receive_body[9] == 0x07.toByte() ||
+ receive_body[8] == 0xd2.toByte() && receive_body[9] == 0xd7.toByte() ||
receive_body[8] == 0xb9.toByte() && receive_body[9] == 0x0b.toByte() ||
receive_body[8] == 0xba.toByte() && receive_body[9] == 0x0b.toByte() ||
receive_body[8] == 0xbb.toByte() && receive_body[9] == 0x0b.toByte()
)
{
isReceivedStatusMessage = true
- Log.v(TAG, " >>> RECEIVED HOST PRIMARY MESSAGE. <<<")
+ Log.v(TAG, " >>> RECEIVED HOST PRIMARY MESSAGE. (${receive_body.size} bytes.)<<<")
+ statusChecker.receivedMessage(0, receive_body)
}
}
catch (e: Exception)
import androidx.collection.SparseArrayCompat
import android.util.SparseIntArray
+import jp.osdn.gokigen.gokigenassets.camera.interfaces.ICameraStatus
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.IPixproCommandPublisher
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.base.PixproCommandOnlyCallback
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.PixproFlashAuto
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.PixproFlashOff
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.PixproFlashOn
+import jp.osdn.gokigen.gokigenassets.camera.vendor.pixpro.wrapper.command.messages.specific.PixproWhiteBalance
import java.lang.Exception
import java.util.*
-import kotlin.collections.ArrayList
-
class PixproStatusHolder
{
-
companion object
{
private val TAG = PixproStatusHolder::class.java.simpleName
private val statusHolder: SparseIntArray = SparseIntArray()
private val statusNameArray: SparseArrayCompat<String> = SparseArrayCompat()
- private fun prepareStatusNameArray() {
-/*
- statusNameArray.clear();
- statusNameArray.append(BATTERY_LEVEL, BATTERY_LEVEL_STR);
- statusNameArray.append(WHITE_BALANCE, WHITE_BALANCE_STR);
- statusNameArray.append(APERTURE, APERTURE_STR);
- statusNameArray.append(FOCUS_MODE, FOCUS_MODE_STR);
- statusNameArray.append(SHOOTING_MODE, SHOOTING_MODE_STR);
- statusNameArray.append(FLASH, FLASH_STR);
- statusNameArray.append(EXPOSURE_COMPENSATION, EXPOSURE_COMPENSATION_STR);
- statusNameArray.append(SELF_TIMER, SELF_TIMER_STR);
- statusNameArray.append(FILM_SIMULATION, FILM_SIMULATION_STR);
- statusNameArray.append(IMAGE_FORMAT, IMAGE_FORMAT_STR);
- statusNameArray.append(RECMODE_ENABLE, RECMODE_ENABLE_STR);
- statusNameArray.append(F_SS_CONTROL, F_SS_CONTROL_STR);
- statusNameArray.append(ISO, ISO_STR);
- statusNameArray.append(MOVIE_ISO, MOVIE_ISO_STR);
- statusNameArray.append(FOCUS_POINT, FOCUS_POINT_STR);
- statusNameArray.append(DEVICE_ERROR, DEVICE_ERROR_STR);
- statusNameArray.append(IMAGE_FILE_COUNT, IMAGE_FILE_COUNT_STR);
- statusNameArray.append(SDCARD_REMAIN_SIZE, SDCARD_REMAIN_SIZE_STR);
- statusNameArray.append(FOCUS_LOCK, FOCUS_LOCK_STR);
- statusNameArray.append(MOVIE_REMAINING_TIME, MOVIE_REMAINING_TIME_STR);
- statusNameArray.append(SHUTTER_SPEED, SHUTTER_SPEED_STR);
- statusNameArray.append(IMAGE_ASPECT,IMAGE_ASPECT_STR);
- statusNameArray.append(BATTERY_LEVEL_2, BATTERY_LEVEL_2_STR);
-
- statusNameArray.append(UNKNOWN_DF00, UNKNOWN_DF00_STR);
- statusNameArray.append(PICTURE_JPEG_COUNT, PICTURE_JPEG_COUNT_STR);
- statusNameArray.append(UNKNOWN_D400, UNKNOWN_D400_STR);
- statusNameArray.append(UNKNOWN_D401, UNKNOWN_D401_STR);
- statusNameArray.append(UNKNOWN_D52F, UNKNOWN_D52F_STR);
-*/
+ private var statusConvert = PixproStatusConvert(this)
+ private lateinit var commandPublisher : IPixproCommandPublisher
+
+ fun setCommandPublisher(commandPublisher : IPixproCommandPublisher)
+ {
+ this.commandPublisher = commandPublisher
}
fun updateValue(
}
}
- /**
- * 認識したカメラのステータス名称のリストを応答する
- *
- */
- private val availableStatusNameList: List<String?>
- private get() {
- val selection: ArrayList<String?> = ArrayList()
- try {
- for (index in 0 until statusHolder.size()) {
- val key = statusHolder.keyAt(index)
- selection.add(
- statusNameArray[key, java.lang.String.format(
- Locale.US,
- "0x%04x",
- key
- )]
- )
- }
- } catch (e: Exception) {
- e.printStackTrace()
- }
- return selection
+ fun getAvailableItemList(key: String?): List<String?>
+ {
+ try
+ {
+ return (when (key) {
+ ICameraStatus.TAKE_MODE -> statusConvert.getAvailableTakeMode()
+ ICameraStatus.SHUTTER_SPEED -> statusConvert.getAvailableShutterSpeed()
+ ICameraStatus.APERTURE -> statusConvert.getAvailableAperture()
+ ICameraStatus.EXPREV -> statusConvert.getAvailableExpRev()
+ ICameraStatus.CAPTURE_MODE -> statusConvert.getAvailableCaptureMode()
+ ICameraStatus.ISO_SENSITIVITY -> statusConvert.getAvailableIsoSensitivity()
+ ICameraStatus.WHITE_BALANCE -> statusConvert.getAvailableWhiteBalance()
+ ICameraStatus.AE -> statusConvert.getAvailableMeteringMode()
+ ICameraStatus.EFFECT -> statusConvert.getAvailablePictureEffect()
+ ICameraStatus.TORCH_MODE -> statusConvert.getAvailableTorchMode()
+ //ICameraStatus.BATTERY -> statusConvert.getAvailableRemainBattery()
+ //ICameraStatus.FOCUS_STATUS -> statusConvert.getAvailableFocusStatus()
+ else -> ArrayList()
+ })
+ //Log.v(TAG, " ----- getAvailableItemList($key) ")
+ //sendCamGetSettingCmd("colormode")
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
}
+ return (ArrayList())
+ }
+
+ fun getItemStatusColor(key: String): Int
+ {
+ return (when (key) {
+ ICameraStatus.BATTERY -> getRemainBatteryColor()
+ else -> Color.WHITE
+ })
+ }
+
+ fun getItemStatus(orgKey: String): String
+ {
+ return (when (orgKey) {
+ ICameraStatus.TAKE_MODE -> getTakeMode()
+ ICameraStatus.SHUTTER_SPEED -> getShutterSpeed()
+ //ICameraStatus.APERTURE -> getAperture()
+ ICameraStatus.EXPREV -> getExpRev()
+ //ICameraStatus.CAPTURE_MODE -> getCaptureMode()
+ ICameraStatus.ISO_SENSITIVITY -> getIsoSensitivity()
+ ICameraStatus.WHITE_BALANCE -> getWhiteBalance()
+ //ICameraStatus.AE -> getMeteringMode()
+ //ICameraStatus.EFFECT -> getPictureEffect()
+ ICameraStatus.BATTERY -> getRemainBattery()
+ ICameraStatus.TORCH_MODE -> getTorchMode()
+ //ICameraStatus.FOCUS_STATUS -> getfocusStatus()
+ else -> ""
+ })
+ }
+
+ private fun getRemainBatteryColor() : Int
+ {
+ return (Color.WHITE)
+ }
- fun getAvailableItemList(listKey: String?): List<String?> {
- if (listKey == null) {
- // アイテム名の一覧を応答する
- return availableStatusNameList
+ private fun getTakeMode() : String
+ {
+ var status = ""
+ try
+ {
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
}
+ return (status)
+ }
- ///// 選択可能なステータスの一覧を取得する : でも以下はアイテム名の一覧... /////
- val selection: ArrayList<String?> = ArrayList()
- try {
- for (index in 0 until statusHolder.size()) {
- val key = statusHolder.keyAt(index)
- selection.add(statusNameArray[key])
+ private fun getShutterSpeed() : String
+ {
+ var status = ""
+ try
+ {
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ return (status)
+ }
+
+ private fun getExpRev() : String
+ {
+ var status = ""
+ try
+ {
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ return (status)
+ }
+
+ private fun getIsoSensitivity() : String
+ {
+ var status = ""
+ try
+ {
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ return (status)
+ }
+
+ private fun getRemainBattery() : String
+ {
+ var status = ""
+ try
+ {
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ return (status)
+ }
+
+ private fun getWhiteBalance() : String
+ {
+ var status = ""
+ try
+ {
+ status = "WB: "
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ return (status)
+ }
+
+ private fun getTorchMode() : String
+ {
+ var status = ""
+ try
+ {
+ status = "Flash: "
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ return (status)
+ }
+
+ fun setItemStatus(key: String, value: String)
+ {
+ Log.v(TAG, " setItemStatus(key:$key, value:$value)")
+ try
+ {
+ when (key) {
+ ICameraStatus.TAKE_MODE -> setTakeMode(value)
+ ICameraStatus.SHUTTER_SPEED -> setShutterSpeed(value)
+ //ICameraStatus.APERTURE -> setAperture(value)
+ ICameraStatus.EXPREV -> setExpRev(value)
+ //ICameraStatus.CAPTURE_MODE -> setCaptureMode(value)
+ ICameraStatus.ISO_SENSITIVITY -> setIsoSensitivity(value)
+ ICameraStatus.WHITE_BALANCE -> setWhiteBalance(value)
+ //ICameraStatus.AE -> setMeteringMode(value)
+ //ICameraStatus.EFFECT -> setPictureEffect(value)
+ ICameraStatus.TORCH_MODE -> setTorchMode(value)
+ //ICameraStatus.BATTERY -> setRemainBattery(value)
+ //ICameraStatus.FOCUS_STATUS -> setfocusStatus(value)
+ else -> return
}
- } catch (e: Exception) {
+ }
+ catch (e: Exception)
+ {
e.printStackTrace()
}
- return selection
}
- fun getItemStatusColor(key: String): Int
+ private fun setTakeMode(value: String)
{
- return (Color.WHITE)
+ try
+ {
+ Log.v(TAG, " setTakeMode($value)")
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
}
- fun getItemStatus(orgKey: String): String {
- var key = orgKey
- try {
- val strIndex = key.indexOf("x")
- Log.v(TAG, "getItemStatus() : $key [$strIndex]")
- if (strIndex >= 1) {
- key = key.substring(strIndex + 1)
- try {
- val id = key.toInt(16)
- val value = statusHolder[id]
- Log.v(TAG, "getItemStatus() value : $value")
- return value.toString() + ""
- } catch (e: Exception) {
- e.printStackTrace()
- }
+ private fun setShutterSpeed(value: String)
+ {
+ try
+ {
+ Log.v(TAG, " setShutterSpeed($value)")
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ }
+
+ private fun setExpRev(value: String)
+ {
+ try
+ {
+ Log.v(TAG, " setExpRev($value)")
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ }
+
+ private fun setIsoSensitivity(value: String)
+ {
+ try
+ {
+ Log.v(TAG, " setIsoSensitivity($value)")
+
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ }
+
+ private fun setWhiteBalance(value: String)
+ {
+ try
+ {
+ if (!::commandPublisher.isInitialized)
+ {
+ // 未初期化の場合はコマンドを送らない
+ return
}
- for (index in 0 until statusNameArray.size()) {
- val id = statusNameArray.keyAt(index)
- val strKey = statusNameArray.valueAt(index)
- if (key.contentEquals(strKey)) {
- val value = statusHolder[id]
- return value.toString() + ""
- }
+ Log.v(TAG, " setWhiteBalance($value)")
+ when (value)
+ {
+ "AUTO" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x04))
+ "Daylight" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x01))
+ "Cloudy" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x02))
+ "Fluorescent" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x10))
+ "Fluorescent CWF" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x20)) //
+ "Incandescent" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x40)) // 白熱灯
+ "Underwater" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x80)) // 不明...
+ "Other" -> commandPublisher.enqueueCommand(PixproWhiteBalance(PixproCommandOnlyCallback(), 0x08)) // 不明...
+ else -> { }
}
- } catch (e: Exception) {
+ }
+ catch (e: Exception)
+ {
+ e.printStackTrace()
+ }
+ }
+
+ private fun setTorchMode(value: String)
+ {
+ try
+ {
+ if (!::commandPublisher.isInitialized)
+ {
+ // 未初期化の場合はコマンドを送らない
+ return
+ }
+ Log.v(TAG, " setTorchMode($value)")
+ when (value)
+ {
+ "OFF" -> commandPublisher.enqueueCommand(PixproFlashOff(PixproCommandOnlyCallback()))
+ "ON" -> commandPublisher.enqueueCommand(PixproFlashOn(PixproCommandOnlyCallback()))
+ "AUTO" -> commandPublisher.enqueueCommand(PixproFlashAuto(PixproCommandOnlyCallback()))
+ else -> { }
+ }
+ }
+ catch (e: Exception)
+ {
e.printStackTrace()
}
- return "? [$key]"
}
- init {
+ init
+ {
statusHolder.clear()
- prepareStatusNameArray()
}
}