OSDN Git Service

pixpro実装。画像取得時に使う key と password を接続シーケンスから取得するところまで。
authorMRSa <mrsa@myad.jp>
Sat, 15 Aug 2020 13:09:37 +0000 (22:09 +0900)
committerMRSa <mrsa@myad.jp>
Sat, 15 Aug 2020 13:09:37 +0000 (22:09 +0900)
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/IPixproInterfaceProvider.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/IConnectionKeyProvider.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/IConnectionKeyReceiver.java [new file with mode: 0644]
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/PixproInterfaceProvider.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/connection/PixproCameraConnectSequence.java
app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/playback/PixproPlaybackControl.java

index 7d526ec..e31c320 100644 (file)
@@ -15,6 +15,7 @@ import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraHardwareStatus;
 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraInformation;
 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatus;
 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusWatcher;
+import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.IConnectionKeyReceiver;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.IPixproCommandPublisher;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.IPixproCommunication;
 
@@ -42,6 +43,8 @@ public interface IPixproInterfaceProvider
     IPixproCommandPublisher getCommandPublisher();
     IPixproCommunication getCommandCommunication();
 
+    IConnectionKeyReceiver getConnectionKeyReceiver();
+
     IInformationReceiver getInformationReceiver();
     String getStringFromResource(int resId);
 }
diff --git a/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/IConnectionKeyProvider.java b/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/IConnectionKeyProvider.java
new file mode 100644 (file)
index 0000000..d7a07b3
--- /dev/null
@@ -0,0 +1,7 @@
+package net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper;
+
+public interface IConnectionKeyProvider
+{
+    String getUserString();
+    String getPasswordString();
+}
diff --git a/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/IConnectionKeyReceiver.java b/app/src/main/java/net/osdn/gokigen/pkremote/camera/vendor/pixpro/wrapper/IConnectionKeyReceiver.java
new file mode 100644 (file)
index 0000000..10d038f
--- /dev/null
@@ -0,0 +1,9 @@
+package net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper;
+
+import androidx.annotation.NonNull;
+
+public interface IConnectionKeyReceiver
+{
+    void receivedPassword(@NonNull String password);
+    void receivedKeyString(@NonNull byte[] keyString);
+}
index 2cba031..141973e 100644 (file)
@@ -2,6 +2,7 @@ package net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper;
 
 import android.app.Activity;
 import android.content.SharedPreferences;
+import android.util.Base64;
 import android.util.Log;
 
 import androidx.annotation.NonNull;
@@ -26,6 +27,7 @@ import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraInformation;
 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatus;
 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusReceiver;
 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusWatcher;
+import net.osdn.gokigen.pkremote.camera.utils.SimpleLogDumper;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.IPixproInterfaceProvider;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.IPixproCommandPublisher;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.IPixproCommunication;
@@ -46,7 +48,7 @@ import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.P
  *
  *
  */
