OSDN Git Service

これであきらめるか、、Nikon機用の接続性更新。
authorMRSa <mrsa@myad.jp>
Mon, 2 Nov 2020 12:11:09 +0000 (21:11 +0900)
committerMRSa <mrsa@myad.jp>
Mon, 2 Nov 2020 12:11:09 +0000 (21:11 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/operation/NikonCaptureControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/operation/NikonFocusingControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/command/messages/specific/NikonLiveViewRequestMessage.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.kt
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/messages/PtpIpCommandGenericWithRetry.kt [new file with mode: 0644]

index 7baf2ab..4ce51fd 100644 (file)
@@ -8,6 +8,7 @@ import net.osdn.gokigen.a01d.camera.ICaptureControl;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpCommandPublisher;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGenericWithRetry;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 
 import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.REQUEST_SHUTTER_ON;
@@ -36,9 +37,9 @@ public class NikonCaptureControl implements ICaptureControl, IPtpIpCommandCallba
             Log.v(TAG, " doCapture() ");
 
             // シャッターを切る
-            commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, REQUEST_SHUTTER_ON, isDumpLog, 0, 0x9207, 8, 0xffffffff, 0x00));
-            commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, isDumpLog, 0, 0x90c8));
-            commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_EVENT, isDumpLog, 0, 0x90c7));
+            commandPublisher.enqueueCommand(new PtpIpCommandGenericWithRetry(this, REQUEST_SHUTTER_ON, 50, 300, false, isDumpLog, 0, 0x9207, 8, 0xffffffff, 0x00, 0, 0));
+            commandPublisher.enqueueCommand(new PtpIpCommandGenericWithRetry(this, SEQ_DEVICE_READY, 50, 300, false, isDumpLog, 0, 0x90c8, 0, 0, 0, 0, 0));
+            commandPublisher.enqueueCommand(new PtpIpCommandGenericWithRetry(this, SEQ_GET_EVENT, 50, 300, false, isDumpLog, 0, 0x90c7, 0, 0, 0, 0, 0));
         }
         catch (Exception e)
         {
index 3321caa..440b670 100644 (file)
@@ -14,6 +14,7 @@ import net.osdn.gokigen.a01d.camera.IFocusingControl;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpCommandPublisher;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGenericWithRetry;
 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
@@ -116,7 +117,7 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
         try
         {
             Log.v(TAG, " Unlock AF ");
-            commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_UNLOCK, isDumpLog, 0, 0x9206));
+            commandPublisher.enqueueCommand(new PtpIpCommandGenericWithRetry(this, FOCUS_UNLOCK, 30, 100, false, isDumpLog, 0, 0x9206, 0, 0, 0, 0, 0));
         }
         catch (Exception e)
         {
@@ -128,7 +129,7 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
     public void halfPressShutter(boolean isPressed)
     {
         //unlockAutoFocus();
-        commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));
+        commandPublisher.enqueueCommand(new PtpIpCommandGenericWithRetry(this, FOCUS_MOVE, 30, 250, false, isDumpLog, 0, 0x90c1, 0, 0, 0, 0, 0));
         //lockAutoFocus(new PointF(0.5f, 0.5f));
     }
 
@@ -140,9 +141,9 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
             int y = (0x0000ffff & (Math.round(point.y * maxPointLimitHeight) + 1));
             Log.v(TAG, "Lock AF: [" + x + ","+ y + "]");
             if (!not_support_focus_lock) {
-                commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_LOCK, isDumpLog, 0, 0x9205, 8, x, y));
+                commandPublisher.enqueueCommand(new PtpIpCommandGenericWithRetry(this, FOCUS_LOCK, 30, 250, false, isDumpLog, 0, 0x9205, 8, x, y, 0, 0));
             } else {
-                commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));
+                commandPublisher.enqueueCommand(new PtpIpCommandGenericWithRetry(this, FOCUS_MOVE, 30, 250, false, isDumpLog, 0, 0x90c1, 0, 0, 0, 0, 0));
             }
         }
         catch (Exception e)
