Tested and added new protobuf features with frontend

This commit is contained in:
Ezra Taimuty-Loomis 2020-04-03 13:29:43 -04:00
parent 1e427715ed
commit 7206c745a4
6 changed files with 50 additions and 35 deletions

@ -1 +1 @@
Subproject commit 745d53b6edf0d68c2b92da8e5bb927182de9b569
Subproject commit a3eaf9a87999e9a15bdcce131f5cf223c5eaa645

View File

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

View File

@ -225,7 +225,7 @@ int ServerManager::giveRequest(void* request){
void ServerManager::_handleMessage(std::shared_ptr<Message> message){
assert(message->destination == SERVER_MAN);
auto msg = std::dynamic_pointer_cast<ServerMessage>(message);
int* level = nullptr;
int level = 0;
switch (msg->type) {
case ServerMessage::CONTEXT_UPDATE:
switch(message->source){
@ -250,9 +250,9 @@ void ServerManager::_handleMessage(std::shared_ptr<Message> message){
break;
case ServerMessage::SIGNAL_LEVEL:
DLOG_F(7, "Broadcast siglevel update");
level = reinterpret_cast<int*>(msg->pData);
_broadcastSignalLevelUpdate(*level);
delete level;
level = *(reinterpret_cast<int*>(msg->pData));
delete msg->pData;
_broadcastSignalLevelUpdate(level);
break;
default:
break;

View File

@ -69,7 +69,7 @@ void SocketConnection::contextUpdate(const ScannerContext context){
msg.SerializeToArray(_writeBuffer, WRITE_BUFFER_LENGTH);
_startWrite(_writeBuffer, msg.ByteSize());
delete ctx;
//delete ctx; // its seems protobuf handles deletion, leaving this causes a double free error
}
void SocketConnection::contextUpdate(const DemodContext context){
@ -84,7 +84,7 @@ void SocketConnection::contextUpdate(const DemodContext context){
msg.SerializeToArray(_writeBuffer, WRITE_BUFFER_LENGTH);
_startWrite(_writeBuffer, msg.ByteSize());
delete ctx;
//delete ctx;
}
void SocketConnection::handleSystemMessage(const GeneralMessage message) {
@ -113,7 +113,7 @@ void SocketConnection::handleSystemMessage(const GeneralMessage message) {
msg.SerializeToArray(_writeBuffer, WRITE_BUFFER_LENGTH);
_startWrite(_writeBuffer, msg.ByteSize());
delete ctx;
//delete ctx;
}
void SocketConnection::handleSystemInfo(const SystemInfo info){
@ -131,7 +131,7 @@ void SocketConnection::handleSystemInfo(const SystemInfo info){
msg.SerializeToArray(_writeBuffer, WRITE_BUFFER_LENGTH);
_startWrite(_writeBuffer, msg.ByteSize());
delete ctx;
//delete ctx;
}
void SocketConnection::handleSignalLevel(const int level){
@ -146,7 +146,7 @@ void SocketConnection::handleSignalLevel(const int level){
msg.SerializeToArray(_writeBuffer, WRITE_BUFFER_LENGTH);
_startWrite(_writeBuffer, msg.ByteSize());
delete ctx;
//delete ctx;
}
void SocketConnection::_startRead() {
@ -207,25 +207,28 @@ void SocketConnection::_handleWrite(const boost::system::error_code& err,
}
void SocketConnection::_handleGeneralRequest(const piscan_pb::GeneralRequest& rq) {
static std::map<piscan_pb::GeneralRequest_RequestType, std::function<int(void)>> rqHandlers = {
{piscan_pb::GeneralRequest_RequestType_SCANNER_CONTEXT, [this]{return getScannerContext();}},
{piscan_pb::GeneralRequest_RequestType_DEMOD_CONTEXT, [this]{return getDemodContext();}},
{piscan_pb::GeneralRequest_RequestType_SYSTEM_INFO, [this]{return getSystemInfo();}},
};
// static std::map<piscan_pb::GeneralRequest_RequestType, std::function<int(void)>> rqHandlers = {
// {piscan_pb::GeneralRequest_RequestType_SCANNER_CONTEXT, [this]{return getScannerContext();}},
// {piscan_pb::GeneralRequest_RequestType_DEMOD_CONTEXT, [this]{return getDemodContext();}},
// {piscan_pb::GeneralRequest_RequestType_SYSTEM_INFO, [this]{return getSystemInfo();}},
// };
/*switch(rq.type()){
switch(rq.type()){
case piscan_pb::GeneralRequest_RequestType_SCANNER_CONTEXT:
getScannerContext();
break;
case piscan_pb::GeneralRequest_RequestType_DEMOD_CONTEXT:
getDemodContext();
break;
case piscan_pb::GeneralRequest_RequestType_SYSTEM_INFO:
getSystemInfo();
break;
default:
LOG_F(WARNING, "Invalid GeneralRequest from %s", _socket.remote_endpoint().address().to_string().c_str());
break;
}*/
}
rqHandlers[rq.type()]();
// rqHandlers[rq.type()]();
}
void SocketConnection::_handleScanStateRequest(

View File

@ -15,7 +15,7 @@
#define DEFAULT_SDR_SAMPLE_RATE 2048000
#define INIT_FREQUENCY 100000000
#define NUM_RATES_DEFAULT 4
#define SIGLEVEL_REFRESH_INTERVAL 250 // milliseconds
#define SIGLEVEL_REFRESH_INTERVAL 100 // milliseconds
using namespace piscan;
@ -150,11 +150,12 @@ void Demodulator::start(){
//create signal level refresh timer
std::function<void()> func([this](){
int level = getSignalStrength();
LOG_F(7, "Signal strength %i", level);
app::signalLevelUpdate(level);
});
_sigLevelRefresher = new IntervalTimer();
_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);
@ -163,6 +164,9 @@ void Demodulator::start(){
}
void Demodulator::stop(){
_sigLevelRefresher.stop();
//delete _sigLevelRefresher;
_cubic->stopDevice(false, 2000);
_cubic->OnExit();
@ -170,9 +174,6 @@ 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");
@ -220,8 +221,8 @@ float Demodulator::getDecodedPL() { return 0; }
unsigned int Demodulator::getDecodedDC() { return 0; }
bool Demodulator::squelchThresholdMet() {
return (getSignalLevel() >= _squelchLevel); //dBm comparison
//return (getSignalStrength() >= _squelchLevel); //SNR
//return (getSignalLevel() >= _squelchLevel); //dBm comparison
return (getSignalStrength() >= _squelchLevel); //SNR
/*return (std::abs(
_demodMgr.getActiveContextModem()->getSignalLevel()
- _demodMgr.getActiveContextModem()->getSignalFloor())
@ -254,12 +255,23 @@ float Demodulator::getSNR() {
}
int Demodulator::getSignalStrength() {
float fractional = getSNR() - 1;
int percent = 100*fractional;
if(percent >= 100)
return 100;
DRAW_LOG_F(7, "\t\t\tsigstrength %i", percent);
return percent;
// float fractional = getSNR() - 1;
// int percent = 100*fractional;
// if(percent >= 100)
// return 100;
float signal = _demodMgr.getActiveContextModem()->getSignalLevel();
float floor = _demodMgr.getActiveContextModem()->getSignalFloor();
float ceiling = 0.0;
float range = ceiling - floor;
int level = (100 * (signal - floor)) / range;
if (level > 100)
level = 100;
// DRAW_LOG_F(7, "\t\t\tsigstrength %i", percent);
// return percent;
return level;
}
void Demodulator::giveMessage(std::shared_ptr<Message> message){
@ -350,7 +362,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);