Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 2 additions & 15 deletions src/SerialTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,8 @@ class SerialTransport: public ITransport {
}

size_t read(uint8_t* buffer, size_t size) override {

size_t r_size = 0;

while (_stream->available()){
if (r_size == size){
return r_size;
}
buffer[r_size] = _stream->read();
r_size++;
// TODO the following delay is essential for GIGA to work. Is it worth making giga-specific?
delay(1);
}

return r_size;

_stream->setTimeout(0);
return _stream->readBytes(buffer, size);
}

size_t read_byte(uint8_t& r) override {
Expand Down
25 changes: 13 additions & 12 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "dispatcher.h"
#include "rpclite_utils.h"

using namespace RpcUtils::detail;

#define NO_MSG -1
#define CALL_MSG 0
Expand All @@ -30,7 +31,7 @@ class RpcDecoder {

if (call_type!=CALL_MSG && call_type!=NOTIFY_MSG) return false;

static MsgPack::Packer packer;
MsgPack::Packer packer;
packer.clear();

if (call_type == CALL_MSG){
Expand All @@ -57,7 +58,7 @@ class RpcDecoder {

if (!packet_incoming() || packet_type()!=RESP_MSG) return false;

static MsgPack::Unpacker unpacker;
MsgPack::Unpacker unpacker;

size_t bytes_checked = 0;

Expand Down Expand Up @@ -87,7 +88,7 @@ class RpcDecoder {

template<typename RType>
bool send_response(const int msg_id, const RpcError& error, const RType& result) {
static MsgPack::Packer packer;
MsgPack::Packer packer;
MsgPack::arr_size_t resp_size(RESPONSE_SIZE);
MsgPack::object::nil_t nil;

Expand All @@ -108,8 +109,8 @@ class RpcDecoder {
void process_requests(RpcFunctionDispatcher<N>& dispatcher) {
if (_packet_type!=CALL_MSG && _packet_type!=NOTIFY_MSG) return;

static MsgPack::Unpacker unpacker;
static MsgPack::Packer packer;
MsgPack::Unpacker unpacker;
MsgPack::Packer packer;

size_t bytes_checked = 0;

Expand Down Expand Up @@ -170,17 +171,17 @@ class RpcDecoder {
}

void process(){
if (advance()) parse_packet();
advance();
parse_packet();
}

// Fill the raw buffer to its capacity
bool advance() {
void advance() {

uint8_t temp_buf[CHUNK_SIZE];

if (_transport.available() && !buffer_full()){
int bytes_read = _transport.read(temp_buf, CHUNK_SIZE);
if (bytes_read <= 0) return false;

for (int i = 0; i < bytes_read; ++i) {
_raw_buffer[_bytes_stored] = temp_buf[i];
Expand All @@ -190,14 +191,14 @@ class RpcDecoder {
}
}
}
return true;

}

void parse_packet(){

if (packet_incoming() || buffer_empty()){return;}

static MsgPack::Unpacker unpacker;
MsgPack::Unpacker unpacker;
unpacker.clear();
unpacker.feed(_raw_buffer, 2);

Expand Down Expand Up @@ -264,7 +265,7 @@ class RpcDecoder {
inline bool buffer_full() const { return _bytes_stored == BufferSize; }
inline bool buffer_empty() const { return _bytes_stored == 0;}
inline void flush_buffer() {
uint8_t* discard_buf;
uint8_t discard_buf[CHUNK_SIZE];
while (_transport.read(discard_buf, CHUNK_SIZE) > 0);
_bytes_stored = 0;
}
Expand All @@ -276,7 +277,7 @@ class RpcDecoder {

size_t bytes_checked = 0;
size_t container_size;
static MsgPack::Unpacker unpacker;
MsgPack::Unpacker unpacker;

while (bytes_checked < _bytes_stored){
bytes_checked++;
Expand Down
1 change: 1 addition & 0 deletions src/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using namespace RpcUtils::detail;
#include <stdexcept>
#endif


template<typename F>
class RpcFunctionWrapper;

Expand Down