Flipper sub (raw+binraw AND ONLY OOK) TX (#2361)

This commit is contained in:
Totoo
2024-11-16 18:03:53 +01:00
committed by GitHub
parent 31c53dc455
commit 59f72cbff1
13 changed files with 889 additions and 34 deletions

View File

@@ -656,6 +656,14 @@ set(MODE_CPPSRC
)
DeclareTargets(PADT adsbtx)
### OOKStream
set(MODE_CPPSRC
proc_ook_stream_tx.cpp
)
DeclareTargets(POSK ookstream)
### HackRF "factory" firmware

View File

@@ -0,0 +1,127 @@
/*
* Copyright (C) 2024 HTotoo
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "proc_ook_stream_tx.hpp"
#include "sine_table_int8.hpp"
#include "portapack_shared_memory.hpp"
#include "event_m4.hpp"
#include "utility.hpp"
OOKProcessorStreamed::OOKProcessorStreamed() {
configured = false;
baseband_thread.start();
}
inline void OOKProcessorStreamed::write_sample(const buffer_c8_t& buffer, bool bit_value, size_t i) {
int8_t re, im;
if (bit_value) {
phase = (phase + 200); // What ?
sphase = phase + (64 << 18);
re = (sine_table_i8[(sphase & 0x03FC0000) >> 18]);
im = (sine_table_i8[(phase & 0x03FC0000) >> 18]);
} else {
re = 0;
im = 0;
}
buffer.p[i] = {re, im};
}
void OOKProcessorStreamed::execute(const buffer_c8_t& buffer) {
if (!configured || !stream) return;
for (size_t i = 0; i < buffer.count; i++) {
if (rem_samples <= curr_samples) {
// get a new sample from stream
int32_t sample = -13346;
rem_samples = 0; // reset my pointer
curr_samples = 0;
size_t readed = 0;
if (configured) readed = stream->read(&sample, 4); // read from stream // todo htotoo error handling?!
if (readed == 0) {
txprogress_message.progress = -10;
shared_memory.application_queue.push(txprogress_message); // debug
} else {
if (sample == endsignals[readerrs + 1]) { // if no more samples, stop
readerrs++;
if (readerrs == 2) {
configured = false;
txprogress_message.done = true;
txprogress_message.progress = 100;
curr_hilow = false;
shared_memory.application_queue.push(txprogress_message);
}
} else {
if (sample < 0) {
rem_samples = OOK_SAMPLERATE * ((-1 * sample) / 1000000.0);
curr_hilow = false;
} else {
rem_samples = OOK_SAMPLERATE * (sample / 1000000.0);
curr_hilow = true;
}
}
}
}
++curr_samples;
write_sample(buffer, curr_hilow, i);
}
}
void OOKProcessorStreamed::on_message(const Message* const message) {
switch (message->id) {
case Message::ID::ReplayConfig:
configured = false;
replay_config(*reinterpret_cast<const ReplayConfigMessage*>(message));
break;
case Message::ID::FIFOData:
configured = true;
txprogress_message.progress = -4;
shared_memory.application_queue.push(txprogress_message);
break;
default:
break;
}
}
void OOKProcessorStreamed::replay_config(const ReplayConfigMessage& message) {
if (message.config) {
txprogress_message.progress = -2;
shared_memory.application_queue.push(txprogress_message);
stream = std::make_unique<StreamOutput>(message.config);
// Tell application that the buffers and FIFO pointers are ready, prefill
RequestSignalMessage sig_message{RequestSignalMessage::Signal::FillRequest};
shared_memory.application_queue.push(sig_message);
} else {
txprogress_message.progress = -3;
shared_memory.application_queue.push(txprogress_message);
stream.reset();
}
}
int main() {
EventDispatcher event_dispatcher{std::make_unique<OOKProcessorStreamed>()};
event_dispatcher.run();
return 0;
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (C) 2024 HTotoo
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
/*
For usage check the FlipperTX app. Don't forget to "close" the tx by sending 42069, 613379 values at the end of the stream.
Only close baseband when you get the TX done msg, not on replay thread done, because, there can still data in the buffer.
*/
#ifndef __PROC_OOKSTREAMTX_HPP__
#define __PROC_OOKSTREAMTX_HPP__
#include "baseband_processor.hpp"
#include "baseband_thread.hpp"
#include "stream_output.hpp"
#include <array>
#include <memory>
#define OOK_SAMPLERATE 2280000U
class OOKProcessorStreamed : public BasebandProcessor {
public:
OOKProcessorStreamed();
void execute(const buffer_c8_t& buffer) override;
void on_message(const Message* const message) override;
private:
uint32_t rem_samples = 0;
uint32_t curr_samples = 0;
bool curr_hilow = false;
uint32_t phase{0}, sphase{0};
void write_sample(const buffer_c8_t& buffer, bool bit_value, size_t i);
std::unique_ptr<StreamOutput> stream{};
bool configured{false};
void replay_config(const ReplayConfigMessage& message);
int32_t endsignals[3] = {0, 42069, 613379}; // 0 is skipped, count from 1, don't ask...
uint8_t readerrs = 0; // to count in the array
TXProgressMessage txprogress_message{};
/* NB: Threads should be the last members in the class definition. */
BasebandThread baseband_thread{OOK_SAMPLERATE, this, baseband::Direction::Transmit};
};
#endif /*__PROC_OOKSTREAMTX_HPP__*/