From fd64d8726cf72d2d0367f0c4d4c2be48fc1dd72a Mon Sep 17 00:00:00 2001 From: Christos Choutouridis Date: Fri, 24 Sep 2021 18:06:45 +0300 Subject: [PATCH] WIP: BG95_base::command parser and sequencer script representation --- include/drv/BG95_base.h | 118 +++++++++++++----------- include/utils/sequencer.h | 186 ++++++++++++++++---------------------- test/tests/BG95_base.cpp | 40 ++++---- test/tests/sequencer.cpp | 63 ++++++------- 4 files changed, 192 insertions(+), 215 deletions(-) diff --git a/include/drv/BG95_base.h b/include/drv/BG95_base.h index fdf8030..1630aa4 100644 --- a/include/drv/BG95_base.h +++ b/include/drv/BG95_base.h @@ -31,6 +31,7 @@ #ifndef TBX_DRV_BG95_base_H_ #define TBX_DRV_BG95_base_H_ +#define __cplusplus 201703L #include #include @@ -39,10 +40,10 @@ #include #include -#include +#include #include -//#include +#include #include namespace tbx { @@ -116,7 +117,6 @@ class BG95_base using base_type = sequencer; using str_view_t = typename base_type::str_view_t; using range_t = typename Cont_t::range_t; - using status_t = typename base_type::status_t; //! \name Public types //! @{ @@ -124,17 +124,22 @@ class BG95_base using action_t = typename base_type::action_t; using control_t = typename base_type::control_t; using match_t = typename base_type::match_t; - using handler_t = typename base_type::handler_ft; - template - using script_t = typename base_type::template script_t; + using handler_ft = typename base_type::handler_ft; + template + using script_t = typename base_type::template script_t; //! Publish delimiter constexpr static char delimiter = Delimiter; - //! Required typenames for async operation + //! Required types for inetd async handler operation //! @{ + struct inetd_handler_t { + str_view_t token; + match_t match; + handler_ft handler; + }; template - using async_handlers = std::array; + using inetd_handlers = std::array; //! @} //! @} @@ -176,32 +181,48 @@ class BG95_base //! @{ private: template - ptrdiff_t parse (char* str, size_t n, char next, T& value) { - auto next_ptr = std::find(str, &str[n], next); - char save = *next_ptr; - *next_ptr =0; - + void extract (const char* str, T* value) { + static_assert ( + std::is_same_v, int> + || std::is_same_v, double> + || std::is_same_v, char>, + "Not supported conversion type."); if constexpr (std::is_same_v, int>) { - sscanf(str, "%d", &value); - } else if (std::is_same_v, float>) { - sscanf(str, "%f", &value); + *value = std::atoi(str); } else if (std::is_same_v, double>) { - sscanf(str, "%lf", &value); + *value = std::atof(str); } else if (std::is_same_v, char>) { - sscanf(str, "%c", &value); + std::strcpy(value, str); } - *next_ptr = save; - return next_ptr - str; } - ptrdiff_t parse (char* str, size_t n, char next, char* value) { - auto next_ptr = std::find(str, &str[n], next); - char save = *next_ptr; - *next_ptr =0; - strcpy(value, str); - *next_ptr = save; - return next_ptr - str; + template + std::pair parse (const char* expected, const str_view_t buffer, char* token) { + if (*expected == Marker) { + // We have Marker. Copy to token the next part of buffer, from begin up to expected[1] where + // the expected[1] character is and return the size of that part. + auto next = std::find(buffer.begin(), buffer.end(), expected[1]); + if (next == buffer.end()) { + *token =0; + return std::make_pair(0, false); + } + char* nullpos = std::copy(buffer.begin(), next, token); + *nullpos =0; + return std::make_pair(next - buffer.begin(), true); + } + else if (*expected == buffer.front()) { + // We have character match, copy the character to token and return 1 (the char size) + *token++ = buffer.front(); + *token =0; + return std::make_pair(1, false); + } + else { + // Discrepancy. Return 0 (none parsed) + *token =0; + return std::make_pair(0, false); + } } + //! @} //! \name public functionality @@ -248,9 +269,6 @@ class BG95_base return 0; } - // cmd: "AT+CREG?" - // expected: "\r\n+CREG: 0,%\r\n\r\nOK\r\n" - /*! * \brief * Send a command to modem and check if the response matches to @@ -279,32 +297,26 @@ class BG95_base * \endcode */ template - bool command (const char* cmd, const str_view_t expected, T& t, clock_t timeout =0) { + bool command (const str_view_t cmd, const str_view_t expected, T* value, clock_t timeout =0) { char buffer[N]; + char token[N]; - transmit(cmd); + transmit(cmd.data()); // send command - for (size_t pos =0, i=0, j=0 ; pos < expected.size(); pos += j) { - str_view_t ex = expected.substr(pos); // get starting point of expected + for (auto ex = expected.begin() ; ex != expected.end() ; ) { + clock_t mark = clock(); // load the answer with timeout size_t sz =0; - clock_t mark = clock(); do { - sz = receive(buffer); // load the answer with timeout - if ((timeout != 0 )&& ((clock() - mark) >= timeout)) { + sz = receive(buffer); + if ((timeout != 0 )&& ((clock() - mark) >= timeout)) return false; - } } while (!sz); - for (i=0, j=0 ; i (ex++, {&buffer[i], sz-i}, token); + if (!step) return false; + if (marker) extract(token, value); + i += step; } } return true; @@ -322,16 +334,16 @@ class BG95_base * \param loop Flag to indicate blocking mode. If true blocking. */ template - void inetd (bool loop =true, const async_handlers* async_handles =nullptr) { + void inetd (bool loop =true, const inetd_handlers* inetd_handlers =nullptr) { std::array buffer; size_t resp_size; do { if ((resp_size = get_(buffer.data())) != 0) { // on data check for async handlers bool match = false; - if (async_handles != nullptr) { - for (auto& h : *async_handles) - match |= base_type::check_handle (h, buffer.data()); + if (inetd_handlers != nullptr) { + for (auto& h : *inetd_handlers) + match |= base_type::check_handle(h.token, h.match, h.handler, {buffer.data(), resp_size}); } // if no match forward data to receive channel. if (!match) { diff --git a/include/utils/sequencer.h b/include/utils/sequencer.h index 4c30586..daf49df 100644 --- a/include/utils/sequencer.h +++ b/include/utils/sequencer.h @@ -41,7 +41,8 @@ #include #include #include -#include +#include +#include namespace tbx { @@ -87,26 +88,18 @@ class sequencer { //! \name Public types //! @{ public: - //! \enum status_t - //! \brief The sequencer run status - enum class status_t { - OK, ERROR - }; - - - //! \enum action_t - //! \brief Possible response actions for the sequencer - enum class action_t { - NO, NEXT, GOTO, EXIT_OK, EXIT_ERROR - }; + using str_view_t = std::basic_string_view; //! \enum control_t //! \brief The control type of the script entry. enum class control_t { - NOP, //!< No command, dont send or expect anything, used for delays - SEND, //!< Send data to implementation through put() - EXPECT, //!< Expects data from implementation via get() - DETECT //!< Detects data into rx buffer without receiving them via contents() + NOP, //!< No command, dont send or expect anything, used for delays + SEND, //!< Send data to implementation through put() + EXPECT, //!< Expects data from implementation via get() + OR_EXPECT, //!< Expects data from implementation via get() in conjunction with previous EXPECT + DETECT, //!< Detects data into rx buffer without receiving them via contents() + OR_DETECT //!< Detects data into rx buffer without receiving them via contents() in conjunction with + //!< previous DETECT //! \note //! The \c DETECT extra incoming channel serve the purpose of sneak into receive @@ -118,6 +111,15 @@ class sequencer { //! lets say ">$ " without '\n' at the end. }; + //! \enum action_t + //! \brief Possible response actions for the sequencer + struct action_t { + enum { + NO =0, NEXT, GOTO, EXIT_OK, EXIT_ERROR + } type; + size_t step; + }; + //! \enum match_t //! \brief Token match types enum class match_t { @@ -130,24 +132,6 @@ class sequencer { */ using handler_ft = void (*) (const Data_t*, size_t); - /*! - * \struct handle_t - * \brief - * The script record handle block. - * - * Each script record contains some blocks for matching functionality. Each block - * has a token and a matching type. If the response matches the token, the sequencer calls - * the handler and perform the action. - */ - struct handle_t { - std::basic_string_view - token; //!< The token for the match - match_t match_type; //!< The matching type functionality - handler_ft handler; //!< The handler to called if the match is successful. - action_t action; //!< The action to be performer if the match is successful - size_t idx; //!< The index for the action_t::GOTO action. Otherwise can be left 0. - }; - /*! * \struct record_t * \brief @@ -156,11 +140,12 @@ class sequencer { * Each line consist from a control, 2 blocks and a timeout. The control says if we send or receive data. * The blocks contain the data and the matching information. And the timeout guards the entire line. */ - template struct record_t { control_t control; //!< The type of the entry - std::array - block; //!< The matching blocks + str_view_t token; + match_t match; + handler_ft handler; //!< The handler to called if the match is successful. + action_t action; clock_t timeout; //!< Timeout in CPU time }; @@ -183,10 +168,14 @@ class sequencer { * }}; * \endcode */ - template - using script_t = std::array, Nrecords>; + template + using script_t = std::array; + + + enum class seq_status_t { + CONTINUE, EXIT_OK, EXIT_ERROR + }; - using str_view_t = std::basic_string_view; //! @} @@ -251,6 +240,19 @@ class sequencer { static bool contains_ (const str_view_t haystack, const str_view_t needle) { return (haystack.find(needle) != str_view_t::npos); } + + bool is_step_extend (control_t control) { + return (control == control_t::OR_EXPECT || control == control_t::OR_DETECT); + } + + static bool handle_ (handler_ft handler, const str_view_t buffer = str_view_t{}) { + if (handler) { + handler (buffer.begin(), buffer.size()); + return true; + } + return false; + } + /*! * \brief * Return the new sequencer's step value. @@ -262,33 +264,18 @@ class sequencer { * \param go_idx The new value of the step in the case of GOTO type * \return The new sequencer's step value */ - static size_t step_ (size_t current_idx, action_t action, size_t go_idx =0) { - switch (action) { + static std::pair action_ (const action_t& action, size_t step) { + switch (action.type) { default: - case action_t::NO: return current_idx; - case action_t::NEXT: return ++current_idx; - case action_t::GOTO: return go_idx; + case action_t::NO: return std::make_pair(step, seq_status_t::CONTINUE); + case action_t::NEXT: return std::make_pair(++step, seq_status_t::CONTINUE); + case action_t::GOTO: return std::make_pair(action.step, seq_status_t::CONTINUE); case action_t::EXIT_OK: + return std::make_pair(std::numeric_limits::max(), seq_status_t::EXIT_OK); case action_t::EXIT_ERROR: - return 0; + return std::make_pair(std::numeric_limits::max(), seq_status_t::EXIT_ERROR); } } - static status_t action_ (size_t& step, const handle_t& block, const str_view_t buffer = str_view_t{}) { - if (block.handler != nullptr) - block.handler(buffer.begin(), buffer.size()); - switch (block.action) { - case action_t::EXIT_OK: - step = std::numeric_limits::max(); - return status_t::OK; - case action_t::EXIT_ERROR: - step = std::numeric_limits::max(); - return status_t::ERROR; - default: - step = step_(step, block.action, block.idx); - return status_t::OK; - } - - } //! @} @@ -325,10 +312,9 @@ class sequencer { * \param buffer The buffer to check * \return True on match, false otherwise */ - static bool check_handle (const handle_t& handle, const str_view_t buffer) { - size_t tmp{}; - if (match(buffer, handle.token, handle.match_type)) { - action_ (tmp, handle, buffer); + static bool check_handle (const str_view_t token, match_t match_type, handler_ft handle, const str_view_t buffer) { + if (match(buffer, token, match_type)) { + handle_ (handle, buffer); return true; } return false; @@ -364,82 +350,70 @@ class sequencer { * \param script Reference to script to run * \return The status of entire operation as described above */ - template - bool run (const script_t& script) { + template + bool run (const script_t& script) { Data_t buffer[N]; - size_t resp_size{}; - status_t status{}; + size_t resp_size; + seq_status_t status{seq_status_t::CONTINUE}; + size_t step =0, p_step =0; clock_t mark = clock_(); - for (size_t step =0, p_step =0 ; step < Steps ; ) { - const record_t& it = script[step]; - + do { if (step != p_step) { p_step = step; mark = clock_(); } - switch (it.control) { + switch (script[step].control) { default: case control_t::NOP: - if ((clock_() - mark) >= it.timeout) - status = action_ (step, it.block[0]); + if ((clock_() - mark) >= script[step].timeout) + std::tie(step, status) = action_ (script[step].action, step); break; case control_t::SEND: - if (put_(it.block[0].token.data(), it.block[0].token.size()) != it.block[0].token.size()) + if (put_(script[step].token.data(), script[step].token.size()) != script[step].token.size()) return false; - status = action_ (step, it.block[0]); + std::tie(step, status) = action_ (script[step].action, step); break; case control_t::EXPECT: + case control_t::OR_EXPECT: resp_size = get_(buffer); if (resp_size) { - for (auto& block : it.block) { - if (match( - {buffer, resp_size}, - block.token, - block.match_type)) { - status = action_ (step, block, {buffer, resp_size}); + for (size_t s = step ; script[s].control == control_t::OR_EXPECT; ++s) { + if (match({buffer, resp_size}, script[s].token, script[s].match)) { + handle_ (script[s].handler, {buffer, resp_size}); + std::tie(step, status) = action_ (script[s].action, s); break; } } } - if (it.timeout && (clock_() - mark) >= it.timeout) + if (script[step].timeout && (clock_() - mark) >= script[step].timeout) return false; break; + case control_t::DETECT: + case control_t::OR_DETECT: auto data = contents_(); if (data.begin() != data.end()) { - for (auto& block : it.block) { - if (match( - {data.begin(), static_cast(data.end() - data.begin())}, - block.token, - block.match_type)) { - status = action_ (step, block, {buffer, resp_size}); + for (size_t s = step ; script[s].control == control_t::OR_DETECT ; ++s) { + if (match({buffer, resp_size}, script[s].token, script[s].match)) { + handle_ (script[s].handler, {buffer, resp_size}); + std::tie(step, status) = action_ (script[s].action, s); break; } } } - if (it.timeout && (clock_() - mark) >= it.timeout) + if (script[step].timeout && (clock_() - mark) >= script[step].timeout) return false; break; } // switch (it.control) - } - return (status == status_t::OK); + } while ( status == seq_status_t::CONTINUE); + + return (status == seq_status_t::EXIT_OK); } }; -/*! - * An "empty" block for convenience. - */ -template -constexpr typename sequencer::handle_t Sequencer_null_block = { - "", - sequencer::match_t::NO, - nullptr, - sequencer::action_t::NO, - 0 -}; } #endif /* TBX_UTILS_SEQUENCER_H_ */ diff --git a/test/tests/BG95_base.cpp b/test/tests/BG95_base.cpp index 40689a1..49ebad3 100644 --- a/test/tests/BG95_base.cpp +++ b/test/tests/BG95_base.cpp @@ -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]; diff --git a/test/tests/sequencer.cpp b/test/tests/sequencer.cpp index abdae80..503d7fa 100644 --- a/test/tests/sequencer.cpp +++ b/test/tests/sequencer.cpp @@ -76,62 +76,55 @@ namespace test_sequencer { */ TEST(Tsequencer, run_delay) { Seq s; - const std::array, 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, 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, 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, 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, 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); }