int main() { init(); usart0_init(); uint8_t slave_id=~(PINB); char tx_buffer[4]; tx_buffer[0]=slave_id; tx_buffer[1]=DEVICE_ID; sei(); while(1) { if(!(PIN_BUT & (BUT1))) { tx_buffer[2]=LED_GO_ON; tx_buffer[3]=_crc8_update(tx_buffer, (sizeof(tx_buffer)-1)); for(uint8_t i=0; i<sizeof(tx_buffer); i++) usart0_write(tx_buffer[i]); _delay_ms(PAUSE); } if(!(PIN_BUT & (BUT2))) { tx_buffer[2]=LED_GO_OFF; tx_buffer[3]=_crc8_update(tx_buffer, (sizeof(tx_buffer)-1)); for(uint8_t i=0; i<sizeof(tx_buffer); i++) usart0_write(tx_buffer[i]); _delay_ms(PAUSE); } usart0_clear_tx_buffer(); } }
/// @details /// Handles a RFM12 interrupt depending on rxstate and the status reported by the RF /// module. static void rf12_interrupt() { uint8_t in; state = rf12_xferState(&in); // data received or byte needed for sending if (state & RF_FIFO_BIT) { if (rxstate == TXRECV) { // we are receiving if (rxfill == 0 && group != 0) { rf12_buf[rxfill++] = group; #if 0 if (fixedLength) { rf12_crc8 = 0; if (((in & 0xF0) == 0xA0) && (fixedLength > 10) && (fixedLengthBase < 10)) { minLengthCrcOk = 10; // otherwise repeating Fine Offset packages are missed } else { minLengthCrcOk = fixedLengthBase; } } #endif } rf12_buf[rxfill++] = in; if (fixedLength) { #if 0 if ((rxfill == 2) && ((in & 0xF) >= 4) && ((in & 0xF) <= 5) && ((rf12_buf[1] & 0xF) == 0xA)) { minLengthCrcOk = fixedLength; fixedLength = 13 + 1; // ws1600 is longer } #endif rf12_crc8 = _crc8_update(rf12_crc8, in); } else { rf12_crc = _crc16_update(rf12_crc, in); } // do drssi binary-tree search if ( drssi < 3 && ((rxfill-2)%drssi_bytes_per_decision)==0 ) {// not yet final value // top nibble when going up, bottom one when going down drssi = bitRead(state,8) ? (drssi_dec_tree[drssi] & B1111) : (drssi_dec_tree[drssi] >> 4); if ( drssi < 3 ) { // not yet final destination, set new threshold rf12_xfer(RF_RECV_CONTROL | drssi*2+1); } } // check if we got all the bytes (or maximum packet length was reached) if (fixedLength) { if ((rf12_crc8 == 0) && minLengthCrcOk > 0 && (rxfill >= minLengthCrcOk)) { rf12_buf[0] = rxfill; #if 0 while (rxfill < fixedLength) { rf12_buf[rxfill++] = 0; } #endif rf12_idle(); } else if (rxfill >= fixedLength || rxfill >= RF_MAX) { rf12_buf[0] = rxfill; rf12_idle(); } } else if (rxfill >= rf12_len + 5 || rxfill >= RF_MAX) { rf12_idle(); } } else { // we are sending