lib/RFM69/RFM69_ATC.cpp
//=============================================================================
// sendFrame() - the new one with additional parameters.  This packages recv'd RSSI with the packet, if required.
//=============================================================================
the new one with additional parameters.  This packages recv'd RSSI with the packet, if required.
the new one with additional parameters . This packages recv ' d RSSI with the packet if required .
void RFM69_ATC::sendFrame(uint16_t toAddress, const void* buffer, uint8_t bufferSize, bool requestACK, bool sendACK, bool sendRSSI, int16_t lastRSSI) {
  setMode(RF69_MODE_STANDBY); 
  while ((readReg(REG_IRQFLAGS1) & RF_IRQFLAGS1_MODEREADY) == 0x00); 
  bufferSize += (sendACK && sendRSSI)?1:0;  
  if (bufferSize > RF69_MAX_DATA_LEN) bufferSize = RF69_MAX_DATA_LEN;
  select();
  _spi->transfer(REG_FIFO | 0x80);
  _spi->transfer(bufferSize + 3);
  _spi->transfer((uint8_t)toAddress); 
  _spi->transfer((uint8_t)_address);  
  uint8_t CTLbyte=0x0;
  if (toAddress > 0xFF) CTLbyte |= (toAddress & 0x300) >> 6; 
  if (_address > 0xFF) CTLbyte |= (_address & 0x300) >> 8;   
  if (sendACK) {                   
    _spi->transfer(CTLbyte | RFM69_CTL_SENDACK | (sendRSSI?RFM69_CTL_RESERVE1:0));  
    if (sendRSSI) {
      _spi->transfer(abs(lastRSSI)); 
      bufferSize -=1;              
    }
  }
  else if (requestACK) {  
    _spi->transfer(CTLbyte | (_targetRSSI ? RFM69_CTL_REQACK | RFM69_CTL_RESERVE1 : RFM69_CTL_REQACK));
  }
  else _spi->transfer(CTLbyte);
  for (uint8_t i = 0; i < bufferSize; i++)
    _spi->transfer(((uint8_t*) buffer)[i]);
  unselect();
  setMode(RF69_MODE_TX);
  while ((readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PACKETSENT) == 0x00); 
  setMode(RF69_MODE_STANDBY);
}
void RFM69_ATC :: sendFrame ( uint16_t toAddress , const void * buffer , uint8_t bufferSize , bool requestACK , bool sendACK , bool sendRSSI , int16_t lastRSSI ) { setMode ( RF69_MODE_STANDBY ) ; while ( ( readReg ( REG_IRQFLAGS1 ) & RF_IRQFLAGS1_MODEREADY ) == 0x00 ) ; bufferSize += ( sendACK && sendRSSI ) ? 1 : 0 ; if ( bufferSize > RF69_MAX_DATA_LEN ) bufferSize = RF69_MAX_DATA_LEN ; select ( ) ; _spi -> transfer ( REG_FIFO | 0x80 ) ; _spi -> transfer ( bufferSize + 3 ) ; _spi -> transfer ( ( uint8_t ) toAddress ) ; _spi -> transfer ( ( uint8_t ) _address ) ; uint8_t CTLbyte = 0x0 ; if ( toAddress > 0xFF ) CTLbyte |= ( toAddress & 0x300 ) >> 6 ; if ( _address > 0xFF ) CTLbyte |= ( _address & 0x300 ) >> 8 ; if ( sendACK ) { _spi -> transfer ( CTLbyte | RFM69_CTL_SENDACK | ( sendRSSI ? RFM69_CTL_RESERVE1 : 0 ) ) ; if ( sendRSSI ) { _spi -> transfer ( abs ( lastRSSI ) ) ; bufferSize -= 1 ; } } else if ( requestACK ) { _spi -> transfer ( CTLbyte | ( _targetRSSI ? RFM69_CTL_REQACK | RFM69_CTL_RESERVE1 : RFM69_CTL_REQACK ) ) ; } else _spi -> transfer ( CTLbyte ) ; for ( uint8_t i = 0 ; i < bufferSize ; i ++ ) _spi -> transfer ( ( ( uint8_t * ) buffer ) [ i ] ) ; unselect ( ) ; setMode ( RF69_MODE_TX ) ; while ( ( readReg ( REG_IRQFLAGS2 ) & RF_IRQFLAGS2_PACKETSENT ) == 0x00 ) ; setMode ( RF69_MODE_STANDBY ) ; }
sendFrame() - the new one with additional parameters.
sendFrame () - the new one with additional parameters .
// turn off receiver to prevent reception while filling fifo // wait for ModeReady //writeReg(REG_DIOMAPPING1, RF_DIOMAPPING1_DIO0_00); // DIO0 is "Packet Sent" // if sending ACK_RSSI then increase data size by 1 // write to FIFO //lower 8bits //lower 8bits // CTL (control byte) //assign last 2 bits of address if > 255 //assign last 2 bits of address if > 255 // TomWS1: adding logic to return ACK_RSSI if requested // TomWS1  TODO: Replace with EXT1 //RSSI dBm is negative expected between [-100 .. -20], convert to positive and pass along as single extra header byte // account for the extra ACK-RSSI 'data' byte // TODO: add logic to request ackRSSI with ACK - this is when both ends of a transmission would dial power down. May not work well for gateways in multi node networks // no need to wait for transmit mode to be ready since its handled by the radio //uint32_t txStart = millis(); //while (digitalRead(_interruptPin) == 0 && millis() - txStart < RF69_TX_LIMIT_MS); // wait for DIO0 to turn HIGH signalling transmission finish // wait for PacketSent