c-api : add toggleRxProtocol() (#60)

This function allows to enable/disable Rx protocols during the decoding
process. This is useful when the Tx/Rx protocol is known in advance.
This commit is contained in:
Georgi Gerganov
2021-11-22 21:29:26 +02:00
committed by GitHub
parent 7b39e51440
commit bbacdbcc96
7 changed files with 96 additions and 4 deletions

View File

@@ -25,6 +25,7 @@
namespace {
FILE * g_fptr = stderr;
std::map<ggwave_Instance, GGWave *> g_instances;
std::map<ggwave_Instance, GGWave::RxProtocols> g_rxProtocols;
}
extern "C"
@@ -178,6 +179,27 @@ int ggwave_ndecode(
return rxDataLength;
}
extern "C"
void ggwave_toggleRxProtocol(
ggwave_Instance instance,
ggwave_TxProtocolId rxProtocolId,
int state) {
// if never called - initialize with all available protocols
if (g_rxProtocols.find(instance) == g_rxProtocols.end()) {
g_rxProtocols[instance] = GGWave::getTxProtocols();
}
if (state == 0) {
// disable Rx protocol
g_rxProtocols[instance].erase(rxProtocolId);
} else if (state == 1) {
// enable Rx protocol
g_rxProtocols[instance][rxProtocolId] = GGWave::getTxProtocols().at(rxProtocolId);
}
g_instances[instance]->setRxProtocols(g_rxProtocols[instance]);
}
//
// C++ implementation
//