--- /dev/null
+package net.osdn.gokigen.a01d.camera.nikon.wrapper.command.messages.specific;
+
+import androidx.annotation.NonNull;
+
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
+import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.messages.PtpIpCommandBase;
+
+public class NikonLiveViewRequestMessage extends PtpIpCommandBase
+{
+ private final IPtpIpCommandCallback callback;
+ private final boolean isDumpLog;
+ private final int delayMs;
+
+ public NikonLiveViewRequestMessage(@NonNull IPtpIpCommandCallback callback,int delayMs, boolean isDumpLog)
+ {
+ this.callback = callback;
+ this.delayMs = delayMs;
+ this.isDumpLog = isDumpLog;
+ }
+
+ @Override
+ public IPtpIpCommandCallback responseCallback()
+ {
+ return (callback);
+ }
+
+ @Override
+ public int getId()
+ {
+ return (SEQ_GET_VIEWFRAME);
+ }
+
+ @Override
+ public byte[] commandBody()
+ {
+ return (new byte[]{
+
+ // packet type
+ (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+
+ // data phase info
+ (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+
+ // operation code
+ (byte) 0x03, (byte) 0x92,
+
+ // sequence number
+ (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
+ });
+ }
+
+ @Override
+ public boolean dumpLog()
+ {
+ return (isDumpLog);
+ }
+
+ @Override
+ public int receiveDelayMs()
+ {
+ return (delayMs);
+ }
+
+ @Override
+ public boolean isRetrySend()
+ {
+ return (true);
+ }
+
+ @Override
+ public int maxRetryCount()
+ {
+ return (5);
+ }
+
+}
import androidx.annotation.NonNull;
import net.osdn.gokigen.a01d.camera.ILiveViewControl;
+import net.osdn.gokigen.a01d.camera.nikon.wrapper.command.messages.specific.NikonLiveViewRequestMessage;
import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_AFDRIVE;
import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_DEVICE_READY;
-import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_GET_VIEWFRAME;
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;
private IImageDataReceiver dataReceiver = null;
private boolean liveViewIsReceiving = false;
private boolean commandIssued = false;
- private boolean isDumpLog = false;
+ private boolean isDumpLog = true;
public NikonLiveViewControl(@NonNull Activity context, @NonNull IPtpIpInterfaceProvider interfaceProvider, int delayMs)
{
if (!commandIssued)
{
commandIssued = true;
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(imageReceiver, SEQ_GET_VIEWFRAME, 80, true, 0, 0x9203, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 90, isDumpLog));
}
try
{
// リトライオーバー発生時、コマンドを再送するか?
boolean isRetrySend();
+
+ // 受信待ち再試行回数
+ int maxRetryCount();
}
import androidx.annotation.NonNull;
-import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
-
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
}
// 初回データが受信バッファにデータが溜まるまで待つ...
- int read_bytes = waitForReceive(is, delayMs);
+ int read_bytes = waitForReceive(is, delayMs, command.maxRetryCount());
if (read_bytes < 0)
{
// リトライオーバー...
private boolean receive_multi(@NonNull IPtpIpCommand command, int delayMs)
{
//int estimatedSize = command.estimatedReceiveDataSize();
- int maxRetryCount = 20;
+ int maxRetryCount = command.maxRetryCount();
int id = command.getId();
IPtpIpCommandCallback callback = command.responseCallback();
}
// 初回データが受信バッファにデータが溜まるまで待つ...
- int read_bytes = waitForReceive(is, delayMs);
+ int read_bytes = waitForReceive(is, delayMs, command.maxRetryCount());
if (read_bytes < 0)
{
// リトライオーバー...
}
//byteStream.write(byte_array, 0, read_bytes);
- maxRetryCount = 20;
+ maxRetryCount = command.maxRetryCount();
//do
{
sleep(delayMs);
if (callback != null)
{
Log.v(TAG, " --- receive_multi : " + id + " (" + read_bytes + ") [" + maxRetryCount + "] " + receive_message_buffer_size + " (" + received_length + ") ");
- callback.receivedMessage(id, null);
+ try
+ {
+ callback.receivedMessage(id, Arrays.copyOfRange(byte_array, 0, received_length));
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
}
catch (Throwable e)
if (packetType == 0x09)
{
lenlen = ((((int) byte_array[15]) & 0xff) << 24) + ((((int) byte_array[14]) & 0xff) << 16) + ((((int) byte_array[13]) & 0xff) << 8) + (((int) byte_array[12]) & 0xff);
- packetType = (((int) byte_array[16]) & 0xff);
+ //packetType = (((int) byte_array[16]) & 0xff);
}
// Log.v(TAG, " --- RECEIVED MESSAGE : " + len + " bytes (BUFFER: " + byte_array.length + " bytes)" + " length : " + lenlen + " TYPE : " + packetType + " --- ");
if (lenlen == 0)
while (position < limit)
{
lenlen = ((((int) byte_array[position + 3]) & 0xff) << 24) + ((((int) byte_array[position + 2]) & 0xff) << 16) + ((((int) byte_array[position + 1]) & 0xff) << 8) + (((int) byte_array[position]) & 0xff);
- packetType = (((int) byte_array[position + 4]) & 0xff);
/*
+ packetType = (((int) byte_array[position + 4]) & 0xff);
if (packetType != 0x0a)
{
Log.v(TAG, " <><><> PACKET TYPE : " + packetType + " LENGTH : " + lenlen);
return (receivedBuffer);
}
- private int waitForReceive(InputStream is, int delayMs)
+ private int waitForReceive(InputStream is, int delayMs, int retry_count)
{
boolean isLogOutput = true;
- int retry_count = 50;
int read_bytes = 0;
try
{
{
return (true);
}
+
+ @Override
+ public int maxRetryCount()
+ {
+ return (20);
+ }
}