OSDN Git Service

Kodak PIXPRO WPZ2 の接続シーケンスを強化。
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / camera / kodak / wrapper / command / KodakCommandCommunicator.java
index 83c3373..796486c 100644 (file)
@@ -3,6 +3,7 @@ package net.osdn.gokigen.a01d.camera.kodak.wrapper.command;
 import android.util.Log;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 
 import net.osdn.gokigen.a01d.camera.kodak.wrapper.command.messages.KodakCommandReceiveOnly;
 
@@ -174,6 +175,7 @@ public class KodakCommandCommunicator implements IKodakCommandPublisher, IKodakC
                             Thread.sleep(COMMAND_POLL_QUEUE_MS);
                             if ((is != null)&&(is.available() > 0))
                             {
+                                Log.v(TAG, " --- RECV MSG --- ");
                                 receive_from_camera(new KodakCommandReceiveOnly(SEQ_RECEIVE_ONLY, null));
                             }
                         }
@@ -381,7 +383,7 @@ public class KodakCommandCommunicator implements IKodakCommandPublisher, IKodakC
         }
         if (checkReceiveStatusMessage(body))
         {
-            send_secondary_message(body);
+            send_secondary_message(isDumpReceiveLog, body);
         }
 
         if (callback != null)
@@ -390,42 +392,64 @@ public class KodakCommandCommunicator implements IKodakCommandPublisher, IKodakC
         }
     }
 
-    private void send_secondary_message(byte[] received_body)
+    private void send_secondary_message(boolean isDumpReceiveLog, @Nullable byte[] received_body)
     {
-        Log.v(TAG, "send_secondary_message ");
-        try
+        if (received_body == null)
         {
+            Log.v(TAG, "send_secondary_message : NULL ");
+            return;
+        }
+        Log.v(TAG, "send_secondary_message : [" + received_body[8] + "] [" + received_body[9] + "] ");
+        try {
             byte[] message_to_send = null;
-            if ((received_body[8] == (byte) 0xd2)&&(received_body[9] == (byte) 0xd2))
-            {
-                message_to_send = new byte[] {
-                                (byte) 0x2e , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0xd2 , (byte) 0x07 , (byte) 0x00 , (byte) 0x00 , (byte) 0x01 , (byte) 0x10 , (byte) 0x00 , (byte) 0x80 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x01 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0xff , (byte) 0xff , (byte) 0xff , (byte) 0xff , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
+            if ((received_body[8] == (byte) 0xd2) && (received_body[9] == (byte) 0xd2)) {
+                message_to_send = new byte[]{
+                        (byte) 0x2e, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                        (byte) 0xd2, (byte) 0x07, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x80,
+                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                        (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                        (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
                 };
             }
 
-            if ((received_body[8] == (byte) 0xba)&&(received_body[9] == (byte) 0x0b))
-            {
+            if ((received_body[8] == (byte) 0xba) && (received_body[9] == (byte) 0x0b)) {
+                message_to_send = new byte[]
+                        {
+                                (byte) 0x2e, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0xba, (byte) 0x0b, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x80,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                        };
+            }
+            if ((received_body[8] == (byte) 0xbb) && (received_body[9] == (byte) 0x0b)) {
                 message_to_send = new byte[]
                         {
-                                (byte) 0x2e , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0xba , (byte) 0x0b , (byte) 0x00 , (byte) 0x00 , (byte) 0x01 , (byte) 0x10 , (byte) 0x00 , (byte) 0x80 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x01 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
-                                (byte) 0xff , (byte) 0xff , (byte) 0xff , (byte) 0xff , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 , (byte) 0x00 ,
+                                (byte) 0x2e, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0xbb, (byte) 0x0b, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x10, (byte) 0x00, (byte) 0x80,
+                                (byte) 0x1f, (byte) 0x00, (byte) 0x00, (byte) 0x90, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+                                (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
                         };
             }
+            if ((isDumpReceiveLog)&&(message_to_send != null))
+            {
+                // ログに受信メッセージを出力する
+                dump_bytes("SND2[" + message_to_send.length + "] ", message_to_send);
+            }
+
             if ((dos != null)&&(message_to_send != null))
             {
                 // (データを)送信
@@ -439,20 +463,27 @@ public class KodakCommandCommunicator implements IKodakCommandPublisher, IKodakC
         }
     }
 
-    private boolean checkReceiveStatusMessage(byte[] receive_body)
+    private boolean checkReceiveStatusMessage(@Nullable byte[] receive_body)
     {
         boolean isReceivedStatusMessage = false;
         try
         {
+            if (receive_body == null)
+            {
+                return (false);
+            }
             if (receive_body.length < 16)
             {
-                return (isReceivedStatusMessage);
+                Log.v(TAG, " BODY SIZE IS SMALL. : " + receive_body.length);
+                return (false);
             }
-            if (((receive_body[8] == (byte) 0xd2)&&(receive_body[9] == (byte) 0xd2))||
-                    ((receive_body[8] == (byte) 0xba)&&(receive_body[9] == (byte) 0x0b)))
+            if (((receive_body[8] == (byte) 0xd2)&&(receive_body[9] == (byte) 0x07))||
+                    ((receive_body[8] == (byte) 0xba)&&(receive_body[9] == (byte) 0x0b))||
+                    ((receive_body[8] == (byte) 0xbb)&&(receive_body[9] == (byte) 0x0b)))
+
             {
                 isReceivedStatusMessage = true;
-                Log.v(TAG, " RECEIVED HOST PRIMARY MESSAGE.");
+                Log.v(TAG, "  >>> RECEIVED HOST PRIMARY MESSAGE. <<<");
             }
         }
         catch (Exception e)
@@ -477,7 +508,7 @@ public class KodakCommandCommunicator implements IKodakCommandPublisher, IKodakC
                 {
                     if (isLogOutput)
                     {
-                        Log.v(TAG, "waitForReceive:: is.available() WAIT... : " + delayMs + "ms");
+                        Log.v(TAG, "  waitForReceive:: is.available() WAIT... : " + delayMs + "ms");
                         isLogOutput = false;
                     }
                     retry_count--;