OSDN Git Service

ステータスの更新を実施。
authorMRSa <mrsa@myad.jp>
Thu, 6 Jun 2019 11:36:14 +0000 (20:36 +0900)
committerMRSa <mrsa@myad.jp>
Thu, 6 Jun 2019 11:36:14 +0000 (20:36 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/fujix/wrapper/command/FujiXCommandIssuer.java
app/src/main/java/net/osdn/gokigen/a01d/camera/fujix/wrapper/command/IFujiXCommand.java
app/src/main/java/net/osdn/gokigen/a01d/camera/fujix/wrapper/command/messages/FujiXCommandBase.java
app/src/main/java/net/osdn/gokigen/a01d/camera/fujix/wrapper/command/messages/RegistrationMessage.java
app/src/main/java/net/osdn/gokigen/a01d/camera/fujix/wrapper/connection/FujiXCameraConnectSequence.java
app/src/main/java/net/osdn/gokigen/a01d/camera/fujix/wrapper/status/FujiXStatusChecker.java

index b5bbf09..ef57cf4 100644 (file)
@@ -199,8 +199,7 @@ public class FujiXCommandIssuer implements IFujiXCommandIssuer, IFujiXCommunicat
             {
                 delayMs = COMMAND_SEND_RECEIVE_DURATION_MS;
             }
-            Thread.sleep(delayMs);
-            receive_from_camera(command.dumpLog(), command.getId(), command.responseCallback());
+            receive_from_camera(command.dumpLog(), command.getId(), command.responseCallback(), command.receiveAgainShortLengthMessage(), delayMs);
         }
         catch (Exception e)
         {
@@ -253,15 +252,27 @@ public class FujiXCommandIssuer implements IFujiXCommandIssuer, IFujiXCommunicat
         }
     }
 
