OSDN Git Service

安定性検討中。
authorMRSa <mrsa@myad.jp>
Sun, 1 Mar 2020 14:30:10 +0000 (23:30 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 1 Mar 2020 14:30:10 +0000 (23:30 +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/NikonInterfaceProvider.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/nikon/wrapper/liveview/NikonLiveViewControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewImageReceiver.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.java

index 0b8611c..ab66390 100644 (file)
@@ -19,7 +19,7 @@ public class NikonCaptureControl implements ICaptureControl, IPtpIpCommandCallba
     private final String TAG = this.toString();
     private final PtpIpCommandPublisher commandPublisher;
     //private final IAutoFocusFrameDisplay frameDisplayer;
-    private boolean isDumpLog = true;
+    private boolean isDumpLog = false;
 
     public NikonCaptureControl(@NonNull PtpIpCommandPublisher commandPublisher, IAutoFocusFrameDisplay frameDisplayer)
     {
index d19811d..86c3381 100644 (file)
@@ -34,7 +34,7 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
     private float maxPointLimitWidth;
     private float maxPointLimitHeight;
     private RectF preFocusFrameRect = null;
-    private boolean isDumpLog = true;
+    private boolean isDumpLog = false;
 
     public NikonFocusingControl(@NonNull Activity context, @NonNull PtpIpCommandPublisher commandPublisher, IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator)
     {
@@ -251,6 +251,6 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
     @Override
     public boolean isReceiveMulti()
     {
-        return (true);
+        return (false);
     }
 }
index f20bd68..64cbbf2 100644 (file)
@@ -64,7 +64,7 @@ public class NikonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay
     {
         this.activity = context;
         commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT);
-        liveViewControl = new NikonLiveViewControl(context, this, 20);
+        liveViewControl = new NikonLiveViewControl(context, this, 40);
         asyncReceiver = new PtpIpAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
         statusChecker = new NikonStatusChecker(activity, commandPublisher, CAMERA_IP, EVENT_PORT);
         canonConnection = new NikonConnection(context, provider, this, statusChecker);
index aea84a0..f707877 100644 (file)
@@ -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 = true;
+    private boolean isDumpLog = false;
 
     public NikonLiveViewControl(@NonNull Activity context, @NonNull IPtpIpInterfaceProvider interfaceProvider, int delayMs)
     {
@@ -60,7 +60,7 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
         Log.v(TAG, " startLiveView() ");
         try
         {
-            commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_START_LIVEVIEW, 20, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
+            commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_START_LIVEVIEW, 30, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
         }
         catch (Exception e)
         {
@@ -102,7 +102,7 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
                             if (!commandIssued)
                             {
                                 commandIssued = true;
-                                commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 30, isDumpLog));
+                                commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 65, isDumpLog));
                             }
                             try
                             {
@@ -254,11 +254,11 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
             Log.v(TAG, String.format(" OK REPLY (ID : %d) ", id));
             if (id == SEQ_START_LIVEVIEW)
             {
-                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 20, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
+                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 30, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
             }
             else if (id == SEQ_DEVICE_READY)
             {
-                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 20, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
+                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 30, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
             }
             else
             {
@@ -278,15 +278,15 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
         {
             if (id == SEQ_START_LIVEVIEW)
             {
-                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_START_LIVEVIEW, 20, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
+                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_START_LIVEVIEW, 30, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
             }
             else if (id == SEQ_DEVICE_READY)
             {
-                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 20, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
+                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 30, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
             }
             else
             {
-                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 20, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
+                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 30, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
             }
         }
         catch (Exception e)
index 865a52b..27c2216 100644 (file)
@@ -19,7 +19,7 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback
     private int received_total_bytes = 0;
     private int received_remain_bytes = 0;
 
-    private int target_image_size = 0;
+    //private int target_image_size = 0;
     private boolean receivedFirstData = false;
     private ByteArrayOutputStream byteStream;
 
@@ -90,7 +90,8 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback
             {
                 body_length = rx_body.length;
             }
-            Log.v(TAG, " receivedMessage_multi()  id[" + id + "] size : " + body_length + " target length : " +  target_image_size + " ");
+            Log.v(TAG, " receivedMessage_multi()  id[" + id + "] size : " + body_length + " ");
+            //Log.v(TAG, " receivedMessage_multi()  id[" + id + "] size : " + body_length + " target length : " +  target_image_size + " ");
 
             // end of receive sequence.
             //byte [] thumbnail = byteStream.toByteArray();
@@ -98,12 +99,12 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback
             //Log.v(TAG, " TransferComplete() RECEIVED  id[" + id + "] size : " + target_image_size + " (" + thumbnail.length + ")");
             //SimpleLogDumper.dump_bytes(" [xxxxx]", Arrays.copyOfRange(thumbnail, 0, (512)));
             //SimpleLogDumper.dump_bytes(" [zzzzz]", Arrays.copyOfRange(thumbnail, (thumbnail.length - 128), (thumbnail.length)));
-            callback.onCompleted(byteStream.toByteArray(), null);
             //callback.onCompleted(rx_body, null);
+            callback.onCompleted(byteStream.toByteArray(), null);
             receivedFirstData = false;
             received_remain_bytes = 0;
             received_total_bytes = 0;
-            target_image_size = 0;
+            //target_image_size = 0;
             byteStream.reset();
         }
         catch (Exception e)
@@ -155,7 +156,8 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback
             int body_size = (rx_body[data_position] & 0xff) + ((rx_body[data_position + 1] & 0xff) << 8) + ((rx_body[data_position + 2] & 0xff) << 16) + ((rx_body[data_position + 3] & 0xff) << 24);
             if (body_size <= 12)
             {
-                Log.v(TAG, " --- BODY SIZE IS SMALL : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] " + rx_body.length + "  (" + target_image_size + ")");
+                Log.v(TAG, " ----- BODY SIZE IS SMALL : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] " + rx_body.length + " ");
+                //Log.v(TAG, " --- BODY SIZE IS SMALL : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] " + rx_body.length + "  (" + target_image_size + ")");
                 //int startpos = (data_position > 48) ? (data_position - 48) : 0;
                 //SimpleLogDumper.dump_bytes(" [xxx]", Arrays.copyOfRange(rx_body, startpos, (data_position + 48)));
                 break;
index 883043d..0617275 100644 (file)
@@ -4,6 +4,8 @@ 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;
@@ -472,7 +474,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             if (read_bytes < 0)
             {
                 // リトライオーバー...
-                Log.v(TAG, " RECEIVE : RETRY OVER......");
+                Log.v(TAG, " RECEIVE : RETRY OVER...... : " + delayMs + "ms x " + command.maxRetryCount());
                 if (command.isRetrySend())
                 {
                     // 要求を再送する場合、、、ダメな場合は受信待ちとする
@@ -480,23 +482,34 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
                 }
             }
 
-            // 初回データの読み込み
-            read_bytes = is.read(byte_array, 0, receive_message_buffer_size);
-            int target_length = parseDataLength(byte_array, read_bytes);
-            int received_length = read_bytes;
+            boolean read_retry = false;
+            int target_length = 0;
+            int received_length = 0;
 
-            if (target_length <= 0)
+            do
             {
-                // 受信サイズ異常の場合...
-                Log.v(TAG, " WRONG LENGTH. : " + target_length);
-                callback.receivedMessage(id, null);
-                return (false);
-            }
+                // 初回データの読み込み...
+                read_bytes = is.read(byte_array, 0, receive_message_buffer_size);
+                target_length = parseDataLength(byte_array, read_bytes);
+                received_length = read_bytes;
+                if (target_length <= 0)
+                {
+                    // 受信サイズ異常の場合...
+                    if (received_length > 0)
+                    {
+                        SimpleLogDumper.dump_bytes("WRONG DATA : ", Arrays.copyOfRange(byte_array, 0, (Math.min(received_length, 64))));
+                    }
+                    Log.v(TAG, " WRONG LENGTH. : " + target_length + " READ : " + received_length + " bytes.");
+                    callback.receivedMessage(id, null);
+                    return (false);
+                }
+
+            } while (read_retry);
 
             //  一時的な処理
             if (callback != null)
             {
-                Log.v(TAG, "  --- 1st CALL : read_bytes : "+ read_bytes + "(" + received_length + ") : target_length : " + target_length + "  buffer SIZE : " + byte_array.length);
+                Log.v(TAG, "  -=-=-=- 1st CALL : read_bytes : "+ read_bytes + "(" + received_length + ") : target_length : " + target_length + "  buffer SIZE : " + byte_array.length);
                 callback.onReceiveProgress(received_length, target_length, Arrays.copyOfRange(byte_array, 0, received_length));
             }
 
@@ -568,16 +581,26 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
 
     private int parseDataLength(byte[] byte_array, int read_bytes)
     {
+        int offset = 0;
         int lenlen = 0;
         //int packetType = 0;
         try
         {
-            if ((read_bytes > 20)&&((int) byte_array[4] == 0x09))
+            if (read_bytes > 20)
             {
-                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);
+                if ((int) byte_array[offset + 4] == 0x07)
+                {
+                    // 前の応答が入っていると考える...
+                    offset = 14;
+                }
+
+                if (((int) byte_array[offset + 4] == 0x09))
+                {
+                    lenlen = ((((int) byte_array[offset + 15]) & 0xff) << 24) + ((((int) byte_array[offset + 14]) & 0xff) << 16) + ((((int) byte_array[offset + 13]) & 0xff) << 8) + (((int) byte_array[offset + 12]) & 0xff);
+                    //packetType = (((int)byte_array[offset + 16]) & 0xff);
+                }
             }
-            //Log.v(TAG, " --- parseDataLength() length: " + lenlen + " TYPE: " + packetType + " read_bytes: " + read_bytes);
+            //Log.v(TAG, " --- parseDataLength() length: " + lenlen + " TYPE: " + packetType + " read_bytes: " + read_bytes + "  offset : " + offset);
         }
         catch (Exception e)
         {
@@ -624,7 +647,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
                     Log.v(TAG, " <><><> PACKET TYPE : " + packetType + " LENGTH : " + lenlen);
                 }
 */
-                int copyByte = ((lenlen - 12) > (limit - (position + 12))) ? (limit - (position + 12)) : (lenlen - 12);
+                int copyByte =  Math.min((limit - (position + 12)), (lenlen - 12));
                 outputStream.write(byte_array, (position + 12), copyByte);
                 position = position + lenlen;
             }
@@ -648,7 +671,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
             {
                 sleep(delayMs);
                 read_bytes = is.available();
-                if (read_bytes == 0)
+                if (read_bytes <= 0)
                 {
                     if (isLogOutput)
                     {