From 8ec6b75e54c03d5f104dd391d9471c1a7e49264f Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Fri, 9 Jan 2015 17:17:56 -0500 Subject: [PATCH] Session save handler --- src/AppFrame.cpp | 33 ++++++++++++++++++++++++++++++++- src/AppFrame.h | 5 +++++ src/CubicSDRDefs.h | 2 ++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/AppFrame.cpp b/src/AppFrame.cpp index d7bf65d..1dc2877 100644 --- a/src/AppFrame.cpp +++ b/src/AppFrame.cpp @@ -17,6 +17,7 @@ #include "DemodulatorMgr.h" #include "AudioThread.h" #include "CubicSDR.h" +#include "DataTree.h" #include @@ -32,7 +33,7 @@ EVT_IDLE(AppFrame::OnIdle) wxEND_EVENT_TABLE() AppFrame::AppFrame() : - wxFrame(NULL, wxID_ANY, wxT("CubicSDR v0.1a by Charles J. Cliffe (@ccliffe)")), activeDemodulator(NULL) { + wxFrame(NULL, wxID_ANY, wxT("CubicSDR " CUBICSDR_VERSION " by Charles J. Cliffe (@ccliffe)")), activeDemodulator(NULL) { wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); wxBoxSizer *demodOpts = new wxBoxSizer(wxVERTICAL); @@ -282,3 +283,33 @@ void AppFrame::OnIdle(wxIdleEvent& event) { event.Skip(); } } + +void AppFrame::saveSession(std::string fileName) { + DataTree s("cubicsdr_session"); + DataNode &header = s.rootNode().newChild("header"); + header.newChild("version") = std::string(CUBICSDR_VERSION); + header.newChild("center_freq") = wxGetApp().getFrequency(); + header.newChild("offset") = wxGetApp().getOffset(); + + DataNode &demods = s.rootNode().newChild("demodulators"); + + std::vector &instances = wxGetApp().getDemodMgr().getDemodulators(); + std::vector::iterator instance_i; + for (instance_i = instances.begin(); instance_i != instances.end(); instance_i++) { + DataNode &demod = demods.newChild("demodulator"); + demod.newChild("bandwidth") = (long)(*instance_i)->getBandwidth(); + demod.newChild("frequency") = (long long)(*instance_i)->getFrequency(); + demod.newChild("type") = (int)(*instance_i)->getDemodulatorType(); + if ((*instance_i)->isSquelchEnabled()) { + demod.newChild("squelch") = (*instance_i)->getSquelchLevel(); + demod.newChild("squelch_enabled") = (char)1; + } + demod.newChild("stereo") = (char)(*instance_i)->isStereo(); + demod.newChild("output_device") = outputDevices[(*instance_i)->getOutputDevice()].name; + } + + s.SaveToFileXML(fileName); +} + +bool AppFrame::loadSession(std::string fileName) { +} diff --git a/src/AppFrame.h b/src/AppFrame.h index 4df734d..ca0df5b 100644 --- a/src/AppFrame.h +++ b/src/AppFrame.h @@ -23,6 +23,9 @@ public: void OnThread(wxCommandEvent& event); void OnEventInput(wxThreadEvent& event); + void saveSession(std::string fileName); + bool loadSession(std::string fileName); + private: void OnMenu(wxCommandEvent& event); void OnClose(wxCommandEvent& event); @@ -46,5 +49,7 @@ private: std::map outputDevices; std::map outputDeviceMenuItems; + std::string currentSessionFile; + wxDECLARE_EVENT_TABLE(); }; diff --git a/src/CubicSDRDefs.h b/src/CubicSDRDefs.h index 1a8fa98..1c0493b 100644 --- a/src/CubicSDRDefs.h +++ b/src/CubicSDRDefs.h @@ -1,5 +1,7 @@ #pragma once +#define CUBICSDR_VERSION "v0.01a" + #ifdef __APPLE__ #define BUF_SIZE (16384*2) #define SRATE 2000000