@@ -201,6 +202,12 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
     {
         try
         {
+            if (rx_body == null)
+            {
+                Log.v(TAG, " RECEIVED BODY IS NULL.");
+                return;
+            }
+
             if (rx_body.length < 10)
             {
                 Log.v(TAG, " --- BODY LENGTH IS SHORT : FOCUS OPERATION ---");
index f258ec1..31942a8 100644 (file)
@@ -45,10 +45,11 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
             socket?.tcpNoDelay = tcpNoDelay
             if (tcpNoDelay)
             {
+                socket?.tcpNoDelay = true
                 //socket?.keepAlive = false
                 socket?.keepAlive = false
                 //socket?.setPerformancePreferences(0, 1, 2)
-                //socket?.setPerformancePreferences(0, 2, 0)
+                socket?.setPerformancePreferences(0, 1, 2)
                 //socket?.setPerformancePreferences(0, 1, 2)
                 //socket?.setPerformancePreferences(1, 0, 0)
                 //socket?.setPerformancePreferences(0, 0, 2)
@@ -57,8 +58,8 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
                 socket?.trafficClass = 0x80 // 0x80
                 //socket?.soTimeout = 800
                 socket?.soTimeout = 0
-                //socket?.receiveBufferSize = 8192 // 49152 // 65536 // 32768
-                //socket?.sendBufferSize = 8192 // 2048 // 1024 // 2048
+                //socket?.receiveBufferSize = 8192  // 10240 // 16384 // 6144// 8192 // 49152 // 65536 // 32768
+                //socket?.sendBufferSize = 8192 // 4096 // 2048 // 10248
                 socket?.setSoLinger(true, 3000);
                 //socket?.setReceiveBufferSize(2097152);
                 //socket?.setSendBufferSize(524288);
@@ -382,11 +383,12 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
             if (readBytes <= 0)
             {
                 // リトライオーバー...
-                Log.v(TAG, " RECEIVE : RETRY OVER...")
+                Log.v(TAG, " RECEIVE : RETRY OVER...... : $delayMs ms x ${command.maxRetryCount()}  SEQ: $sequenceNumber isRetry: ${command.isRetrySend}")
                 if (!command.isRetrySend)
                 {
                     // 再送しない場合には、応答がないことを通知する
                     receivedAllMessage(isDumpReceiveLog, id, null, callback)
+                    return (false)
                 }
                 return (true)
             }
@@ -462,7 +464,7 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
             if (readBytes <= 0)
             {
                 // リトライオーバー...
-                Log.v(TAG, " RECEIVE : RETRY OVER...... : " + delayMs + "ms x " + command.maxRetryCount() + " SEQ: $sequenceNumber")
+                Log.v(TAG, " RECEIVE : RETRY OVER...... : $delayMs ms x ${command.maxRetryCount()}  SEQ: $sequenceNumber ")
                 if (command.isRetrySend)
                 {
                     // 要求を再送する場合、、、ダメな場合は受信待ちとする
diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/messages/PtpIpCommandGenericWithRetry.kt b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/messages/PtpIpCommandGenericWithRetry.kt
new file mode 100644 (file)
index 0000000..1c2254c
--- /dev/null
@@ -0,0 +1,110 @@
+package net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages
+
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback
+
+
+class PtpIpCommandGenericWithRetry(private val callback: IPtpIpCommandCallback, private val id: Int, private val delayMs: Int, private val retryCount: Int, private val isRetry: Boolean, private val isDumpLog: Boolean, private val holdId: Int, opcode: Int, private val bodySize: Int, value: Int, value2: Int = 0, value3: Int = 0, value4: Int = 0) : PtpIpCommandBase()
+{
+    private val opCode0: Byte = (0x000000ff and opcode).toByte()
+    private val opCode1: Byte = (0x0000ff00 and opcode shr 8).toByte()
+    private val data0: Byte = (0x000000ff and value).toByte()
+    private val data1: Byte = (0x0000ff00 and value shr 8).toByte()
+    private val data2: Byte = (0x00ff0000 and value shr 16).toByte()
+    private val data3: Byte = (-0x1000000 and value shr 24).toByte()
+    private val data4: Byte = (0x000000ff and value2).toByte()
+    private val data5: Byte = (0x0000ff00 and value2 shr 8).toByte()
+    private val data6: Byte = (0x00ff0000 and value2 shr 16).toByte()
+    private val data7: Byte = (-0x1000000 and value2 shr 24).toByte()
+    private val data8: Byte = (0x000000ff and value3).toByte()
+    private val data9: Byte = (0x0000ff00 and value3 shr 8).toByte()
+    private val dataA: Byte = (0x00ff0000 and value3 shr 16).toByte()
+    private val dataB: Byte = (-0x1000000 and value3 shr 24).toByte()
+    private val dataC: Byte = (0x000000ff and value4).toByte()
+    private val dataD: Byte = (0x0000ff00 and value4 shr 8).toByte()
+    private val dataE: Byte = (0x00ff0000 and value4 shr 16).toByte()
+    private val dataF: Byte = (-0x1000000 and value4 shr 24).toByte()
+
+    override fun responseCallback(): IPtpIpCommandCallback {
+        return callback
+    }
+
+    override fun getId(): Int {
+        return id
+    }
+
+    override fun estimatedReceiveDataSize(): Int {
+        return -1
+    }
+
+    override fun commandBody(): ByteArray {
+        return if (bodySize == 2) {
+            byteArrayOf( // packet type
+                    0x06.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data phase info
+                    0x01.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // operation code
+                    opCode0, opCode1,  // sequence number
+                    0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data ...
+                    data0, data1)
+        } else if (bodySize == 4) {
+            byteArrayOf( // packet type
+                    0x06.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data phase info
+                    0x01.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // operation code
+                    opCode0, opCode1,  // sequence number
+                    0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data ...
+                    data0, data1, data2, data3)
+        } else if (bodySize == 8) {
+            byteArrayOf( // packet type
+                    0x06.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data phase info
+                    0x01.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // operation code
+                    opCode0, opCode1,  // sequence number
+                    0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data ...
+                    data0, data1, data2, data3,
+                    data4, data5, data6, data7)
+        } else if (bodySize == 12) {
+            byteArrayOf( // packet type
+                    0x06.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data phase info
+                    0x01.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // operation code
+                    opCode0, opCode1,  // sequence number
+                    0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data ...
+                    data0, data1, data2, data3,
+                    data4, data5, data6, data7,
+                    data8, data9, dataA, dataB)
+        } else if (bodySize == 16) {
+            byteArrayOf( // packet type
+                    0x06.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data phase info
+                    0x01.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // operation code
+                    opCode0, opCode1,  // sequence number
+                    0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data ...
+                    data0, data1, data2, data3,
+                    data4, data5, data6, data7,
+                    data8, data9, dataA, dataB,
+                    dataC, dataD, dataE, dataF)
+        } else  //  ボディ長が 2, 4, 8, 12 以外の場合... (ボディなし)
+        {
+            byteArrayOf( // packet type
+                    0x06.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // data phase info
+                    0x01.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte(),  // operation code
+                    opCode0, opCode1,  // sequence number
+                    0x00.toByte(), 0x00.toByte(), 0x00.toByte(), 0x00.toByte())
+        }
+    }
+
+    override fun receiveDelayMs(): Int {
+        return delayMs
+    }
+
+    override fun getHoldId(): Int {
+        return holdId
+    }
+
+    override fun maxRetryCount(): Int {
+        return retryCount
+    }
+
+    override fun isRetrySend(): Boolean {
+        return isRetry
+    }
+
+    override fun dumpLog(): Boolean {
+        return isDumpLog
+    }
+}