WIP: BG95_base::command parser and sequencer script representation
This commit is contained in:
+19
-21
@@ -178,9 +178,9 @@ namespace test_bg95_base {
|
||||
BG95<256> modem;
|
||||
char buffer[256];
|
||||
|
||||
const BG95<256>::async_handlers<2> async = {{
|
||||
{"+QMTOPEN:", BG95<256>::match_t::STARTS_WITH, handler, BG95<256>::action_t::NO, 0},
|
||||
{"+QMT", BG95<256>::match_t::STARTS_WITH, handler, BG95<256>::action_t::NO, 0},
|
||||
const BG95<256>::inetd_handlers<2> async = {{
|
||||
{"+QMTOPEN:", BG95<256>::match_t::STARTS_WITH, handler},
|
||||
{"+QMT", BG95<256>::match_t::STARTS_WITH, handler},
|
||||
}};
|
||||
|
||||
clear_flag();
|
||||
@@ -225,24 +225,22 @@ namespace test_bg95_base {
|
||||
TEST(TBG95_base, run) {
|
||||
BG95<256> modem;
|
||||
|
||||
const BG95<256>::async_handlers<2> async = {{
|
||||
{"+QMTOPEN:", BG95<256>::match_t::STARTS_WITH, handler, BG95<256>::action_t::NO, 0},
|
||||
{"+QMT", BG95<256>::match_t::STARTS_WITH, handler, BG95<256>::action_t::NO, 0},
|
||||
using Control = BG95<256>::control_t;
|
||||
using Match = BG95<256>::match_t;
|
||||
using Action = BG95<256>::action_t;
|
||||
|
||||
const BG95<256>::inetd_handlers<2> async = {{
|
||||
{"+QMTOPEN:", Match::STARTS_WITH, handler},
|
||||
{"+QMT", Match::STARTS_WITH, handler},
|
||||
}};
|
||||
const BG95<256>::script_t<5> script = {{
|
||||
/* 0 */{BG95<256>::control_t::NOP, {"", BG95<256>::match_t::NO, nullptr, BG95<256>::action_t::GOTO, 1}, 1000},
|
||||
/* 1 */{BG95<256>::control_t::SEND, {"ATE0\r\n", BG95<256>::match_t::NO, nullptr, BG95<256>::action_t::NEXT, 0}, 0},
|
||||
/* 2 */{BG95<256>::control_t::EXPECT, {{
|
||||
{"OK\r\n", BG95<256>::match_t::ENDS_WITH, nullptr, BG95<256>::action_t::NEXT, 0},
|
||||
{"ERROR", BG95<256>::match_t::CONTAINS, nullptr, BG95<256>::action_t::EXIT_ERROR, 0} }},
|
||||
1000
|
||||
},
|
||||
/* 3 */{BG95<256>::control_t::SEND, {"AT+CSQ\r\n", BG95<256>::match_t::NO, nullptr, BG95<256>::action_t::NEXT, 0}, 0},
|
||||
/* 4 */{BG95<256>::control_t::EXPECT, {{
|
||||
{"OK\r\n", BG95<256>::match_t::ENDS_WITH, nullptr, BG95<256>::action_t::EXIT_OK, 0},
|
||||
{"ERROR", BG95<256>::match_t::CONTAINS, nullptr, BG95<256>::action_t::EXIT_ERROR, 0} }},
|
||||
1000
|
||||
},
|
||||
const BG95<256>::script_t<7> script = {{
|
||||
{Control::NOP, "", Match::NO, nullptr, {Action::GOTO, 1}, 1000},
|
||||
{Control::SEND, "ATE0\r\n", Match::NO, nullptr, {Action::NEXT, 0}, 0},
|
||||
{Control::EXPECT, "OK\r\n", Match::ENDS_WITH, nullptr, {Action::NEXT, 0}, 1000},
|
||||
{Control::OR_EXPECT,"ERROR", Match::CONTAINS, nullptr, {Action::EXIT_ERROR, 0}, 1000},
|
||||
{Control::SEND, "AT+CSQ\r\n", Match::NO, nullptr, {Action::NEXT, 0}, 0},
|
||||
{Control::EXPECT, "OK\r\n", Match::ENDS_WITH, nullptr, {Action::NEXT, 0}, 1000},
|
||||
{Control::OR_EXPECT,"ERROR", Match::CONTAINS, nullptr, {Action::EXIT_ERROR, 0}, 1000},
|
||||
}};
|
||||
|
||||
std::mutex m;
|
||||
@@ -270,7 +268,7 @@ namespace test_bg95_base {
|
||||
m.unlock();
|
||||
});
|
||||
int status;
|
||||
EXPECT_EQ (modem.command("AT+CREG?\r\n", "\r\n+CREG: 0,%\r\n\r\nOK\r\n", status), true);
|
||||
EXPECT_EQ (modem.command("AT+CREG?\r\n", "\r\n+CREG: 0,%\r\n\r\nOK\r\n", &status), true);
|
||||
EXPECT_EQ (status, 5);
|
||||
|
||||
char substr[32];
|
||||
|
||||
+28
-35
@@ -76,62 +76,55 @@ namespace test_sequencer {
|
||||
*/
|
||||
TEST(Tsequencer, run_delay) {
|
||||
Seq s;
|
||||
const std::array<Seq::record_t<1>, 1> script = {{
|
||||
/* 0 */{Seq::control_t::NOP, {"", Seq::match_t::NO, nullptr, Seq::action_t::EXIT_OK, 0}, 1000}
|
||||
const Seq::script_t<1> script = {{
|
||||
{Seq::control_t::NOP, "", Seq::match_t::NO, nullptr, {Seq::action_t::EXIT_OK, 0}, 1000}
|
||||
}};
|
||||
EXPECT_EQ (s.run(script), true);
|
||||
}
|
||||
|
||||
TEST(Tsequencer, run_dummy_output) {
|
||||
Seq s;
|
||||
const std::array<Seq::record_t<1>, 2> script = {{
|
||||
/* 0 */{Seq::control_t::SEND, {"", Seq::match_t::NO, nullptr, Seq::action_t::NEXT, 0}, 1000},
|
||||
/* 1 */{Seq::control_t::SEND, {"", Seq::match_t::NO, nullptr, Seq::action_t::EXIT_OK, 0}, 1000}
|
||||
const Seq::script_t<2> script = {{
|
||||
{Seq::control_t::SEND, "", Seq::match_t::NO, nullptr, {Seq::action_t::NEXT, 0}, 1000},
|
||||
{Seq::control_t::SEND, "", Seq::match_t::NO, nullptr, {Seq::action_t::EXIT_OK, 0}, 1000}
|
||||
}};
|
||||
EXPECT_EQ (s.run(script), true);
|
||||
}
|
||||
|
||||
TEST(Tsequencer, run_exits) {
|
||||
Seq s;
|
||||
const std::array<Seq::record_t<1>, 1> script1 = {{
|
||||
/* 0 */{Seq::control_t::SEND, {"", Seq::match_t::NO, nullptr, Seq::action_t::EXIT_OK, 0}, 1000},
|
||||
const Seq::script_t<1> script1 = {{
|
||||
{Seq::control_t::SEND, "", Seq::match_t::NO, nullptr, {Seq::action_t::EXIT_OK, 0}, 1000},
|
||||
}};
|
||||
EXPECT_EQ (s.run(script1), true);
|
||||
|
||||
const std::array<Seq::record_t<1>, 1> script2 = {{
|
||||
/* 0 */{Seq::control_t::SEND, {"", Seq::match_t::NO, nullptr, Seq::action_t::EXIT_ERROR, 0}, 1000},
|
||||
const Seq::script_t<1> script2 = {{
|
||||
{Seq::control_t::SEND, "", Seq::match_t::NO, nullptr, {Seq::action_t::EXIT_ERROR, 0}, 1000},
|
||||
}};
|
||||
EXPECT_EQ (s.run(script2), false);
|
||||
}
|
||||
|
||||
TEST(Tsequencer, run_sequence) {
|
||||
Seq s;
|
||||
const std::array<Seq::record_t<2>, 9> script = {{
|
||||
/* 0 */{Seq::control_t::NOP, {"", Seq::match_t::NO, nullptr, Seq::action_t::GOTO, 1}, 1000},
|
||||
/* 1 */{Seq::control_t::SEND, {"ATE0\r\n", Seq::match_t::NO, nullptr, Seq::action_t::NEXT, 0}, 1000},
|
||||
/* 2 */{Seq::control_t::EXPECT, {{
|
||||
{"OK\r\n", Seq::match_t::ENDS_WITH, nullptr, Seq::action_t::NEXT, 0},
|
||||
{"ERROR", Seq::match_t::CONTAINS, nullptr, Seq::action_t::EXIT_ERROR, 0} }},
|
||||
1000
|
||||
},
|
||||
/* 3 */{Seq::control_t::DETECT, {{
|
||||
{"+CCLK", Seq::match_t::CONTAINS, nullptr, Seq::action_t::NEXT, 0},
|
||||
{"ERROR", Seq::match_t::CONTAINS, nullptr, Seq::action_t::EXIT_ERROR, 0} }},
|
||||
1000
|
||||
},
|
||||
/* 4 */{Seq::control_t::SEND, {"AT+CCLK?", Seq::match_t::NO, nullptr, Seq::action_t::NEXT, 0}, 1000},
|
||||
/* 5 */{Seq::control_t::EXPECT, {{
|
||||
{"OK\r\n", Seq::match_t::ENDS_WITH, Seq::my_handler, Seq::action_t::NEXT, 0},
|
||||
{"ERROR", Seq::match_t::CONTAINS, nullptr, Seq::action_t::EXIT_ERROR, 0} }},
|
||||
1000
|
||||
},
|
||||
/* 6 */{Seq::control_t::SEND, {"AT+CT?", Seq::match_t::NO, nullptr, Seq::action_t::NEXT, 0}, 1000},
|
||||
/* 7 */{Seq::control_t::EXPECT, {{
|
||||
{"OK\r\n", Seq::match_t::ENDS_WITH, nullptr, Seq::action_t::NEXT, 0},
|
||||
{"ERROR", Seq::match_t::CONTAINS, nullptr, Seq::action_t::EXIT_ERROR, 0} }},
|
||||
1000
|
||||
},
|
||||
/* 8 */{Seq::control_t::SEND, {"AT+POWD=0", Seq::match_t::NO, nullptr, Seq::action_t::EXIT_OK, 0}, 1000}
|
||||
const Seq::script_t<13> script = {{
|
||||
/* 0 */{Seq::control_t::NOP, "", Seq::match_t::NO, nullptr, {Seq::action_t::GOTO, 1}, 1000},
|
||||
|
||||
/* 1 */{Seq::control_t::SEND, "ATE0\r\n", Seq::match_t::NO, nullptr, {Seq::action_t::NEXT, 0}, 1000},
|
||||
/* 2 */{Seq::control_t::EXPECT, "OK\r\n", Seq::match_t::ENDS_WITH, nullptr, {Seq::action_t::NEXT, 0}, 1000},
|
||||
/* 3 */{Seq::control_t::OR_EXPECT, "ERROR", Seq::match_t::CONTAINS, nullptr, {Seq::action_t::EXIT_ERROR, 0}, 1000},
|
||||
|
||||
/* 4 */{Seq::control_t::DETECT, "+CCLK", Seq::match_t::CONTAINS, nullptr, {Seq::action_t::NEXT, 0}, 1000},
|
||||
/* 5 */{Seq::control_t::OR_DETECT, "ERROR", Seq::match_t::CONTAINS, nullptr, {Seq::action_t::EXIT_ERROR, 0}, 1000},
|
||||
|
||||
/* 6 */{Seq::control_t::SEND, "AT+CCLK?", Seq::match_t::NO, nullptr, {Seq::action_t::NEXT, 0}, 1000},
|
||||
/* 7 */{Seq::control_t::EXPECT, "OK\r\n", Seq::match_t::ENDS_WITH, Seq::my_handler, {Seq::action_t::NEXT, 0}, 1000},
|
||||
/* 8 */{Seq::control_t::OR_EXPECT, "ERROR", Seq::match_t::CONTAINS, nullptr, {Seq::action_t::EXIT_ERROR, 0}, 1000},
|
||||
|
||||
/* 9 */{Seq::control_t::SEND, "AT+CT?", Seq::match_t::NO, nullptr, {Seq::action_t::NEXT, 0}, 1000},
|
||||
/*10 */{Seq::control_t::EXPECT, "OK\r\n", Seq::match_t::ENDS_WITH, nullptr, {Seq::action_t::NEXT, 0}, 1000},
|
||||
/*11 */{Seq::control_t::OR_EXPECT, "ERROR", Seq::match_t::CONTAINS, nullptr, {Seq::action_t::EXIT_ERROR, 0}, 1000},
|
||||
|
||||
/*12 */{Seq::control_t::SEND, "AT+POWD=0", Seq::match_t::NO, nullptr, {Seq::action_t::EXIT_OK, 0}, 1000}
|
||||
}};
|
||||
EXPECT_EQ (s.run(script), false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user