161 ESP_LOGV(TAG,
"Read from serial: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
164 ESP_LOGI(TAG,
"Comment: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
167 std::string::size_type newlineposn = this->
buffer_.find(
'\n');
168 if (newlineposn <= 1) {
170 ESP_LOGD(TAG,
"Received empty line");
173 if (newlineposn <= 2) {
175 ESP_LOGD(TAG,
"Received ack: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
178 if (this->
buffer_.find(
"LensBad") != std::string::npos) {
179 ESP_LOGW(TAG,
"Received LensBad!");
182 if (this->
buffer_.find(
"EmSat") != std::string::npos) {
183 ESP_LOGW(TAG,
"Received EmSat!");
186 if (
buffer_.starts_with(
"PwrDays")) {
194 ESP_LOGI(TAG,
"Boot detected: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
215 if (
buffer_.starts_with(
"SW")) {
216 std::string::size_type majend = this->
buffer_.find(
'.');
217 std::string::size_type endversion = this->
buffer_.find(
' ', 3);
218 if (majend == std::string::npos || endversion == std::string::npos || majend > endversion) {
219 ESP_LOGW(TAG,
"invalid version string: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
221 int major = strtol(this->
buffer_.substr(3, majend - 3).c_str(),
nullptr, 10);
222 int minor = strtol(this->
buffer_.substr(majend + 1, endversion - (majend + 1)).c_str(),
nullptr, 10);
224 if (major > 10 || minor >= 1000 || minor < 0 || major < 0) {
225 ESP_LOGW(TAG,
"invalid version: %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
228 ESP_LOGI(TAG,
"detected sw version %i", this->
sw_version_);
231 bool is_data_line =
false;
232 for (
int i = 0; i < NUM_SENSORS; i++) {
233 if (this->
sensors_[i] !=
nullptr && this->
buffer_.find(PROTOCOL_NAMES[i]) != std::string::npos) {
239 std::string::size_type tc = this->
buffer_.find(
"TooCold");
240 this->
too_cold_ |= tc != std::string::npos;
242 ESP_LOGD(TAG,
"Received TooCold");
244 for (
int i = 0; i < NUM_SENSORS; i++) {
248 std::string::size_type n = this->
buffer_.find(PROTOCOL_NAMES[i]);
249 if (n == std::string::npos) {
253 if (n == this->
buffer_.find(
't', n)) {
257 n = this->
buffer_.find(
'F', n);
258 if (n == std::string::npos) {
263 n += strlen(PROTOCOL_NAMES[i]);
267 float data = strtof(this->
buffer_.substr(n).c_str(),
nullptr);
269 ESP_LOGD(TAG,
"Received %s: %f", PROTOCOL_NAMES[i], this->
sensors_[i]->get_raw_state());
276 for (
const auto *ignore : IGNORE_STRINGS) {
277 if (
buffer_.starts_with(ignore)) {
278 ESP_LOGI(TAG,
"Ignoring %s", this->
buffer_.substr(0, this->buffer_.size() - 2).c_str());
282 ESP_LOGI(TAG,
"Got unknown line: %s", this->
buffer_.c_str());