diff --git a/src/PiScan.h b/src/PiScan.h index a6d898b..13887ad 100644 --- a/src/PiScan.h +++ b/src/PiScan.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "messages/context.h" #include "Configuration.h" @@ -15,6 +16,13 @@ class DemodInterface; namespace piscan { namespace app { +enum ReturnStatus { + SUCCESS, + INVALID, + NOT_IMPLEMENTED, +}; +typedef std::tuple BasicReturnTuple; + struct ManualEntryData { public: ManualEntryData(ManualEntryData& copy) : freq(copy.freq), modulation(copy.modulation){}; @@ -65,5 +73,140 @@ namespace audio { AudioThread* getAudioController(); } +/* database */ +namespace data { +/* + Retrieve the entire System tree +*/ +BasicReturnTuple getScanList(); //TODO + +/* + Retrieve list of Systems and their indices, tags, and types +*/ +BasicReturnTuple getSystemList(); + +/* + Retrieve tree of System and its Entries at index +*/ +BasicReturnTuple getSystemByIndex(size_t sys_index); //TODO + +/* + Retrieve list of Entries within indexed System and their indices and descriptors +*/ +BasicReturnTuple getEntryList(size_t sys_index); + +/* + Retrieve Entry at index +*/ +BasicReturnTuple getEntryByIndex(size_t sys_index, size_t entry_index); //TODO + +namespace system { + /* + Create a new Radio System + */ + BasicReturnTuple create(/*TODO data*/); + + /* + Replace the Radio System header at index. Entries will be retained unless the system type is changed. + */ + BasicReturnTuple replace(size_t sys_index /*, TODO new*/); + + /* + Remove the Radio System and its Entries at index. Indices of succeeding Systems will be updated upon success + */ + BasicReturnTuple remove(size_t sys_index); + + /* + Set lockout status of System at index. + - '0' for unlocked + - '-1' for persistent lock + - '>1' lock for duration in seconds + */ + BasicReturnTuple setLockout(size_t sys_index, int duration_seconds); + + /* + Move Radio System from original index to new index. All other indices are updated upon success + */ + BasicReturnTuple setIndex(size_t original_sys_index, size_t new_sys_index); + + namespace entry { + /* + Create a new Entry within the indexed System + */ + BasicReturnTuple create(size_t sys_index /*,TODO data*/); + + /* + Replace the Entry at index + */ + BasicReturnTuple replace(size_t sys_index, size_t entry_index /*, TODO new*/); + + /* + Remove the Entry at index. Succeeding indices within the System are updated upon success + */ + BasicReturnTuple remove(size_t sys_index, size_t entry_index); + + /* + Set lockout status of Entry at index. + - '0' for unlocked + - '-1' for persistent lock + - '>1' lock for duration in seconds + */ + BasicReturnTuple setLockout(size_t sys_index, size_t entry_index, int duration_seconds); + + /* + Move Entry within System from original index to new index. All other indices are updated upon success + */ + BasicReturnTuple setIndex(size_t sys_index, size_t original_entry_index, size_t new_entry_index); + } +} +} + +namespace configuration { + /* + Retrieve the full system configuration + */ + BasicReturnTuple getFullConfig(); + + /* + Set the full system configuration. Requires restart + */ + BasicReturnTuple setConfig(/*TODO*/); + + /* + Retrieve general configuration + */ + BasicReturnTuple getGeneralConfig(); + + /* + Set the general configuration + */ + BasicReturnTuple setGeneralConfig(/*TODO*/); + + /* + Retrieve configuration for demodulators + */ + BasicReturnTuple getDemodConfig(); + + /* + Set the configuration for demodulators. Restart bit required + */ + BasicReturnTuple setDemodConfig(/*TODO*/); + + /* + Retrieve configuration for RTSP server + */ + BasicReturnTuple getAudioServerConfig(); + + /* + Set the configuration for RTSP server. Requires restart + */ + BasicReturnTuple setAudioServerConfig(/*TODO*/); + + /* + Retrieve a list of configured tuners + */ + BasicReturnTuple getTunerList(); +} + } // namespace app } // namespace piscan diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index c8a67d4..4277cb9 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(common + ${CMAKE_CURRENT_SOURCE_DIR}/config_api.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Configuration.cpp ${CMAKE_CURRENT_SOURCE_DIR}/State.cpp ) diff --git a/src/common/config_api.cpp b/src/common/config_api.cpp new file mode 100644 index 0000000..c14cc4a --- /dev/null +++ b/src/common/config_api.cpp @@ -0,0 +1,66 @@ +#include "PiScan.h" + +namespace piscan::app::configuration { + /* + */ + BasicReturnTuple getFullConfig() + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + */ + BasicReturnTuple setConfig(/*TODO*/) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + */ + BasicReturnTuple getGeneralConfig() + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + */ + BasicReturnTuple setGeneralConfig(/*TODO*/) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + */ + BasicReturnTuple getDemodConfig() + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + */ + BasicReturnTuple setDemodConfig(/*TODO*/) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + */ + BasicReturnTuple getAudioServerConfig() + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + */ + BasicReturnTuple setAudioServerConfig(/*TODO*/) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + */ + BasicReturnTuple getTunerList() + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } +} diff --git a/src/scan/CMakeLists.txt b/src/scan/CMakeLists.txt index 2f0eacc..2daa3a0 100644 --- a/src/scan/CMakeLists.txt +++ b/src/scan/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(scan + ${CMAKE_CURRENT_SOURCE_DIR}/api.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Entry.cpp ${CMAKE_CURRENT_SOURCE_DIR}/RadioSystem.cpp ${CMAKE_CURRENT_SOURCE_DIR}/SystemList.cpp diff --git a/src/scan/api.cpp b/src/scan/api.cpp new file mode 100644 index 0000000..379b3ec --- /dev/null +++ b/src/scan/api.cpp @@ -0,0 +1,138 @@ +#include + +#include "PiScan.h" + +namespace piscan::app::data +{ + /* + Retrieve the entire System tree +*/ + BasicReturnTuple getScanList() + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Retrieve list of Systems and their indices, tags, and types +*/ + BasicReturnTuple getSystemList() + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Retrieve tree of System and its Entries at index +*/ + BasicReturnTuple getSystemByIndex(size_t sys_index) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } //TODO + + /* + Retrieve list of Entries within indexed System and their indices and descriptors +*/ + BasicReturnTuple getEntryList(size_t sys_index) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Retrieve Entry at index +*/ + BasicReturnTuple getEntryByIndex(size_t sys_index, size_t entry_index) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } //TODO + + namespace system + { + /* + Create a new Radio System + */ + BasicReturnTuple create(/*TODO data*/) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Replace the Radio System header at index. Entries will be retained unless the system type is changed. + */ + BasicReturnTuple replace(size_t sys_index /*, TODO new*/) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Remove the Radio System and its Entries at index. Indices of succeeding Systems will be updated upon success + */ + BasicReturnTuple remove(size_t sys_index) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Set lockout status of System at index. + - '0' for unlocked + - '-1' for persistent lock + - '>1' lock for duration in seconds + */ + BasicReturnTuple setLockout(size_t sys_index, int duration_seconds) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Move Radio System from original index to new index. All other indices are updated upon success + */ + BasicReturnTuple setIndex(size_t original_sys_index, size_t new_sys_index) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + namespace entry + { + /* + Create a new Entry within the indexed System + */ + BasicReturnTuple create(size_t sys_index /*,TODO data*/) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Replace the Entry at index + */ + BasicReturnTuple replace(size_t sys_index, size_t entry_index /*, TODO new*/) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Remove the Entry at index. Succeeding indices within the System are updated upon success + */ + BasicReturnTuple remove(size_t sys_index, size_t entry_index) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Set lockout status of Entry at index. + - '0' for unlocked + - '-1' for persistent lock + - '>1' lock for duration in seconds + */ + BasicReturnTuple setLockout(size_t sys_index, size_t entry_index, int duration_seconds) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + + /* + Move Entry within System from original index to new index. All other indices are updated upon success + */ + BasicReturnTuple setIndex(size_t sys_index, size_t original_entry_index, size_t new_entry_index) + { + return std::make_tuple(NOT_IMPLEMENTED, nullptr); + } + } + } +} diff --git a/src/server/connection/DebugConsole.cpp b/src/server/connection/DebugConsole.cpp index 00dd4d3..18ac97c 100644 --- a/src/server/connection/DebugConsole.cpp +++ b/src/server/connection/DebugConsole.cpp @@ -11,6 +11,7 @@ #include #include +#include "PiScan.h" #include "DebugServer.h" #include "loguru.hpp" #include "threadname.h" @@ -24,6 +25,7 @@ namespace connection { #define DS_THREAD_NAME "DebugConsole" using namespace piscan; +using piscan::app::BasicReturnTuple; bool DebugConsole::connect(){ std::cerr << "\nConnecting...\n"; @@ -49,6 +51,37 @@ void DebugConsole::_consoleInputFunc() { std::string intermediate; std::cerr << "\nConsole connected\n"; + std::map friendlyReturnCodes; + friendlyReturnCodes[app::SUCCESS] = "Success"; + friendlyReturnCodes[app::INVALID] = "Invalid parameters"; + friendlyReturnCodes[app::NOT_IMPLEMENTED] = "Function not yet implemented"; + + std::map> apiMap; + apiMap["scanlist"] = []() { return app::data::getScanList(); }; + apiMap["systems"] = []() { return app::data::getSystemList(); }; + apiMap["systemat"] = [tokens]() { return app::data::getSystemByIndex(std::stoi(tokens[1])); }; + apiMap["entrylist"] = [tokens]() { return app::data::getEntryList(std::stoi(tokens[1])); }; + apiMap["entryat"] = [tokens]() { return app::data::getEntryByIndex(std::stoi(tokens[1]), std::stoi(tokens[2])); }; + apiMap["createsystem"] = [tokens]() { return app::data::system::create(/*TODO*/); }; + apiMap["replacesystem"] = [tokens]() { return app::data::system::replace(std::stoi(tokens[1])/*, TODO*/); }; + apiMap["removesystem"] = [tokens]() { return app::data::system::remove(std::stoi(tokens[1])); }; + apiMap["locksystem"] = [tokens]() { return app::data::system::setLockout(std::stoi(tokens[1]), std::stoi(tokens[2])); }; + apiMap["setsystemindex"] = [tokens]() { return app::data::system::setIndex(std::stoi(tokens[1]), std::stoi(tokens[2])); }; + apiMap["createentry"] = [tokens]() { return app::data::system::entry::create(std::stoi(tokens[1])/*,TODO*/); }; + apiMap["replaceentry"] = [tokens]() { return app::data::system::entry::replace(std::stoi(tokens[1]), std::stoi(tokens[2])/*, TODO*/); }; + apiMap["removeentry"] = [tokens]() { return app::data::system::entry::remove(std::stoi(tokens[1]), std::stoi(tokens[2])); }; + apiMap["lockentry"] = [tokens]() { return app::data::system::entry::setLockout(std::stoi(tokens[1]), std::stoi(tokens[2]), std::stoi(tokens[3])); }; + apiMap["setentryindex"] = [tokens]() { return app::data::system::entry::setIndex(std::stoi(tokens[1]), std::stoi(tokens[2]), std::stoi(tokens[3])); }; + apiMap["config"] = []() { return app::configuration::getFullConfig(); }; + apiMap["setconfig"] = [tokens]() { return app::configuration::setConfig(); }; + apiMap["generalcfg"] = []() { return app::configuration::getGeneralConfig(); }; + apiMap["setgeneralcfg"] = [tokens]() { return app::configuration::setGeneralConfig(); }; + apiMap["demodcfg"] = []() { return app::configuration::getDemodConfig(); }; + apiMap["setdemodcfg"] = [tokens]() { return app::configuration::setDemodConfig(); }; + apiMap["rtspcfg"] = []() { return app::configuration::getAudioServerConfig(); }; + apiMap["setrtspcfg"] = [tokens]() { return app::configuration::setAudioServerConfig(); }; + apiMap["tunerlist"] = []() { return app::configuration::getTunerList(); }; + getSystemInfo(); getScannerContext(); getDemodContext(); @@ -122,8 +155,16 @@ void DebugConsole::_consoleInputFunc() { << "\n\tget [subcommand]" << "\n\t\tcontext\t\tReturns scanner status" << "\n"; + for (auto cmd = apiMap.begin(); cmd != apiMap.end(); cmd++) { + std::cerr << "\t" << cmd->first << "\n"; + } } else + try { + auto ret = apiMap[tokens[0]](); + std::cerr << "Status: " << friendlyReturnCodes[std::get<0>(ret)] << "\n"; + } catch (std::exception& e) { std::cerr << "Invalid command\n"; + } } catch (std::exception& e) { std::cerr << "Argument missing or typo in the command\n"; }