コード例 #1
0
ファイル: RFM69.cpp プロジェクト: mike-zero/RFM69
void RFM69::interruptHandler() {
  //pinMode(4, OUTPUT);
  //digitalWrite(4, 1);
  if (_mode == RF69_MODE_RX && (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PAYLOADREADY))
  {
    setMode(RF69_MODE_STANDBY);
    select();
    SPI.transfer(REG_FIFO & 0x7f);
    PAYLOADLEN = SPI.transfer(0);
    PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; //precaution
    TARGETID = SPI.transfer(0);
    if(!(_promiscuousMode || TARGETID==_address || TARGETID==RF69_BROADCAST_ADDR)) //match this node's address, or broadcast address or anything in promiscuous mode
    {
      PAYLOADLEN = 0;
      unselect();
      //digitalWrite(4, 0);
      return;
    }
    DATALEN = PAYLOADLEN - 3;
    SENDERID = SPI.transfer(0);
    byte CTLbyte = SPI.transfer(0);
    
    ACK_RECEIVED = CTLbyte & 0x80; //extract ACK-requested flag
    ACK_REQUESTED = CTLbyte & 0x40; //extract ACK-received flag
    
    for (byte i= 0; i < DATALEN; i++)
    {
      DATA[i] = SPI.transfer(0);
    }
    unselect();
    setMode(RF69_MODE_RX);
  }
  RSSI = readRSSI();
  //digitalWrite(4, 0);
}
コード例 #2
0
ファイル: RFM69.cpp プロジェクト: mike-zero/RFM69
bool RFM69::canSend()
{
  if (_mode == RF69_MODE_RX && PAYLOADLEN == 0 && readRSSI() < CSMA_LIMIT) //if signal stronger than -100dBm is detected assume channel activity
  {
    setMode(RF69_MODE_STANDBY);
    return true;
  }
  return false;
}
コード例 #3
0
ファイル: rfm69.cpp プロジェクト: abouillot/HomeAutomation
bool RFM69::canSend()
{
// printf("mode %d, payload %d, rssi %d %d\n", _mode, PAYLOADLEN, readRSSI(), CSMA_LIMIT);
  if (_mode == RF69_MODE_RX && PAYLOADLEN == 0 && readRSSI() < CSMA_LIMIT) // if signal stronger than -100dBm is detected assume channel activity
  {
    setMode(RF69_MODE_STANDBY);
    return true;
  }
  return false;
}
コード例 #4
0
ファイル: RFM69.cpp プロジェクト: aarlaud/ArduinoLibraries
void RFM69::interruptHandler() {
  //pinMode(4, OUTPUT);
  //digitalWrite(4, 1);
  if (_mode == RF69_MODE_RX && (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PAYLOADREADY))
  {
    //RSSI = readRSSI();
    setMode(RF69_MODE_STANDBY);
    select();
    SPI.transfer(REG_FIFO & 0x7F);
    PAYLOADLEN = SPI.transfer(0);
    PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; // precaution
    TARGETID = SPI.transfer(0);
    if(!(_promiscuousMode || TARGETID == _address || TARGETID == RF69_BROADCAST_ADDR) // match this node's address, or broadcast address or anything in promiscuous mode
       || PAYLOADLEN < 3) // address situation could receive packets that are malformed and don't fit this libraries extra fields
    {
      PAYLOADLEN = 0;
      unselect();
      receiveBegin();
      //digitalWrite(4, 0);
      return;
    }

    DATALEN = PAYLOADLEN - 3;
    SENDERID = SPI.transfer(0);
    uint8_t CTLbyte = SPI.transfer(0);

    ACK_RECEIVED = CTLbyte & 0x80; // extract ACK-received flag
    ACK_REQUESTED = CTLbyte & 0x40; // extract ACK-requested flag

    for (uint8_t i = 0; i < DATALEN; i++)
    {
      DATA[i] = SPI.transfer(0);
    }
    if (DATALEN < RF69_MAX_DATA_LEN) DATA[DATALEN] = 0; // add null at end of string
    unselect();
    setMode(RF69_MODE_RX);
  }
  RSSI = readRSSI();
  //digitalWrite(4, 0);
}
コード例 #5
0
ファイル: rfm69.cpp プロジェクト: abouillot/HomeAutomation
// internal function - interrupt gets called when a packet is received
void RFM69::interruptHandler() {

#ifdef RASPBERRY
  unsigned char thedata[67];
  char i;
  for(i = 0; i < 67; i++) thedata[i] = 0;
//  printf("interruptHandler %d\n", intCount);
#endif
 
 //pinMode(4, OUTPUT);
  //digitalWrite(4, 1);
  if (_mode == RF69_MODE_RX && (readReg(REG_IRQFLAGS2) & RF_IRQFLAGS2_PAYLOADREADY))
  {
    //RSSI = readRSSI();
    setMode(RF69_MODE_STANDBY);
#ifdef RASPBERRY
    thedata[0] = REG_FIFO & 0x7F;
    thedata[1] = 0; // PAYLOADLEN
    thedata[2] = 0; //  TargetID
    wiringPiSPIDataRW(SPI_DEVICE, thedata, 3);
    delayMicroseconds(MICROSLEEP_LENGTH);

    PAYLOADLEN = thedata[1];
    PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; // precaution
    TARGETID = thedata[2];
#else
    select();
    SPI.transfer(REG_FIFO & 0x7F);
    PAYLOADLEN = SPI.transfer(0);
    PAYLOADLEN = PAYLOADLEN > 66 ? 66 : PAYLOADLEN; // precaution
    TARGETID = SPI.transfer(0);
#endif
    if(!(_promiscuousMode || TARGETID == _address || TARGETID == RF69_BROADCAST_ADDR) // match this node's address, or broadcast address or anything in promiscuous mode
       || PAYLOADLEN < 3) // address situation could receive packets that are malformed and don't fit this libraries extra fields
    {
      PAYLOADLEN = 0;
      unselect();
      receiveBegin();
      //digitalWrite(4, 0);
      return;
    }
#ifdef RASPBERRY
    DATALEN = PAYLOADLEN - 3;
    thedata[0] = REG_FIFO & 0x77;
    thedata[1] = 0; //SENDERID
    thedata[2] = 0; //CTLbyte;
    for(i = 0; i< DATALEN; i++) {
      thedata[i+3] = 0;
    }

    wiringPiSPIDataRW(SPI_DEVICE, thedata, DATALEN + 3);

    SENDERID = thedata[1];
    uint8_t CTLbyte = thedata[2];

    ACK_RECEIVED = CTLbyte & 0x80; //extract ACK-requested flag
    ACK_REQUESTED = CTLbyte & 0x40; //extract ACK-received flag
    for (i= 0; i < DATALEN; i++)
      {
      DATA[i] = thedata[i+3];
      }
#else
    DATALEN = PAYLOADLEN - 3;
    SENDERID = SPI.transfer(0);
    uint8_t CTLbyte = SPI.transfer(0);

    ACK_RECEIVED = CTLbyte & RFM69_CTL_SENDACK; // extract ACK-received flag
    ACK_REQUESTED = CTLbyte & RFM69_CTL_REQACK; // extract ACK-requested flag
    
    interruptHook(CTLbyte);     // TWS: hook to derived class interrupt function
    for (uint8_t i = 0; i < DATALEN; i++)
    {
      DATA[i] = SPI.transfer(0);
    }
#endif
    if (DATALEN < RF69_MAX_DATA_LEN) DATA[DATALEN] = 0; // add null at end of string
    unselect();
    setMode(RF69_MODE_RX);
  }
  RSSI = readRSSI();
  //digitalWrite(4, 0);

}
コード例 #6
0
ファイル: main.c プロジェクト: pe1jpd/23cm
int rxtx()
{
	int s;

	// read ptt on PORTD
	int c = PIND;

	// listen reverse?
	if (rv) {
		if (c & (1<<REVERSE)) {
			lastFreq = 0;
			rv = FALSE;
		}
	}
	else {
		if (!(c & (1<<REVERSE))) {
			lastFreq = 0;
			rv = TRUE;
		}
	}

	if (tx) {
		//keep smeter clear
		s = 0;
		// switch from tx to rx??
		if (c & (1<<PTT) ) {
			cbi(PORTC, TXON);
			lastFreq = 0;
			tx = FALSE;
		}
	}
	else {
		s = readRSSI();
		displaySmeter(s);

		// switch from rx to tx?
		if (!(c & (1<<PTT) )) {
			// clear smeter
			s = 0;
			displaySmeter(s);
			sbi(PORTC, MUTE);
			sbi(PORTC, TXON);
			// force update pll
			lastFreq = 0;
			tx = TRUE;
		}
	}

	// calc value for ISR
	toneCount = 5*F_CPU/tone;

	// freq change or update needed?
	if (freq != lastFreq) {
		long int f = freq;
		if (tx) {
			f += (long int) shift*1000;
			setFrequency(f);
		}
		else {
			if (rv) f += (long int)shift*1000;
			setFrequency(f - IF);
		}
		displayFrequency(f);
		lastFreq = freq;
		lcdCursor(15,0);
		if (tx)
			lcdChar('T');
		else
			lcdChar('R');
	}

	return s;
}