import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
-import net.osdn.gokigen.a01d.camera.ptpip.wrapper.status.PtpIpStatusChecker;
+import net.osdn.gokigen.a01d.camera.canon.wrapper.status.CanonStatusChecker;
public class CanonCameraConnectSequence implements Runnable, IPtpIpCommandCallback, IPtpIpMessages
{
private final ICameraStatusReceiver cameraStatusReceiver;
private final IPtpIpInterfaceProvider interfaceProvider;
private final IPtpIpCommandPublisher commandIssuer;
- private final PtpIpStatusChecker statusChecker;
+ private final CanonStatusChecker statusChecker;
private boolean isDumpLog = true;
- CanonCameraConnectSequence(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection, @NonNull IPtpIpInterfaceProvider interfaceProvider, @NonNull PtpIpStatusChecker statusChecker)
+ CanonCameraConnectSequence(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection, @NonNull IPtpIpInterfaceProvider interfaceProvider, @NonNull CanonStatusChecker statusChecker)
{
Log.v(TAG, " CanonCameraConnectSequence");
this.context = context;
break;
case SEQ_OPEN_SESSION:
+ Log.v(TAG, " SEQ_OPEN_SESSION ");
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting2), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_INIT_SESSION, isDumpLog, 0, 0x902f));
break;
case SEQ_INIT_SESSION:
+ Log.v(TAG, " SEQ_INIT_SESSION ");
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting3), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_CHANGE_REMOTE, isDumpLog, 0, 0x9114, 4, 0x15));
break;
case SEQ_CHANGE_REMOTE:
+ Log.v(TAG, " SEQ_CHANGE_REMOTE ");
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting4), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_SET_EVENT_MODE, isDumpLog, 0, 0x9115, 4, 0x02));
break;
case SEQ_SET_EVENT_MODE:
+ Log.v(TAG, " SEQ_SET_EVENT_MODE ");
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting5), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_EVENT, isDumpLog, 0, 0x913d, 4, 0x0fff));
// commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_EVENT, isDumpLog, 0, 0x902f, 4, 0x02));
break;
case SEQ_GET_EVENT:
+ Log.v(TAG, " SEQ_GET_EVENT ");
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting6), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_EVENT1, isDumpLog, 0, 0x9033, 4, 0x0000));
// commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_EVENT, isDumpLog, 0, 0x902f, 4, 0x02));
break;
case SEQ_GET_EVENT1:
+ Log.v(TAG, " SEQ_GET_EVENT1 ");
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting7), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_INFORMATION, isDumpLog, 0, 0x1001));
break;
case SEQ_DEVICE_INFORMATION:
+ Log.v(TAG, " SEQ_DEVICE_INFORMATION ");
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting8), false, false, 0);
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_PROPERTY, isDumpLog, 0, 0x9127, 4, 0x0000d1a6));
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_PROPERTY, isDumpLog, 0, 0x9127, 4, 0x0000d169));
break;
case SEQ_DEVICE_PROPERTY:
- interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting9), false, false, 0);
Log.v(TAG, " SEQ_DEVICE_PROPERTY ");
+ interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting9), false, false, 0);
if ((rx_body[8] == (byte) 0x01)&&(rx_body[9] == (byte) 0x20))
{
- // コマンドが受け付けられた!
+ // コマンドが受け付けられたときだけ次に進む!
try
{
- // ちょっと(200ms)待つ
- Thread.sleep(200);
+ // ちょっと(250ms)待つ
+ Thread.sleep(250);
// コマンド発行
- commandIssuer.enqueueCommand(new CanonSetDevicePropertyValue(this, SEQ_SET_DEVICE_PROPERTY, isDumpLog, 0, 20, 0xd136, 0x00));
+ commandIssuer.enqueueCommand(new CanonSetDevicePropertyValue(this, SEQ_SET_DEVICE_PROPERTY, isDumpLog, 0, 150, 0xd136, 0x00));
}
catch (Exception e)
{
break;
case SEQ_SET_DEVICE_PROPERTY:
- interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting10), false, false, 0);
Log.v(TAG, " SEQ_SET_DEVICE_PROPERTY ");
- commandIssuer.enqueueCommand(new CanonSetDevicePropertyValue(this, SEQ_SET_DEVICE_PROPERTY_2, isDumpLog, 0, 20, 0xd136, 0x01));
+ interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting10), false, false, 0);
+ commandIssuer.enqueueCommand(new CanonSetDevicePropertyValue(this, SEQ_SET_DEVICE_PROPERTY_2, isDumpLog, 0, 150, 0xd136, 0x01));
break;
case SEQ_SET_DEVICE_PROPERTY_2:
- interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting10), false, false, 0);
Log.v(TAG, " SEQ_SET_DEVICE_PROPERTY_2 ");
- commandIssuer.enqueueCommand(new CanonSetDevicePropertyValue(this, SEQ_SET_DEVICE_PROPERTY_3, isDumpLog, 0, 20, 0xd136, 0x00));
+ interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting11), false, false, 0);
+ commandIssuer.enqueueCommand(new CanonSetDevicePropertyValue(this, SEQ_SET_DEVICE_PROPERTY_3, isDumpLog, 0, 150, 0xd136, 0x00));
break;
case SEQ_SET_DEVICE_PROPERTY_3:
- interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting11), false, false, 0);
Log.v(TAG, " SEQ_SET_DEVICE_PROPERTY_3 ");
- commandIssuer.enqueueCommand(new CanonSetDevicePropertyValue(this, SEQ_DEVICE_PROPERTY_FINISHED, isDumpLog, 0, 20, 0xd1b0, 0x08));
+ interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting12), false, false, 0);
+ commandIssuer.enqueueCommand(new CanonSetDevicePropertyValue(this, SEQ_DEVICE_PROPERTY_FINISHED, isDumpLog, 0, 300, 0xd1b0, 0x08));
break;
case SEQ_DEVICE_PROPERTY_FINISHED:
- interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting12), false, false, 0);
Log.v(TAG, " SEQ_DEVICE_PROPERTY_FINISHED ");
-/*
- if (rx_body.length <= 80)
- {
- // 『仮』: OP CODE: 0x9116 の応答データが80バイト以下なら、再度イベントを要求する
- Log.v(TAG, " TRY AGAIN ... : " + rx_body.length);
- interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.canon_connect_connecting5), false, false, 0);
- //commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_PROPERTY_FINISHED, isDumpLog, 0, 0x9116));
- }
- else
- */
- {
- interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.connect_connect_finished), false, false, 0);
- connectFinished();
- Log.v(TAG, "CHANGED MODE : DONE.");
- }
-
- // 実験...
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_VIEWFRAME, isDumpLog, 0, 0x9153, 12, 0x00200000, 0x01, 0x00));
+ interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.connect_connect_finished), false, false, 0);
+ connectFinished();
+ Log.v(TAG, "CHANGED MODE : DONE.");
break;
default:
// ちょっと待つ
Thread.sleep(1000);
- //interfaceProvider.getAsyncEventCommunication().connect();
- //interfaceProvider.getCameraStatusWatcher().startStatusWatch(interfaceProvider.getStatusListener()); ステータスの定期確認は実施しない
+ // // ステータスの監視はイベント受信時のみに実施する
+ // interfaceProvider.getCameraStatusWatcher().startStatusWatch(interfaceProvider.getStatusListener());
// 接続成功!のメッセージを出す
interfaceProvider.getInformationReceiver().updateMessage(context.getString(R.string.connect_connected), false, false, 0);
-package net.osdn.gokigen.a01d.camera.ptpip.wrapper.status;
+package net.osdn.gokigen.a01d.camera.canon.wrapper.status;
import android.app.Activity;
import android.util.Log;
import static net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper.dump_bytes;
-public class PtpIpStatusChecker implements IPtpIpCommandCallback, ICameraStatusWatcher, ICameraStatus
+public class CanonStatusChecker implements IPtpIpCommandCallback, ICameraStatusWatcher, ICameraStatus
{
private final String TAG = toString();
private static final int BUFFER_SIZE = 1024 * 1024 + 8;
private static final int STATUS_MESSAGE_HEADER_SIZE = 14;
- private int sleepMs;
private final IPtpIpCommandPublisher issuer;
private ICameraStatusUpdateNotify notifier = null;
- private PtpIpStatusHolder statusHolder;
+ private CanonStatusHolder statusHolder;
private boolean whileFetching = false;
private boolean logcat = false;
private final String ipAddress;
private BufferedReader bufferedReader = null;
private int eventConnectionNumber = 0;
- public PtpIpStatusChecker(@NonNull Activity activity, @NonNull IPtpIpCommandPublisher issuer, @NonNull String ip, int portNumber)
+ public CanonStatusChecker(@NonNull Activity activity, @NonNull IPtpIpCommandPublisher issuer, @NonNull String ip, int portNumber)
{
this.issuer = issuer;
- this.statusHolder = new PtpIpStatusHolder();
+ this.statusHolder = new CanonStatusHolder();
this.ipAddress = ip;
this.portNumber = portNumber;
- Log.v(TAG, "POLLING WAIT : " + sleepMs);
}
@Override
Log.v(TAG, "received status length is short. (" + data.length + " bytes.)");
return;
}
-/*
int nofStatus = (data[13] * 256) + data[12];
int statusCount = 0;
int index = STATUS_MESSAGE_HEADER_SIZE;
index = index + 6;
statusCount++;
}
-*/
}
catch (Exception e)
{
int parameter1 = ((((int) received_message[17]) & 0xff) << 24) + ((((int) received_message[16]) & 0xff) << 16) + ((((int) received_message[15]) & 0xff) << 8) + (((int) received_message[14]) & 0xff);
int parameter2 = ((((int) received_message[21]) & 0xff) << 24) + ((((int) received_message[20]) & 0xff) << 16) + ((((int) received_message[19]) & 0xff) << 8) + (((int) received_message[18]) & 0xff);
int parameter3 = ((((int) received_message[25]) & 0xff) << 24) + ((((int) received_message[24]) & 0xff) << 16) + ((((int) received_message[23]) & 0xff) << 8) + (((int) received_message[22]) & 0xff);
-
+ Log.v(TAG, String.format(" event : 0x%x, code: 0x%x, prm1: 0x%x, prm2: 0x%x, prm3 : 0x%x", packetType, eventCode, parameter1, parameter2, parameter3));
if (eventCode == 0xc101)
{
- // イベント受信指示
- issuer.enqueueCommand(new PtpIpCommandGeneric(this, IPtpIpMessages.SEQ_GET_STATUS, true, 0, 0x9116));
- issuer.enqueueCommand(new PtpIpCommandGeneric(this, IPtpIpMessages.SEQ_GET_STATUS, true, 0, 0x9116));
+ // イベントの受信指示
issuer.enqueueCommand(new PtpIpCommandGeneric(this, IPtpIpMessages.SEQ_GET_STATUS, true, 0, 0x9116));
}
-
}
}
catch (Exception e)
}
}
}
-