jesserockz

Untitled

Jan 17th, 2021
566
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void ICACHE_RAM_ATTR CrowAlarmPanelStore::interrupt(CrowAlarmPanelStore *arg) {
  2.   bool data_bit = arg->data_pin_->digital_read();
  3.  
  4.   arg->buffer.push_back(data_bit);
  5.  
  6.   std::vector<bool> last8(arg->buffer.end() - 8, arg->buffer.end());
  7.  
  8.   if (byte_from_binary(last8) == BOUNDARY) {
  9.     // Found right boundary?
  10.     if (arg->inside_) {
  11.       if (arg->buffer.size() % 8 == 0) { // Ignore data that is not solid bytes
  12.         CrowAlarmPanelMessage message;
  13.         std::vector<uint8_t> bytes;
  14.         std::vector<bool> type_bits(arg->buffer.begin() + 8, arg->buffer.begin() + 16);
  15.         message.type = byte_from_binary(type_bits, true);
  16.         for (uint8_t i = 16; i < arg->buffer.size() - 8; i += 8) {
  17.           std::vector<bool> bits(arg->buffer.begin() + i, arg->buffer.begin() + i + 8);
  18.           uint8_t byte = byte_from_binary(bits, true);
  19.           bytes.push_back(byte);
  20.         }
  21.         message.data = bytes;
  22.         arg->messages.push_back(std::move(message));
  23.       }
  24.       arg->buffer.clear();
  25.     }
  26.  
  27.     arg->inside_ = !arg->inside_;
  28.   } else if (!arg->inside_ && arg->buffer.size() >= 8) {
  29.     arg->buffer.pop_front();
  30.   }
  31.  
  32.   // Wrong side of boundary?
  33.   if (arg->inside_ && arg->buffer.size() > 200) {
  34.     arg->inside_ = false;
  35.     ESP_LOGD(TAG, "Wrong side of boundary");
  36.   }
  37. }
RAW Paste Data