Added console application, Fixes #5
This commit is contained in:
parent
7143900c22
commit
8ad494f977
@ -20,7 +20,17 @@ add_executable(qSniff
|
||||
mainwindow.ui
|
||||
sniffthread.cpp
|
||||
sniffthread.h
|
||||
sniffer.cpp
|
||||
sniffer.h
|
||||
)
|
||||
|
||||
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
22
source/sniff.cpp
Normal 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
22
source/sniffer.cpp
Normal 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
15
source/sniffer.h
Normal 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();
|
||||
};
|
@ -1,37 +1,20 @@
|
||||
#include "sniffthread.h"
|
||||
#include <wiringPi.h>
|
||||
#include "rc-switch/RCSwitch.h"
|
||||
#include "sniffer.h"
|
||||
#include <sstream>
|
||||
|
||||
void SniffThread::run()
|
||||
{
|
||||
wiringPiSetup();
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
mySwitch.enableReceive(6);
|
||||
Sniffer sniffer(6);
|
||||
|
||||
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("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();
|
||||
emit dataReceived(dataStream.str().c_str());
|
||||
}
|
||||
|
||||
delay(100);
|
||||
|
Reference in New Issue
Block a user