Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite765a31

Browse files
committed
standardized on arduino String, builds for both tests and sketches now
1 parentdeaf832 commite765a31

File tree

8 files changed

+36
-33
lines changed

8 files changed

+36
-33
lines changed

‎src/modem/SerialProtocol.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef MODEM_SERIAL_PROTOCOL_H
22
#defineMODEM_SERIAL_PROTOCOL_H
33

4-
#include<string>
4+
#include<WString.h>
55
#include<vector>
66

77
namespacefirebase {
@@ -21,12 +21,12 @@ class SerialProtocol {
2121
/*
2222
* Returns all commands this protocol supports, commands are single words.
2323
*/
24-
virtualconst std::vector<std::string>&commands()const = 0;
24+
virtualconst std::vector<String>&commands()const = 0;
2525

2626
/*
2727
* Execute command, takes over the serial line until execution is done.
2828
*/
29-
virtualvoidExecute(conststd::string& command, InputStream* in, OutputStream* out) = 0;
29+
virtualvoidExecute(constString& command, InputStream* in, OutputStream* out) = 0;
3030

3131
};
3232

‎src/modem/SerialTransceiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ void SerialTransceiver::begin(Stream* serial) {
99
}
1010

1111
voidSerialTransceiver::RegisterProtocol(std::unique_ptr<SerialProtocol> protocol) {
12-
for (conststd::string& command : protocol->commands()) {
12+
for (constString& command : protocol->commands()) {
1313
command_to_protocol_.insert({command, protocol.get()});
1414
}
1515

‎src/modem/SerialTransceiver.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#defineMODEM_SERIAL_TRANSCIEVER_H
33

44
#include<memory>
5-
#include<unordered_map>
5+
#include<map>
66

77
#include"modem/SerialProtocol.h"
88
#include"modem/input-stream.h"
@@ -26,7 +26,7 @@ class SerialTransceiver {
2626
std::unique_ptr<ArduinoInputStream> in_;
2727
std::unique_ptr<ArduinoOutputStream> out_;
2828
std::vector<std::unique_ptr<SerialProtocol>> protocols_;
29-
std::unordered_map<std::string, SerialProtocol*> command_to_protocol_;
29+
std::map<String, SerialProtocol*> command_to_protocol_;
3030
};
3131

3232
}// modem

‎src/modem/db/DatabaseProtocol.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,46 @@
33
namespacefirebase {
44
namespacemodem {
55
namespace {
6-
const std::vector<std::string> commands {
6+
const std::vector<String>kCommands {
77
"BEGIN_DB",
88
"GET",
99
"SET",
1010
"PUSH",
1111
"REMOVE",
1212
"BEGIN_STREAM"
13-
}
13+
};
1414
}
1515

16-
const std::vector<std::string>&DatabaseProtocol::commands()const {
17-
returncommands;
16+
const std::vector<String>&DatabaseProtocol::commands()const {
17+
returnkCommands;
1818
}
1919

20-
voidDatabaseProtocol::Execute(conststd::string& command, InputStream* in,
20+
voidDatabaseProtocol::Execute(constString& command_name, InputStream* in,
2121
OutputStream* out) {
2222
if (command_name =="BEGIN_DB") {
2323
BeginCommand command;
24-
if (command.execute(command_name,in_.get(), out_.get())) {
24+
if (command.execute(command_name,in, out)) {
2525
fbase_ =std::move(command.firebase());
2626
}
2727
return;
2828
}elseif (!fbase_) {
29-
in_->drain();
30-
out_->println("-FAIL Must call BEGIN_DB before anything else.");
29+
in->drain();
30+
out->println("-FAIL Must call BEGIN_DB before anything else.");
3131
return;
3232
}
3333

3434
std::unique_ptr<Command> command =CreateCommand(command_name, fbase_.get());
3535
if (!command) {
36-
in_->drain();
37-
out_->println(String("-FAIL Invalid command '") + command_name +"'." );
36+
in->drain();
37+
out->println(String("-FAIL Invalid command '") + command_name +"'." );
3838
return;
3939
}
4040

41-
command->execute(command_name,in_.get(), out_.get());
41+
command->execute(command_name,in, out);
4242
}
4343

44-
std::unique_ptr<Command>SerialTransceiver::CreateCommand(const String& text,
45-
Firebase* fbase) {
44+
std::unique_ptr<Command>DatabaseProtocol::CreateCommand(const String& text,
45+
Firebase* fbase) {
4646
std::unique_ptr<Command> command;
4747
if (text =="GET") {
4848
command.reset(newGetCommand(fbase));

‎src/modem/db/DatabaseProtocol.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33

44
#include"modem/SerialProtocol.h"
55
#include"modem/db/commands.h"
6+
#include"Firebase.h"
67

78
namespacefirebase {
89
namespacemodem {
910

1011
classDatabaseProtocol :publicSerialProtocol {
1112
public:
12-
const std::vector<std::string>&commands()constoverride;
13-
voidExecute(conststd::string& command, InputStream* in, OutputStream* out)override;
13+
const std::vector<String>&commands()constoverride;
14+
voidExecute(constString& command, InputStream* in, OutputStream* out)override;
1415
private:
1516
std::unique_ptr<Command>CreateCommand(const String& text, Firebase* fbase);
17+
18+
std::unique_ptr<Firebase> fbase_;
1619
};
1720

1821

‎test/Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ FIREBASE_DIR=..
1818
GTEST_DIR=googletest/googletest
1919
ARDUINOJSON_DIR=../src/third-party/arduino-json-5.3
2020

21-
FIREBASE_SRCS=${FIREBASE_DIR}/src/FirebaseObject.cpp\
22-
${FIREBASE_DIR}/src/FirebaseObject.h
21+
FIREBASE_SRCS=${FIREBASE_DIR}/src/FirebaseObject.cpp
2322
GTEST_SRCS=${GTEST_DIR}/src/gtest-all.cpp
2423
ARDUINOJSON_SRCS=${ARDUINOJSON_DIR}/src/JsonBuffer.cpp\
2524
${ARDUINOJSON_DIR}/src/JsonObject.cpp\
@@ -51,6 +50,5 @@ firebase-test: ${OBJS}
5150
check: firebase-test
5251
./firebase-test
5352

54-
#TODO: had to echo this because it picks up FirebaseObject.h as well and deletes it :(
5553
clean:
56-
echorm -f${OBJS} firebase-test
54+
rm -f${OBJS} firebase-test

‎test/modem/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ push-command_test : push-command.o push-command_test.o Firebase.o FirebaseHttpCl
215215
arduino_mock_all.a arduino_json.a
216216
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
217217

218+
218219
begin-command.o :$(SRC_ROOT)/modem/db/begin-command.cpp
219220
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/modem/db/begin-command.cpp
220221

@@ -225,6 +226,7 @@ begin-command_test : begin-command.o begin-command_test.o Firebase.o FirebaseHtt
225226
arduino_mock_all.a arduino_json.a
226227
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
227228

229+
228230
stream-command.o :$(SRC_ROOT)/modem/db/stream-command.cpp
229231
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/modem/db/stream-command.cpp
230232

@@ -235,6 +237,7 @@ stream-command_test : stream-command.o stream-command_test.o Firebase.o Firebase
235237
arduino_mock_all.a arduino_json.a
236238
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
237239

240+
238241
SerialTransceiver.o :$(SRC_ROOT)/modem/SerialTransceiver.cpp
239242
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -c$(SRC_ROOT)/modem/SerialTransceiver.cpp
240243

@@ -244,4 +247,3 @@ serial-transceiver_test.o : $(TEST_DIR)/serial-transceiver_test.cpp $(GMOCK_HEAD
244247
serial-transceiver_test : SerialTransceiver.o serial-transceiver_test.o gmock_main.a arduino_mock_all.a arduino_json.a
245248
$(CXX)$(CPPFLAGS)$(CXXFLAGS) -lpthread$^ -o$@
246249

247-

‎test/modem/serial-transceiver_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ using ::testing::_;
1313

1414
classMockSerialProtocol :publicSerialProtocol {
1515
public:
16-
MOCK_CONST_METHOD0(commands,const std::vector<std::string>&());
17-
MOCK_METHOD3(Execute,void(conststd::string&, InputStream*, OutputStream*));
16+
MOCK_CONST_METHOD0(commands,const std::vector<String>&());
17+
MOCK_METHOD3(Execute,void(constString&, InputStream*, OutputStream*));
1818
};
1919

2020
classMockStream :publicStream {
@@ -26,8 +26,8 @@ class SerialTranscieverTest : public ::testing::Test {
2626
};
2727

2828
TEST_F(SerialTranscieverTest, delegatesCommand) {
29-
conststd::string good_command ="GOOD";
30-
const std::vector<std::string> commands{good_command};
29+
constString good_command ="GOOD";
30+
const std::vector<String> commands{good_command};
3131

3232
MockStream serial;
3333
EXPECT_CALL(serial,readStringUntil(''))
@@ -45,9 +45,9 @@ TEST_F(SerialTranscieverTest, delegatesCommand) {
4545
}
4646

4747
TEST_F(SerialTranscieverTest, doesNotDelegateInvalidCommand) {
48-
conststd::string good_command ="GOOD";
49-
conststd::string bad_command ="BAD";
50-
const std::vector<std::string> commands{good_command};
48+
constString good_command ="GOOD";
49+
constString bad_command ="BAD";
50+
const std::vector<String> commands{good_command};
5151

5252
MockStream serial;
5353
EXPECT_CALL(serial,readStringUntil(''))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp