import net.osdn.gokigen.a01d.camera.ILiveViewControl;
import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
-import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpResponseReceiver;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpResponseReceiver;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandGeneric;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.liveview.IPtpIpLiveViewImageCallback;
import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_START_LIVEVIEW;
import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_STOP_LIVEVIEW;
-public class NikonLiveViewControl implements ILiveViewControl, ILiveViewListener, IPtpIpCommunication, IPtpIpLiveViewImageCallback
+public class NikonLiveViewControl implements ILiveViewControl, ILiveViewListener, IPtpIpCommunication, IPtpIpLiveViewImageCallback, IPtpIpResponseReceiver
{
private final String TAG = this.toString();
private final IPtpIpCommandPublisher commandIssuer;
private IImageDataReceiver dataReceiver = null;
private boolean liveViewIsReceiving = false;
private boolean commandIssued = false;
- private boolean isDumpLog = true;
+ private boolean isDumpLog = false;
public NikonLiveViewControl(@NonNull Activity context, @NonNull IPtpIpInterfaceProvider interfaceProvider, int delayMs)
{
Log.v(TAG, " startLiveView() ");
try
{
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(new PtpIpResponseReceiver(), SEQ_START_LIVEVIEW, 20, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(new PtpIpResponseReceiver(), SEQ_DEVICE_READY, 20, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(new PtpIpResponseReceiver(), SEQ_AFDRIVE, 20, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(new PtpIpResponseReceiver(null), SEQ_START_LIVEVIEW, 20, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(new PtpIpResponseReceiver(null), SEQ_DEVICE_READY, 20, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(new PtpIpResponseReceiver(this), SEQ_AFDRIVE, 20, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
}
catch (Exception e)
{
public void stopLiveView()
{
Log.v(TAG, " stopLiveView() ");
- liveViewIsReceiving = false;
try
{
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(new PtpIpResponseReceiver(), SEQ_STOP_LIVEVIEW, 20, isDumpLog, 0, 0x9202, 0, 0x00, 0x00, 0x00, 0x00));
+ if (liveViewIsReceiving)
+ {
+ liveViewIsReceiving = false;
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(new PtpIpResponseReceiver(null), SEQ_STOP_LIVEVIEW, 20, isDumpLog, 0, 0x9202, 0, 0x00, 0x00, 0x00, 0x00));
+ }
}
catch (Exception e)
{
}
}
-
-
-
@Override
public void updateDigitalZoom()
{
Log.v(TAG, " onErrorOccurred () : " + e.getLocalizedMessage());
commandIssued = false;
}
+
+ @Override
+ public void response(int id, int responseCode)
+ {
+ // 応答OKなら LV開始。
+ if ((id == SEQ_AFDRIVE)&&(responseCode == 0x2001))
+ {
+ startLiveviewImpl();
+ }
+ else
+ {
+ Log.v(TAG, String.format(" ===== NikonLiveViewControl::response() ID : %d, RESPONSE CODE : 0x%04x ", id, responseCode));
+ }
+ }
}
@Override
public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
{
- // Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
+ Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
// 受信したデータから、通信のヘッダ部分を削除する
cutHeader(rx_body);
// データを最初に読んだとき。ヘッダ部分を読み飛ばす
receivedFirstData = true;
data_position = (int) rx_body[0] & (0xff);
- //Log.v(TAG, " FIRST DATA POS. : " + data_position);
- //SimpleLogDumper.dump_bytes(" [sssss]", Arrays.copyOfRange(rx_body, 0, (64)));
+ Log.v(TAG, " FIRST DATA POS. : " + data_position);
+ SimpleLogDumper.dump_bytes(" [sssss]", Arrays.copyOfRange(rx_body, 0, (512)));
}
else if (received_remain_bytes > 0)
{
}
// 受信データ(のヘッダ部分)をダンプする
- Log.v(TAG, " RX DATA : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] (" + received_total_bytes + ")");
- SimpleLogDumper.dump_bytes(" [zzz] " + data_position + ": ", Arrays.copyOfRange(rx_body, data_position, (data_position + 48)));
+ //Log.v(TAG, " RX DATA : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] (" + received_total_bytes + ")");
+ //SimpleLogDumper.dump_bytes(" [zzz] " + data_position + ": ", Arrays.copyOfRange(rx_body, data_position, (data_position + 48)));
if ((data_position + body_size) > length) {
// データがすべてバッファ内になかったときは、バッファすべてコピーして残ったサイズを記憶しておく。
@Override
public boolean isReceiveMulti()
{
- return (true);
+ return (false);
}
}
import android.util.Log;
+import androidx.annotation.Nullable;
+
public class PtpIpResponseReceiver implements IPtpIpCommandCallback
{
private final String TAG = toString();
+ private final IPtpIpResponseReceiver callback;
- public PtpIpResponseReceiver()
+ public PtpIpResponseReceiver(@Nullable IPtpIpResponseReceiver callback)
{
- //
+ this.callback = callback;
}
@Override
public void receivedMessage(int id, byte[] rx_body)
{
+ int responseCode = 0;
if (rx_body != null)
{
try
{
if (rx_body.length > 10)
{
- int responseCode = (rx_body[9] & 0xff) + ((rx_body[10] & 0xff) * 256);
- Log.v(TAG, String.format(" ID : %d, RESPONSE CODE : 0x%x ", id, responseCode));
+ responseCode = (rx_body[8] & 0xff) + ((rx_body[9] & 0xff) * 256);
+ Log.v(TAG, String.format(" ID : %d, RESPONSE CODE : 0x%04x ", id, responseCode));
}
else
{
{
Log.v(TAG, " receivedMessage() " + id);
}
+ if (callback != null)
+ {
+ callback.response(id, responseCode);
+ }
}
@Override