Exemplo n.º 1
0
const bool Manager::process_rx_packet_buffer(const uint32_t& target_uid)
{
	bool success = false;
	uint32_t uid;
	RXPacket* packet = NULL;

	for (uint8_t packet_i=0; packet_i<=rfm.rx_packet_buffer.current_packet; packet_i++) {
		packet = &rfm.rx_packet_buffer.packets[packet_i];
		if (packet->done()) {
			if (packet->is_ok()) {
				packet->print_uid_and_watts(); // send data over serial
				uid = packet->get_uid();
				success = (uid == target_uid);

				if (!uid_is_iam(uid)) {
					process_whole_house_uid(uid, *packet);
				}

			} else {
				Serial.print(millis());
				Serial.println(" Broken packet received.");
			}
		}
	}

	rfm.rx_packet_buffer.reset_all();
	return success;
}
Exemplo n.º 2
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("}"));
    }
}
Exemplo n.º 3
0
void append_array(RXPacket& rx_packet,
        const byte data[], const index_t length)
{
    for (index_t i=0; i<length; i++){
        rx_packet.append(data[i]);
    }
}
Exemplo n.º 4
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
}
Exemplo n.º 5
0
void Sensor::update(const RXPacket& packet)
{
	eta = packet.get_timecode() + SAMPLE_PERIOD;
}
Exemplo n.º 6
0
bool Manager::process_rx_pack_buf_and_find_id(const id_t& target_id)
{
    bool success = false;
    TxType tx_type;
    id_t id;
    RXPacket* packet = NULL; // just using this pointer to make code more readable

    /* Loop through every packet in packet buffer. If it's done then post-process it
     * and then check if it's valid.  If so then handle the different types of
     * packet.  Finally reset the packet and return.
     */
    for (index_t packet_i=0; packet_i<PACKET_BUF_LENGTH; packet_i++) {

        packet = &rfm.rx_packet_buffer.packets[packet_i];
        if (packet->done()) {
            tx_type = packet->get_tx_type();
            if (packet->is_ok()) {
                id = packet->get_id();
                success |= (id == target_id); // Was this the packet we were looking for?

                //******** PAIRING REQUEST **********************
                if (packet->is_pairing_request()) {
                    packet->reset();
                    handle_pair_request(*packet);
                    break;
                }

                //********* CC TX (transmit-only sensor) ********
                switch (tx_type) {
                case TX:
                    bool found;
                    index_t cc_tx_i;
                    found = cc_txs.find(id, cc_tx_i);
                    if (found) { // received ID is a CC_TX id we know about
                        packet->print_id_and_watts(); // send data over serial
                        cc_txs[cc_tx_i].update(*packet);
                        cc_txs.next();
                    } else {
                        log(INFO, PSTR("Rx'd CC_TX packet with unknown ID %lu"), id);
                        if (print_packets >= ALL_VALID) {
                            packet->print_id_and_watts(); // send data over serial
                        }
                    }
                    break;
                case TRX:
                    //****** CC TRX (transceiver; e.g. EDF IAM) ******
                    if (cc_trxs.find(id)) {
                        // Received ID is a CC_TRX id we know about
                        packet->print_id_and_watts(); // send data over serial
                    }
                    //********* UNKNOWN TRX ID *************************
                    else {
                        log(INFO, PSTR("Rx'd CC_TRX packet with unknown ID %lu"), id);
                        if (print_packets >= ALL_VALID) {
                            packet->print_id_and_watts(); // send data over serial
                        }
                    }
                    break;
                }

            } else { // packet is not OK
                log(INFO, PSTR("Rx'd broken %s packet"), tx_type==TX ? "TX" : "TRX");
                if (print_packets == ALL) {
                    packet->print_bytes();
                }
            }
            packet->reset();
        }
    }

    return success;
}