Radio: Make modulation property of RadioDevice
This commit is contained in:
parent
5eb3dbcd9f
commit
e2db52c0dc
@ -3,14 +3,8 @@
|
||||
|
||||
constexpr const char* TAG = "RadiolibThreadedDevice";
|
||||
|
||||
bool RadiolibThreadedDevice::start(const Modulation modulation) {
|
||||
bool RadiolibThreadedDevice::start() {
|
||||
auto lock = getMutex().asScopedLock();
|
||||
|
||||
if (!canTransmit(modulation)) {
|
||||
TT_LOG_E(TAG, "Can't start device \"%s\", not capable of modulation \"%s\"", getName().c_str(), toString(modulation));
|
||||
return false;
|
||||
}
|
||||
|
||||
lock.lock();
|
||||
|
||||
if ((thread != nullptr) && (thread->getState() != tt::Thread::State::Stopped)) {
|
||||
@ -26,8 +20,8 @@ bool RadiolibThreadedDevice::start(const Modulation modulation) {
|
||||
thread = std::make_unique<tt::Thread>(
|
||||
threadName,
|
||||
threadSize,
|
||||
[this, modulation]() {
|
||||
return this->threadMain(modulation);
|
||||
[this]() {
|
||||
return this->threadMain();
|
||||
}
|
||||
);
|
||||
thread->setPriority(tt::Thread::Priority::High);
|
||||
@ -71,9 +65,9 @@ bool RadiolibThreadedDevice::isThreadInterrupted() const {
|
||||
return threadInterrupted;
|
||||
}
|
||||
|
||||
int32_t RadiolibThreadedDevice::threadMain(const Modulation modulation) {
|
||||
int32_t RadiolibThreadedDevice::threadMain() {
|
||||
|
||||
int rc = doBegin(modulation);
|
||||
int rc = doBegin(getModulation());
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ private:
|
||||
bool threadInterrupted = false;
|
||||
|
||||
protected:
|
||||
virtual int32_t threadMain(const Modulation modulation);
|
||||
virtual int32_t threadMain();
|
||||
bool isThreadInterrupted() const;
|
||||
|
||||
virtual void interruptSignal() = 0;
|
||||
@ -31,6 +31,6 @@ public:
|
||||
|
||||
~RadiolibThreadedDevice() override = default;
|
||||
|
||||
virtual bool start(const Modulation modulation) override;
|
||||
virtual bool start() override;
|
||||
virtual bool stop() override;
|
||||
};
|
||||
|
||||
@ -233,7 +233,6 @@ int Sx1262::doBegin(const Modulation modulation) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
currentModem = modulation;
|
||||
registerDio1Isr();
|
||||
return 0;
|
||||
}
|
||||
@ -275,7 +274,7 @@ void Sx1262::doTransmit() {
|
||||
}
|
||||
|
||||
void Sx1262::doListen() {
|
||||
if (currentModem != Modulation::LrFhss) {
|
||||
if (getModulation() != Modulation::LrFhss) {
|
||||
radio.startReceive();
|
||||
events.wait(SX1262_INTERRUPT_BIT | SX1262_DIO1_EVENT_BIT | SX1262_QUEUED_TX_BIT);
|
||||
} else {
|
||||
@ -286,7 +285,7 @@ void Sx1262::doListen() {
|
||||
|
||||
void Sx1262::doReceive() {
|
||||
// LR-FHSS modem only supports TX
|
||||
if (currentModem == Modulation::LrFhss) return;
|
||||
if (getModulation() == Modulation::LrFhss) return;
|
||||
|
||||
uint16_t rxSize = radio.getPacketLength(true);
|
||||
std::vector<uint8_t> data(rxSize);
|
||||
|
||||
@ -38,7 +38,6 @@ private:
|
||||
Module radioModule;
|
||||
SX1262 radio;
|
||||
TxItem currentTx;
|
||||
Modulation currentModem;
|
||||
|
||||
int8_t power = 0;
|
||||
float frequency = 0.0;
|
||||
@ -73,7 +72,6 @@ public:
|
||||
, hal(configuration.spiHostDevice, configuration.spiFrequency, configuration.csPin, lock)
|
||||
, radioModule(&hal, configuration.csPin, configuration.irqPin, configuration.resetPin, configuration.busyPin)
|
||||
, radio(&radioModule)
|
||||
, currentModem(Modulation::None)
|
||||
{}
|
||||
|
||||
~Sx1262() override = default;
|
||||
|
||||
@ -88,6 +88,7 @@ private:
|
||||
};
|
||||
|
||||
State state;
|
||||
Modulation modulation;
|
||||
Mutex mutex = Mutex(Mutex::Type::Recursive);
|
||||
std::vector<RxSubscription> rxSubscriptions;
|
||||
std::deque<TxItem> txQueue;
|
||||
@ -121,19 +122,21 @@ protected:
|
||||
|
||||
public:
|
||||
explicit RadioDevice()
|
||||
: state(State::Off) {}
|
||||
: state(State::Off), modulation(Modulation::None) {}
|
||||
|
||||
~RadioDevice() override = default;
|
||||
|
||||
Type getType() const override { return Type::Radio; }
|
||||
|
||||
bool setModulation(const Modulation newModulation);
|
||||
Modulation getModulation() const;
|
||||
virtual ParameterStatus setParameter(const Parameter parameter, const float value) = 0;
|
||||
virtual ParameterStatus getParameter(const Parameter parameter, float &value) const = 0;
|
||||
virtual Unit getParameterUnit(const Parameter parameter) const = 0;
|
||||
virtual bool canTransmit(const Modulation modulation) = 0;
|
||||
virtual bool canReceive(const Modulation modulation) = 0;
|
||||
|
||||
virtual bool start(const Modulation modulation) = 0;
|
||||
virtual bool start() = 0;
|
||||
virtual bool stop() = 0;
|
||||
|
||||
TxId transmit(const TxPacket& packet, TxStateCallback callback) {
|
||||
|
||||
@ -469,8 +469,9 @@ public:
|
||||
loraDevice = loraDevs[lv_dropdown_get_selected(loraDeviceInput)];
|
||||
if (loraDevice) {
|
||||
disableForm();
|
||||
loraDevice->setModulation(tt::hal::radio::RadioDevice::Modulation::LoRa);
|
||||
configureFromForm();
|
||||
loraDevice->start(tt::hal::radio::RadioDevice::Modulation::LoRa);
|
||||
loraDevice->start();
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
if (loraDevice->getState() != tt::hal::radio::RadioDevice::State::On) {
|
||||
lv_obj_clear_state(loraDeviceOn, LV_STATE_CHECKED);
|
||||
|
||||
@ -5,6 +5,31 @@ namespace tt::hal::radio {
|
||||
|
||||
constexpr const char* TAG = "RadioDevice";
|
||||
|
||||
bool RadioDevice::setModulation(const RadioDevice::Modulation newModulation) {
|
||||
// A bool is chosen over an enum class because:
|
||||
// - this is not tied to user input and
|
||||
// - the programmer can infer why it didn't work using
|
||||
// other methods such as getState() and canTransmit/Receive()
|
||||
const auto state = getState();
|
||||
if ((state == State::PendingOn) || (state == State::On)) {
|
||||
return false;
|
||||
} else if (!(canTransmit(newModulation) || canReceive(newModulation))) {
|
||||
return false;
|
||||
} else {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
modulation = newModulation;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
RadioDevice::Modulation RadioDevice::getModulation() const {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
return modulation;
|
||||
}
|
||||
|
||||
RadioDevice::State RadioDevice::getState() const {
|
||||
auto lock = mutex.asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user