Example #1
0
uint8_t AQERF_Remote::pair(void){
    // try this for a period of time up to the pairing duration
    for(uint32_t ii = 0; ii < AQERF_PAIRING_DURATION_MS; ii++){
        if (rf12_recvDone()) {   // incoming data is present
            if(0 == rf12_crc){   // otherwise the data is unreliable
                if(AQERF_PACKET_TYPE_BASE_STATION_ADVERTISEMENT == rf12_data[AQERF_PACKET_TYPE_OFFSET]){
                    // we have a pairing ... 
                    //   store the advertised base address in RAM and EEPROM
                    memcpy(base_station_address, (const void *) (rf12_data + AQERF_BASE_ADDRESS_OFFSET), AQERF_BASE_ADDRESS_LENGTH);
                    
                    //TODO: Store the base_station_address to EEPROM
                    eeprom_write_block(base_station_address, (void *) AQERF_EEPROM_LAST_KNOWN_BASE_ADDRESS, 6);
                    return 1;
                }
            }
        }
        delay(1);
    }
    return 0;
}
Example #2
0
boolean AQERF_Base::pair(void){
    uint32_t current_time = millis();
    boolean pairing_done = false;
    if(current_time < end_time){
        rf12_recvDone();
        if(current_time - previous_time > PAIRING_BROADCAST_INTERVAL_MS) {
            previous_time = current_time; 
            need_to_send = 1;
        }

        if(rf12_canSend() && need_to_send){
            rf12_sendStart(0, packet, AQERF_BASE_STATION_ADVERTISEMENT_PACKET_LENGTH);
            need_to_send = 0;
        }

        pairing_done = false;
    }       
    else{
        pairing_done = true;
    }

    return pairing_done;
}
Example #3
0
void sendPulsePacket() {
	cli();
	volatile unsigned long long pulsesNow = pulses;
	volatile unsigned long noiseNow = noise;
	sei();
	Serial.print("(");
	Serial.print(millis());
	Serial.print(")");
    digitalWrite(PIN_LED, HIGH);
	Serial.print("[P:");
	Serial.print((unsigned long)pulsesNow);
	Serial.print(",");
	Serial.print(noise);
	pulsePayload[4] = 4;
	*((unsigned long long*)(pulsePayload + 5)) = pulsesNow;
	*((unsigned long*)(pulsePayload + 13)) = noiseNow;
    // send our packet, once possible
    while (!rf12_canSend())
        rf12_recvDone();
    Serial.print(" *");
    rf12_sendStart(0, pulsePayload, sizeof pulsePayload, 1);
    Serial.println("]");
    digitalWrite(PIN_LED, LOW);
}
Example #4
0
/// @details
/// Wait until transmission is possible, then start it as soon as possible.
/// @note This uses a (brief) busy loop and will discard any incoming packets.
/// @param hdr The header contains information about the destination of the
///            packet to send, and flags such as whether this should be
///            acknowledged - or if it actually is an acknowledgement.
/// @param ptr Pointer to the data to send as packet.
/// @param len Number of data bytes to send. Must be in the range 0 .. 65.
void rf12_sendNow (uint8_t hdr, const void* ptr, uint8_t len) {
    while (!rf12_canSend())
        rf12_recvDone(); // keep the driver state machine going, ignore incoming
    rf12_sendStart(hdr, ptr, len);
}
Example #5
0
//Transceiver functions:
void OpenGardenClass::initRF(void){
  rf12_initialize(myNodeID,RF12_433MHZ,100); // (GatewayNodeID,freq,network)
  rf12_recvDone();
}
Example #6
0
// must be called often to keep the driver moving
uint8_t AQERF_Remote::clearToSend(void){
    rf12_recvDone(); 
    return rf12_canSend();
}