Ejemplo 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;
}
Ejemplo n.º 2
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;
}