--- /dev/null
+package net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages;
+
+import androidx.annotation.NonNull;
+
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.IFujiXCommandCallback;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence;
+
+public class StartMessage2ndRead extends FujiXCommandBase
+{
+ private final IFujiXCommandCallback callback;
+
+ public StartMessage2ndRead(@NonNull IFujiXCommandCallback callback)
+ {
+ this.callback = callback;
+ }
+
+ @Override
+ public IFujiXCommandCallback responseCallback()
+ {
+ return (callback);
+ }
+
+ @Override
+ public int getId()
+ {
+ return (FujiXCameraConnectSequence.SEQ_START_2ND_READ);
+ }
+
+ @Override
+ public byte[] commandBody()
+ {
+ return (new byte[] {
+
+ // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+ (byte)0x01, (byte)0x00,
+
+ // message_header.type : single_part (0x1015) : 0xd212 (status_request)
+ (byte)0x15, (byte)0x10,
+
+ // sequence number
+ (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+
+ // data ...
+ (byte)0x12, (byte)0xd2, (byte)0x00, (byte)0x00,
+ });
+ }
+}
--- /dev/null
+package net.osdn.gokigen.a01d.camera.fujix.wrapper.connection;
+
+import android.app.Activity;
+import android.content.SharedPreferences;
+import android.util.Log;
+
+import androidx.annotation.NonNull;
+import androidx.preference.PreferenceManager;
+
+import net.osdn.gokigen.a01d.R;
+import net.osdn.gokigen.a01d.camera.ICameraConnection;
+import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
+import net.osdn.gokigen.a01d.camera.fujix.IFujiXInterfaceProvider;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.IFujiXCommandCallback;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.IFujiXCommandPublisher;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.CameraRemoteMessage;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.QueryCameraCapabilities;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.RegistrationMessage;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.StartMessage;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.StartMessage2nd;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.StartMessage2ndRead;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.StartMessage3rd;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.StartMessage4th;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.StartMessage5th;
+import net.osdn.gokigen.a01d.camera.fujix.wrapper.command.messages.StatusRequestMessage;
+import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
+
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_CAMERA_REMOTE;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_QUERY_CAMERA_CAPABILITIES;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_REGISTRATION;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_START;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_START_2ND;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_START_2ND_READ;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_START_2ND_RECEIVE;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_START_3RD;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_START_4TH;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_START_5TH;
+import static net.osdn.gokigen.a01d.camera.fujix.wrapper.connection.FujiXCameraConnectSequence.SEQ_STATUS_REQUEST;
+
+public class FujiXCameraConnectSequenceForRead implements Runnable, IFujiXCommandCallback
+{
+ private final String TAG = this.toString();
+
+ private final Activity context;
+ private final ICameraConnection cameraConnection;
+ private final ICameraStatusReceiver cameraStatusReceiver;
+ private final IFujiXInterfaceProvider interfaceProvider;
+ private final IFujiXCommandPublisher commandIssuer;
+ private boolean isBothLiveView = false;
+
+ FujiXCameraConnectSequenceForRead(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection, @NonNull IFujiXInterfaceProvider interfaceProvider)
+ {
+ Log.v(TAG, " FujiXCameraConnectSequenceForRead");
+ this.context = context;
+ this.cameraConnection = cameraConnection;
+ this.cameraStatusReceiver = statusReceiver;
+ this.interfaceProvider = interfaceProvider;
+ this.commandIssuer = interfaceProvider.getCommandPublisher();
+ }
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ try
+ {
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ isBothLiveView = preferences.getBoolean(IPreferencePropertyAccessor.FUJIX_DISPLAY_CAMERA_VIEW, false);
+ }
+ catch (Exception e)
+ {
+ //isBothLiveView = false;
+ e.printStackTrace();
+ }
+
+ // カメラとTCP接続
+ IFujiXCommandPublisher issuer = interfaceProvider.getCommandPublisher();
+ if (!issuer.isConnected())
+ {
+ if (!interfaceProvider.getCommandCommunication().connect())
+ {
+ // 接続失敗...
+ onConnectError(context.getString(R.string.dialog_title_connect_failed));
+ return;
+ }
+ }
+ // コマンドタスクの実行開始
+ issuer.start();
+
+ // 接続シーケンスの開始
+ sendRegistrationMessage();
+
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ onConnectError(e.getLocalizedMessage());
+ }
+ }
+
+ private void onConnectError(String reason)
+ {
+ cameraConnection.alertConnectingFailed(reason);
+ }
+
+ @Override
+ public void receivedMessage(int id, byte[] rx_body)
+ {
+ //Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
+ //int bodyLength = 0;
+ switch (id)
+ {
+ case SEQ_REGISTRATION:
+ if (checkRegistrationMessage(rx_body))
+ {
+ commandIssuer.enqueueCommand(new StartMessage(this));
+ }
+ break;
+
+ case SEQ_START:
+ commandIssuer.enqueueCommand(new StartMessage2ndRead(this));
+ break;
+
+ case SEQ_START_2ND_READ:
+ cameraStatusReceiver.onStatusNotify(context.getString(R.string.connect_connecting));
+ if (rx_body.length == (int)rx_body[0])
+ {
+ // なぜかもうちょっとデータが飛んでくるので待つ
+ //commandIssuer.enqueueCommand(new ReceiveOnly(this));
+
+ commandIssuer.enqueueCommand(new StartMessage3rd(this));
+ }
+ else
+ {
+ commandIssuer.enqueueCommand(new StartMessage3rd(this));
+ }
+ break;
+
+ case SEQ_START_2ND_RECEIVE:
+ commandIssuer.enqueueCommand(new StartMessage3rd(this));
+ break;
+
+ case SEQ_START_3RD:
+ commandIssuer.enqueueCommand(new StartMessage4th(this));
+ break;
+
+ case SEQ_START_4TH:
+ if (isBothLiveView)
+ {
+ // カメラのLCDと遠隔のライブビューを同時に表示する場合...
+ commandIssuer.enqueueCommand(new CameraRemoteMessage(this));
+ }
+ else
+ {
+ commandIssuer.enqueueCommand(new StartMessage5th(this));
+ }
+ break;
+ case SEQ_START_5TH:
+ commandIssuer.enqueueCommand(new StatusRequestMessage(this));
+ break;
+
+ case SEQ_STATUS_REQUEST:
+ commandIssuer.enqueueCommand(new QueryCameraCapabilities(this));
+ break;
+
+ case SEQ_QUERY_CAMERA_CAPABILITIES:
+ commandIssuer.enqueueCommand(new CameraRemoteMessage(this));
+ break;
+
+ case SEQ_CAMERA_REMOTE:
+ connectFinished();
+ break;
+
+ default:
+ Log.v(TAG, "RECEIVED UNKNOWN ID : " + id);
+ onConnectError(context.getString(R.string.connect_receive_unknown_message));
+ break;
+ }
+ }
+
+ private void sendRegistrationMessage()
+ {
+ cameraStatusReceiver.onStatusNotify(context.getString(R.string.connect_start));
+ commandIssuer.enqueueCommand(new RegistrationMessage(this));
+ }
+
+ private boolean checkRegistrationMessage(byte[] receiveData)
+ {
+ // 応答エラーかどうかをチェックする
+ if (receiveData.length == 8)
+ {
+ if ((receiveData[0] == 0x05) && (receiveData[1] == 0x00) && (receiveData[2] == 0x00) && (receiveData[3] == 0x00) &&
+ (receiveData[4] == 0x19) && (receiveData[5] == 0x20) && (receiveData[6] == 0x00) && (receiveData[7] == 0x00)) {
+ // 応答エラー...
+ return (false);
+ }
+ return (false);
+ }
+ return (true);
+ }
+
+
+ private void connectFinished()
+ {
+ try
+ {
+ // ちょっと待つ
+ Thread.sleep(1000);
+ interfaceProvider.getAsyncEventCommunication().connect();
+ //interfaceProvider.getStatusWatcher().startStatusWatch(interfaceProvider.getStatusListener()); ステータスの定期確認は実施しない
+ onConnectNotify();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void onConnectNotify()
+ {
+ try
+ {
+ final Thread thread = new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ // カメラとの接続確立を通知する
+ cameraStatusReceiver.onStatusNotify(context.getString(R.string.connect_connected));
+ cameraStatusReceiver.onCameraConnected();
+ Log.v(TAG, "onConnectNotify()");
+ }
+ });
+ thread.start();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
+import androidx.preference.PreferenceManager;
import net.osdn.gokigen.a01d.R;
import net.osdn.gokigen.a01d.camera.ICameraConnection;
import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
import net.osdn.gokigen.a01d.camera.fujix.IFujiXInterfaceProvider;
+import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
connectionStatus = CameraConnectionStatus.CONNECTING;
try
{
+ boolean isReadOnly = false;
interfaceProvider.getCommandPublisher();
- cameraExecutor.execute(new FujiXCameraConnectSequence(context, statusReceiver, this, interfaceProvider));
+ try
+ {
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
+ isReadOnly = preferences.getBoolean(IPreferencePropertyAccessor.FUJIX_CONNECTION_FOR_READ, false);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ cameraExecutor.execute((!isReadOnly)? new FujiXCameraConnectSequence(context, statusReceiver, this, interfaceProvider) : new FujiXCameraConnectSequenceForRead(context, statusReceiver, this, interfaceProvider));
}
catch (Exception e)
{