OSDN Git Service

リトライ待ち時間を変更可能にする。
authorMRSa <mrsa@myad.jp>
Sun, 23 Feb 2020 16:04:17 +0000 (01:04 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 23 Feb 2020 16:04:17 +0000 (01:04 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/command/messages/specific/NikonLiveViewRequestMessage.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/IPtpIpCommand.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/messages/PtpIpCommandBase.java

diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/command/messages/specific/NikonLiveViewRequestMessage.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/command/messages/specific/NikonLiveViewRequestMessage.java
new file mode 100644 (file)
index 0000000..76cd06b
--- /dev/null
@@ -0,0 +1,76 @@
+package net.osdn.gokigen.a01d.camera.nikon.wrapper.command.messages.specific;
+
+import androidx.annotation.NonNull;
+
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandBase;
+
+public class NikonLiveViewRequestMessage extends PtpIpCommandBase
+{
+    private final IPtpIpCommandCallback callback;
+    private final boolean isDumpLog;
+    private final int delayMs;
+
+    public NikonLiveViewRequestMessage(@NonNull IPtpIpCommandCallback callback,int delayMs, boolean isDumpLog)
+    {
+        this.callback = callback;
+        this.delayMs = delayMs;
+        this.isDumpLog = isDumpLog;
+    }
+
+    @Override
+    public IPtpIpCommandCallback responseCallback()
+    {
+        return (callback);
+    }
+
+    @Override
+    public int getId()
+    {
+        return (SEQ_GET_VIEWFRAME);
+    }
+
+    @Override
+    public byte[] commandBody()
+    {
+        return (new byte[]{
+
+                // packet type
+                (byte) 0x06, (byte) 0x00,  (byte) 0x00, (byte) 0x00,
+
+                // data phase info
+                (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+
+                // operation code
+                (byte) 0x03, (byte) 0x92,
+
+                // sequence number
+                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+        });
+    }
+
+    @Override
+    public boolean dumpLog()
+    {
+        return (isDumpLog);
+    }
+
+    @Override
+    public int receiveDelayMs()
+    {
+        return (delayMs);
+    }
+
+    @Override
+    public boolean isRetrySend()
+    {
+        return (true);
+    }
+
+    @Override
+    public int maxRetryCount()
+    {
+        return (5);
+    }
+
+}
index 140b74a..59119c6 100644 (file)
@@ -6,6 +6,7 @@ import android.util.Log;
 import androidx.annotation.NonNull;
 
 import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.nikon.wrapper.command.messages.specific.NikonLiveViewRequestMessage;
 import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
@@ -21,7 +22,6 @@ import java.util.Map;
 
 import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_AFDRIVE;
 import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_DEVICE_READY;
-import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_GET_VIEWFRAME;
 import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_START_LIVEVIEW;
 import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_STOP_LIVEVIEW;
 
@@ -34,7 +34,7 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
     private IImageDataReceiver dataReceiver = null;
     private boolean liveViewIsReceiving = false;
     private boolean commandIssued = false;
-    private boolean isDumpLog = false;
+    private boolean isDumpLog = true;
 
     public NikonLiveViewControl(@NonNull Activity context, @NonNull IPtpIpInterfaceProvider interfaceProvider, int delayMs)
     {
@@ -104,7 +104,7 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
                             if (!commandIssued)
                             {
                                 commandIssued = true;
-                                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(imageReceiver, SEQ_GET_VIEWFRAME, 80, true, 0, 0x9203, 0, 0x00, 0x00, 0x00, 0x00));
+                                commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 90, isDumpLog));
                             }
                             try
                             {
index 73bdd54..950a180 100644 (file)
@@ -55,4 +55,7 @@ public interface IPtpIpCommand
 
     // リトライオーバー発生時、コマンドを再送するか?
     boolean isRetrySend();
+
+    // 受信待ち再試行回数
+    int maxRetryCount();
 }
index 20e413d..9b2cb9b 100644 (file)
@@ -4,8 +4,6 @@ import android.util.Log;
 
 import androidx.annotation.NonNull;
 
-import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
-
 import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
@@ -393,7 +391,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             }
 
             // 初回データが受信バッファにデータが溜まるまで待つ...
