OSDN Git Service

NikonのLV、すこし改善。
authorMRSa <mrsa@myad.jp>
Sun, 18 Oct 2020 13:52:36 +0000 (22:52 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 18 Oct 2020 13:52:36 +0000 (22:52 +0900)
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/NikonLiveViewImageReceiver.kt
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.kt

index ad6e1cc..128b80a 100644 (file)
@@ -9,7 +9,7 @@ import java.util.*
 
 class NikonLiveViewImageReceiver(private var callback: IPtpIpLiveViewImageCallback) : IPtpIpCommandCallback
 {
-    private val isDumpLog = true
+    private val isDumpLog = false
     private var receivedTotalBytes = 0
     private var receivedRemainBytes = 0
     private var receivedFirstData = false
@@ -19,7 +19,8 @@ class NikonLiveViewImageReceiver(private var callback: IPtpIpLiveViewImageCallba
     {
         if (rx_body == null)
         {
-            Log.v(TAG, " MSG BODY IS NULL. $id")
+            Log.v(TAG, " NikonLiveViewImageReceiver: MSG BODY IS NULL. (ID:$id)")
+            callback.onCompleted(rx_body, null)
             return
         }
         if (isReceiveMulti)
@@ -36,7 +37,7 @@ class NikonLiveViewImageReceiver(private var callback: IPtpIpLiveViewImageCallba
     {
         if (rx_body == null)
         {
-            Log.v(TAG, " MSG BODY IS NULL.")
+            Log.v(TAG, " NikonLiveViewImageReceiver: MSG BODY IS NULL.")
             return
         }
         Log.v(TAG, " onReceiveProgress() $currentBytes/$totalBytes LENGTH: ${rx_body.size} bytes.")
@@ -122,17 +123,14 @@ class NikonLiveViewImageReceiver(private var callback: IPtpIpLiveViewImageCallba
         while (dataPosition <= length - 12)
         {
             val body_size = (rx_body[dataPosition].toUByte()).toInt() + ((rx_body[dataPosition + 1].toUByte()).toInt() * 256) + ((rx_body[dataPosition + 2].toUByte()).toInt() * 256 * 256) + ((rx_body[dataPosition + 3].toUByte()).toInt() * 256 * 256 * 256)
-
-            Log.v(TAG, " XX body_size : ${body_size} [$dataPosition] ($length)  aa: ${rx_body[dataPosition].toUByte().toInt()}  ${rx_body[dataPosition + 1].toUByte().toInt()} + ${rx_body[dataPosition + 2].toUByte().toInt()}")
-            SimpleLogDumper.dump_bytes("XX", Arrays.copyOfRange(rx_body, 0, 32))
+            //Log.v(TAG, " <> body_size : ${body_size} [$dataPosition] ($length)  aa: ${rx_body[dataPosition].toUByte().toInt()}  ${rx_body[dataPosition + 1].toUByte().toInt()} + ${rx_body[dataPosition + 2].toUByte().toInt()}")
             if (body_size <= 12)
             {
                 Log.v(TAG, " ----- BODY SIZE IS SMALL : " + dataPosition + " (" + body_size + ") [" + receivedRemainBytes + "] " + rx_body.size + " ")
                 break
             }
 
-            // 受信データ(のヘッダ部分)をダンプする
-            Log.v(TAG, " RX DATA : " + dataPosition + " (" + body_size + ") [" + receivedRemainBytes + "] (" + receivedTotalBytes + ")");
+            //Log.v(TAG, " RX DATA : " + dataPosition + " (" + body_size + ") [" + receivedRemainBytes + "] (" + receivedTotalBytes + ")");
             if (dataPosition + body_size > length)
             {
                 // データがすべてバッファ内になかったときは、バッファすべてコピーして残ったサイズを記憶しておく。
index 6988b1f..07cf62e 100644 (file)
@@ -407,7 +407,7 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
     private fun receivedAllMessage(isDumpReceiveLog: Boolean, id: Int, body: ByteArray?, callback: IPtpIpCommandCallback?)
     {
         Log.v(TAG, "receivedAllMessage() : " + (body?.size ?: 0) + " bytes.")
-        if (isDumpReceiveLog && body != null)
+        if ((isDumpReceiveLog)&&(body != null))
         {
             // ログに受信メッセージを出力する
             SimpleLogDumper.dump_bytes("RECV[" + body.size + "] ", body)
@@ -417,13 +417,13 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
 
     private fun receiveMulti(command: IPtpIpCommand, delayMs: Int): Boolean
     {
-        //int estimatedSize = command.estimatedReceiveDataSize();
+        val isDumpLog = command.dumpLog()
         var maxRetryCount = command.maxRetryCount()
         val id = command.id
         val callback = command.responseCallback()
         try
         {
-            Log.v(TAG, " ===== receive_multi() =====")
+            // Log.v(TAG, " ===== receive_multi() =====")
             val receiveMessageBufferSize = BUFFER_SIZE
             val byteArray = ByteArray(receiveMessageBufferSize)
             val inputStream = socket?.getInputStream()
@@ -442,6 +442,7 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
                 if (command.isRetrySend)
                 {
                     // 要求を再送する場合、、、ダメな場合は受信待ちとする
+                    Log.v(TAG, " --- SEND RETRY ---")
                     return (true)
                 }
             }
@@ -457,19 +458,25 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
                 if (targetLength <= 0)
                 {
                     // 受信サイズ異常の場合...
-                    if (receivedLength > 0)
+                    if (isDumpLog)
                     {
-                        SimpleLogDumper.dump_bytes("WRONG DATA : ", byteArray.copyOfRange(0, Math.min(receivedLength, 64)))
+                        if (receivedLength > 0)
+                        {
+                            SimpleLogDumper.dump_bytes("WRONG DATA : ", byteArray.copyOfRange(0, Math.min(receivedLength, 64)))
+                        }
+                        Log.v(TAG, " WRONG LENGTH. : $targetLength READ : $receivedLength bytes.")
                     }
-                    Log.v(TAG, " WRONG LENGTH. : $targetLength READ : $receivedLength bytes.")
                     callback?.receivedMessage(id, null)
-                    //return (false)
+
                     // データが不足しているので、もう一度受信待ち
                     return (true)
                 }
             }
 
-            Log.v(TAG, "  -=-=-=- 1st CALL : read_bytes : " + readBytes + "(" + receivedLength + ") : target_length : " + targetLength + "  buffer SIZE : " + byteArray.size)
+            if (isDumpLog)
+            {
+                Log.v(TAG, "  -=-=-=- 1st CALL : read_bytes : " + readBytes + "(" + receivedLength + ") : target_length : " + targetLength + "  buffer SIZE : " + byteArray.size)
+            }
             callback?.onReceiveProgress(receivedLength, targetLength, byteArray.copyOfRange(fromIndex = 0, toIndex = receivedLength))
 
             run {
@@ -485,11 +492,13 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
                 readBytes = inputStream.read(byteArray, 0, receiveMessageBufferSize)
                 if (readBytes <= 0)
                 {
-                    Log.v(TAG, "  RECEIVED MESSAGE FINISHED ($readBytes)")
+                    if (isDumpLog)
+                    {
+                        Log.v(TAG, "  RECEIVED MESSAGE FINISHED ($readBytes)")
+                    }
                     break
                 }
                 receivedLength += readBytes
-
                 callback?.onReceiveProgress(receivedLength, targetLength, byteArray.copyOfRange(0, readBytes))
                 maxRetryCount = command.maxRetryCount()
 
@@ -498,14 +507,17 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
                     readBytes = inputStream.available()
                     if (readBytes == 0)
                     {
-                        Log.v(TAG, " WAIT is.available() ... [$receivedLength, $targetLength] $readBytes retry : $maxRetryCount")
+                        Log.v(TAG, " WAIT is.available() ... [length: $receivedLength, target: $targetLength] $readBytes bytes, retry : $maxRetryCount")
                         maxRetryCount--
                     }
                 }
             }
 
-            //  終了報告...一時的?
-            Log.v(TAG, "  --- receive_multi : $id  ($readBytes) [$maxRetryCount] $receiveMessageBufferSize ($receivedLength) ")
+            //  終了報告...
+            if (isDumpLog)
+            {
+                Log.v(TAG, "  --- receive_multi : $id  ($readBytes) [$maxRetryCount] $receiveMessageBufferSize ($receivedLength) ")
+            }
             callback?.receivedMessage(id, Arrays.copyOfRange(byteArray, 0, receivedLength))
         }
         catch (e: Throwable)
@@ -598,11 +610,11 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
             {
                 sleep(delayMs)
                 readBytes = inputStream.available()
-                if (readBytes <= 0)
+                if (readBytes <= 0)   // if (readBytes <= 0)
                 {
                     if (isLogOutput)
                     {
-                        Log.v(TAG, "waitForReceive:: is.available() WAIT... : " + delayMs + "ms")
+                        Log.v(TAG, "waitForReceive:: is.available() WAIT... : $delayMs ms (Count : $retryCnt) ")
                         isLogOutput = false
                     }
                     retryCount--