Timer fixes

This commit is contained in:
Ezra Taimuty-Loomis 2020-03-01 11:51:58 -05:00
parent be6d69ee8a
commit d1e6d1d7f1
7 changed files with 44 additions and 24 deletions

View File

@ -15,7 +15,7 @@
#include "loguru.hpp"
#include "threadname.h"
#define DMDPRE_THREAD_NAME "Demod Pre Proc"
#define DMDPRE_THREAD_NAME "Pre Proc"
//50 ms
#define HEARTBEAT_CHECK_PERIOD_MICROS (50 * 1000)
@ -67,7 +67,10 @@ void DemodulatorPreThread::run() {
#endif
//std::cout << "Demodulator preprocessor thread started.." << std::endl;
setThreadName(DMDPRE_THREAD_NAME);
{
std::string tname = newDemodType + " " + DMDPRE_THREAD_NAME;
setThreadName(tname.c_str());
}
LOG_F(INFO, "Demodulator prepocessing thread started");
ReBuffer<DemodulatorThreadPostIQData> buffers("DemodulatorPreThreadBuffers");

View File

@ -383,7 +383,7 @@ const SystemInfo app::getSystemInfo(){
SystemInfo info = {
.version = "debug",
.buildNumber = 0,
.squelchRange = {0, 100},
.squelchRange = {-100, 0},
.supportedModulations = {"FM", "AM"},
};
return info;

View File

@ -137,6 +137,16 @@ void SocketConnection::handleSystemInfo(const SystemInfo info){
void SocketConnection::handleSignalLevel(const int level){
//TODO
(void) level;
auto ctx = new piscan_pb::SignalLevel();
ctx->set_level(level);
piscan_pb::ServerToClient msg;
msg.set_type(piscan_pb::ServerToClient_Type_SIGNAL_LEVEL);
msg.set_allocated_signallevel(ctx);
msg.SerializeToArray(_writeBuffer, WRITE_BUFFER_LENGTH);
_startWrite(_writeBuffer, msg.ByteSize());
delete ctx;
}
void SocketConnection::_startRead() {

View File

@ -153,7 +153,8 @@ void Demodulator::start(){
LOG_F(7, "Signal strength %i", level);
app::signalLevelUpdate(level);
});
_sigLevelRefresher.create(SIGLEVEL_REFRESH_INTERVAL, func);
_sigLevelRefresher = new IntervalTimer();
_sigLevelRefresher->create(SIGLEVEL_REFRESH_INTERVAL, func);
//auto message = std::make_shared<ControllerMessage>(DEMOD, ControllerMessage::NOTIFY_READY);
//_centralQueue.giveMessage(message);
@ -169,6 +170,9 @@ void Demodulator::stop(){
state.gain = _gain;
state.squelch = _squelchLevel;
_sigLevelRefresher->stop();
delete _sigLevelRefresher;
//auto message = std::make_shared<ControllerMessage>(DEMOD, ControllerMessage::NOTIFY_STOPPED);
//_centralQueue.giveMessage(message);
LOG_F(1, "Demodulator stopped");
@ -216,12 +220,12 @@ float Demodulator::getDecodedPL() { return 0; }
unsigned int Demodulator::getDecodedDC() { return 0; }
bool Demodulator::squelchThresholdMet() {
//return (getSignalLevel() >= _squelchLevel); //dBm comparison
return (getSignalLevel() >= _squelchLevel); //dBm comparison
//return (getSignalStrength() >= _squelchLevel); //SNR
return (std::abs(
/*return (std::abs(
_demodMgr.getActiveContextModem()->getSignalLevel()
- _demodMgr.getActiveContextModem()->getSignalFloor())
>= _squelchLevel);
>= _squelchLevel);*/
}
bool Demodulator::setModem(Modulation mode) {
@ -346,7 +350,7 @@ float Demodulator::getSquelch(){
void Demodulator::squelchBreak(bool mute){
//mute = !mute;
mute ? _sigLevelRefresher.start() : _sigLevelRefresher.stop();
mute ? _sigLevelRefresher->start() : _sigLevelRefresher->stop();
_demodMgr.getCurrentModem()->setMuted(!mute);
}

View File

@ -81,7 +81,7 @@ private:
std::map<Modulation, DemodulatorInstancePtr> _demods;
IntervalTimer _sigLevelRefresher;
IntervalTimer* _sigLevelRefresher;
void _handleMessage(std::shared_ptr<DemodMessage> message);
void _handleRequest(ClientRequest& request);

View File

@ -15,8 +15,8 @@
#define READ_BUFFER_LENGTH 1024
#define WRITE_BUFFER_LENGTH 1024
using namespace boost::asio;
using ip::tcp;
using namespace boost;
using asio::ip::tcp;
using std::string;
using std::cout;
using std::endl;
@ -27,7 +27,7 @@ namespace piscan {
class TestClient : public ServerInterface, public boost::enable_shared_from_this<TestClient>{
public:
TestClient(io_service& io_service, tcp::socket& socket) : _console(*this), _io_service(io_service), _socket(socket) {
TestClient(asio::io_service& io_service, tcp::socket& socket) : _console(*this), _io_service(io_service), _socket(socket) {
//_console(this);
}
@ -40,14 +40,14 @@ public:
_startRead();
}
static boost::shared_ptr<TestClient> create(io_service& io_service, tcp::socket& socket){
static boost::shared_ptr<TestClient> create(asio::io_service& io_service, tcp::socket& socket){
return boost::shared_ptr<TestClient>(new TestClient(io_service, socket));
}
private:
DebugServer _console;
io_service& _io_service;
asio::io_service& _io_service;
tcp::socket& _socket;
unsigned char _readBuffer[READ_BUFFER_LENGTH];
unsigned char _writeBuffer[WRITE_BUFFER_LENGTH];
@ -57,15 +57,15 @@ private:
void _startRead() {
_socket.async_read_some(boost::asio::buffer(_readBuffer, READ_BUFFER_LENGTH),
boost::bind(&TestClient::_handleRead, shared_from_this(),
placeholders::error,
placeholders::bytes_transferred));
asio::placeholders::error,
asio::placeholders::bytes_transferred));
}
void _startWrite(uint8_t* buffer, size_t length) {
_socket.async_write_some(boost::asio::buffer(buffer, length),
boost::bind(&TestClient::_handleWrite, shared_from_this(),
placeholders::error,
placeholders::bytes_transferred));
asio::placeholders::error,
asio::placeholders::bytes_transferred));
}
void _handleRead(const boost::system::error_code& err,
@ -226,7 +226,7 @@ using namespace piscan;
int main(int argc, char **argv) {
loguru::init(argc, argv);
io_service io_service;
asio::io_service io_service;
tcp::socket socket(io_service);
std::string address;
@ -234,7 +234,7 @@ int main(int argc, char **argv) {
std::cin >> address;
socket.connect(
tcp::endpoint(ip::address::from_string(address),
tcp::endpoint(asio::ip::address::from_string(address),
1234));
boost::shared_ptr<TestClient> client = TestClient::create(io_service,

View File

@ -85,7 +85,6 @@ public:
}
}
});
_timerThread.detach();
}
@ -111,9 +110,13 @@ private:
inline void destroy(){
//std::cout << "\tdestroy timer\n";
_execute = false;
unique_lock<mutex> lock(_mtx);
_cv.notify_all();
stop();
if(_runTimer.load())
stop();
else{
unique_lock<mutex> lock(_mtx);
_cv.notify_all();
}
_timerThread.join();
}
private: