OSDN Git Service

FujiXのJPEGダウンロード機能を追加。
authorMRSa <mrsa@myad.jp>
Sun, 14 Jul 2019 12:39:12 +0000 (21:39 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 14 Jul 2019 12:39:12 +0000 (21:39 +0900)
19 files changed:
app/build.gradle
app/src/main/AndroidManifest.xml
app/src/main/java/net/osdn/gokigen/pkremote/MainActivity.java
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
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/command/messages/GetFullImage.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

index 0ae5e8d..ee856d3 100644 (file)
@@ -1,13 +1,13 @@
 apply plugin: 'com.android.application'
 
 android {
-    compileSdkVersion 28
+    compileSdkVersion 29
     defaultConfig {
         applicationId "net.osdn.gokigen.pkremote"
         minSdkVersion 14
-        targetSdkVersion 28
-        versionCode 10103
-        versionName "1.1.3"
+        targetSdkVersion 29
+        versionCode 10200
+        versionName "1.2.0"
     }
     buildTypes {
         release {
index bbc33b0..12f0142 100644 (file)
@@ -9,6 +9,8 @@
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
+    <uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
     <uses-permission android:name="android.permission.VIBRATE" />
 
     <application
index f024950..c32c1e8 100644 (file)
@@ -122,7 +122,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
         // パーミッション群のオプトイン
         final int REQUEST_NEED_PERMISSIONS = 1010;
+
         if ((ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
+                (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) ||
+                (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_MEDIA_LOCATION) != PackageManager.PERMISSION_GRANTED) ||
                 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) ||
                 (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) ||
                 (ContextCompat.checkSelfPermission(this, Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED) ||
@@ -130,6 +133,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
             ActivityCompat.requestPermissions(this,
                     new String[]{
                             Manifest.permission.WRITE_EXTERNAL_STORAGE,
+                            Manifest.permission.READ_EXTERNAL_STORAGE,
+                            Manifest.permission.ACCESS_MEDIA_LOCATION,
                             Manifest.permission.ACCESS_NETWORK_STATE,
                             Manifest.permission.ACCESS_WIFI_STATE,
                             Manifest.permission.VIBRATE,
index a0ef0cc..33857b3 100644 (file)
@@ -38,12 +38,18 @@ class FujiXCameraCommandResponse  implements IFujiXCommandCallback
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "RECEIVE : " + rx_body.length + " bytes.");
index d473163..be4e5da 100644 (file)
@@ -50,8 +50,14 @@ public class FujiXCaptureControl implements ICaptureControl, IFujiXCommandCallba
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
+
+    @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
 }
index 5f81412..e679418 100644 (file)
@@ -186,12 +186,18 @@ public class FujiXFocusingControl implements IFocusingControl, IFujiXCommandCall
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         if (id == FOCUS_LOCK)
index 8c865d0..5ab2012 100644 (file)
@@ -1,6 +1,5 @@
 package net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper;
 
-import android.content.Context;
 import android.util.Log;
 
 import androidx.annotation.NonNull;
@@ -9,18 +8,16 @@ import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCall
 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;
+    private int receivedLength;
 
-    FujiXFullImageReceiver(Context context, @NonNull IDownloadContentCallback callback)
+    FujiXFullImageReceiver( @NonNull IDownloadContentCallback callback)
     {
-        this.context = context;
         this.callback = callback;
+        this.receivedLength = 0;
     }
 
     @Override
@@ -28,31 +25,8 @@ public class FujiXFullImageReceiver implements IFujiXCommandCallback
     {
         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());
-            }
+            Log.v(TAG, " receivedMessage() : onCompleted. " + id + " (" + receivedLength + " bytes.)");
+            callback.onCompleted();
         }
         catch (Exception e)
         {
@@ -64,16 +38,17 @@ public class FujiXFullImageReceiver implements IFujiXCommandCallback
     }
 
     @Override
-    public void onReceiveProgress(final int currentBytes, final int totalBytes)
+    public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] body)
     {
         try
         {
-            Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
+            receivedLength = receivedLength + currentBytes;
+            //Log.v(TAG, " onReceiveProgress() " + receivedLength + "/" + totalBytes);
 
-            callback.onProgress(null, currentBytes, new IProgressEvent() {
+            callback.onProgress(body, currentBytes, new IProgressEvent() {
                 @Override
                 public float getProgress() {
-                    return( (float) currentBytes / (float) totalBytes);
+                    return( (float) receivedLength / (float) totalBytes);
                 }
 
                 @Override
@@ -92,6 +67,10 @@ public class FujiXFullImageReceiver implements IFujiXCommandCallback
         }
     }
 
-
+    @Override
+    public boolean isReceiveMulti()
+    {
+        return (true);
+    }
 
 }
index ec601d4..47e39d3 100644 (file)
@@ -76,12 +76,18 @@ public class FujiXImageContentInfo implements ICameraContent, IFujiXCommandCallb
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         Log.v(TAG, "RX : " + indexNumber + "(" + id + ") " + rx_body.length + " bytes.");
index 693030e..7f3ce83 100644 (file)
@@ -114,7 +114,7 @@ public class FujiXPlaybackControl implements IPlaybackControl, IFujiXCommandCall
             if ((index > 0)&&(index <= imageInfo.size()))
             {
                 IFujiXCommandPublisher publisher = provider.getCommandPublisher();
-                publisher.enqueueCommand(new GetFullImage(index, new FujiXFullImageReceiver(activity, callback)));
+                publisher.enqueueCommand(new GetFullImage(index, new FujiXFullImageReceiver(callback)));
             }
         }
         catch (Exception e)
@@ -182,7 +182,7 @@ public class FujiXPlaybackControl implements IPlaybackControl, IFujiXCommandCall
         try
         {
             imageInfo.clear();
-            IFujiXCommandPublisher publisher = provider.getCommandPublisher();
+            //IFujiXCommandPublisher publisher = provider.getCommandPublisher();
             for (int index = 1; index <= nofFiles; index++)
             {
                 FujiXImageContentInfo info = new FujiXImageContentInfo(index, null);
@@ -222,12 +222,18 @@ public class FujiXPlaybackControl implements IPlaybackControl, IFujiXCommandCall
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         // イメージ数の一覧が取得できなかった場合にここで作る。
index cb6b1d8..50e94ec 100644 (file)
@@ -48,8 +48,14 @@ public class FujiXThumbnailImageReceiver implements IFujiXCommandCallback
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
+
+    @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
 }
index a1a7194..1e8b0d5 100644 (file)
@@ -277,18 +277,26 @@ public class FujiXCommandPublisher implements IFujiXCommandPublisher, IFujiXComm
         try
         {
             sleep(delayMs);
-            byte[] byte_array = new byte[BUFFER_SIZE];
+            boolean isFirstTime = true;
+            int totalReadBytes;
+            int receive_message_buffer_size = BUFFER_SIZE;
+            byte[] byte_array = new byte[receive_message_buffer_size];
             InputStream is = socket.getInputStream();
             if (is != null)
             {
-                int read_bytes = is.read(byte_array, 0, BUFFER_SIZE);
+                int read_bytes = is.read(byte_array, 0, receive_message_buffer_size);
                 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);
-                        while ((length > read_bytes)||((length == read_bytes)&&((int) byte_array[4] == 0x02)))
+                        if (length > receive_message_buffer_size)
+                        {
+                            Log.v(TAG, "+++++ TOTAL RECEIVE MESSAGE SIZE IS " + length + " +++++");
+                        }
+                        totalReadBytes = read_bytes;
+                        while ((length > totalReadBytes)||((length == read_bytes)&&((int) byte_array[4] == 0x02)))
                         {
                             // データについて、もう一回受信が必要な場合...
                             if (isDumpReceiveLog)
@@ -296,19 +304,37 @@ public class FujiXCommandPublisher implements IFujiXCommandPublisher, IFujiXComm
                                 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);
+                            int read_bytes2 = is.read(byte_array, read_bytes, receive_message_buffer_size - read_bytes);
                             if (read_bytes2 > 0)
                             {
                                 read_bytes = read_bytes + read_bytes2;
+                                totalReadBytes = totalReadBytes + read_bytes2;
                             }
                             else
                             {
-                                // よみだし
+                                // よみだし終了。
+                                Log.v(TAG, "FINISHED RECEIVE... ");
                                 break;
                             }
                             if (callback != null)
                             {
-                                callback.onReceiveProgress(read_bytes, length);
+                                if (callback.isReceiveMulti())
+                                {
+                                    int offset = 0;
+                                    if (isFirstTime)
+                                    {
+                                        // 先頭のヘッダ部分をカットして送る
+                                        offset = 12;
+                                        isFirstTime = false;
+                                        //Log.v(TAG, " FIRST TIME : " + read_bytes + " " + offset);
+                                    }
+                                    callback.onReceiveProgress(read_bytes - offset, length, Arrays.copyOfRange(byte_array, offset, read_bytes));
+                                    read_bytes = 0;
+                                }
+                                else
+                                {
+                                    callback.onReceiveProgress(read_bytes, length, null);
+                                }
                             }
                         }
                     }
@@ -321,16 +347,23 @@ public class FujiXCommandPublisher implements IFujiXCommandPublisher, IFujiXComm
                 if (isDumpReceiveLog)
                 {
                     // ログに受信メッセージを出力する
-                    Log.v(TAG, "receive_from_camera() : " + read_bytes + " bytes.");
+                    Log.v(TAG, "receive_from_camera() : " + read_bytes + " bytes. [" + receive_message_buffer_size + "]");
                     dump_bytes("RECV[" + receive_body.length + "] ", receive_body);
                 }
                if (callback != null)
                 {
-                    callback.receivedMessage(id, receive_body);
+                    if (callback.isReceiveMulti())
+                    {
+                        callback.receivedMessage(id, null);
+                    }
+                    else
+                    {
+                        callback.receivedMessage(id, receive_body);
+                    }
                 }
             }
         }
-        catch (Exception e)
+        catch (Throwable e)
         {
             e.printStackTrace();
         }
index 24fc7b4..d241f27 100644 (file)
@@ -3,5 +3,6 @@ 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);
+    void onReceiveProgress(int currentBytes, int totalBytes, byte[] rx_body);
+    boolean isReceiveMulti();
 }
index c41cb1b..5eed32a 100644 (file)
@@ -43,8 +43,13 @@ public class GetFullImage  extends FujiXCommandBase
                 // sequence number
                 (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
 
-                // data ...
+                // data ... (index number)
                 lower, upper, (byte)0x00, (byte)0x00,
+
+                // 現物合わせ1  : 0~ 
+                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+                // 現物合わせ2  : ~0x01000000 bytes
+                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01,
         });
     }
     @Override
index 2f53e0e..075a50d 100644 (file)
@@ -94,12 +94,18 @@ public class FujiXCameraConnectSequence implements Runnable, IFujiXCommandCallba
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
index b931762..7d6a1d1 100644 (file)
@@ -98,12 +98,18 @@ public class FujiXCameraConnectSequenceForPlayback implements Runnable, IFujiXCo
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
index 9814412..df5d058 100644 (file)
@@ -93,12 +93,18 @@ public class FujiXCameraConnectSequenceForRead implements Runnable, IFujiXComman
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
index 3875506..035204e 100644 (file)
@@ -55,12 +55,18 @@ public class FujiXCameraModeChangeToLiveView implements View.OnClickListener, IF
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
index c152ebe..a4af17c 100644 (file)
@@ -55,12 +55,18 @@ public class FujiXCameraModeChangeToPlayback implements View.OnClickListener, IF
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] rx_body)
     {
         //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
index 94d1c46..cc7abfe 100644 (file)
@@ -49,12 +49,18 @@ public class FujiXStatusChecker implements IFujiXCommandCallback, ICameraStatusW
     }
 
     @Override
-    public void onReceiveProgress(int currentBytes, int totalBytes)
+    public void onReceiveProgress(int currentBytes, int totalBytes, byte[] body)
     {
         Log.v(TAG, " " + currentBytes + "/" + totalBytes);
     }
 
     @Override
+    public boolean isReceiveMulti()
+    {
+        return (false);
+    }
+
+    @Override
     public void receivedMessage(int id, byte[] data)
     {
         try