Created demo data for testing
This commit is contained in:
parent
a4eeb6053e
commit
0415edfbcf
|
|
@ -8,6 +8,9 @@
|
|||
#include <ScannerSM.h>
|
||||
#include "loguru.hpp"
|
||||
|
||||
//TODO temporary
|
||||
#include "rtl_fm.h"
|
||||
|
||||
#define DELAY_TIMEOUT 2.0
|
||||
|
||||
ScannerSM::ScannerSM(MessageReceiver& central, SystemList& dataSource) :
|
||||
|
|
@ -67,6 +70,8 @@ void ScannerSM::ST_Load(EventData* data){
|
|||
DLOG_F(9, "ST_Load");
|
||||
//file read and system tree population
|
||||
|
||||
_currentSystem = _systems[0];
|
||||
|
||||
// do not issue event - SM will wait until an event is generated before proceeding
|
||||
//InternalEvent(ST_SCAN);
|
||||
Message* message = new ControllerMessage(SCANNER_SM, ControllerMessage::NOTIFY_READY);
|
||||
|
|
@ -95,8 +100,12 @@ void ScannerSM::ST_Scan(EventData* data){
|
|||
assert(_currentEntry != NULL);
|
||||
|
||||
if(_currentEntry->hasSignal()){
|
||||
LOG_F(1, "Signal found: %s", _currentEntry->getTag().c_str());
|
||||
InternalEvent(ST_RECEIVE);
|
||||
}
|
||||
else{
|
||||
InternalEvent(ST_SCAN);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -130,6 +139,8 @@ void ScannerSM::ST_Hold(EventData* data){
|
|||
InternalEvent(ST_SCAN);
|
||||
}
|
||||
|
||||
/* wait for 1ms */
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
void ScannerSM::ST_Receive(EventData* data){
|
||||
|
|
@ -144,7 +155,11 @@ void ScannerSM::ST_Receive(EventData* data){
|
|||
LOG_F(1, "Signal lost");
|
||||
InternalEvent(ST_HOLD);
|
||||
timeoutStart = std::time(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
/* wait for 1ms */
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
void ScannerSM::ST_Manual(EventData* data){
|
||||
|
|
@ -167,35 +182,38 @@ void ScannerSM::ST_Stopped(EventData* data){
|
|||
}
|
||||
|
||||
void ScannerSM::_broadcastSystemContext(RadioSystem* sys){
|
||||
assert(sys != NULL);
|
||||
/*assert(sys != NULL);
|
||||
//TODO not thread safe
|
||||
_currentContext.state = static_cast<States>(currentState);
|
||||
_currentContext.system = sys;
|
||||
_currentContext.entry = nullptr;
|
||||
Message* message = new ServerMessage(SCANNER_SM, ServerMessage::CONTEXT_UPDATE, &_currentContext);
|
||||
_centralQueue.giveMessage(*message);
|
||||
_centralQueue.giveMessage(*message);*/
|
||||
}
|
||||
|
||||
void ScannerSM::_broadcastEntryContext(RadioSystem* sys, Entry* entry){
|
||||
assert(sys != NULL);
|
||||
/*assert(sys != NULL);
|
||||
assert(entry != NULL);
|
||||
//TODO not thread safe
|
||||
_currentContext.state = static_cast<States>(currentState);
|
||||
_currentContext.system = sys;
|
||||
_currentContext.entry = entry;
|
||||
Message* message = new ServerMessage(SCANNER_SM, ServerMessage::CONTEXT_UPDATE, &_currentContext);
|
||||
_centralQueue.giveMessage(*message);
|
||||
_centralQueue.giveMessage(*message);*/
|
||||
}
|
||||
|
||||
void ScannerSM::_enableAudioOut(bool en){
|
||||
Message* message;
|
||||
/*Message* message;
|
||||
if(en){
|
||||
message = new AudioMessage(SCANNER_SM, AudioMessage::ENABLE_OUTPUT);
|
||||
}
|
||||
else{
|
||||
message = new AudioMessage(SCANNER_SM, AudioMessage::DISABLE_OUTPUT);
|
||||
}
|
||||
_centralQueue.giveMessage(*message);
|
||||
_centralQueue.giveMessage(*message);*/
|
||||
|
||||
//TODO temporary
|
||||
rtl_fm_mute((int)(!en));
|
||||
}
|
||||
|
||||
void ScannerSM::giveMessage(Message& message) {
|
||||
|
|
|
|||
|
|
@ -70,11 +70,11 @@ void StateMachine::StateEngine(void)
|
|||
_cv.wait(lock, [this]{return this->_eventGenerated;});
|
||||
|
||||
// while events are being generated keep executing states
|
||||
while (_eventGenerated) {
|
||||
if (_eventGenerated) {
|
||||
pDataTemp = _pEventData; // copy of event data pointer
|
||||
_pEventData = NULL; // event data used up, reset ptr
|
||||
_eventGenerated = false; // event used up, reset flag
|
||||
lock.unlock();
|
||||
//lock.unlock();
|
||||
|
||||
assert(currentState < _maxStates);
|
||||
|
||||
|
|
@ -89,8 +89,8 @@ void StateMachine::StateEngine(void)
|
|||
}
|
||||
if(!_run)
|
||||
return;
|
||||
if(_eventGenerated)
|
||||
lock.lock();
|
||||
//if(!_eventGenerated)
|
||||
//lock.unlock();
|
||||
}
|
||||
|
||||
// TBD - unlock semaphore here
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* demo_system.h
|
||||
*
|
||||
* Created on: Mar 5, 2019
|
||||
* Author: ezra
|
||||
*/
|
||||
|
||||
#include "RadioSystem.h"
|
||||
|
||||
#ifndef DEMO_SYSTEM_H_
|
||||
#define DEMO_SYSTEM_H_
|
||||
|
||||
class DemoSystem : public AnalogSystem {
|
||||
public:
|
||||
DemoSystem() : AnalogSystem() {
|
||||
entries.push_back(new FMChannel(453700000, std::string("Pit Fire 1"), false, true));
|
||||
entries.push_back(new FMChannel(453850000, std::string("Pit Fire 2"), false, false));
|
||||
entries.push_back(new FMChannel(462950000, std::string("Pit EMS 1"), false, true));
|
||||
entries.push_back(new FMChannel(453100000, std::string("Pit PD 1,2"), false, false));
|
||||
entries.push_back(new FMChannel(453250000, std::string("Pit PD 3,6"), false, false));
|
||||
entries.push_back(new FMChannel(453400000, std::string("Pit PD 4,5"), false, false));
|
||||
entries.push_back(new FMChannel(453150000, std::string("Pitt Police"), false, false));
|
||||
entries.push_back(new FMChannel(471312500, std::string("East EMS"), false, true));
|
||||
entries.push_back(new FMChannel(462450000, std::string("CMU Police"), false, false));
|
||||
entries.push_back(new FMChannel(471337500, std::string("South EMS"), false, true));
|
||||
entries.push_back(new FMChannel(470437500, std::string("West EMS"), false, true));
|
||||
|
||||
}
|
||||
|
||||
~DemoSystem() {};
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* DEMO_SYSTEM_H_ */
|
||||
|
|
@ -901,10 +901,16 @@ void software_agc(struct demod_state *d)
|
|||
}
|
||||
}
|
||||
|
||||
//TODO temporary
|
||||
int do_squelch = 0;
|
||||
void rtl_fm_mute(int mute){
|
||||
do_squelch = mute;
|
||||
}
|
||||
|
||||
void full_demod(struct demod_state *d)
|
||||
{
|
||||
int i, ds_p;
|
||||
int do_squelch = 0;
|
||||
//int do_squelch = 0;
|
||||
int sr = 0;
|
||||
if(d->rotate_enable) {
|
||||
translate(d);
|
||||
|
|
@ -1318,8 +1324,8 @@ int rtl_fm_setfreq(uint32_t freq){
|
|||
assert(freq > 0);
|
||||
int r;
|
||||
optimal_settings(freq, demod.rate_in);
|
||||
//r = rtlsdr_set_center_freq(dongle.dev, freq);
|
||||
r = verbose_set_frequency(dongle.dev, dongle.freq);
|
||||
r = rtlsdr_set_center_freq(dongle.dev, dongle.freq);
|
||||
//r = verbose_set_frequency(dongle.dev, dongle.freq);
|
||||
dongle.mute = BUFFER_DUMP;
|
||||
return r;
|
||||
}
|
||||
|
|
@ -1558,7 +1564,7 @@ int generate_header(struct demod_state *d, struct output_state *o)
|
|||
|
||||
//TODO modified signature
|
||||
//int main(int argc, char **argv)
|
||||
int rtl_fm_init(void* audioBuffer, size_t bufferSize, int sampleRate)
|
||||
int rtl_fm_init(void* audioBuffer, size_t bufferSize, int sampleRate, int gain)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
struct sigaction sigact;
|
||||
|
|
@ -1575,6 +1581,7 @@ int rtl_fm_init(void* audioBuffer, size_t bufferSize, int sampleRate)
|
|||
|
||||
controller.freqs[controller.freq_len] = 100000000;
|
||||
controller.freq_len++;
|
||||
dongle.gain = gain;
|
||||
|
||||
output.rate = sampleRate;
|
||||
demod.rate_out2 = sampleRate;
|
||||
|
|
|
|||
|
|
@ -25,12 +25,15 @@ enum mode_demod {
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
int rtl_fm_init(void* audioBuffer, size_t bufferSize, int sampleRate);
|
||||
int rtl_fm_init(void* audioBuffer, size_t bufferSize, int sampleRate, int gain);
|
||||
int rtl_fm_deinit();
|
||||
|
||||
int rtl_fm_setfreq(uint32_t freq);
|
||||
int rtl_fm_setmode(enum mode_demod newMode);
|
||||
float rtl_fm_get_rssi();
|
||||
|
||||
//TODO temporary
|
||||
void rtl_fm_mute(int mute);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ using namespace std;
|
|||
#include "ScannerSM.h"
|
||||
#include "SystemList.h"
|
||||
|
||||
#include "demo_system.h"
|
||||
|
||||
//enum {
|
||||
// SYSTEM_CONTROL,
|
||||
// SCANNER_SM,
|
||||
|
|
@ -145,6 +147,7 @@ public:
|
|||
LOG_F(INFO, "System initialized");
|
||||
|
||||
_connectionManager.allowConnections();
|
||||
_scanner.startScan();
|
||||
|
||||
sysRun = true;
|
||||
}
|
||||
|
|
@ -274,7 +277,7 @@ void setDemodulator(DemodInterface* demod) {
|
|||
int main(int argc, char **argv) {
|
||||
loguru::init(argc, argv);
|
||||
loguru::add_file(LOG_PATH, loguru::Truncate, loguru::Verbosity_2);
|
||||
loguru::g_stderr_verbosity = loguru::Verbosity_MAX;
|
||||
//loguru::g_stderr_verbosity = loguru::Verbosity_MAX;
|
||||
|
||||
signal(SIGINT, sigHandler);
|
||||
signal(SIGTERM, sigHandler);
|
||||
|
|
@ -287,6 +290,10 @@ int main(int argc, char **argv) {
|
|||
messageManager.setReceiver(SERVER_MAN, &connectionManager);
|
||||
//messageManager.setReceiver(AUDIO_MAN, &audioControl);
|
||||
|
||||
//DEMO
|
||||
AnalogSystem demo = DemoSystem();
|
||||
scanSystems.addSystem(dynamic_cast<RadioSystem&>(demo));
|
||||
|
||||
setDemodulator(&demod);
|
||||
|
||||
messageManager.start();
|
||||
|
|
|
|||
|
|
@ -14,12 +14,12 @@
|
|||
|
||||
class Entry {
|
||||
public:
|
||||
Entry(std::string tag, bool lo, bool del);
|
||||
Entry(std::string tag, bool lo, bool del) : tag(tag), lockedOut(lo), scanDelay(del){};
|
||||
virtual ~Entry() {};
|
||||
|
||||
std::string* getTag() { return &tag; }
|
||||
std::string getTag() { return tag; }
|
||||
virtual std::string getModulation() = 0;
|
||||
virtual std::string* getIdentity() = 0;
|
||||
virtual std::string getIdentity() = 0;
|
||||
bool isLockedOut() { return lockedOut; }
|
||||
bool useDelay() { return scanDelay; }
|
||||
void lockout(bool val) { lockedOut = val; }
|
||||
|
|
@ -36,7 +36,7 @@ protected:
|
|||
|
||||
class Channel: public Entry {
|
||||
public:
|
||||
Channel(unsigned long freq, char* tag, bool lo, bool del) : Entry(tag, lo, del), frequency(freq){}
|
||||
Channel(unsigned long freq, std::string tag, bool lo, bool del) : Entry(tag, lo, del), frequency(freq){}
|
||||
virtual ~Channel() {};
|
||||
protected:
|
||||
const unsigned long frequency;
|
||||
|
|
@ -44,19 +44,23 @@ protected:
|
|||
|
||||
class FMChannel : public Channel {
|
||||
public:
|
||||
FMChannel(unsigned long freq, char* tag, bool lo, bool del) : Channel(freq, tag, lo, del){}
|
||||
FMChannel(unsigned long freq, std::string tag, bool lo, bool del) : Channel(freq, tag, lo, del){}
|
||||
~FMChannel() {};
|
||||
|
||||
std::string getModulation() {
|
||||
return "FM";
|
||||
}
|
||||
|
||||
std::string getIdentity() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
bool hasSignal();
|
||||
};
|
||||
|
||||
class PLChannel: public FMChannel {
|
||||
public:
|
||||
PLChannel(unsigned long freq, float tn, char* tag, bool lo, bool del) :
|
||||
PLChannel(unsigned long freq, float tn, std::string tag, bool lo, bool del) :
|
||||
FMChannel(freq, tag, lo, del), tone(tn) {
|
||||
}
|
||||
~PLChannel() {};
|
||||
|
|
@ -68,7 +72,7 @@ protected:
|
|||
|
||||
class DCChannel : public FMChannel {
|
||||
public:
|
||||
DCChannel(unsigned long freq, unsigned int tn, char* tag, bool lo, bool del) :
|
||||
DCChannel(unsigned long freq, unsigned int tn, std::string tag, bool lo, bool del) :
|
||||
FMChannel(freq, tag, lo, del), code(tn) {
|
||||
}
|
||||
~DCChannel() {};
|
||||
|
|
@ -80,7 +84,7 @@ protected:
|
|||
|
||||
class AMChannel : public Channel {
|
||||
public:
|
||||
AMChannel(unsigned long freq, char* tag, bool lo, bool del) : Channel(freq, tag, lo, del){}
|
||||
AMChannel(unsigned long freq, std::string tag, bool lo, bool del) : Channel(freq, tag, lo, del){}
|
||||
~AMChannel() {};
|
||||
|
||||
bool hasSignal() { return false; };
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ public:
|
|||
|
||||
virtual Entry* operator[](size_t pos) = 0;
|
||||
|
||||
size_t size() { return _size; }
|
||||
virtual size_t size() { return _size; }
|
||||
private:
|
||||
//const RadioSystemType type;
|
||||
const std::string tag;
|
||||
|
|
@ -37,10 +37,14 @@ public:
|
|||
AnalogSystem() : RadioSystem() {};
|
||||
~AnalogSystem() {};
|
||||
|
||||
Entry* operator[](size_t pos) { return &entries[pos]; };
|
||||
Entry* operator[](size_t pos) { return entries[pos]; };
|
||||
|
||||
size_t size() {
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::vector<Entry> entries;
|
||||
std::vector<Entry*> entries;
|
||||
};
|
||||
|
||||
#endif /* RADIOSYSTEM_H_ */
|
||||
|
|
|
|||
|
|
@ -17,12 +17,15 @@ public:
|
|||
SystemList();
|
||||
~SystemList();
|
||||
|
||||
RadioSystem* operator[](size_t pos) { return nullptr; };
|
||||
RadioSystem* operator[](size_t pos) { return _systems[pos]; };
|
||||
|
||||
size_t size(){ return _size; }
|
||||
size_t size(){ return _systems.size(); }
|
||||
void addSystem(RadioSystem& system){
|
||||
_systems.push_back(&system);
|
||||
}
|
||||
private:
|
||||
std::vector<RadioSystem*> _systems;
|
||||
size_t _size = 0;
|
||||
//size_t _size = 0;
|
||||
};
|
||||
|
||||
#endif /* SYSTEMLIST_H_ */
|
||||
|
|
|
|||
|
|
@ -26,9 +26,17 @@ void Demodulator::stop(){
|
|||
LOG_F(1, "Demodulator stopped");
|
||||
}
|
||||
|
||||
bool Demodulator::setFrequency(unsigned long freq) {
|
||||
if(_tuner.setFrequency(freq) == TunerStatus::TUNER_SUCCESS)
|
||||
bool Demodulator::setFrequency(uint32_t freq) {
|
||||
if(freq == _currentFreq){
|
||||
DLOG_F(8, "Frequency already set");
|
||||
return true;
|
||||
}
|
||||
if(_tuner.setFrequency(freq) == TunerStatus::TUNER_SUCCESS){
|
||||
_currentFreq = freq;
|
||||
return true;
|
||||
}
|
||||
|
||||
LOG_F(ERROR, "Tuning error");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@
|
|||
#include "messages.h"
|
||||
#include "Tuner.h"
|
||||
|
||||
#define DEFAULT_SQUELCH 65.0
|
||||
#define DEFAULT_SQUELCH 70.0
|
||||
|
||||
class DemodInterface {
|
||||
public:
|
||||
virtual ~DemodInterface() {};
|
||||
|
||||
virtual bool setFrequency(unsigned long freq) = 0;
|
||||
virtual bool setFrequency(uint32_t freq) = 0;
|
||||
virtual float getRssi() = 0;
|
||||
virtual float getDecodedPL() = 0;
|
||||
virtual unsigned int getDecodedDC() = 0;
|
||||
|
|
@ -40,9 +40,10 @@ private:
|
|||
MessageReceiver& _centralQueue;
|
||||
Tuner& _tuner;
|
||||
float _squelchLevel = DEFAULT_SQUELCH;
|
||||
uint32_t _currentFreq = 0;
|
||||
|
||||
void giveMessage(Message& message) {};
|
||||
bool setFrequency(unsigned long freq);
|
||||
bool setFrequency(uint32_t freq);
|
||||
float getRssi();
|
||||
float getDecodedPL();
|
||||
unsigned int getDecodedDC();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include "loguru.hpp"
|
||||
|
||||
#define RTL_DEMOD_WAIT 50000
|
||||
#define RTL_GAIN -100
|
||||
|
||||
enum TunerStatus {
|
||||
TUNER_ERROR = -1,
|
||||
|
|
@ -56,7 +57,7 @@ public:
|
|||
|
||||
TunerStatus init() {
|
||||
LOG_F(2, "Starting rtl_fm");
|
||||
if(rtl_fm_init(nullptr, 0, 12000))
|
||||
if(rtl_fm_init(nullptr, 0, 12000, RTL_GAIN))
|
||||
return TUNER_ERROR;
|
||||
return TUNER_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ int main(int argc, char** argv){
|
|||
timespec time1, time2;
|
||||
|
||||
timespec_get(&time1, TIME_UTC);
|
||||
if(rtl_fm_init((void*)0, (size_t)0, 12000))
|
||||
if(rtl_fm_init((void*)0, (size_t)0, 12000, 30))
|
||||
return 1;
|
||||
timespec_get(&time2, TIME_UTC);
|
||||
fprintf(stderr, "%li\n", (time2.tv_nsec - time1.tv_nsec)/1000);
|
||||
|
|
|
|||
Loading…
Reference in New Issue