mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Examples/PPPoS: Fix handling empty lines with CRLF only
Tokenizing data by '\n' will effectively replace all LF characters by '\0' so checking for phantom lines has to be adjusted: * minimal empty line is CR only (strlen = 1) * checking for lines containing CR only
This commit is contained in:
parent
0a15cc5e5a
commit
14a652376f
@ -60,15 +60,15 @@ typedef struct {
|
|||||||
} esp_modem_dte_t;
|
} esp_modem_dte_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns true if the supplied string contains only CR or LF
|
* @brief Returns true if the supplied string contains only <CR> characters
|
||||||
*
|
*
|
||||||
* @param str string to check
|
* @param str string to check
|
||||||
* @param len length of string
|
* @param len length of string
|
||||||
*/
|
*/
|
||||||
static inline bool is_only_cr_lf(const char *str, uint32_t len)
|
static inline bool is_only_cr(const char *str, uint32_t len)
|
||||||
{
|
{
|
||||||
for (int i=0; i<len; ++i) {
|
for (int i=0; i<len; ++i) {
|
||||||
if (str[i] != '\r' && str[i] != '\n') {
|
if (str[i] != '\r') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ static esp_err_t esp_dte_handle_line(esp_modem_dte_t *esp_dte, char * line, size
|
|||||||
char *p = strtok_r(line, "\n", &str_ptr);
|
char *p = strtok_r(line, "\n", &str_ptr);
|
||||||
while (p) {
|
while (p) {
|
||||||
int plen = strlen(p);
|
int plen = strlen(p);
|
||||||
if (plen > 2 && !is_only_cr_lf(p, plen)) {
|
if (plen > 1 && !is_only_cr(p, plen)) {
|
||||||
ESP_LOGD(MODEM_TAG, "Handling line: >>%s\n<<", p);
|
ESP_LOGD(MODEM_TAG, "Handling line: >>%s\n<<", p);
|
||||||
if (dce->handle_line == NULL) {
|
if (dce->handle_line == NULL) {
|
||||||
/* Received an asynchronous line, but no handler waiting this this */
|
/* Received an asynchronous line, but no handler waiting this this */
|
||||||
|
Loading…
Reference in New Issue
Block a user