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 net.osdn.gokigen.a01d.camera.utils.SimpleLogDumper;
import net.osdn.gokigen.a01d.liveview.liveviewlistener.IImageDataReceiver;
import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
import java.util.Map;
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_CHECK_EVENT;
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_DEVICE_PROP1;
+import static net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpMessages.SEQ_GET_DEVICE_PROP2;
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;
//SimpleLogDumper.dump_bytes(" [LVLV] " + ": ", Arrays.copyOfRange(data, 0, (0 + 512)));
//dataReceiver.setImageData(data, metadata);
int offset = searchJpegHeader(data);
- if (data.length > 8)
+ if ((data.length > 8)&&(offset < data.length))
{
dataReceiver.setImageData(Arrays.copyOfRange(data, offset, data.length), metadata); // ヘッダ部分を切り取って送る
}
{
e.printStackTrace();
}
+ //commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP1, 30, isDumpLog, 0, 0x1015, 4, 0x5007, 0x00, 0x00, 0x00));
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_CHECK_EVENT, 30, isDumpLog, 0, 0x90c7, 0, 0x00, 0x00, 0x00, 0x00));
commandIssued = false;
}
@Override
public void receivedMessage(int id, byte[] rx_body)
{
- Log.v(TAG, " NikonLiveViewControl::receivedMessage() : ");
+ Log.v(TAG, " NikonLiveViewControl::receivedMessage() [id:" + id + "]");
try
{
if (rx_body.length < 10)
{
+ Log.v(TAG, " NikonLiveViewControl::receivedMessage() : BODY LENGTH IS TOO SHORT. SEND RETRY MESSAGE");
retrySendMessage(id);
return;
}
+/**/
int responseCode = (rx_body[8] & 0xff) + ((rx_body[9] & 0xff) * 256);
+ if (id == SEQ_CHECK_EVENT)
+ {
+ // 応答にはデータが含まれているので....受信データの末尾を拾う
+ //SimpleLogDumper.dump_bytes("CHECK EVENT", Arrays.copyOfRange(rx_body, 0, Math.min(rx_body.length, 128)));
+ responseCode = (rx_body[rx_body.length - 6] & 0xff) + ((rx_body[rx_body.length - 5] & 0xff) * 256);
+ }
+/**/
+ //int responseCode = (rx_body[rx_body.length - 6] & 0xff) + ((rx_body[rx_body.length - 5] & 0xff) * 256);
if (responseCode != 0x2001)
{
// NG応答を受信...同じコマンドを再送する
return;
}
- Log.v(TAG, String.format(" OK REPLY (ID : %d) ", id));
+ Log.v(TAG, String.format(" ----- OK REPLY (ID : %d) ----- ", id));
if (id == SEQ_START_LIVEVIEW)
{
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_DEVICE_READY, 30, isDumpLog, 0, 0x90c8, 0, 0x00, 0x00, 0x00, 0x00));
{
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 30, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));
}
- else
+ else if (id == SEQ_CHECK_EVENT)
+ {
+ commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 35, isDumpLog));
+ }
+ else if (id == SEQ_GET_DEVICE_PROP1)
+ {
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP2, 30, isDumpLog, 0, 0x1015, 4, 0xd100, 0x00, 0x00, 0x00));
+ }
+ else if (id == SEQ_GET_DEVICE_PROP2)
+ {
+ commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 35, isDumpLog));
+ }
+ else // SEQ_AFDRIVE
{
// ライブビューの開始。
- startLiveviewImpl();
+ //startLiveviewImpl();
+ commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 80, isDumpLog));
}
}
catch (Exception e)
}
}
+ private void waitSleep()
+ {
+ try
+ {
+ Thread.sleep(delayMs);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
private void retrySendMessage(int id)
{
try
{
+ waitSleep();
if (id == SEQ_START_LIVEVIEW)
{
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_START_LIVEVIEW, 30, isDumpLog, 0, 0x9201, 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_CHECK_EVENT)
+ {
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_CHECK_EVENT, 30, isDumpLog, 0, 0x90c7, 0, 0x00, 0x00, 0x00, 0x00));
+ }
+ else if (id == SEQ_GET_DEVICE_PROP1)
+ {
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP1, 30, isDumpLog, 0, 0x5007, 4, 0x5007, 0x00, 0x00, 0x00));
+ }
+ else if (id == SEQ_GET_DEVICE_PROP2)
+ {
+ commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP2, 30, isDumpLog, 0, 0x1015, 4, 0xd100, 0x00, 0x00, 0x00));
+ }
else
{
commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_AFDRIVE, 30, isDumpLog, 0, 0x90c1, 0, 0x00, 0x00, 0x00, 0x00));