Main firmware - basic functions

This commit is contained in:
Martin Bauer
2019-09-08 19:25:05 +02:00
parent d8732643f3
commit fb5c8361a7
4 changed files with 96 additions and 44 deletions

View File

@@ -19,6 +19,21 @@ struct DummyWriter {
void write(const void*, uint32_t) {}
};
class CopyWriter {
public:
CopyWriter(uint8_t * bufferToWrite)
: bufferToWrite_( bufferToWrite )
{}
void write(const void* data, uint32_t length) {
memcpy(bufferToWrite_, data, length);
bufferToWrite_ += length;
}
private:
uint8_t * bufferToWrite_;
};
template<typename Writer>
class StreamingMsgPackEncoder
{
@@ -141,7 +156,7 @@ class ChunkedStreamingMsgPackEncoder
{
public:
ChunkedStreamingMsgPackEncoder(Writer * writer_, uint32_t offset, uint32_t maxSize)
: encoder_(writer_), offsetToStart_(offset), maxBytes_(maxSize), sentBytes_(0), sendingFinished_(false)
: encoder_(writer_), sentBytes_(0), maxBytes_(maxSize), offsetToStart_(offset), sendingFinished_(false)
{}
void sendMap16(byte size) {
@@ -175,7 +190,6 @@ public:
return;
}
uint32_t sizeForFullArray = sizeof(T) * length;
uint32_t elementsToSkip = 0;
if( sentBytes_ < offsetToStart_ ) {
elementsToSkip = (offsetToStart_ - sentBytes_) / sizeof(T);