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 @@ -30,21 +30,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
5 changes: 3 additions & 2 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ class RPCClient {
RpcError error;
// blocking call
while (!decoder.get_response(msg_id, result, error)){
decoder.process();
delay(1);
if (!decoder.process()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour is still under test in a multithreading context. The delay here is actually a placeholder for a thread yield.
If the client doesn't yield every time its waiting response is not ready, then it can slow down another thread (eg server).
It's better to leave everything as it was and make a decision when we discuss about if/how threading is involved

delay(1);
}
}

lastError.code = error.code;
Expand Down
13 changes: 9 additions & 4 deletions src/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ class RpcDecoder {

}

void process(){
if (advance()) parse_packet();
bool process(){
if (advance()) {
parse_packet();
return true;
}
return false;
}

// Fill the raw buffer to its capacity
Expand All @@ -188,8 +192,9 @@ class RpcDecoder {
delay(1);
}
}
return true;
}
return true;
return false;
}

void parse_packet(){
Expand Down Expand Up @@ -263,7 +268,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 Down