Yes, it returns. Some Quote from the documentation: "SPI.transfer is based on a simultaneous send and receive: the received data is returned".
buffer is a queue (first-in-first-out) with the size of (32 Byte * 1024 =) 32 KByte. This queue is filled by data received from Wifi-/HTTP-Connection.
Internal my queue is a simple one-dimension-array.
buffer->read() returns a pointer to the current reading-position.
buffer->write() returns a pointer to the current writing-position.
To reduce the overhead of each function call the queue is seperated in (logical!) parts of 32 Bytes, so every read-call reads 32 Bytes.
My HTTP-receive-function writes directly 32 Bytes into the queue using buffer->write(), so I do not need to copy memory.
Code: Select all
uint8_t data_block[this->chunkSize * this->amount]; //32 * 1024
//public reading access
uint8_t *RingBuffer::read() {
space++; //Now more space is available. space is public accessable and was set at the beginning to 1024 by constructor
return this->get(&this->index_read);
}
//public writing access
uint8_t *RingBuffer::write() {
space--; //Now less space is available
return this->get(&this->index_write);
}
//private internal function
uint8_t *RingBuffer::get(uint16_t *index) { //this->chunkSize is set to 32
uint8_t *buf = &this->data_block[((*index) * this->chunkSize)]; //get a pointer to an array field
(*index)++; //increase the writing/reading index
if(*index == this->amount) { //jump back to the first index, when the buffer is full (ringbuffer)
*index = 0; //this->amount is set to 1024
}
return buf;
}
The loop runs 48-times, but only as long as we have current data in queue - that is necessary to prevent reading old data from the queue.
So 1536 Bytes are send each time, normaly. The queue is filled regulary with new data, so normaly it works good.