160 ESP_LOGV(TAG,
"Read from serial: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
163 ESP_LOGI(TAG,
"Comment: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
166 std::string::size_type newlineposn = this->
buffer_.find(
'\n');
167 if (newlineposn <= 1) {
169 ESP_LOGD(TAG,
"Received empty line");
172 if (newlineposn <= 2) {
174 ESP_LOGD(TAG,
"Received ack: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
177 if (this->
buffer_.find(
"LensBad") != std::string::npos) {
178 ESP_LOGW(TAG,
"Received LensBad!");
181 if (this->
buffer_.find(
"EmSat") != std::string::npos) {
182 ESP_LOGW(TAG,
"Received EmSat!");
185 if (
buffer_.starts_with(
"PwrDays")) {
193 ESP_LOGI(TAG,
"Boot detected: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
214 if (
buffer_.starts_with(
"SW")) {
215 std::string::size_type majend = this->
buffer_.find(
'.');
216 std::string::size_type endversion = this->
buffer_.find(
' ', 3);
217 if (majend == std::string::npos || endversion == std::string::npos || majend > endversion) {
218 ESP_LOGW(TAG,
"invalid version string: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
220 int major = strtol(this->
buffer_.substr(3, majend - 3).c_str(),
nullptr, 10);
221 int minor = strtol(this->
buffer_.substr(majend + 1, endversion - (majend + 1)).c_str(),
nullptr, 10);
223 if (major > 10 || minor >= 1000 || minor < 0 || major < 0) {
224 ESP_LOGW(TAG,
"invalid version: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
227 ESP_LOGI(TAG,
"detected sw version %i", this->
sw_version_);
230 bool is_data_line =
false;
231 for (
int i = 0; i < NUM_SENSORS; i++) {
232 if (this->
sensors_[i] !=
nullptr && this->
buffer_.find(PROTOCOL_NAMES[i]) != std::string::npos) {
238 std::string::size_type tc = this->
buffer_.find(
"TooCold");
239 this->
too_cold_ |= tc != std::string::npos;
241 ESP_LOGD(TAG,
"Received TooCold");
243 for (
int i = 0; i < NUM_SENSORS; i++) {
247 std::string::size_type n = this->
buffer_.find(PROTOCOL_NAMES[i]);
248 if (n == std::string::npos) {
252 if (n == this->
buffer_.find(
't', n)) {
256 n = this->
buffer_.find(
'F', n);
257 if (n == std::string::npos) {
262 n += strlen(PROTOCOL_NAMES[i]);
266 float data = strtof(this->
buffer_.substr(n).c_str(),
nullptr);
268 ESP_LOGD(TAG,
"Received %s: %f", PROTOCOL_NAMES[i], this->
sensors_[i]->get_raw_state());
275 for (
const auto *ignore : IGNORE_STRINGS) {
276 if (
buffer_.starts_with(ignore)) {
277 ESP_LOGI(TAG,
"Ignoring %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
281 ESP_LOGI(TAG,
"Got unknown line: %s", this->
buffer_.c_str());