Introduce parse_number() helper function (#2659)

This commit is contained in:
Oxan van Leeuwen
2021-11-10 19:15:06 +01:00
committed by GitHub
parent 219b225ac0
commit 15f9677d33
15 changed files with 70 additions and 36 deletions
+2 -2
View File
@@ -128,7 +128,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
if (message.compare(0, 5, "+CSQ:") == 0) {
size_t comma = message.find(',', 6);
if (comma != 6) {
this->rssi_ = strtol(message.substr(6, comma - 6).c_str(), nullptr, 10);
this->rssi_ = parse_number<int>(message.substr(6, comma - 6)).value_or(0);
ESP_LOGD(TAG, "RSSI: %d", this->rssi_);
}
}
@@ -146,7 +146,7 @@ void Sim800LComponent::parse_cmd_(std::string message) {
while (end != start) {
item++;
if (item == 1) { // Slot Index
this->parse_index_ = strtol(message.substr(start, end - start).c_str(), nullptr, 10);
this->parse_index_ = parse_number<uint8_t>(message.substr(start, end - start)).value_or(0);
}
// item 2 = STATUS, usually "REC UNERAD"
if (item == 3) { // recipient