Files
2026-09-14 12:43:38 +02:00

69 lines
1.7 KiB
C++
Executable File

#include "/home/lucas/433Utils/rc-switch/RCSwitch.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
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; //G27
if(wiringPiSetup() == -1) {
printf("wiringPiSetup failed, exiting...");
return 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
unsigned long value;
unsigned long previous=0;
int length;
int protocol;
unsigned int* raw;
struct timeval time1,time2;
long long elapsedTime;
int delay;
printf("Stetup Finished, Start Sniffing\n");
while(1) {
if (mySwitch.available()) {
value = mySwitch.getReceivedValue();
length = mySwitch.getReceivedBitlength();
protocol = mySwitch.getReceivedProtocol();
raw = mySwitch.getReceivedRawdata();
delay = mySwitch.getReceivedDelay();
if (value == 0)
{
printf("Unknown encoding\n");
}
else if (value != previous)
{
gettimeofday(&time1,NULL);
printf("Received %i\nLength: %i\nProtocol: %i\nDelay: %i\nRaw Data:\n", value,length,protocol, delay );
for (int i=0; i<= length*2; i++)
{
printf("%i",raw[i]);
printf(",");
}
printf("\n");
}
previous = value;
mySwitch.resetAvailable();
}
gettimeofday(&time2,NULL);
if ((time2.tv_sec - time1.tv_sec) > 2) previous=0;
}
exit(0);
}