Skip to content

Commit 531c719

Browse files
committed
complete public Client API
1 parent 700d26e commit 531c719

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/ArduinoSerialToTCPBridgeClient.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ size_t ArduinoSerialToTCPBridgeClient::write(const uint8_t *buf, size_t size) {
150150
}
151151

152152
int ArduinoSerialToTCPBridgeClient::available() {
153-
if (rxBufisFull) {
153+
if (rxBufisFull)
154154
return 256;
155-
}
155+
156156
if (rxBufpT >= rxBufpH) {
157157
return (int) (rxBufpT - rxBufpH);
158158
} else {
@@ -161,19 +161,27 @@ int ArduinoSerialToTCPBridgeClient::available() {
161161
}
162162

163163
int ArduinoSerialToTCPBridgeClient::read() {
164-
if (!available()) {
164+
if (available() == 0)
165165
return -1;
166-
}
167166

168167
uint8_t ch = rxBuf[rxBufpH++];
169168
rxBufisFull = false;
170169
return ch;
171170
}
172171

173172
int ArduinoSerialToTCPBridgeClient::read(uint8_t *buf, size_t size) {
174-
if (!available()) {
173+
int have = available();
174+
if (have == 0)
175175
return -1;
176-
}
176+
177+
int toRead = (size > have) ? have : size;
178+
179+
for (size_t i = 0; i < toRead; i++)
180+
buf[i] = rxBuf[rxBufpH++];
181+
182+
rxBufisFull = false;
183+
// should we return rather when number of bytes requested is read?
184+
return toRead;
177185
}
178186

179187
int ArduinoSerialToTCPBridgeClient::peek() {

0 commit comments

Comments
 (0)