Porównaj commity

...

5 Commity

Autor SHA1 Wiadomość Data
sh123 e78e0e8513 Serial tx delay update 2023-11-17 15:49:48 +02:00
sh123 cf99eb014d Avoid switching to rx on each packet 2023-11-17 14:25:06 +02:00
sh123 b89a13680e Handle control data escape 2023-11-17 14:25:06 +02:00
sh123 0a43429b1c Convert to khz 2023-11-17 14:25:06 +02:00
sh123 2083f946d9 Update SetHardware command 2023-11-17 14:25:06 +02:00
5 zmienionych plików z 94 dodań i 39 usunięć

Wyświetl plik

@ -50,6 +50,7 @@ protected:
None = 0x80
};
static const int CfgToSerialDelayMs = 10;
static const int CfgSerialToRigQueueSize = 4096;
static const int CfgRigToSerialQueueSize = 4096;

Wyświetl plik

@ -52,9 +52,14 @@ private:
void onRigTaskRxPacket();
void onRigTaskTxPacket();
void onRigTaskStartRx();
void onRigTaskStartTx();
static void rigTask(void *self);
static ICACHE_RAM_ATTR void onRigIsrRxPacket();
void startRx();
static bool startRxTimer(void *param);
void onAprsisDataAvailable();
void sendSignalReportEvent(int rssi, float snr);
@ -106,13 +111,18 @@ protected:
private:
struct SetHardware {
uint32_t freq;
uint32_t freqRx;
uint32_t freqTx;
uint8_t modType;
int16_t pwr;
uint32_t bw;
uint16_t sf;
uint16_t cr;
uint16_t pwr;
uint16_t sync;
uint8_t crc;
uint32_t fskBitRate;
uint32_t fskFreqDev;
uint32_t fskRxBw;
} __attribute__((packed));
struct SignalReport {
@ -125,7 +135,7 @@ private:
} __attribute__((packed));
private:
const String CfgLoraprsVersion = "LoRAPRS 1.0.13";
const String CfgLoraprsVersion = "LoRAPRS 1.0.14";
// processor config
const int CfgConnRetryMs = 500; // connection retry delay, e.g. wifi
@ -145,7 +155,9 @@ private:
// radio task commands
enum RadioTaskBits {
Receive = 0x01,
Transmit = 0x02
Transmit = 0x02,
StartReceive = 0x04,
StartTransmit = 0x10
};
private:
@ -164,6 +176,7 @@ private:
// peripherals, radio
static TaskHandle_t rigTaskHandle_;
Timer<1> startRxTimer_;
static volatile bool rigIsRxActive_;
static volatile bool rigIsRxIsrEnabled_;
bool rigIsImplicitMode_;

Wyświetl plik

