{
delayMs = COMMAND_SEND_RECEIVE_DURATION_MS;
}
- Thread.sleep(delayMs);
- receive_from_camera(command.dumpLog(), command.getId(), command.responseCallback());
+ receive_from_camera(command.dumpLog(), command.getId(), command.responseCallback(), command.receiveAgainShortLengthMessage(), delayMs);
}
catch (Exception e)
{
}
}
+ private void sleep(int delayMs)
+ {
+ try
+ {
+ Thread.sleep(delayMs);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
/**
* カメラからにコマンドの結果を受信する(メイン部分)
*
*/
- private void receive_from_camera(boolean isDumpReceiveLog, int id, IFujiXCommandCallback callback)
+ private void receive_from_camera(boolean isDumpReceiveLog, int id, IFujiXCommandCallback callback, boolean receiveAgain, int delayMs)
{
try
{
-
+ sleep(delayMs);
byte[] byte_array = new byte[BUFFER_SIZE];
InputStream is = socket.getInputStream();
if (is != null)
byte[] receive_body;
if (read_bytes > 4)
{
+ if (receiveAgain)
+ {
+ int length = ((((int) byte_array[3]) & 0xff) << 24) + ((((int) byte_array[2]) & 0xff) << 16) + ((((int) byte_array[1]) & 0xff) << 8) + (((int) byte_array[0]) & 0xff);
+ if ((length > read_bytes)||((length == read_bytes)&&((int) byte_array[4] == 0x02)))
+ {
+ // データについて、もう一回受信が必要な場合...
+ Log.v(TAG, "--- RECEIVE AGAIN --- [" + length + "(" + read_bytes + ") " + byte_array[4]+ "] ");
+ sleep(delayMs);
+ int read_bytes2 = is.read(byte_array, read_bytes, BUFFER_SIZE - read_bytes);
+ if (read_bytes2 > 0)
+ {
+ read_bytes = read_bytes + read_bytes2;
+ }
+ }
+ }
receive_body = Arrays.copyOfRange(byte_array, 0, read_bytes);
}
else
Log.v(TAG, "receive_from_camera() : " + read_bytes + " bytes.");
dump_bytes(isDumpReceiveLog, "RECV[" + receive_body.length + "] ", receive_body);
}
- if (callback != null)
+ if (callback != null)
{
callback.receivedMessage(id, receive_body);
}
public void receivedMessage(int id, byte[] rx_body)
{
//Log.v(TAG, "receivedMessage : " + id + "[" + rx_body.length + " bytes]");
+ int bodyLength = 0;
switch (id)
{
case SEQ_REGISTRATION:
break;
case SEQ_STATUS_REQUEST:
- if ((rx_body[4] == (byte) 0x02)&&((int) rx_body[0] == rx_body.length))
+ bodyLength = ((((int) rx_body[3]) & 0xff) << 24) + ((((int) rx_body[2]) & 0xff) << 16) + ((((int) rx_body[1]) & 0xff) << 8) + (((int) rx_body[0]) & 0xff);
+/*
+ if ((rx_body[4] == (byte) 0x02)&&(bodyLength == rx_body.length))
{
//// 受信データが分割されている場合、、もう一度受信する
+ Log.v(TAG, "] BODY : " + rx_body.length + " BodyLength : " + bodyLength + " [");
commandIssuer.enqueueCommand(new StatusRequestReceive(this));
}
else
+*/
{
+ Log.v(TAG, "[ BODY : " + rx_body.length + " BodyLength : " + bodyLength + " ]");
commandIssuer.enqueueCommand(new QueryCameraCapabilities(this));
}
break;
break;
case SEQ_QUERY_CAMERA_CAPABILITIES:
- int bodyLength = ((((int) rx_body[3]) & 0xff) << 24) + ((((int) rx_body[2]) & 0xff) << 16) + ((((int) rx_body[1]) & 0xff) << 8) + (((int) rx_body[0]) & 0xff);
- if (bodyLength > rx_body.length)
+ bodyLength = ((((int) rx_body[3]) & 0xff) << 24) + ((((int) rx_body[2]) & 0xff) << 16) + ((((int) rx_body[1]) & 0xff) << 8) + (((int) rx_body[0]) & 0xff);
+/*
+ if ((rx_body[4] == (byte) 0x02)&&(bodyLength == rx_body.length))
{
- Log.v(TAG, "> BODY : " + rx_body.length + " BodyLength : " + bodyLength);
+ //// 受信データが分割されている場合、、もう一度受信する
+ Log.v(TAG, "> BODY : " + rx_body.length + " BodyLength : " + bodyLength + " <");
commandIssuer.enqueueCommand(new StartReceiveOnly2(this));
}
else
+*/
{
- Log.v(TAG, "> BODY : " + rx_body.length + " BodyLength : " + bodyLength);
+ Log.v(TAG, "< BODY : " + rx_body.length + " BodyLength : " + bodyLength + " >");
commandIssuer.enqueueCommand(new CameraRemoteMessage(this));
}
break;