int y = (0x0000ffff & (Math.round(point.y * maxPointLimitHeight) + 1));
Log.v(TAG, "Lock AF: [" + x + ","+ y + "]");
commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_LOCK, isDumpLog, 0, 0x9205, 8, x, y));
- commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));
-
+ //commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));
}
catch (Exception e)
{
if ((id == FOCUS_LOCK)||(id == FOCUS_LOCK_PRE))
{
Log.v(TAG, "FOCUS LOCKED");
+ commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1)); // OKのときは駆動
if (preFocusFrameRect != null)
{
// showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Focused, 1.0); // 1秒だけ表示
@Override
public boolean isReceiveMulti()
{
- return (false);
+ return (true);
}
}
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;
if (!commandIssued)
{
commandIssued = true;
- commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 90, isDumpLog));
+ commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 30, isDumpLog));
}
try
{
//Log.v(TAG, " ---+++--- RECEIVED LV IMAGE ---+++--- : " + data.length + " bytes.");
//SimpleLogDumper.dump_bytes(" [LVLV] " + ": ", Arrays.copyOfRange(data, 0, (0 + 512)));
//dataReceiver.setImageData(data, metadata);
- int offset = 384;
+ int offset = searchJpegHeader(data);
if (data.length > 8)
{
dataReceiver.setImageData(Arrays.copyOfRange(data, offset, data.length), metadata); // ヘッダ部分を切り取って送る
commandIssued = false;
}
+ private int searchJpegHeader(byte[] data)
+ {
+ try
+ {
+ int pos = 0;
+
+ // 先頭の 1024bytesまで
+ int limit = (data.length < 1024) ? (data.length - 1): 1024;
+ while (pos < limit)
+ {
+ if ((data[pos] == (byte) 0xff)&&(data[pos + 1] == (byte) 0xd8))
+ {
+
+ return (pos);
+ }
+ pos++;
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return (384);
+ }
+
+
@Override
public void onErrorOccurred(Exception e)
{
import androidx.annotation.NonNull;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
import net.osdn.gokigen.a01d.camera.ptpip.wrapper.liveview.IPtpIpLiveViewImageCallback;
+import net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
public class NikonLiveViewImageReceiver implements IPtpIpCommandCallback
{
@Override
public void receivedMessage(int id, byte[] rx_body)
{
+ if (isReceiveMulti())
+ {
+ receivedMessage_multi(id, rx_body);
+ }
+ else
+ {
+ receivedMessage_single(id, rx_body);
+ }
+ }
+
+ @Override
+ public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
+ {
+ int body_length = 0;
+ if (rx_body != null)
+ {
+ body_length = rx_body.length;
+ }
+ Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes + " LENGTH: " + body_length + " bytes.");
+
+ // 受信したデータから、通信のヘッダ部分を削除する
+ cutHeader(rx_body);
+ }
+
+ private void receivedMessage_single(int id, byte[] rx_body)
+ {
try
{
+ if (rx_body != null)
+ {
+ Log.v(TAG, "receivedMessage_single() : " + rx_body.length + " bytes.");
+ if (rx_body.length > 64)
+ {
+ SimpleLogDumper.dump_bytes(" LV (FIRST) : ", Arrays.copyOfRange(rx_body, 0, 64));
+ SimpleLogDumper.dump_bytes(" LV (-END-) : ", Arrays.copyOfRange(rx_body, (rx_body.length - 64), rx_body.length));
+ }
+ callback.onCompleted(rx_body, null);
+ }
+ else
+ {
+ Log.v(TAG, "receivedMessage_single() : NULL");
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void receivedMessage_multi(int id, byte[] rx_body)
+ {
+ try
+ {
+ int body_length = 0;
+ if (rx_body != null)
+ {
+ body_length = rx_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();
+ //byte [] thumbnail = byteStream.toByteArray();
//byte [] thumbnail = rx_body;
- Log.v(TAG, " TransferComplete() RECEIVED id[" + id + "] size : " + target_image_size + " (" + thumbnail.length + ")");
+ //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);
}
}
- @Override
- public void onReceiveProgress(final int currentBytes, final int totalBytes, byte[] rx_body)
- {
- //Log.v(TAG, " onReceiveProgress() " + currentBytes + "/" + totalBytes);
-
- // 受信したデータから、通信のヘッダ部分を削除する
- cutHeader(rx_body);
- }
-
private void cutHeader(byte[] rx_body)
{
if (rx_body == null)
// コマンドを再送信しない場合はここで抜ける
break;
}
- // 再送信...のために、シーケンス番号を戻す...
- sequenceNumber--;
+ if (!command.isIncrementSequenceNumberToRetry())
+ {
+ // 再送信...のために、シーケンス番号を戻す...
+ sequenceNumber--;
+ }
}
}
}
if (is == null)
{
Log.v(TAG, " InputStream is NULL... RECEIVE ABORTED.");
+ receivedAllMessage(isDumpReceiveLog, id, null, callback);
return (false);
}
{
// リトライオーバー...
Log.v(TAG, " RECEIVE : RETRY OVER...");
+ if (!command.isRetrySend())
+ {
+ // 再送しない場合には、応答がないことを通知する
+ receivedAllMessage(isDumpReceiveLog, id, null, callback);
+ }
return (true);
}