OSDN Git Service

安定性調査中。
authorMRSa <mrsa@myad.jp>
Thu, 5 Mar 2020 15:01:43 +0000 (00:01 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 5 Mar 2020 15:01:43 +0000 (00:01 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/CanonInterfaceProvider.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/ptpip/wrapper/command/IPtpIpMessages.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.java

index 06f85df..5100eb7 100644 (file)
@@ -63,7 +63,7 @@ public class CanonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay
     public CanonInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
     {
         this.activity = context;
-        commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT);
+        commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT, false);
         liveViewControl = new CanonLiveViewControl(context, this, 10);  //
         asyncReceiver = new PtpIpAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
         statusChecker = new CanonStatusChecker(context, commandPublisher, CAMERA_IP, EVENT_PORT);
index 86c3381..b6b3808 100644 (file)
@@ -125,7 +125,8 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
     @Override
     public void halfPressShutter(boolean isPressed)
     {
-        unlockAutoFocus();
+        //unlockAutoFocus();
+        commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));
         //lockAutoFocus(new PointF(0.5f, 0.5f));
     }
 
index 64cbbf2..3494c7d 100644 (file)
@@ -63,8 +63,8 @@ public class NikonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay
     public NikonInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
     {
         this.activity = context;
-        commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT);
-        liveViewControl = new NikonLiveViewControl(context, this, 40);
+        commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT, false);
+        liveViewControl = new NikonLiveViewControl(context, this, 20);
         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 f707877..cfb3eda 100644 (file)
@@ -14,6 +14,7 @@ import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpResponseReceiver;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.liveview.IPtpIpLiveViewImageCallback;
+import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
 import net.osdn.gokigen.a01d.liveview.liveviewlistener.IImageDataReceiver;
 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
 
@@ -21,7 +22,10 @@ import java.util.Arrays;
 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_CHECK_EVENT;
 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_DEVICE_PROP1;
+import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_GET_DEVICE_PROP2;
 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;
 
@@ -185,7 +189,7 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
                 //SimpleLogDumper.dump_bytes(" [LVLV] " + ": ", Arrays.copyOfRange(data, 0, (0 + 512)));
                 //dataReceiver.setImageData(data, metadata);
                 int offset = searchJpegHeader(data);
-                if (data.length > 8)
+                if ((data.length > 8)&&(offset < data.length))
                 {
                     dataReceiver.setImageData(Arrays.copyOfRange(data, offset, data.length), metadata);  // ヘッダ部分を切り取って送る
                 }
@@ -195,6 +199,8 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
         {
             e.printStackTrace();
         }
+        //commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP1, 30, isDumpLog, 0, 0x1015, 4, 0x5007, 0x00, 0x00, 0x00));
+        commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_CHECK_EVENT, 30, isDumpLog, 0, 0x90c7, 0, 0x00, 0x00, 0x00, 0x00));
         commandIssued = false;
     }
 
@@ -234,15 +240,25 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
     @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
-        Log.v(TAG, " NikonLiveViewControl::receivedMessage() ");
+        Log.v(TAG, " NikonLiveViewControl::receivedMessage() [id:" + id + "]");
         try
         {
             if (rx_body.length < 10)
             {
+                Log.v(TAG, " NikonLiveViewControl::receivedMessage() : BODY LENGTH IS TOO SHORT. SEND RETRY MESSAGE");
                 retrySendMessage(id);
                 return;
             }
+/**/
             int responseCode = (rx_body[8] & 0xff) + ((rx_body[9] & 0xff) * 256);
+            if (id == SEQ_CHECK_EVENT)
+            {
+                // 応答にはデータが含まれているので....受信データの末尾を拾う
+                //SimpleLogDumper.dump_bytes("CHECK EVENT", Arrays.copyOfRange(rx_body, 0, Math.min(rx_body.length, 128)));
+                responseCode = (rx_body[rx_body.length - 6] & 0xff) + ((rx_body[rx_body.length - 5] & 0xff) * 256);
+            }
+/**/
+            //int responseCode = (rx_body[rx_body.length - 6] & 0xff) + ((rx_body[rx_body.length - 5] & 0xff) * 256);
             if (responseCode != 0x2001)
             {
                 // NG応答を受信...同じコマンドを再送する
@@ -251,7 +267,7 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
                 return;
             }
 
-            Log.v(TAG, String.format(" OK REPLY (ID : %d) ", id));
+            Log.v(TAG, String.format(" ----- OK REPLY (ID : %d) ----- ", id));
             if (id == SEQ_START_LIVEVIEW)
             {
                 commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 30, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
@@ -260,10 +276,23 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
             {
                 commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 30, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
             }
-            else
+            else if (id == SEQ_CHECK_EVENT)
+            {
+                commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 35, isDumpLog));
+            }
+            else if (id == SEQ_GET_DEVICE_PROP1)
+            {
+                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP2, 30, isDumpLog, 0, 0x1015, 4, 0xd100, 0x00, 0x00, 0x00));
+            }
+            else if (id == SEQ_GET_DEVICE_PROP2)
+            {
+                commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 35, isDumpLog));
+            }
+            else  // SEQ_AFDRIVE
             {
                 // ライブビューの開始。
-                startLiveviewImpl();
+                //startLiveviewImpl();
+                commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 80, isDumpLog));
             }
         }
         catch (Exception e)