-public class PixproInterfaceProvider implements IPixproInterfaceProvider, IDisplayInjector
+public class PixproInterfaceProvider implements IPixproInterfaceProvider, IDisplayInjector, IConnectionKeyReceiver, IConnectionKeyProvider
 {
     private final String TAG = toString();
     private final Activity activity;
@@ -59,6 +61,9 @@ public class PixproInterfaceProvider implements IPixproInterfaceProvider, IDispl
     private final PixproRunMode runMode;
     private final ICameraInformation cameraInformation;
 
+    private String password = null;
+    private byte[] keyphrase = null;
+
     /**
      *
      *
@@ -88,7 +93,7 @@ public class PixproInterfaceProvider implements IPixproInterfaceProvider, IDispl
         this.pixproConnection = new PixproConnection(activity, provider, this, statusChecker);
         this.hardwarestatus = new PixproCameraHardwareStatus();
         this.runMode = new PixproRunMode();
-        this.playbackControl = new PixproPlaybackControl();
+        this.playbackControl = new PixproPlaybackControl(this);
     }
 
     private int parseInt(@NonNull String key, int defaultValue)
@@ -213,6 +218,12 @@ public class PixproInterfaceProvider implements IPixproInterfaceProvider, IDispl
     }
 
     @Override
+    public IConnectionKeyReceiver getConnectionKeyReceiver()
+    {
+        return (this);
+    }
+
+    @Override
     public IInformationReceiver getInformationReceiver()
     {
         return (informationReceiver);
@@ -223,4 +234,50 @@ public class PixproInterfaceProvider implements IPixproInterfaceProvider, IDispl
     {
         return (activity.getString(resId));
     }
+
+    @Override
+    public void receivedPassword(@NonNull String password)
+    {
+        Log.v(TAG, " receivedPassword [" + password.length() + "] : " + password);
+        this.password = password;
+    }
+
+    @Override
+    public void receivedKeyString(@NonNull byte[] keyString)
+    {
+        Log.v(TAG, " receivedKeyString");
+        SimpleLogDumper.dump_bytes(" Key[" + keyString.length + "]", keyString);
+        this.keyphrase = keyString;
+    }
+
+    @Override
+    public String getUserString()
+    {
+        return ("usr=dscuser");
+    }
+
+    @Override
+    public String getPasswordString()
+    {
+        String passwordString = "pwd=";
+        try
+        {
+            if (password != null)
+            {
+                passwordString = passwordString + password + "&";
+            }
+            if (keyphrase != null)
+            {
+                // Base64 変換  22文字で切って埋める。
+                String encodeString = Base64.encodeToString(keyphrase, Base64.DEFAULT);
+                passwordString = passwordString + encodeString.substring(0, 22) + "==";
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+            passwordString = "pwd=12345678";
+        }
+        return (passwordString);
+    }
 }
index 7ead46a..93242c6 100644 (file)
@@ -10,6 +10,7 @@ import net.osdn.gokigen.pkremote.R;
 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraConnection;
 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusReceiver;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.IPixproInterfaceProvider;
+import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.IConnectionKeyReceiver;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.IPixproCommandCallback;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.IPixproCommandPublisher;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.messages.IPixproMessages;
@@ -25,6 +26,8 @@ import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.messages.c
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.messages.connection.PixproConnectSequence10;
 import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.command.messages.connection.PixproConnectSequence11;
 
+import java.util.Arrays;
+
 public class PixproCameraConnectSequence implements Runnable, IPixproCommandCallback, IPixproMessages
 {
     private final String TAG = this.toString();
@@ -109,12 +112,14 @@ public class PixproCameraConnectSequence implements Runnable, IPixproCommandCall
                 break;
             case SEQ_CONNECT_04:
                 interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.pixpro_connect_connecting4), false, false, 0);
-                // ここで、パスワードの Base64情報を切り出す(FC 03 の応答、 0x0058 ~ 64バイトの文字列を切り出して、Base64エンコードする)
+                // ここで、キー文字列の Base64情報を切り出す(FC 03 の応答、 0x0058 ~ 64バイトの文字列を切り出して、Base64エンコードする)
+                getKeyString(rx_body);
                 commandIssuer.enqueueCommand(new PixproConnectSequence05(this));
                 break;
             case SEQ_CONNECT_05:
                 interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.pixpro_connect_connecting5), false, false, 0);
                 // ここで、パスワードの情報を切り出す (FE 03 の応答、 0x0078 ~ 文字列を切り出す。)
+                getPassword(rx_body);
                 commandIssuer.enqueueCommand(new PixproConnectSequence06(this));
                 break;
             case SEQ_CONNECT_06:
@@ -156,6 +161,59 @@ public class PixproCameraConnectSequence implements Runnable, IPixproCommandCall
         commandIssuer.enqueueCommand(new PixproConnectSequence01(this));
     }
 
+
+    private void getPassword(byte[] rx_body)
+    {
+        try
+        {
+            int startPosition = 0x78;
+            int index = 0x00;
+            while (((startPosition + index) < rx_body.length)&&(rx_body[startPosition + index] != (byte) 0x00))
+            {
+                index++;
+            }
+            if ((startPosition + index) <= rx_body.length)
+            {
+                String password = new String(rx_body, startPosition, index);
+                IConnectionKeyReceiver receiver = interfaceProvider.getConnectionKeyReceiver();
+                if (receiver != null)
+                {
+                    receiver.receivedPassword(password);
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+    private void getKeyString(byte[] rx_body)
+    {
+        try
+        {
+            int startPosition = 0x58;
+            int index = 0x00;
+            while (((startPosition + index) < rx_body.length)&&(rx_body[startPosition + index] != (byte) 0x00))
+            {
+                index++;
+            }
+            if ((startPosition + index) <= rx_body.length)
+            {
+                byte[] keyString = Arrays.copyOfRange(rx_body, startPosition, (startPosition + index));
+                IConnectionKeyReceiver receiver = interfaceProvider.getConnectionKeyReceiver();
+                if (receiver != null)
+                {
+                    receiver.receivedKeyString(keyString);
+                }
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
     private void connectFinished()
     {
         try
index 197913b..27a5cef 100644 (file)
@@ -1,5 +1,9 @@
 package net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.playback;
 
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraContentListCallback;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.ICameraFileInfo;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IContentInfoCallback;
@@ -7,62 +11,86 @@ import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentCall
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadContentListCallback;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IDownloadThumbnailImageCallback;
 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
+import net.osdn.gokigen.pkremote.camera.vendor.pixpro.wrapper.IConnectionKeyProvider;
 
 public class PixproPlaybackControl implements IPlaybackControl
 {
-    public PixproPlaybackControl()
+    private final String TAG = toString();
+
+    private final IConnectionKeyProvider keyProvider;
+
+    public PixproPlaybackControl(@NonNull IConnectionKeyProvider keyProvider)
     {
+        this.keyProvider = keyProvider;
 
     }
 
 
     @Override
-    public String getRawFileSuffix() {
-        return null;
+    public String getRawFileSuffix()
+    {
+        return (null);
     }
 
     @Override
-    public void downloadContentList(IDownloadContentListCallback callback) {
+    public void downloadContentList(IDownloadContentListCallback callback)
+    {
 
     }
 
     @Override
-    public void getContentInfo(String path, String name, IContentInfoCallback callback) {
+    public void getContentInfo(String path, String name, IContentInfoCallback callback)
+    {
 
     }
 
     @Override
-    public void updateCameraFileInfo(ICameraFileInfo info) {
+    public void updateCameraFileInfo(ICameraFileInfo info)
+    {
 
     }
 
     @Override
-    public void downloadContentScreennail(String path, IDownloadThumbnailImageCallback callback) {
+    public void downloadContentScreennail(String path, IDownloadThumbnailImageCallback callback)
+    {
 
     }
 
     @Override
-    public void downloadContentThumbnail(String path, IDownloadThumbnailImageCallback callback) {
+    public void downloadContentThumbnail(String path, IDownloadThumbnailImageCallback callback)
+    {
 
     }
 
     @Override
-    public void downloadContent(String path, boolean isSmallSize, IDownloadContentCallback callback) {
+    public void downloadContent(String path, boolean isSmallSize, IDownloadContentCallback callback)
+    {
 
     }
 
     @Override
-    public void getCameraContentList(ICameraContentListCallback callback) {
+    public void getCameraContentList(ICameraContentListCallback callback)
+    {
 
     }
 
     @Override
-    public void showPictureStarted() {
+    public void showPictureStarted()
+    {
 
     }
 
     @Override
-    public void showPictureFinished() {
+    public void showPictureFinished()
+    {
 
     }
+
+    private String getConnectionString()
+    {
+        String connectionString = keyProvider.getUserString() + "&" + keyProvider.getPasswordString();
+        Log.v(TAG, " connectionString : " + connectionString);
+        return (connectionString);
+    }
+
 }