Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit c9c4cc1

Browse files
committed
Fixes to get FirebaseSerialHost.ino working!
1 parent f4acb3f commit c9c4cc1

File tree

5 files changed

+11
-21
lines changed

5 files changed

+11
-21
lines changed

SerialTransceiver.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ namespace modem {
66
void SerialTransceiver::begin(Stream* serial) {
77
std::unique_ptr<Firebase> fbase;
88

9-
// Timeout in 5min of waiting for serial.
10-
serial->setTimeout(300000);
11-
129
in_.reset(new ArduinoInputStream(serial));
1310
out_.reset(new ArduinoOutputStream(serial));
1411
}
1512

1613
void SerialTransceiver::loop() {
1714
String command_name = in_->readStringUntil(' ');
18-
if (command_name.length() == 0) {
19-
// Generally means a timeout has occured.
15+
16+
if (command_name.length() == 0 // Generally means a timeout has occured.
17+
&& command_name != '\n') {
2018
return;
2119
}
2220

@@ -25,6 +23,7 @@ void SerialTransceiver::loop() {
2523
if (command.execute(command_name, in_.get(), out_.get())) {
2624
fbase_ = std::move(command.firebase());
2725
}
26+
return;
2827
} else if (!fbase_) {
2928
in_->drain();
3029
out_->println("-FAIL Must call BEGIN before anything else.");
@@ -56,6 +55,5 @@ std::unique_ptr<Command> SerialTransceiver::CreateCommand(const String& text,
5655
return command;
5756
}
5857

59-
6058
} // modem
6159
} // firebase

modem/begin-command.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ bool BeginCommand::execute(const String& command,
1717
String auth;
1818

1919
String data(in->readLine());
20-
// Remove leading ' '.
21-
data = data.substring(1);
2220

2321
int space_index = data.indexOf(' ');
2422
if (space_index == -1) {
@@ -30,7 +28,7 @@ bool BeginCommand::execute(const String& command,
3028
auth = data.substring(space_index + 1);
3129
}
3230

33-
if (host.length() != 0) {
31+
if (host.length() == 0) {
3432
out->println("-FAIL Missing host");
3533
return false;
3634
}

modem/input-stream.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace modem {
99
class InputStream {
1010
public:
1111
virtual String readLine() = 0;
12+
// This call consumes the terminator.
1213
virtual String readStringUntil(const char terminator) = 0;
1314
virtual void drain() = 0;
1415
};
@@ -17,16 +18,9 @@ class ArduinoInputStream : public InputStream {
1718
public:
1819
ArduinoInputStream(Stream* stream) : stream_(stream) {}
1920
String readLine() {
20-
String out = stream_->readStringUntil('\r');
21-
if (stream_->peek() == '\n') {
22-
// This should be a '\n' so drop it.
23-
stream_->read();
24-
} else {
25-
// Add \r back, this is not our endline.
26-
out += '\r';
27-
28-
// Recurse until \r\n
29-
out += readLine();
21+
String out = stream_->readStringUntil('\n');
22+
if (out[out.length()-1] == '\r') {
23+
out.remove(out.length()-1);
3024
}
3125
return out;
3226
}

modem/test/push-command_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class PushCommandTest : public ::testing::Test {
2020
}
2121

2222
void FeedCommand(const String& path, const String& data) {
23-
const String data_fragment(String(" ") + data);
23+
const String data_fragment(data);
2424
EXPECT_CALL(in_, readStringUntil(' '))
2525
.WillOnce(Return(path));
2626
EXPECT_CALL(in_, readLine())

modem/test/set-command_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class SetCommandTest : public ::testing::Test {
2020
}
2121

2222
void FeedCommand(const String& path, const String& data) {
23-
const String data_fragment(String(" ") + data);
23+
const String data_fragment(data);
2424
EXPECT_CALL(in_, readStringUntil(' '))
2525
.WillOnce(Return(path));
2626
EXPECT_CALL(in_, readLine())

0 commit comments

Comments
 (0)