@@ -272,10 +301,23 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
         }
     }
 
+    private void waitSleep()
+    {
+        try
+        {
+            Thread.sleep(delayMs);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
     private void retrySendMessage(int id)
     {
         try
         {
+            waitSleep();
             if (id == SEQ_START_LIVEVIEW)
             {
                 commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_START_LIVEVIEW, 30, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
@@ -284,6 +326,18 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
             {
                 commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 30, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
             }
+            else if (id == SEQ_CHECK_EVENT)
+            {
+                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_CHECK_EVENT, 30, isDumpLog, 0, 0x90c7, 0, 0x00, 0x00, 0x00, 0x00));
+            }
+            else if (id == SEQ_GET_DEVICE_PROP1)
+            {
+                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP1, 30, isDumpLog, 0, 0x5007, 4, 0x5007, 0x00, 0x00, 0x00));
+            }
+            else if (id == SEQ_GET_DEVICE_PROP2)
+            {
+                commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP2, 30, isDumpLog, 0, 0x1015, 4, 0xd100, 0x00, 0x00, 0x00));
+            }
             else
             {
                 commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 30, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
index b824009..1e670bf 100644 (file)
@@ -25,6 +25,9 @@ public interface IPtpIpMessages
     int SEQ_STOP_LIVEVIEW = 20;
     int SEQ_DEVICE_READY = 21;
     int SEQ_AFDRIVE = 22;
+    int SEQ_CHECK_EVENT = 23;
+    int SEQ_GET_DEVICE_PROP1 = 24;
+    int SEQ_GET_DEVICE_PROP2 = 25;
 
     int GET_STORAGE_ID = 101;
     int GET_STORAGE_INFO = 102;
index 0617275..e0468d8 100644 (file)
@@ -32,6 +32,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
 
     private boolean isStart = false;
     private boolean isHold = false;
+    private boolean tcpNoDelay;
     private int holdId = 0;
     private Socket socket = null;
     private DataOutputStream dos = null;
@@ -40,10 +41,11 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
     private Queue<IPtpIpCommand> commandQueue;
     private Queue<IPtpIpCommand> holdCommandQueue;
 
-    public PtpIpCommandPublisher(@NonNull String ip, int portNumber)
+    public PtpIpCommandPublisher(@NonNull String ip, int portNumber, boolean tcpNoDelay)
     {
         this.ipAddress = ip;
         this.portNumber = portNumber;
+        this.tcpNoDelay = tcpNoDelay;
         this.commandQueue = new ArrayDeque<>();
         this.holdCommandQueue = new ArrayDeque<>();
         commandQueue.clear();
@@ -63,6 +65,10 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
         {
             Log.v(TAG, " connect()");
             socket = new Socket(ipAddress, portNumber);
+            socket.setTcpNoDelay(tcpNoDelay);
+            socket.setKeepAlive(true);
+            //socket.setReceiveBufferSize(32768);
+            //socket.setTrafficClass(0x10);
             return (true);
         }
         catch (Exception e)