|
@@ -175,7 +175,33 @@ class BG95_base |
|
|
//! \name Private functionality
|
|
|
//! \name Private functionality
|
|
|
//! @{
|
|
|
//! @{
|
|
|
private:
|
|
|
private:
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
if constexpr (std::is_same_v<std::remove_cv_t<T>, int>) {
|
|
|
|
|
|
sscanf(str, "%d", &value);
|
|
|
|
|
|
} else if (std::is_same_v<std::remove_cv_t<T>, float>) {
|
|
|
|
|
|
sscanf(str, "%f", &value);
|
|
|
|
|
|
} else if (std::is_same_v<std::remove_cv_t<T>, double>) {
|
|
|
|
|
|
sscanf(str, "%lf", &value);
|
|
|
|
|
|
} else if (std::is_same_v<std::remove_cv_t<T>, char>) {
|
|
|
|
|
|
sscanf(str, "%c", &value);
|
|
|
|
|
|
}
|
|
|
|
|
|
*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;
|
|
|
|
|
|
}
|
|
|
//! @}
|
|
|
//! @}
|
|
|
|
|
|
|
|
|
//! \name public functionality
|
|
|
//! \name public functionality
|
|
@@ -222,6 +248,33 @@ class BG95_base |
|
|
return 0;
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// cmd: "AT+CREG?"
|
|
|
|
|
|
// expected: "\r\n+CREG: 0,%\r\n\r\nOK\r\n"
|
|
|
|
|
|
template <typename T, char Marker = '%'>
|
|
|
|
|
|
bool command (const char* cmd, const str_view_t expected, T& t) {
|
|
|
|
|
|
char buffer[N];
|
|
|
|
|
|
|
|
|
|
|
|
transmit(cmd);
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
size_t sz = receive(buffer, 1); // load the answer
|
|
|
|
|
|
for (i=0, j=0 ; i<sz ; ) {
|
|
|
|
|
|
if (ex[j] == Marker) {
|
|
|
|
|
|
i += parse(&buffer[i], sz, ex[j+1], t); // parse and convert
|
|
|
|
|
|
++j;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (ex[j] == buffer[i]) {
|
|
|
|
|
|
++i;
|
|
|
|
|
|
++j; // consume current character
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
return false; // Fail to parse
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/*!
|
|
|
/*!
|
|
|
* \brief
|
|
|
* \brief
|
|
|
* inetd daemon functionality provided as member function of the driver. This should be running
|
|
|
* inetd daemon functionality provided as member function of the driver. This should be running
|
|
@@ -257,58 +310,6 @@ class BG95_base |
|
|
} while (loop);
|
|
|
} while (loop);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
template <size_t Steps, size_t Nhandles>
|
|
|
|
|
|
bool configure (const script_t<Steps, Nhandles>& script) {
|
|
|
|
|
|
return base_type::run (script);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// // General API
|
|
|
|
|
|
// static constexpr typename base_type::handle_t error_handle_ = {
|
|
|
|
|
|
// "ERROR", match_t::CONTAINS, nullptr, action_t::EXIT_ERROR, 0
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
|
void 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;
|
|
|
|
|
|
|
|
|
|
|
|
if constexpr (std::is_same_v<std::remove_cv<T>, int>) {
|
|
|
|
|
|
sscanf(str, "%d", &value);
|
|
|
|
|
|
} else if (std::is_same_v<std::remove_cv<T>, float>) {
|
|
|
|
|
|
sscanf(str, "%f", &value);
|
|
|
|
|
|
} else if (std::is_same_v<std::remove_cv<T>, double>) {
|
|
|
|
|
|
sscanf(str, "%lf", &value);
|
|
|
|
|
|
} else if (std::is_same_v<std::remove_cv<T>, char>) {
|
|
|
|
|
|
sscanf(str, "%c", &value);
|
|
|
|
|
|
} else if (std::is_same_v<std::remove_cv<T>, char*>) {
|
|
|
|
|
|
strcpy(value, str);
|
|
|
|
|
|
}
|
|
|
|
|
|
*next_ptr = save;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// cmd: "AT+CREG?"
|
|
|
|
|
|
// expected: "\r\n+CREG: 0,%\r\nOK\r\n"
|
|
|
|
|
|
template <typename T, char Marker = '%'>
|
|
|
|
|
|
bool command (const str_view_t cmd, const str_view_t expected, T& t) {
|
|
|
|
|
|
char buffer[N];
|
|
|
|
|
|
|
|
|
|
|
|
transmit(cmd);
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t pos =0 ; pos < expected.size(); ) {
|
|
|
|
|
|
str_view_t ex = expected.substr(pos); // get starting point of expected
|
|
|
|
|
|
size_t sz = receive(buffer, 1); // load the answer
|
|
|
|
|
|
for (size_t i ; i<sz ; ) {
|
|
|
|
|
|
if (ex[i] == Marker)
|
|
|
|
|
|
parse(buffer[i], sz, ex[i+1], t); // parse and convert
|
|
|
|
|
|
else if (ex[i] == buffer[i])
|
|
|
|
|
|
++i; // consume current character
|
|
|
|
|
|
else
|
|
|
|
|
|
return false; // Fail to parse
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
//! @}
|
|
|
//! @}
|
|
|
|
|
|
|
|
|
private:
|
|
|
private:
|
|
|