Added console application, Fixes #5

main
mandlm 2017-10-18 22:31:39 +02:00 committed by mandlm
parent 7143900c22
commit 8ad494f977
5 changed files with 76 additions and 24 deletions

View File

@ -20,7 +20,17 @@ add_executable(qSniff
mainwindow.ui mainwindow.ui
sniffthread.cpp sniffthread.cpp
sniffthread.h sniffthread.h
sniffer.cpp
sniffer.h
) )
target_link_libraries(qSniff rc-switch wiringPi Qt5::Widgets) target_link_libraries(qSniff rc-switch wiringPi Qt5::Widgets)
add_executable(Sniff
sniff.cpp
sniffer.cpp
sniffer.h
)
target_link_libraries(Sniff rc-switch wiringPi)

22
source/sniff.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "sniffer.h"
#include <iostream>
int main(int argc, char **argv)
{
std::cout << "Sniff" << std::endl;
Sniffer sniffer(6);
while (true)
{
unsigned int data = sniffer.receive();
if (data != 0)
{
std::cout << "Data: " << data << std::endl;
}
delay(100);
}
return 0;
}

22
source/sniffer.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "sniffer.h"
Sniffer::Sniffer(unsigned int pin)
{
wiringPiSetup();
m_switch.enableReceive(pin);
}
unsigned int Sniffer::receive()
{
if (m_switch.available())
{
unsigned int receivedValue = m_switch.getReceivedValue();
m_switch.resetAvailable();
return receivedValue;
}
return 0;
}

15
source/sniffer.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once
#include "rc-switch/RCSwitch.h"
class Sniffer
{
private:
RCSwitch m_switch;
public:
Sniffer() = delete;
Sniffer(unsigned int pin);
unsigned int receive();
};

View File

@ -1,37 +1,20 @@
#include "sniffthread.h" #include "sniffthread.h"
#include <wiringPi.h> #include "sniffer.h"
#include "rc-switch/RCSwitch.h"
#include <sstream> #include <sstream>
void SniffThread::run() void SniffThread::run()
{ {
wiringPiSetup(); Sniffer sniffer(6);
RCSwitch mySwitch = RCSwitch();
mySwitch.enableReceive(6);
while (true) while (true)
{ {
if (mySwitch.available()) unsigned int data = sniffer.receive();
if (data != 0)
{ {
int value = mySwitch.getReceivedValue(); std::stringstream dataStream;
dataStream << data;
if (value == 0) emit dataReceived(dataStream.str().c_str());
{
emit dataReceived("Unknown encoding");
}
else
{
std::stringstream result;
result << "Received " << value << " / ";
result << mySwitch.getReceivedBitlength() << " bit ";
result << "Protocol: " << mySwitch.getReceivedProtocol();
emit dataReceived(result.str().c_str());
}
mySwitch.resetAvailable();
} }
delay(100); delay(100);