class NikonLiveViewImageReceiver(private var callback: IPtpIpLiveViewImageCallback) : IPtpIpCommandCallback
{
- private val isDumpLog = true
+ private val isDumpLog = false
private var receivedTotalBytes = 0
private var receivedRemainBytes = 0
private var receivedFirstData = false
{
if (rx_body == null)
{
- Log.v(TAG, " MSG BODY IS NULL. $id")
+ Log.v(TAG, " NikonLiveViewImageReceiver: MSG BODY IS NULL. (ID:$id)")
+ callback.onCompleted(rx_body, null)
return
}
if (isReceiveMulti)
{
if (rx_body == null)
{
- Log.v(TAG, " MSG BODY IS NULL.")
+ Log.v(TAG, " NikonLiveViewImageReceiver: MSG BODY IS NULL.")
return
}
Log.v(TAG, " onReceiveProgress() $currentBytes/$totalBytes LENGTH: ${rx_body.size} bytes.")
while (dataPosition <= length - 12)
{
val body_size = (rx_body[dataPosition].toUByte()).toInt() + ((rx_body[dataPosition + 1].toUByte()).toInt() * 256) + ((rx_body[dataPosition + 2].toUByte()).toInt() * 256 * 256) + ((rx_body[dataPosition + 3].toUByte()).toInt() * 256 * 256 * 256)
-
- Log.v(TAG, " XX body_size : ${body_size} [$dataPosition] ($length) aa: ${rx_body[dataPosition].toUByte().toInt()} ${rx_body[dataPosition + 1].toUByte().toInt()} + ${rx_body[dataPosition + 2].toUByte().toInt()}")
- SimpleLogDumper.dump_bytes("XX", Arrays.copyOfRange(rx_body, 0, 32))
+ //Log.v(TAG, " <> body_size : ${body_size} [$dataPosition] ($length) aa: ${rx_body[dataPosition].toUByte().toInt()} ${rx_body[dataPosition + 1].toUByte().toInt()} + ${rx_body[dataPosition + 2].toUByte().toInt()}")
if (body_size <= 12)
{
Log.v(TAG, " ----- BODY SIZE IS SMALL : " + dataPosition + " (" + body_size + ") [" + receivedRemainBytes + "] " + rx_body.size + " ")
break
}
- // 受信データ(のヘッダ部分)をダンプする
- Log.v(TAG, " RX DATA : " + dataPosition + " (" + body_size + ") [" + receivedRemainBytes + "] (" + receivedTotalBytes + ")");
+ //Log.v(TAG, " RX DATA : " + dataPosition + " (" + body_size + ") [" + receivedRemainBytes + "] (" + receivedTotalBytes + ")");
if (dataPosition + body_size > length)
{
// データがすべてバッファ内になかったときは、バッファすべてコピーして残ったサイズを記憶しておく。
private fun receivedAllMessage(isDumpReceiveLog: Boolean, id: Int, body: ByteArray?, callback: IPtpIpCommandCallback?)
{
Log.v(TAG, "receivedAllMessage() : " + (body?.size ?: 0) + " bytes.")
- if (isDumpReceiveLog && body != null)
+ if ((isDumpReceiveLog)&&(body != null))
{
// ログに受信メッセージを出力する
SimpleLogDumper.dump_bytes("RECV[" + body.size + "] ", body)
private fun receiveMulti(command: IPtpIpCommand, delayMs: Int): Boolean
{
- //int estimatedSize = command.estimatedReceiveDataSize();
+ val isDumpLog = command.dumpLog()
var maxRetryCount = command.maxRetryCount()
val id = command.id
val callback = command.responseCallback()
try
{
- Log.v(TAG, " ===== receive_multi() =====")
+ // Log.v(TAG, " ===== receive_multi() =====")
val receiveMessageBufferSize = BUFFER_SIZE
val byteArray = ByteArray(receiveMessageBufferSize)
val inputStream = socket?.getInputStream()
if (command.isRetrySend)
{
// 要求を再送する場合、、、ダメな場合は受信待ちとする
+ Log.v(TAG, " --- SEND RETRY ---")
return (true)
}
}
if (targetLength <= 0)
{
// 受信サイズ異常の場合...
- if (receivedLength > 0)
+ if (isDumpLog)
{
- SimpleLogDumper.dump_bytes("WRONG DATA : ", byteArray.copyOfRange(0, Math.min(receivedLength, 64)))
+ if (receivedLength > 0)
+ {
+ SimpleLogDumper.dump_bytes("WRONG DATA : ", byteArray.copyOfRange(0, Math.min(receivedLength, 64)))
+ }
+ Log.v(TAG, " WRONG LENGTH. : $targetLength READ : $receivedLength bytes.")
}
- Log.v(TAG, " WRONG LENGTH. : $targetLength READ : $receivedLength bytes.")
callback?.receivedMessage(id, null)
- //return (false)
+
// データが不足しているので、もう一度受信待ち
return (true)
}
}
- Log.v(TAG, " -=-=-=- 1st CALL : read_bytes : " + readBytes + "(" + receivedLength + ") : target_length : " + targetLength + " buffer SIZE : " + byteArray.size)
+ if (isDumpLog)
+ {
+ Log.v(TAG, " -=-=-=- 1st CALL : read_bytes : " + readBytes + "(" + receivedLength + ") : target_length : " + targetLength + " buffer SIZE : " + byteArray.size)
+ }
callback?.onReceiveProgress(receivedLength, targetLength, byteArray.copyOfRange(fromIndex = 0, toIndex = receivedLength))
run {
readBytes = inputStream.read(byteArray, 0, receiveMessageBufferSize)
if (readBytes <= 0)
{
- Log.v(TAG, " RECEIVED MESSAGE FINISHED ($readBytes)")
+ if (isDumpLog)
+ {
+ Log.v(TAG, " RECEIVED MESSAGE FINISHED ($readBytes)")
+ }
break
}
receivedLength += readBytes
-
callback?.onReceiveProgress(receivedLength, targetLength, byteArray.copyOfRange(0, readBytes))
maxRetryCount = command.maxRetryCount()
readBytes = inputStream.available()
if (readBytes == 0)
{
- Log.v(TAG, " WAIT is.available() ... [$receivedLength, $targetLength] $readBytes retry : $maxRetryCount")
+ Log.v(TAG, " WAIT is.available() ... [length: $receivedLength, target: $targetLength] $readBytes bytes, retry : $maxRetryCount")
maxRetryCount--
}
}
}
- // 終了報告...一時的?
- Log.v(TAG, " --- receive_multi : $id ($readBytes) [$maxRetryCount] $receiveMessageBufferSize ($receivedLength) ")
+ // 終了報告...
+ if (isDumpLog)
+ {
+ Log.v(TAG, " --- receive_multi : $id ($readBytes) [$maxRetryCount] $receiveMessageBufferSize ($receivedLength) ")
+ }
callback?.receivedMessage(id, Arrays.copyOfRange(byteArray, 0, receivedLength))
}
catch (e: Throwable)
{
sleep(delayMs)
readBytes = inputStream.available()
- if (readBytes <= 0)
+ if (readBytes <= 0) // if (readBytes <= 0)
{
if (isLogOutput)
{
- Log.v(TAG, "waitForReceive:: is.available() WAIT... : " + delayMs + "ms")
+ Log.v(TAG, "waitForReceive:: is.available() WAIT... : $delayMs ms (Count : $retryCnt) ")
isLogOutput = false
}
retryCount--