From 47e9beec8bbfb453ff15832140f62dd66651e5bc Mon Sep 17 00:00:00 2001 From: Christian Frenzl Date: Sun, 19 Apr 2020 22:24:05 +0200 Subject: [PATCH 1/3] code style --- RPi_utils/RFSniffer.cpp | 71 +++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/RPi_utils/RFSniffer.cpp b/RPi_utils/RFSniffer.cpp index 286ab3d..6da7bcc 100644 --- a/RPi_utils/RFSniffer.cpp +++ b/RPi_utils/RFSniffer.cpp @@ -12,54 +12,43 @@ #include #include #include - - -RCSwitch mySwitch; - +RCSwitch mySwitch; int main(int argc, char *argv[]) { - - // This pin is not the first pin on the RPi GPIO header! - // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ - // for more information. - int PIN = 2; - - if(wiringPiSetup() == -1) { - printf("wiringPiSetup failed, exiting..."); - return 0; - } - int pulseLength = 0; - if (argv[1] != NULL) pulseLength = atoi(argv[1]); + // This pin is not the first pin on the RPi GPIO header! + // Consult https://projects.drogon.net/raspberry-pi/wiringpi/pins/ + // for more information. + int PIN = 2; - mySwitch = RCSwitch(); - if (pulseLength != 0) mySwitch.setPulseLength(pulseLength); - mySwitch.enableReceive(PIN); // Receiver on interrupt 0 => that is pin #2 - - - while(1) { - - if (mySwitch.available()) { - - int value = mySwitch.getReceivedValue(); - - if (value == 0) { - printf("Unknown encoding\n"); - } else { - - printf("Received %i\n", mySwitch.getReceivedValue() ); - } - - fflush(stdout); - mySwitch.resetAvailable(); - } - usleep(100); - - } + if (wiringPiSetup() == -1) { + printf("wiringPiSetup failed, exiting..."); + return 0; + } - exit(0); + int pulseLength = 0; + if (argv[1] != NULL) pulseLength = atoi(argv[1]); + mySwitch = RCSwitch(); + if (pulseLength != 0) mySwitch.setPulseLength(pulseLength); + mySwitch.enableReceive(PIN); // Receiver on interrupt 0 => that is pin #2 + while (1) { + if (mySwitch.available()) { + int value = mySwitch.getReceivedValue(); + + if (value == 0) { + printf("Unknown encoding\n"); + } else { + printf("Received %i\n", mySwitch.getReceivedValue()); + } + + fflush(stdout); + mySwitch.resetAvailable(); + } + usleep(100); + } + exit(0); } From 19f8295500fa8a08ac37f90822b6d163621cfd1f Mon Sep 17 00:00:00 2001 From: Christian Frenzl Date: Sun, 19 Apr 2020 22:26:38 +0200 Subject: [PATCH 2/3] RFSniffer: not getting value twice redundantly from RCSwitch --- RPi_utils/RFSniffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RPi_utils/RFSniffer.cpp b/RPi_utils/RFSniffer.cpp index 6da7bcc..da52b96 100644 --- a/RPi_utils/RFSniffer.cpp +++ b/RPi_utils/RFSniffer.cpp @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) { if (value == 0) { printf("Unknown encoding\n"); } else { - printf("Received %i\n", mySwitch.getReceivedValue()); + printf("Received %i\n", value); } fflush(stdout); From cddc0f11297c3d10b2a4ef04d357255bb176d03e Mon Sep 17 00:00:00 2001 From: Christian Frenzl Date: Sun, 19 Apr 2020 22:59:45 +0200 Subject: [PATCH 3/3] made RFSniffer more verbose (now prints all the info it can get from RCSwitch) --- RPi_utils/RFSniffer.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/RPi_utils/RFSniffer.cpp b/RPi_utils/RFSniffer.cpp index da52b96..30ef2d0 100644 --- a/RPi_utils/RFSniffer.cpp +++ b/RPi_utils/RFSniffer.cpp @@ -41,7 +41,14 @@ int main(int argc, char *argv[]) { if (value == 0) { printf("Unknown encoding\n"); } else { - printf("Received %i\n", value); + printf( + "Received %i (bitlength: %i, delay: %i, protocol: %i, rawdata: %i)\n", + value, + mySwitch.getReceivedBitlength(), + mySwitch.getReceivedDelay(), + mySwitch.getReceivedProtocol(), + mySwitch.getReceivedRawdata() + ); } fflush(stdout);