bool MTPD::SendObject() {
bool return_value = false;
uint8_t print_count = 0;
pull_packet(rx_data_buffer);
read(0,0);
uint32_t len = ReadMTPHeader();
uint32_t index = sizeof(MTPHeader);
printf("MTPD::SendObject: len:%u\n", len);
elapsedMicros em_total = 0;
uint32_t cb_write = MTP_RX_SIZE - index; // how many data in usb-packet
if (cb_write > len) cb_write = len;
if(!storage_->write((char*)rx_data_buffer + index, cb_write)) goto abort;
len -= cb_write;
cb_write = MTP_RX_SIZE;
while (len)
{
printf(".");
if (!(++print_count & 0x3f)) printf("\n");
// Build in timeout...
uint32_t elapsed_before_packet = em_total;
elapsedMillis em_packet = 0;
while(!usb_mtp_available())
{
if (em_packet > 1000)
{
printf("\nTimeout: %u\n", elapsed_before_packet);
goto abort;
}
}
usb_mtp_recv(rx_data_buffer, 60);
if (cb_write > len) cb_write = len;
if(!storage_->write((char*)rx_data_buffer, cb_write)) goto abort;
len -= cb_write;
}
return_value = true;
printf("$");
abort:
storage_->close();
printf(">> %u\n", (uint32_t)em_total);
return return_value;
}