Esempio n. 1
0
void Manager::handle_pair_request(const RXPacket& packet)
{
    const TxType tx_type = packet.get_tx_type();
    const id_t id = packet.get_id();

    log(DEBUG, PSTR("Pair req from %lu"), id);
    if (tx_type==TX && cc_txs.find(id)) {
        // ignore pair request from CC_TX we're already paired with
    } else if (tx_type==TRX && cc_trxs.find(id)) {
        // pair request from CC_TRX we previously attempted to pair with
        // this means our ACK response failed so try again
        pair_with = id;
        pair(packet);
    } else if (auto_pair) {
        // Auto pair mode. Go ahead and pair.
        pair_with = id;
        pair(packet);
    } else if (pair_with == id) {
        // Manual pair mode and pair_with has already been set so pair.
        pair(packet);
    } else {
        // Manual pair mode. Tell user about pair request.
        Serial.print(F("{\"pr\": "));
        packet.print_id_and_type(true);
        Serial.println(F("}"));
    }
}
Esempio n. 2
0
void Manager::pair(const RXPacket& packet)
{
    bool success = false;

    switch (packet.get_tx_type()) {
    case TX:
        success = cc_txs.append(pair_with);
        break;
    case TRX: // transceiver. So we need to ACK.
        rfm.ack_cc_trx(pair_with);
        success = cc_trxs.append(pair_with);
        // Note that this may be a re-try to ACK a TRX we
        // previously added if our first ACK failed.
        break;
    }

    if (success) {
        Serial.print(F("{\"pw\": "));
        packet.print_id_and_type(true);
        Serial.println(F(" }"));
    }

    pair_with = ID_INVALID; // reset
}