fixed bogus slotcount use display + moved some stuff to dynalloc to save ram

This commit is contained in:
2018-01-14 00:21:13 +01:00
parent 7df577f9b1
commit 05875a8167
5 changed files with 12 additions and 17 deletions
+6 -5
View File
@@ -5,14 +5,12 @@
#include "platform.h"
#include <TinyFrame.h>
#include "utils/malloc_safe.h"
#include "messages.h"
#include "utils/payload_parser.h"
#include "utils/payload_builder.h"
/** Buffer for preparing bulk chunks */
static uint8_t bulkread_buffer[BULK_READ_BUF_LEN];
/**
* TF listener for the bulk read transaction
*/
@@ -26,6 +24,7 @@ static TF_Result bulkread_lst(TinyFrame *tf, TF_Msg *msg)
}
assert_param(NULL != bulk);
assert_param(NULL != bulk->_buffer);
if (msg->type == MSG_BULK_ABORT) {
goto close;
@@ -39,7 +38,7 @@ static TF_Result bulkread_lst(TinyFrame *tf, TF_Msg *msg)
chunk = MIN(chunk, BULK_READ_BUF_LEN);
// load data into the buffer
bulk->read(bulk, chunk, bulkread_buffer);
bulk->read(bulk, chunk, bulk->_buffer);
bool last = (bulk->offset + chunk >= bulk->len);
@@ -47,7 +46,7 @@ static TF_Result bulkread_lst(TinyFrame *tf, TF_Msg *msg)
TF_ClearMsg(&resp);
resp.frame_id = bulk->frame_id;
resp.type = (last ? MSG_BULK_END : MSG_BULK_DATA); // the last chunk has the END type
resp.data = bulkread_buffer;
resp.data = bulk->_buffer;
resp.len = (TF_LEN) chunk;
TF_Respond(tf, &resp);
@@ -64,6 +63,7 @@ close:
// Ask user to free the bulk and userdata
bulk->read(bulk, 0, NULL);
msg->userdata = NULL;
free_ck(bulk->_buffer);
}
return TF_CLOSE;
}
@@ -76,6 +76,7 @@ void bulkread_start(TinyFrame *tf, BulkRead *bulk)
assert_param(bulk->read);
bulk->offset = 0;
bulk->_buffer = malloc_ck(BULK_READ_BUF_LEN);
{
uint8_t buf[8];
+1
View File
@@ -30,6 +30,7 @@ struct bulk_read {
bulkread_data_cb read; //!< Read callback
uint32_t len; //!< Total data length
void *userdata; //!< A place for arbitrary userdata
uint8_t *_buffer;
uint32_t offset; //!< Internal offset counter, will be set to 0 on start.
};