aboutsummaryrefslogtreecommitdiff
path: root/car/common.cpp
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2017-01-25 02:50:39 +0100
committerDimitri Sokolyuk <demon@dim13.org>2017-01-25 02:50:39 +0100
commit427998e3506be484caeec94ab720cefbfebf35f2 (patch)
tree2c7a05f7b4cec72f20b8473d9f8dba5daea8f7f3 /car/common.cpp
parent5ba39ddb1385043ed29cb913597e4e285e457273 (diff)
wip
Diffstat (limited to 'car/common.cpp')
-rw-r--r--car/common.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/car/common.cpp b/car/common.cpp
index 90f08d2..7b5522f 100644
--- a/car/common.cpp
+++ b/car/common.cpp
@@ -3,31 +3,36 @@
#include "pb_encode.h"
#include "pb_decode.h"
+#define MAXSZ 32
+
bool
write_callback(pb_ostream_t *stream, const uint8_t *buf, size_t count)
{
- return Serial.write(buf, count) == count;
+ int result = Serial.write(buf, count);
+// Serial.flush();
+ return result == count;
}
bool
read_callback(pb_istream_t *stream, uint8_t *buf, size_t count)
{
int result = Serial.readBytes(buf, count);
- if (result <= 0)
+ if (result == 0) {
stream->bytes_left = 0; // EOF
+ }
return result == count;
}
pb_ostream_t
pb_ostream_from_serial()
{
- pb_ostream_t stream = {&write_callback, NULL, SIZE_MAX, 0};
+ pb_ostream_t stream = {write_callback, NULL, MAXSZ, 0};
return stream;
}
pb_istream_t
pb_istream_from_serial()
{
- pb_istream_t stream = {&read_callback, NULL, SIZE_MAX};
+ pb_istream_t stream = {read_callback, NULL, MAXSZ};
return stream;
}