Download this file
#include "listener.h"
#include "heater_controller_slave.h"

bool Listener::canRun(uint32_t now) {
  if (rf12_recvDone()) {
    //Serial.println("recvDone");
    return (rf12_crc == 0 &&  rf12_len <= BUFFER_LEN);
  }
  return false;
}

void Listener::run(uint32_t now) {
  recv_buffer_len = rf12_len;
  memcpy((void *)recv_buffer, (void *)rf12_data, recv_buffer_len);
  //SHOW_BUFFER("RECV: ", rf12_hdr, recv_buffer, recv_buffer_len);
  if (rf12_hdr == (RF12_HDR_CTL | (MASTER_ID & RF12_HDR_MASK)))
    // received an ACK from MASTER
    protocol->got_ack();
  else {
    if (RF12_WANTS_ACK) {
      //SHOW_BUFFER("SACK: ", RF12_ACK_REPLY, recv_buffer, 0);
      rf12_sendStart(RF12_ACK_REPLY, 0, 0);
      rf12_sendWait(0);
    }
    protocol->handle(recv_buffer, recv_buffer_len);
  }
}

// vim:ft=arduino