+    private void sleep(int delayMs)
+    {
+        try
+        {
+            Thread.sleep(delayMs);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
     /**
      *    カメラからにコマンドの結果を受信する(メイン部分)
      *
      */
-    private void receive_from_camera(boolean isDumpReceiveLog, int id, IFujiXCommandCallback callback)
+    private void receive_from_camera(boolean isDumpReceiveLog, int id, IFujiXCommandCallback callback, boolean receiveAgain, int delayMs)
     {
         try
         {
-
+            sleep(delayMs);
             byte[] byte_array = new byte[BUFFER_SIZE];
             InputStream is = socket.getInputStream();
             if (is != null)
@@ -270,6 +281,21 @@ public class FujiXCommandIssuer implements IFujiXCommandIssuer, IFujiXCommunicat
                 byte[] receive_body;
                 if (read_bytes > 4)
                 {
+                    if (receiveAgain)
+                    {
+                        int length = ((((int) byte_array[3]) & 0xff) << 24) + ((((int) byte_array[2]) & 0xff) << 16) + ((((int) byte_array[1]) & 0xff) << 8) + (((int) byte_array[0]) & 0xff);
+                        if ((length > read_bytes)||((length == read_bytes)&&((int) byte_array[4] == 0x02)))
+                        {
+                            // データについて、もう一回受信が必要な場合...
+                            Log.v(TAG, "--- RECEIVE AGAIN --- [" + length + "(" + read_bytes + ") " + byte_array[4]+ "] ");
+                            sleep(delayMs);
+                            int read_bytes2 = is.read(byte_array, read_bytes, BUFFER_SIZE - read_bytes);
+                            if (read_bytes2 > 0)
+                            {
+                                read_bytes = read_bytes + read_bytes2;
+                            }
+                        }
+                    }
                     receive_body = Arrays.copyOfRange(byte_array, 0, read_bytes);
                 }
                 else
@@ -282,7 +308,7 @@ public class FujiXCommandIssuer implements IFujiXCommandIssuer, IFujiXCommunicat
                     Log.v(TAG, "receive_from_camera() : " + read_bytes + " bytes.");
                     dump_bytes(isDumpReceiveLog, "RECV[" + receive_body.length + "] ", receive_body);
                 }
-                if (callback != null)
+               if (callback != null)
                 {
                     callback.receivedMessage(id, receive_body);
                 }
index 6df567d..9fa368a 100644 (file)
@@ -5,6 +5,9 @@ public interface IFujiXCommand
     // メッセージの識別子
     int getId();
 
+    // 短い長さのメッセージを受け取ったときに再度受信するか
+    boolean receiveAgainShortLengthMessage();
+
     // シーケンス番号を埋め込むかどうか
     boolean useSequenceNumber();
 
index 7a75776..d8e48ca 100644 (file)
@@ -13,6 +13,12 @@ public class FujiXCommandBase implements IFujiXCommand
     }
 
     @Override
+    public boolean receiveAgainShortLengthMessage()
+    {
+        return (true);
+    }
+
+    @Override
     public boolean useSequenceNumber()
     {
         return (true);
index 733dadd..3f5a0c9 100644 (file)
@@ -27,6 +27,12 @@ public class RegistrationMessage extends FujiXCommandBase
     }
 
     @Override
+    public boolean receiveAgainShortLengthMessage()
+    {
+        return (false);
+    }
+
+    @Override
     public boolean useSequenceNumber()
     {
         return (false);
index 3b9eb7a..ef3585c 100644 (file)
@@ -114,6 +114,7 @@ public class FujiXCameraConnectSequence implements Runnable, IFujiXCommandCallba
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
+        int bodyLength = 0;
         switch (id)
         {
             case SEQ_REGISTRATION:
@@ -166,13 +167,18 @@ public class FujiXCameraConnectSequence implements Runnable, IFujiXCommandCallba
                 break;
 
             case SEQ_STATUS_REQUEST:
-                if ((rx_body[4] == (byte) 0x02)&&((int) rx_body[0] == rx_body.length))
+                bodyLength = ((((int) rx_body[3]) & 0xff) << 24) + ((((int) rx_body[2]) & 0xff) << 16) + ((((int) rx_body[1]) & 0xff) << 8) + (((int) rx_body[0]) & 0xff);
+/*
+                if ((rx_body[4] == (byte) 0x02)&&(bodyLength == rx_body.length))
                 {
                     //// 受信データが分割されている場合、、もう一度受信する
+                    Log.v(TAG, "] BODY : " + rx_body.length + "  BodyLength : " + bodyLength + " [");
                     commandIssuer.enqueueCommand(new StatusRequestReceive(this));
                 }
                 else
+*/
                 {
+                    Log.v(TAG, "[ BODY : " + rx_body.length + "  BodyLength : " + bodyLength + " ]");
                     commandIssuer.enqueueCommand(new QueryCameraCapabilities(this));
                 }
                 break;
@@ -182,15 +188,18 @@ public class FujiXCameraConnectSequence implements Runnable, IFujiXCommandCallba
                 break;
 
             case SEQ_QUERY_CAMERA_CAPABILITIES:
-                int bodyLength = ((((int) rx_body[3]) & 0xff) << 24) + ((((int) rx_body[2]) & 0xff) << 16) + ((((int) rx_body[1]) & 0xff) << 8) + (((int) rx_body[0]) & 0xff);
-                if (bodyLength > rx_body.length)
+                bodyLength = ((((int) rx_body[3]) & 0xff) << 24) + ((((int) rx_body[2]) & 0xff) << 16) + ((((int) rx_body[1]) & 0xff) << 8) + (((int) rx_body[0]) & 0xff);
+/*
+                if ((rx_body[4] == (byte) 0x02)&&(bodyLength == rx_body.length))
                 {
-                    Log.v(TAG, "> BODY : " + rx_body.length + "  BodyLength : " + bodyLength);
+                    //// 受信データが分割されている場合、、もう一度受信する
+                    Log.v(TAG, "> BODY : " + rx_body.length + "  BodyLength : " + bodyLength + " <");
                     commandIssuer.enqueueCommand(new StartReceiveOnly2(this));
                 }
                 else
+*/
                 {
-                    Log.v(TAG, "> BODY : " + rx_body.length + "  BodyLength : " + bodyLength);
+                    Log.v(TAG, "< BODY : " + rx_body.length + "  BodyLength : " + bodyLength + " >");
                     commandIssuer.enqueueCommand(new CameraRemoteMessage(this));
                 }
                 break;
index 1db5c31..cea3868 100644 (file)
@@ -41,7 +41,7 @@ public class FujiXStatusChecker implements IFujiXCommandCallback, ICameraStatusW
         catch (Exception e)
         {
             e.printStackTrace();
-            this.sleepMs = 500;
+            this.sleepMs = 400;
         }
         Log.v(TAG, "POLLING WAIT : " + sleepMs);
     }