-            int read_bytes = waitForReceive(is, delayMs);
+            int read_bytes = waitForReceive(is, delayMs, command.maxRetryCount());
             if (read_bytes < 0)
             {
                 // リトライオーバー...
@@ -444,7 +442,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
     private boolean receive_multi(@NonNull IPtpIpCommand command, int delayMs)
     {
         //int estimatedSize = command.estimatedReceiveDataSize();
-        int maxRetryCount = 20;
+        int maxRetryCount = command.maxRetryCount();
         int id = command.getId();
         IPtpIpCommandCallback callback = command.responseCallback();
 
@@ -461,7 +459,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             }
 
             // 初回データが受信バッファにデータが溜まるまで待つ...
-            int read_bytes = waitForReceive(is, delayMs);
+            int read_bytes = waitForReceive(is, delayMs, command.maxRetryCount());
             if (read_bytes < 0)
             {
                 // リトライオーバー...
@@ -522,7 +520,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
                 }
                 //byteStream.write(byte_array, 0, read_bytes);
 
-                maxRetryCount = 20;
+                maxRetryCount = command.maxRetryCount();
                 //do
                 {
                     sleep(delayMs);
@@ -542,7 +540,14 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             if (callback != null)
             {
                 Log.v(TAG, "  --- receive_multi : " + id + "  (" + read_bytes + ") [" + maxRetryCount + "] " + receive_message_buffer_size + " (" + received_length + ") ");
-                callback.receivedMessage(id, null);
+                try
+                {
+                    callback.receivedMessage(id, Arrays.copyOfRange(byte_array, 0, received_length));
+                }
+                catch (Exception e)
+                {
+                    e.printStackTrace();
+                }
             }
         }
         catch (Throwable e)
@@ -589,7 +594,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             if (packetType == 0x09)
             {
                 lenlen = ((((int) byte_array[15]) & 0xff) << 24) + ((((int) byte_array[14]) & 0xff) << 16) + ((((int) byte_array[13]) & 0xff) << 8) + (((int) byte_array[12]) & 0xff);
-                packetType = (((int) byte_array[16]) & 0xff);
+                //packetType = (((int) byte_array[16]) & 0xff);
             }
             // Log.v(TAG, " ---  RECEIVED MESSAGE : " + len + " bytes (BUFFER: " + byte_array.length + " bytes)" + " length : " + lenlen + " TYPE : " + packetType + " --- ");
             if (lenlen == 0)
@@ -603,8 +608,8 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             while (position < limit)
             {
                 lenlen = ((((int) byte_array[position + 3]) & 0xff) << 24) + ((((int) byte_array[position + 2]) & 0xff) << 16) + ((((int) byte_array[position + 1]) & 0xff) << 8) + (((int) byte_array[position]) & 0xff);
-                packetType = (((int) byte_array[position + 4]) & 0xff);
 /*
+                packetType = (((int) byte_array[position + 4]) & 0xff);
                 if (packetType != 0x0a)
                 {
                     Log.v(TAG, " <><><> PACKET TYPE : " + packetType + " LENGTH : " + lenlen);
@@ -624,10 +629,9 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
         return (receivedBuffer);
     }
 
-    private int waitForReceive(InputStream is, int delayMs)
+    private int waitForReceive(InputStream is, int delayMs, int retry_count)
     {
         boolean isLogOutput = true;
-        int retry_count = 50;
         int read_bytes = 0;
         try
         {
index bcd50e2..ced2c4a 100644 (file)
@@ -113,4 +113,10 @@ public class PtpIpCommandBase implements IPtpIpCommand, IPtpIpMessages
     {
         return (true);
     }
+
+    @Override
+    public int maxRetryCount()
+    {
+        return (20);
+    }
 }