From: MRSa Date: Sat, 22 Feb 2020 14:43:37 +0000 (+0900) Subject: NIKON対応途中。 X-Git-Url: http://git.osdn.net/view?p=gokigen%2FA01d.git;a=commitdiff_plain;h=c4ce68be83fd47d87cb25072daf3d5dc5b56eff9 NIKON対応途中。 --- diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/command/messages/specific/NikonRegistrationMessage.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/command/messages/specific/NikonRegistrationMessage.java index 12f7ae0..2238ffe 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/command/messages/specific/NikonRegistrationMessage.java +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/command/messages/specific/NikonRegistrationMessage.java @@ -6,7 +6,6 @@ import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback; import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandBase; import java.nio.ByteBuffer; -import java.util.UUID; public class NikonRegistrationMessage extends PtpIpCommandBase { @@ -56,7 +55,7 @@ public class NikonRegistrationMessage extends PtpIpCommandBase @Override public byte[] commandBody() { - int uuid = UUID.randomUUID().hashCode(); + //int uuid = UUID.randomUUID().hashCode(); byte[] typeArray = { (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x00, diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/connection/NikonCameraConnectSequence.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/connection/NikonCameraConnectSequence.java index 957df30..9b445fb 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/connection/NikonCameraConnectSequence.java +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/connection/NikonCameraConnectSequence.java @@ -27,7 +27,7 @@ public class NikonCameraConnectSequence implements Runnable, IPtpIpCommandCallba private final IPtpIpInterfaceProvider interfaceProvider; private final IPtpIpCommandPublisher commandIssuer; private final NikonStatusChecker statusChecker; - private boolean isDumpLog = true; + private boolean isDumpLog = false; NikonCameraConnectSequence(@NonNull Activity context, @NonNull ICameraStatusReceiver statusReceiver, @NonNull final ICameraConnection cameraConnection, @NonNull IPtpIpInterfaceProvider interfaceProvider, @NonNull NikonStatusChecker statusChecker) { diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewControl.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewControl.java index 6c36f2a..4cfbf62 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewControl.java +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewControl.java @@ -7,9 +7,9 @@ import androidx.annotation.NonNull; 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; @@ -25,7 +25,7 @@ import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages. 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; @@ -34,7 +34,7 @@ public class NikonLiveViewControl implements ILiveViewControl, ILiveViewListene 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) { @@ -60,9 +60,9 @@ public class NikonLiveViewControl implements ILiveViewControl, ILiveViewListene 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) { @@ -74,10 +74,13 @@ public class NikonLiveViewControl implements ILiveViewControl, ILiveViewListene 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) { @@ -127,9 +130,6 @@ public class NikonLiveViewControl implements ILiveViewControl, ILiveViewListene } } - - - @Override public void updateDigitalZoom() { @@ -204,4 +204,18 @@ public class NikonLiveViewControl implements ILiveViewControl, ILiveViewListene 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)); + } + } } diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewImageReceiver.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewImageReceiver.java index ad2db78..a690a62 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewImageReceiver.java +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewImageReceiver.java @@ -59,7 +59,7 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback @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); @@ -78,8 +78,8 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback // データを最初に読んだとき。ヘッダ部分を読み飛ばす 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) { @@ -111,8 +111,8 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback } // 受信データ(のヘッダ部分)をダンプする - 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) { // データがすべてバッファ内になかったときは、バッファすべてコピーして残ったサイズを記憶しておく。 @@ -139,7 +139,7 @@ public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback @Override public boolean isReceiveMulti() { - return (true); + return (false); } } diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/IPtpIpResponseReceiver.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/IPtpIpResponseReceiver.java new file mode 100644 index 0000000..e5c7973 --- /dev/null +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/IPtpIpResponseReceiver.java @@ -0,0 +1,6 @@ +package net.osdn.gokigen.a01d.camera.ptpip.wrapper.command; + +public interface IPtpIpResponseReceiver +{ + void response(int id, int responseCode); +} diff --git a/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpResponseReceiver.java b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpResponseReceiver.java index d53890b..f9e4957 100644 --- a/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpResponseReceiver.java +++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpResponseReceiver.java @@ -2,26 +2,30 @@ package net.osdn.gokigen.a01d.camera.ptpip.wrapper.command; 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 { @@ -37,6 +41,10 @@ public class PtpIpResponseReceiver implements IPtpIpCommandCallback { Log.v(TAG, " receivedMessage() " + id); } + if (callback != null) + { + callback.response(id, responseCode); + } } @Override