OSDN Git Service

FujiXのカメラ接続シーケンスの少しエラー強化。
authorMRSa <mrsa@myad.jp>
Fri, 12 Jul 2019 16:25:28 +0000 (01:25 +0900)
committerMRSa <mrsa@myad.jp>
Fri, 12 Jul 2019 16:25:28 +0000 (01:25 +0900)
17 files changed:
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/cameraproperty/FujiXCameraCommandResponse.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/operation/FujiXCaptureControl.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/operation/FujiXFocusingControl.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/FujiXFullImageReceiver.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/FujiXImageContentInfo.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/FujiXPlaybackControl.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/FujiXThumbnailImageReceiver.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/command/FujiXCommandPublisher.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/command/IFujiXCommandCallback.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/connection/FujiXCameraConnectSequence.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/connection/FujiXCameraConnectSequenceForPlayback.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/connection/FujiXCameraConnectSequenceForRead.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/connection/FujiXCameraModeChangeToLiveView.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/connection/FujiXCameraModeChangeToPlayback.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/status/FujiXStatusChecker.java
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml

index ceadd54..a0ef0cc 100644 (file)
@@ -1,6 +1,7 @@
 package net.osdn.gokigen.pkremote.camera.vendor.fujix.cameraproperty;
 
 import android.app.Activity;
+import android.util.Log;
 import android.widget.TextView;
 
 import androidx.annotation.NonNull;
@@ -9,6 +10,7 @@ import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXComma
 
 class FujiXCameraCommandResponse  implements IFujiXCommandCallback
 {
+    private final String TAG = toString();
     private final Activity activity;
     private final TextView field;
 
@@ -35,6 +37,11 @@ class FujiXCameraCommandResponse  implements IFujiXCommandCallback
         }
     }
 
+    @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
 
     @Override
     public void receivedMessage(int id, byte[] rx_body)
index 0e4f07e..d473163 100644 (file)
@@ -48,4 +48,10 @@ public class FujiXCaptureControl implements ICaptureControl, IFujiXCommandCallba
         Log.v(TAG, "Response Received.");
         frameDisplay.hideFocusFrame();
     }
+
+    @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
 }
index b5becda..5f81412 100644 (file)
@@ -185,6 +185,11 @@ public class FujiXFocusingControl implements IFocusingControl, IFujiXCommandCall
         indicator.onAfLockUpdate(false);
     }
 
+    @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
 
     @Override
     public void receivedMessage(int id, byte[] rx_body)
diff --git a/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/FujiXFullImageReceiver.java b/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/fujix/wrapper/FujiXFullImageReceiver.java
new file mode 100644 (file)
index 0000000..8c865d0
--- /dev/null
@@ -0,0 +1,97 @@
+package net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper;
+
+import android.content.Context;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
+import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCallback;
+import net.osdn.gokigen.pkremote.camera.interfaces.playback.IProgressEvent;
+import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommandCallback;
+
+import java.util.Arrays;
+
+public class FujiXFullImageReceiver implements IFujiXCommandCallback
+{
+    private final String TAG = toString();
+    private final Context context;
+    private final IDownloadContentCallback callback;
+
+    FujiXFullImageReceiver(Context context, @NonNull IDownloadContentCallback callback)
+    {
+        this.context = context;
+        this.callback = callback;
+    }
+
+    @Override
+    public void receivedMessage(int id, byte[] rx_body)
+    {
+        try
+        {
+            Log.v(TAG, " receivedMessage() " + id + " / " + rx_body.length + " bytes.");
+            int offset = 12;
+            if (rx_body.length > offset)
+            {
+                callback.onProgress(Arrays.copyOfRange(rx_body, offset, (rx_body.length - offset)), rx_body.length, new IProgressEvent() {
+                    @Override
+                    public float getProgress() {
+                        return (1.0f);
+                    }
+
+                    @Override
+                    public boolean isCancellable() {
+                        return (false);
+                    }
+
+                    @Override
+                    public void requestCancellation() { }
+                });
+                callback.onCompleted();
+            }
+            else
+            {
+                Log.v(TAG, "ERROR RESPONSE... : " + rx_body.length);
+                callback.onErrorOccurred(new NullPointerException());
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            {
+                callback.onErrorOccurred(e);
+            }
+        }
+    }
+
+    @Override
+    public void onReceiveProgress(final int currentBytes, final int totalBytes)
+    {
+        try
+        {
+            Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
+
+            callback.onProgress(null, currentBytes, new IProgressEvent() {
+                @Override
+                public float getProgress() {
+                    return( (float) currentBytes / (float) totalBytes);
+                }
+
+                @Override
+                public boolean isCancellable() {
+                    return (false);
+                }
+
+                @Override
+                public void requestCancellation() { }
+            });
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            callback.onErrorOccurred(e);
+        }
+    }
+
+
+
+}
index 427106e..ec601d4 100644 (file)
@@ -76,6 +76,12 @@ public class FujiXImageContentInfo implements ICameraContent, IFujiXCommandCallb
     }
 
     @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         Log.v(TAG, "RX : " + indexNumber + "(" + id + ") " + rx_body.length + " bytes.");
index 75edd81..693030e 100644 (file)
@@ -14,6 +14,7 @@ import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatus;
 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommandCallback;
 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommandPublisher;
+import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.messages.GetFullImage;
 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.messages.GetImageInfo;
 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.messages.GetThumbNail;
 
