Exemplo n.º 1
0
/// @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;

            rf12_buf[rxfill++] = in;
        	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 (rxfill >= fixedLength || rxfill >= RF_MAX) {
					rf12_idle();
				}
			} else if (rxfill >= rf12_len + 5 || rxfill >= RF_MAX) {
       	    	rf12_idle();
			}
    	} else {                  // we are sending
Exemplo n.º 2
0
/// @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