arduino-rx : generate Tx response

This commit is contained in:
Georgi Gerganov
2022-05-29 23:00:33 +03:00
parent 62e54102ed
commit d4a66d9d31
3 changed files with 33 additions and 12 deletions

View File

@@ -53,7 +53,7 @@ void loop() {
p.sampleFormatInp = GGWAVE_SAMPLE_FORMAT_I16;
p.samplesPerFrame = 128;
p.payloadLength = 16;
p.operatingMode = GGWAVE_OPERATING_MODE_RX;
p.operatingMode = (ggwave_OperatingMode) (GGWAVE_OPERATING_MODE_RX | GGWAVE_OPERATING_MODE_TX | GGWAVE_OPERATING_MODE_TX_ONLY_TONES);
GGWave ggwave(p);
ggwave.setRxProtocols({
@@ -105,6 +105,25 @@ void loop() {
Serial.println(tEnd - tStart);
Serial.println(nr);
Serial.println((char *)result.data());
if (strcmp((char *)result.data(), "test") == 0) {
ggwave.init("hello", ggwave.getTxProtocol(GGWAVE_TX_PROTOCOL_MT_FASTEST));
ggwave.encode(nullptr);
const auto & waveformTones = ggwave.getWaveformTones();
for (int i = 0; i < (int) waveformTones.size(); ++i) {
Serial.print(" - frame ");
Serial.print(i);
Serial.print(", ");
Serial.print(waveformTones[i].size());
Serial.print(": ");
for (int j = 0; j < (int) waveformTones[i].size(); ++j) {
Serial.print((int)(waveformTones[i][j].freq_hz));
Serial.print(" ");
}
Serial.println();
}
}
}
}
if (err > 0) {

View File

@@ -364,8 +364,8 @@ public:
}
struct ToneData {
double freq_hz;
double duration_ms;
float freq_hz;
float duration_ms;
};
using Tones = std::vector<ToneData>;

View File

@@ -543,10 +543,12 @@ GGWave::GGWave(const Parameters & parameters) :
if (m_isTxEnabled) {
m_tx = std::unique_ptr<Tx>(new Tx());
{
const int maxDataBits = 2*16*maxBytesPerTx();
const int maxDataBits = 2*16*maxBytesPerTx();
m_tx->dataBits.resize(maxDataBits);
m_tx->txData.resize(kMaxDataSize);
m_tx->dataBits.resize(maxDataBits);
if (m_txOnlyTones == false) {
m_tx->phaseOffsets.resize(maxDataBits);
m_tx->bit0Amplitude.resize(maxDataBits);
for (auto & a : m_tx->bit0Amplitude) {
@@ -556,13 +558,12 @@ GGWave::GGWave(const Parameters & parameters) :
for (auto & a : m_tx->bit1Amplitude) {
a.resize(m_samplesPerFrame);
}
}
m_tx->txData.resize(kMaxDataSize);
m_tx->outputBlock.resize(m_samplesPerFrame),
m_tx->outputBlockResampled.resize(2*m_samplesPerFrame),
m_tx->outputBlockTmp.resize(kMaxRecordedFrames*m_samplesPerFrame*m_sampleSizeBytesOut),
m_tx->outputBlockI16.resize(kMaxRecordedFrames*m_samplesPerFrame);
m_tx->outputBlock.resize(m_samplesPerFrame);
m_tx->outputBlockResampled.resize(2*m_samplesPerFrame);
m_tx->outputBlockTmp.resize(kMaxRecordedFrames*m_samplesPerFrame*m_sampleSizeBytesOut);
m_tx->outputBlockI16.resize(kMaxRecordedFrames*m_samplesPerFrame);
}
// TODO
// m_tx->waveformTones;
@@ -797,6 +798,7 @@ bool GGWave::encode(const CBWaveformOut & cbWaveformOut) {
}
if (m_txOnlyTones) {
m_tx->hasNewTxData = false;
return true;
}
}