@@ -53,6 +54,7 @@ public class FujiXPlaybackControl implements IPlaybackControl, IFujiXCommandCall
     @Override
     public void getContentInfo(String path, String name, IContentInfoCallback callback)
     {
+        // showFileInformation
 
     }
 
@@ -99,7 +101,26 @@ public class FujiXPlaybackControl implements IPlaybackControl, IFujiXCommandCall
     @Override
     public void downloadContent(String path, boolean isSmallSize, IDownloadContentCallback callback)
     {
-
+        try
+        {
+            int start = 0;
+            if (path.indexOf("/") == 0)
+            {
+                start = 1;
+            }
+            String indexStr = path.substring(start, path.indexOf("."));
+            Log.v(TAG, "FujiX::downloadContent() : " + path + " " + indexStr);
+            int index = Integer.parseInt(indexStr);
+            if ((index > 0)&&(index <= imageInfo.size()))
+            {
+                IFujiXCommandPublisher publisher = provider.getCommandPublisher();
+                publisher.enqueueCommand(new GetFullImage(index, new FujiXFullImageReceiver(activity, callback)));
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
     }
 
     @Override
@@ -201,6 +222,12 @@ public class FujiXPlaybackControl implements IPlaybackControl, IFujiXCommandCall
     }
 
     @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         // イメージ数の一覧が取得できなかった場合にここで作る。
index 77672d9..cb6b1d8 100644 (file)
@@ -46,4 +46,10 @@ public class FujiXThumbnailImageReceiver implements IFujiXCommandCallback
             }
         }
     }
+
+    @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
 }
index 48afd25..a1a7194 100644 (file)
@@ -288,7 +288,7 @@ public class FujiXCommandPublisher implements IFujiXCommandPublisher, IFujiXComm
                     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)))
+                        while ((length > read_bytes)||((length == read_bytes)&&((int) byte_array[4] == 0x02)))
                         {
                             // データについて、もう一回受信が必要な場合...
                             if (isDumpReceiveLog)
@@ -301,6 +301,15 @@ public class FujiXCommandPublisher implements IFujiXCommandPublisher, IFujiXComm
                             {
                                 read_bytes = read_bytes + read_bytes2;
                             }
+                            else
+                            {
+                                // よみだし
+                                break;
+                            }
+                            if (callback != null)
+                            {
+                                callback.onReceiveProgress(read_bytes, length);
+                            }
                         }
                     }
                     receive_body = Arrays.copyOfRange(byte_array, 0, read_bytes);
index 835317c..24fc7b4 100644 (file)
@@ -3,4 +3,5 @@ package net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command;
 public interface IFujiXCommandCallback
 {
     void receivedMessage(int id, byte[] rx_body);
+    void onReceiveProgress(int currentBytes, int totalBytes);
 }
index ee726ef..2f53e0e 100644 (file)
@@ -94,6 +94,12 @@ public class FujiXCameraConnectSequence implements Runnable, IFujiXCommandCallba
     }
 
     @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
index def5647..b931762 100644 (file)
@@ -98,6 +98,12 @@ public class FujiXCameraConnectSequenceForPlayback implements Runnable, IFujiXCo
     }
 
     @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
@@ -110,6 +116,10 @@ public class FujiXCameraConnectSequenceForPlayback implements Runnable, IFujiXCo
                 {
                     commandIssuer.enqueueCommand(new StartMessage(this));
                 }
+                else
+                {
+                    onConnectError(context.getString(R.string.connect_error_message));
+                }
                 break;
 
             case SEQ_START:
@@ -216,6 +226,12 @@ public class FujiXCameraConnectSequenceForPlayback implements Runnable, IFujiXCo
 
     private boolean checkRegistrationMessage(byte[] receiveData)
     {
+        // データがないときにはエラー
+        if ((receiveData == null)||(receiveData.length < 8))
+        {
+            return (false);
+        }
+
         // 応答エラーかどうかをチェックする
         if (receiveData.length == 8)
         {
index 508208a..9814412 100644 (file)
@@ -93,6 +93,12 @@ public class FujiXCameraConnectSequenceForRead implements Runnable, IFujiXComman
     }
 
     @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
index 664288e..3875506 100644 (file)
@@ -55,6 +55,12 @@ public class FujiXCameraModeChangeToLiveView implements View.OnClickListener, IF
     }
 
     @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
index 75b9869..c152ebe 100644 (file)
@@ -55,6 +55,12 @@ public class FujiXCameraModeChangeToPlayback implements View.OnClickListener, IF
     }
 
     @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
index 31246bb..94d1c46 100644 (file)
@@ -49,6 +49,12 @@ public class FujiXStatusChecker implements IFujiXCommandCallback, ICameraStatusW
     }
 
     @Override
+    public void onReceiveProgress(int currentBytes, int totalBytes)
+    {
+        Log.v(TAG, " " + currentBytes + "/" + totalBytes);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] data)
     {
         try
index cefb660..791bbdb 100644 (file)
 
     <string name="connect_connecting">接続中&#8230;</string>
     <string name="connect_receive_unknown_message">知らないメッセージを受信</string>
+    <string name="connect_error_message">接続失敗</string>
 
 
     <string name="pref_special_thanks">Special Thanks to</string>
index 28989f7..ad41eaa 100644 (file)
 
     <string name="connect_connecting">connecting&#8230;</string>
     <string name="connect_receive_unknown_message">RECEIVED UNKNOWN ID MESSAGE</string>
+    <string name="connect_error_message">CONNECTION ERROR</string>
 
     <string name="pref_special_thanks">Special Thanks to</string>