/* based on "gettingstarted.cpp" by 2bdy5 */ /** * Behave like we expect a Hoymiles microinverter to behave. */ #include // time() #include // cin, cout, endl #include #include // string, getline() #include #include #include // CLOCK_MONOTONIC_RAW, timespec, clock_gettime() #include // RF24, RF24_PA_LOW, delay() using namespace std; #include "common.hpp" // Generic: RF24 radio(22, 0, 1000000); // See http://nRF24.github.io/RF24/pages.html for more information on usage /** Receive forever */ void receiveForever(int ch, string myaddr) { uint8_t buf[30]; radio.setChannel(ch); radio.enableDynamicPayloads(); radio.setAutoAck(true); radio.setPALevel(RF24_PA_MAX); radio.setDataRate(RF24_250KBPS); radio.openWritingPipe((const uint8_t *)"dummy"); radio.flush_rx(); radio.flush_tx(); radio.openReadingPipe(1, (const uint8_t *)myaddr.c_str()); radio.startListening(); radio.printPrettyDetails(); cout << endl << "I'm listening..." << endl; while (true) { uint8_t pipe; delay(500); if (radio.failureDetected) { cout << "!f! " << flush; } if (radio.rxFifoFull()) { cout << "!F! " << flush; } if (radio.available(&pipe)) { uint8_t bytes = radio.getDynamicPayloadSize(); // get the size of the payload cout << "I was notified of having received " << dec << (unsigned int)bytes; cout << " bytes on pipe " << (unsigned int)pipe << ": " << flush; radio.read(buf, bytes); // fetch payload from FIFO for(int i=0; i