OSDN Git Service

ライブビューデータがなかった時の処理を追加。
authorMRSa <mrsa@myad.jp>
Tue, 22 Dec 2020 14:35:43 +0000 (23:35 +0900)
committerMRSa <mrsa@myad.jp>
Tue, 22 Dec 2020 14:35:43 +0000 (23:35 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/liveview/CanonLiveViewImageReceiver.kt
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/IPtpIpCommandPublisher.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.kt

index 0fca70a..8b2d805 100644 (file)
@@ -22,7 +22,7 @@ class CanonLiveViewImageReceiver(val activity: Activity, val callback: IPtpIpLiv
     {
         if (rx_body == null)
         {
-            Log.v(TAG, " CanonLiveViewReceiver: MSG BODY IS NULL. (ID:$id)")
+            Log.v(TAG, " CanonLiveViewImageReceiver: MSG BODY IS NULL. (ID:$id)")
             callback.onCompleted(rx_body, null)
             return
         }
@@ -33,7 +33,7 @@ class CanonLiveViewImageReceiver(val activity: Activity, val callback: IPtpIpLiv
     {
         if (rx_body == null)
         {
-            Log.v(TAG, " CanonLiveViewReceiver: MSG BODY is NULL. ($currentBytes/$totalBytes)")
+            Log.v(TAG, " CanonLiveViewImageReceiver: MSG BODY is NULL. ($currentBytes/$totalBytes)")
             callback.onCompleted(rx_body, null)
             return
         }
index bcdb127..473c0cc 100644 (file)
@@ -12,6 +12,7 @@ public interface IPtpIpCommandPublisher
     int isExistCommandMessageQueue(int id);
 
     int getCurrentQueueSize();
+    boolean flushQueue();
 
     void start();
     void stop();
index c4de295..aecbbfa 100644 (file)
@@ -60,7 +60,7 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
                 //socket?.soTimeout = 0
                 //socket?.receiveBufferSize = 8192  // 10240 // 16384 // 6144// 8192 // 49152 // 65536 // 32768
                 //socket?.sendBufferSize = 1024 // 8192 // 4096 // 2048 // 10240
-                socket?.setSoLinger(true, 500);
+                socket?.setSoLinger(true, 500)
                 //socket?.setReceiveBufferSize(2097152);
                 //socket?.setSendBufferSize(524288);
 
@@ -201,7 +201,7 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
             if (commandQueue.size > 1)
             {
                 // たまっているときだけログを吐く
-                Log.v(TAG, "Enqueue [ID: " + command.getId() + "] size: " + commandQueue.size)
+                Log.v(TAG, "Enqueue [ID: " + command.id + "] size: " + commandQueue.size)
             }
             return (commandQueue.offer(command))
         }
@@ -217,6 +217,15 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
         return commandQueue.size
     }
 
+    override fun flushQueue(): Boolean
+    {
+        Log.v(TAG, "  flushQueue()  size: ${commandQueue.size}")
+        // TODO: たまっているキューをダンプする
+        commandQueue.clear()
+        System.gc()
+        return (true)
+    }
+
     override fun isExistCommandMessageQueue(id: Int): Int
     {
         var count = 0
@@ -506,6 +515,18 @@ class PtpIpCommandPublisher(private val ipAddress : String, private val portNumb
                 // もう一回データを読み直す...
                 targetLength = parseDataLength(byteArray, readBytes)
             }
+            if ((targetLength == 0)&&(readBytes > 0))
+            {
+                // 知らないデータがついている...ダンプしてみる
+                // Log.v(TAG, " RECEIVE UNKNOWN BYTES : ${readBytes}")
+                if (isDumpLog)
+                {
+                    // ログに送信メッセージを出力する
+                    SimpleLogDumper.dump_bytes("RECV.UNKNOWN[${readBytes}] ", byteArray)
+                }
+                callback?.receivedMessage(id, null)
+                return (false)
+            }
 
             if ((targetLength <= 0)||(readBytes <= 0))
             {