private final String TAG = this.toString();
private final PtpIpCommandPublisher commandPublisher;
//private final IAutoFocusFrameDisplay frameDisplayer;
- private boolean isDumpLog = true;
+ private boolean isDumpLog = false;
public NikonCaptureControl(@NonNull PtpIpCommandPublisher commandPublisher, IAutoFocusFrameDisplay frameDisplayer)
{
private float maxPointLimitWidth;
private float maxPointLimitHeight;
private RectF preFocusFrameRect = null;
- private boolean isDumpLog = true;
+ private boolean isDumpLog = false;
public NikonFocusingControl(@NonNull Activity context, @NonNull PtpIpCommandPublisher commandPublisher, IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator)
{
@Override
public boolean isReceiveMulti()
{
- return (true);
+ return (false);
}
}
{
this.activity = context;
commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT);
- liveViewControl = new NikonLiveViewControl(context, this, 20);
+ liveViewControl = new NikonLiveViewControl(context, this, 40);
asyncReceiver = new PtpIpAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
statusChecker = new NikonStatusChecker(activity, commandPublisher, CAMERA_IP, EVENT_PORT);
canonConnection = new NikonConnection(context, provider, this, statusChecker);
@Override
public int maxRetryCount()
{
- return (5);
+ return (1);
}
@Override
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(this, SEQ_START_LIVEVIEW, 20, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_START_LIVEVIEW, 30, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
}
catch (Exception e)
{
if (!commandIssued)
{
commandIssued = true;
- commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 30, isDumpLog));
+ commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 65, isDumpLog));
}
try
{
Log.v(TAG, String.format(" OK REPLY (ID : %d) ", id));
if (id == SEQ_START_LIVEVIEW)
{
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 20, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 30, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
}
else if (id == SEQ_DEVICE_READY)
{
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 20, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 30, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
}
else
{
{
if (id == SEQ_START_LIVEVIEW)
{
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_START_LIVEVIEW, 20, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_START_LIVEVIEW, 30, isDumpLog, 0, 0x9201, 0, 0x00, 0x00, 0x00, 0x00));
}
else if (id == SEQ_DEVICE_READY)
{
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 20, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 30, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
}
else
{
- commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 20, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 30, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
}
}
catch (Exception e)
private int received_total_bytes = 0;
private int received_remain_bytes = 0;
- private int target_image_size = 0;
+ //private int target_image_size = 0;
private boolean receivedFirstData = false;
private ByteArrayOutputStream byteStream;
{
body_length = rx_body.length;
}
- Log.v(TAG, " receivedMessage_multi() id[" + id + "] size : " + body_length + " target length : " + target_image_size + " ");
+ Log.v(TAG, " receivedMessage_multi() id[" + id + "] size : " + body_length + " ");
+ //Log.v(TAG, " receivedMessage_multi() id[" + id + "] size : " + body_length + " target length : " + target_image_size + " ");
// end of receive sequence.
//byte [] thumbnail = byteStream.toByteArray();
//Log.v(TAG, " TransferComplete() RECEIVED id[" + id + "] size : " + target_image_size + " (" + thumbnail.length + ")");
//SimpleLogDumper.dump_bytes(" [xxxxx]", Arrays.copyOfRange(thumbnail, 0, (512)));
//SimpleLogDumper.dump_bytes(" [zzzzz]", Arrays.copyOfRange(thumbnail, (thumbnail.length - 128), (thumbnail.length)));
- callback.onCompleted(byteStream.toByteArray(), null);
//callback.onCompleted(rx_body, null);
+ callback.onCompleted(byteStream.toByteArray(), null);
receivedFirstData = false;
received_remain_bytes = 0;
received_total_bytes = 0;
- target_image_size = 0;
+ //target_image_size = 0;
byteStream.reset();
}
catch (Exception e)
int body_size = (rx_body[data_position] & 0xff) + ((rx_body[data_position + 1] & 0xff) << 8) + ((rx_body[data_position + 2] & 0xff) << 16) + ((rx_body[data_position + 3] & 0xff) << 24);
if (body_size <= 12)
{
- Log.v(TAG, " --- BODY SIZE IS SMALL : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] " + rx_body.length + " (" + target_image_size + ")");
+ Log.v(TAG, " ----- BODY SIZE IS SMALL : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] " + rx_body.length + " ");
+ //Log.v(TAG, " --- BODY SIZE IS SMALL : " + data_position + " (" + body_size + ") [" + received_remain_bytes + "] " + rx_body.length + " (" + target_image_size + ")");
//int startpos = (data_position > 48) ? (data_position - 48) : 0;
//SimpleLogDumper.dump_bytes(" [xxx]", Arrays.copyOfRange(rx_body, startpos, (data_position + 48)));
break;
import androidx.annotation.NonNull;
+import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
+
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
if (read_bytes < 0)
{
// リトライオーバー...
- Log.v(TAG, " RECEIVE : RETRY OVER......");
+ Log.v(TAG, " RECEIVE : RETRY OVER...... : " + delayMs + "ms x " + command.maxRetryCount());
if (command.isRetrySend())
{
// 要求を再送する場合、、、ダメな場合は受信待ちとする
}
}
- // 初回データの読み込み
- read_bytes = is.read(byte_array, 0, receive_message_buffer_size);
- int target_length = parseDataLength(byte_array, read_bytes);
- int received_length = read_bytes;
+ boolean read_retry = false;
+ int target_length = 0;
+ int received_length = 0;
- if (target_length <= 0)
+ do
{
- // 受信サイズ異常の場合...
- Log.v(TAG, " WRONG LENGTH. : " + target_length);
- callback.receivedMessage(id, null);
- return (false);
- }
+ // 初回データの読み込み...
+ read_bytes = is.read(byte_array, 0, receive_message_buffer_size);
+ target_length = parseDataLength(byte_array, read_bytes);
+ received_length = read_bytes;
+ if (target_length <= 0)
+ {
+ // 受信サイズ異常の場合...
+ if (received_length > 0)
+ {
+ SimpleLogDumper.dump_bytes("WRONG DATA : ", Arrays.copyOfRange(byte_array, 0, (Math.min(received_length, 64))));
+ }
+ Log.v(TAG, " WRONG LENGTH. : " + target_length + " READ : " + received_length + " bytes.");
+ callback.receivedMessage(id, null);
+ return (false);
+ }
+
+ } while (read_retry);
// 一時的な処理
if (callback != null)
{
- Log.v(TAG, " --- 1st CALL : read_bytes : "+ read_bytes + "(" + received_length + ") : target_length : " + target_length + " buffer SIZE : " + byte_array.length);
+ Log.v(TAG, " -=-=-=- 1st CALL : read_bytes : "+ read_bytes + "(" + received_length + ") : target_length : " + target_length + " buffer SIZE : " + byte_array.length);
callback.onReceiveProgress(received_length, target_length, Arrays.copyOfRange(byte_array, 0, received_length));
}
private int parseDataLength(byte[] byte_array, int read_bytes)
{
+ int offset = 0;
int lenlen = 0;
//int packetType = 0;
try
{
- if ((read_bytes > 20)&&((int) byte_array[4] == 0x09))
+ if (read_bytes > 20)
{
- 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);
+ if ((int) byte_array[offset + 4] == 0x07)
+ {
+ // 前の応答が入っていると考える...
+ offset = 14;
+ }
+
+ if (((int) byte_array[offset + 4] == 0x09))
+ {
+ lenlen = ((((int) byte_array[offset + 15]) & 0xff) << 24) + ((((int) byte_array[offset + 14]) & 0xff) << 16) + ((((int) byte_array[offset + 13]) & 0xff) << 8) + (((int) byte_array[offset + 12]) & 0xff);
+ //packetType = (((int)byte_array[offset + 16]) & 0xff);
+ }
}
- //Log.v(TAG, " --- parseDataLength() length: " + lenlen + " TYPE: " + packetType + " read_bytes: " + read_bytes);
+ //Log.v(TAG, " --- parseDataLength() length: " + lenlen + " TYPE: " + packetType + " read_bytes: " + read_bytes + " offset : " + offset);
}
catch (Exception e)
{
Log.v(TAG, " <><><> PACKET TYPE : " + packetType + " LENGTH : " + lenlen);
}
*/
- int copyByte = ((lenlen - 12) > (limit - (position + 12))) ? (limit - (position + 12)) : (lenlen - 12);
+ int copyByte = Math.min((limit - (position + 12)), (lenlen - 12));
outputStream.write(byte_array, (position + 12), copyByte);
position = position + lenlen;
}
{
sleep(delayMs);
read_bytes = is.available();
- if (read_bytes == 0)
+ if (read_bytes <= 0)
{
if (isLogOutput)
{