@ -134,7 +134,7 @@ bool Processor::processRigToSerial()
onRigPacket(&buf, rxPacketSize);
isProcessed = true;
yield();
if (!rigToSerialQueueIndex_.isEmpty()) delay(CfgToSerialDelayMs);
}
return isProcessed;
}
@ -280,11 +280,19 @@ bool Processor::receiveByteKiss(byte rxByte)
break;
case State::Escape:
if (rxByte == Marker::Tfend) {
onRigTx((byte)Marker::Fend);
if (dataType_ == DataType::Raw) {
onRigTx((byte)Marker::Fend);
} else if (dataType_ == DataType::Control) {
cmdBuffer_.push_back((byte)Marker::Fend);
}
state_ = State::GetData;
}
else if (rxByte == Marker::Tfesc) {
onRigTx((byte)Marker::Fesc);
if (dataType_ == DataType::Raw) {
onRigTx((byte)Marker::Fesc);
} else if (dataType_ == DataType::Control) {
cmdBuffer_.push_back((byte)Marker::Fesc);
}
state_ = State::GetData;
}
else if (rxByte != Marker::Fend) {

Wyświetl plik

@ -367,6 +367,7 @@ void Service::loop()
if (config_.TlmEnable) {
telemetryTimer_.tick();
}
startRxTimer_.tick();
}
ICACHE_RAM_ATTR void Service::onRigIsrRxPacket() {
@ -388,9 +389,30 @@ void Service::rigTask(void *self) {
else if (commandBits & RadioTaskBits::Transmit) {
static_cast<Service*>(self)->onRigTaskTxPacket();
}
if (commandBits & RadioTaskBits::StartReceive) {
static_cast<Service*>(self)->onRigTaskStartRx();
}
else if (commandBits & RadioTaskBits::StartTransmit) {
static_cast<Service*>(self)->onRigTaskStartTx();
}
}
}
void Service::onRigTaskStartRx() {
LOG_TRACE("onRigTaskStartRx");
if (config_.PttEnable) {
digitalWrite(config_.PttPin, LOW);
}
if (isHalfDuplex()) {
setFreq(config_.LoraFreqRx);
}
int state = rig_->startReceive();
if (state != RADIOLIB_ERR_NONE) {
LOG_ERROR("Start receive error: ", state);
}
rigIsRxIsrEnabled_ = true;
}
void Service::onRigTaskRxPacket() {
int packetSize = rig_->getPacketLength();
LOG_TRACE("onRigTaskRxPacket", packetSize);
@ -411,15 +433,21 @@ void Service::onRigTaskRxPacket() {
rigIsRxActive_ = false;
}
void Service::onRigTaskTxPacket() {
rigIsRxIsrEnabled_ = false;
if (isHalfDuplex()) {
setFreq(config_.LoraFreqTx);
}
if (config_.PttEnable) {
digitalWrite(config_.PttPin, HIGH);
void Service::onRigTaskStartTx() {
LOG_TRACE("onRigTaskStartTx");
if (rigIsRxIsrEnabled_) {
rigIsRxIsrEnabled_ = false;
if (isHalfDuplex()) {
setFreq(config_.LoraFreqTx);
}
if (config_.PttEnable) {
digitalWrite(config_.PttPin, HIGH);
}
delay(config_.PttTxDelayMs);
}
}
void Service::onRigTaskTxPacket() {
while (rigTxQueueIndex_.size() > 0) {
int txPacketSize = rigTxQueueIndex_.shift();
LOG_TRACE("onRigTaskTxPacket", txPacketSize);
@ -435,18 +463,7 @@ void Service::onRigTaskTxPacket() {
}
vTaskDelay(1);
}
if (config_.PttEnable) {
delay(config_.PttTxTailMs);
digitalWrite(config_.PttPin, LOW);
}
if (isHalfDuplex()) {
setFreq(config_.LoraFreqRx);
}
int state = rig_->startReceive();
if (state != RADIOLIB_ERR_NONE) {
LOG_ERROR("Start receive error: ", state);
}
rigIsRxIsrEnabled_ = true;
startRxTimer_.in(config_.PttTxTailMs, &startRxTimer);
}
void Service::sendPeriodicBeacon()
@ -528,6 +545,16 @@ bool Service::sendModemTelemetryTimer(void *param)
return true;
}
bool Service::startRxTimer(void *param)
{
static_cast<Service*>(param)->startRx();
return true;
}
void Service::startRx() {
xTaskNotify(rigTaskHandle_, RadioTaskBits::StartReceive, eSetBits);
}
void Service::sendModemTelemetry()
{
float batVoltage = 2 * analogRead(config_.TlmBatMonPin) * (3.3 / 4096.0) + config_.TlmBatMonCal;
@ -591,10 +618,6 @@ void Service::performFrequencyCorrection() {
void Service::setFreq(long loraFreq) const {
rig_->setFrequency((float)loraFreq / 1e6);
int state = rig_->startReceive();
if (state != RADIOLIB_ERR_NONE) {
LOG_ERROR("Start receive error:", state);
}
}
void Service::processIncomingRawPacketAsServer(const byte *packet, int packetLength) {
@ -650,6 +673,8 @@ void Service::processIncomingRawPacketAsServer(const byte *packet, int packetLen
bool Service::onRigTxBegin()
{
LOG_TRACE("onRigTxBegin");
startRxTimer_.cancel();
xTaskNotify(rigTaskHandle_, RadioTaskBits::StartTransmit, eSetBits);
rigCurrentTxPacketSize_ = 0;
return true;
}
@ -781,21 +806,29 @@ void Service::onRadioControlCommand(const std::vector<byte> &rawCommand) {
if (config_.KissEnableExtensions && rawCommand.size() == sizeof(SetHardware)) {
LOG_INFO("Setting new radio parameters");
const struct SetHardware * setHardware = reinterpret_cast<const struct SetHardware*>(rawCommand.data());
// TODO, add support for split set hardware
config_.LoraFreqRx = be32toh(setHardware->freq);
config_.LoraFreqTx = be32toh(setHardware->freq);
config_.LoraFreqRx = be32toh(setHardware->freqRx);
config_.LoraFreqTx = be32toh(setHardware->freqTx);
config_.ModType = setHardware->modType;
config_.LoraBw = be32toh(setHardware->bw);
config_.LoraSf = be16toh(setHardware->sf);
config_.LoraCodingRate = be16toh(setHardware->cr);
config_.LoraPower = be16toh(setHardware->pwr);
config_.LoraPower = (int16_t)be16toh(setHardware->pwr);
config_.LoraSync = be16toh(setHardware->sync);
config_.FskBitRate = (float)be32toh(setHardware->fskBitRate) / 1e3;
config_.FskFreqDev = (float)be32toh(setHardware->fskFreqDev) / 1e3;
config_.FskRxBw = (float)be32toh(setHardware->fskRxBw) / 1e3;
int crcType = setHardware->crc ? config_.LoraCrc : 0;
setupRig(config_.LoraFreqRx, config_.LoraBw, config_.LoraSf,
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, crcType, config_.LoraExplicit);
if (config_.ModType == CFG_MOD_TYPE_FSK) {
setupRigFsk(config_.LoraFreqRx, config_.FskBitRate, config_.FskFreqDev, config_.FskRxBw, config_.LoraPower);
}
else {
setupRig(config_.LoraFreqRx, config_.LoraBw, config_.LoraSf,
config_.LoraCodingRate, config_.LoraPower, config_.LoraSync, crcType, config_.LoraExplicit);
}
} else {
LOG_ERROR("Radio control command of wrong size");
LOG_ERROR("Radio control command of wrong size", rawCommand.size());
}
}

Wyświetl plik

@ -17,7 +17,7 @@
#include "loraprs_service.h"
const int CfgPollDelayMs = 20; // main loop delay
const int CfgPollDelayMs = 10; // main loop delay
/*
* Initialize config from config.h options.