
Originally Posted by
mjs513
@KurtE
Think getting the timeout resolved is important as well

Me too,
So I am starting to play again of moving over the code I have in other branch.
But also wondering about the differences in the two current versions of the sendObject code:
The one for T3.x is really simple:
Code:
bool MTPD::SendObject() {
uint32_t len = ReadMTPHeader();
while (len)
{
receive_buffer();
uint32_t to_copy = data_buffer_->len - data_buffer_->index;
to_copy = min(to_copy, len);
if(!storage_->write((char*)(data_buffer_->buf + data_buffer_->index), to_copy)) return false;
data_buffer_->index += to_copy;
len -= to_copy;
if (data_buffer_->index == data_buffer_->len)
{
usb_free(data_buffer_);
data_buffer_ = NULL;
}
}
storage_->close();
return true;
}
It receives a USB buffer and it writes it to the disk... The T4.x version is a little more complicated:
Code:
bool MTPD::SendObject()
{
pull_packet(rx_data_buffer);
read(0,0);
// printContainer();
uint32_t len = ReadMTPHeader();
uint32_t index = sizeof(MTPHeader);
disk_pos=0;
while((int)len>0)
{ uint32_t bytes = MTP_RX_SIZE - index; // how many data in usb-packet
bytes = min(bytes,len); // loimit at end
uint32_t to_copy=min(bytes, DISK_BUFFER_SIZE-disk_pos); // how many data to copy to disk buffer
memcpy(disk_buffer+disk_pos, rx_data_buffer + index,to_copy);
disk_pos += to_copy;
bytes -= to_copy;
len -= to_copy;
//printf("a %d %d %d %d %d\n", len,disk_pos,bytes,index,to_copy);
//
if(disk_pos==DISK_BUFFER_SIZE)
{
if(storage_->write((const char *)disk_buffer, DISK_BUFFER_SIZE)<DISK_BUFFER_SIZE) return false;
disk_pos =0;
if(bytes) // we have still data in transfer buffer, copy to initial disk_buffer
{
memcpy(disk_buffer,rx_data_buffer+index+to_copy,bytes);
disk_pos += bytes;
len -= bytes;
}
//printf("b %d %d %d %d %d\n", len,disk_pos,bytes,index,to_copy);
}
if(len>0) // we have still data to be transfered
{ pull_packet(rx_data_buffer);
index=0;
}
}
//printf("len %d\n",disk_pos);
if(disk_pos)
{
if(storage_->write((const char *)disk_buffer, disk_pos)<disk_pos) return false;
}
storage_->close();
return true;
}
It instead buffers the data internally into its buffer which is currently defined as 8kb and then does a big write. It is trying to write out whole sectors, which depending on the OS, could maybe be faster. That is if the FS does not buffer data internally to do writes...
Again question to self and others: Should FS.h the FS object have some method(s) to ask FS information like: record size, or cluster size, or preferred access size?
But wondering how much of a speed up there is with the buffering and if significant should it be back ported to T3.x...