kopia lustrzana https://github.com/sh123/esp32_loraprs
Refactor for better mgmt
rodzic
752128197e
commit
bec81153ff
|
@ -1,12 +1,12 @@
|
|||
#include <timer.h>
|
||||
#include "WiFi.h"
|
||||
#include "loraprs.h"
|
||||
#include "loraprs_service.h"
|
||||
|
||||
#define LED_BUILTIN 2
|
||||
#define LED_TOGGLE_PERIOD 1000
|
||||
|
||||
LoraPrsConfig cfg;
|
||||
LoraPrs loraPrs;
|
||||
LoraPrs::Config cfg;
|
||||
LoraPrs::Service loraPrsService;
|
||||
|
||||
auto watchdogLedTimer = timer_create_default();
|
||||
|
||||
|
@ -57,13 +57,13 @@ void setup() {
|
|||
while (!Serial);
|
||||
|
||||
initializeConfig();
|
||||
loraPrs.setup(cfg);
|
||||
loraPrsService.setup(cfg);
|
||||
|
||||
watchdogLedTimer.every(LED_TOGGLE_PERIOD, toggleWatchdogLed);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
loraPrs.loop();
|
||||
loraPrsService.loop();
|
||||
watchdogLedTimer.tick();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef LORAPRS_CONFIG_H
|
||||
#define LORAPRS_CONFIG_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace LoraPrs {
|
||||
|
||||
struct Config
|
||||
{
|
||||
bool IsClientMode; // true - client mode, false - server mode
|
||||
|
||||
long LoraFreq; // lora frequency, e.g. 433.775e6
|
||||
int LoraBw; // lora bandwidth, e.g. 125e3
|
||||
byte LoraSf; // lora spreading factor, e.g. 12
|
||||
byte LoraCodingRate; // lora coding rate, e.g. 7
|
||||
byte LoraSync; // lora sync word/packet id, 0x3f
|
||||
byte LoraPower; // lora power level in dbm, 20
|
||||
|
||||
int AprsPort; // aprs server port, 14580
|
||||
String AprsHost; // aprs server hostname, rotate.aprs2.net
|
||||
String AprsLogin; // aprs callsign to use, e.g. MY0CAL-1
|
||||
String AprsPass; // aprs login password
|
||||
String AprsFilter; // aprs filter, see http://www.aprs-is.net/javAPRSFilter.aspx
|
||||
String AprsRawBeacon; // aprs string for server beacon, e.g. NOCALL-1>APZMDM,WIDE1-1:!0000.00N/00000.00E#LoRA 433.775MHz/BW125/SF12/CR7/0xf3
|
||||
int AprsRawBeaconPeriodMinutes; // aprs beacon period
|
||||
|
||||
String BtName; // bluetooth device name for the client
|
||||
|
||||
String WifiSsid; // wifi access point name
|
||||
String WifiKey; // wifi access point key
|
||||
|
||||
bool EnableSignalReport; // true - append signal report on server side for the client to be sent to APRS-IS
|
||||
bool EnableAutoFreqCorrection; // true - correct own frequency based on received packet frequency deviation
|
||||
bool EnablePersistentAprsConnection; // true - keep aprs-is connection active all the time
|
||||
bool EnableRfToIs; // true - enable RF to APRS-IS submission
|
||||
bool EnableIsToRf; // true - enable APRS-IS to RF submission
|
||||
bool EnableRepeater; // true - digirepeat incoming packets based on WIDEn-n paths
|
||||
bool EnableBeacon; // true - send AprsRawBeacon to RF and APRS-IS if EnableRfToIs is true
|
||||
};
|
||||
|
||||
} // LoraPrs
|
||||
|
||||
#endif // LORAPRS_CONFIG_H
|
|
@ -1,13 +1,15 @@
|
|||
#include "loraprs.h"
|
||||
#include "loraprs_service.h"
|
||||
|
||||
LoraPrs::LoraPrs()
|
||||
namespace LoraPrs {
|
||||
|
||||
Service::Service()
|
||||
: serialBt_()
|
||||
, kissState_(KissState::Void)
|
||||
, kissCmd_(KissCmd::NoCmd)
|
||||
{
|
||||
}
|
||||
|
||||
void LoraPrs::setup(const LoraPrsConfig &conf)
|
||||
void Service::setup(const Config &conf)
|
||||
{
|
||||
previousBeaconMs_ = 0;
|
||||
|
||||
|
@ -52,7 +54,7 @@ void LoraPrs::setup(const LoraPrsConfig &conf)
|
|||
}
|
||||
}
|
||||
|
||||
void LoraPrs::setupWifi(const String &wifiName, const String &wifiKey)
|
||||
void Service::setupWifi(const String &wifiName, const String &wifiKey)
|
||||
{
|
||||
if (!isClient_) {
|
||||
Serial.print("WIFI connecting to " + wifiName);
|
||||
|
@ -70,7 +72,7 @@ void LoraPrs::setupWifi(const String &wifiName, const String &wifiKey)
|
|||
}
|
||||
}
|
||||
|
||||
void LoraPrs::reconnectWifi()
|
||||
void Service::reconnectWifi()
|
||||
{
|
||||
Serial.print("WIFI re-connecting...");
|
||||
|
||||
|
@ -83,7 +85,7 @@ void LoraPrs::reconnectWifi()
|
|||
Serial.println("ok");
|
||||
}
|
||||
|
||||
bool LoraPrs::reconnectAprsis()
|
||||
bool Service::reconnectAprsis()
|
||||
{
|
||||
Serial.print("APRSIS connecting...");
|
||||
|
||||
|
@ -97,7 +99,7 @@ bool LoraPrs::reconnectAprsis()
|
|||
return true;
|
||||
}
|
||||
|
||||
void LoraPrs::setupLora(int loraFreq, int bw, byte sf, byte cr, byte pwr, byte sync)
|
||||
void Service::setupLora(int loraFreq, int bw, byte sf, byte cr, byte pwr, byte sync)
|
||||
{
|
||||
Serial.print("LoRa init...");
|
||||
|
||||
|
@ -117,7 +119,7 @@ void LoraPrs::setupLora(int loraFreq, int bw, byte sf, byte cr, byte pwr, byte s
|
|||
Serial.println("ok");
|
||||
}
|
||||
|
||||
void LoraPrs::setupBt(const String &btName)
|
||||
void Service::setupBt(const String &btName)
|
||||
{
|
||||
Serial.print("BT init " + btName + "...");
|
||||
|
||||
|
@ -130,7 +132,7 @@ void LoraPrs::setupBt(const String &btName)
|
|||
}
|
||||
}
|
||||
|
||||
void LoraPrs::loop()
|
||||
void Service::loop()
|
||||
{
|
||||
if (needsWifi() && WiFi.status() != WL_CONNECTED) {
|
||||
reconnectWifi();
|
||||
|
@ -153,7 +155,7 @@ void LoraPrs::loop()
|
|||
delay(10);
|
||||
}
|
||||
|
||||
void LoraPrs::sendBeacon()
|
||||
void Service::sendBeacon()
|
||||
{
|
||||
long currentMs = millis();
|
||||
|
||||
|
@ -172,7 +174,7 @@ void LoraPrs::sendBeacon()
|
|||
previousBeaconMs_ = currentMs;
|
||||
}
|
||||
}
|
||||
void LoraPrs::sendToAprsis(String aprsMessage)
|
||||
void Service::sendToAprsis(String aprsMessage)
|
||||
{
|
||||
if (needsWifi() && WiFi.status() != WL_CONNECTED) {
|
||||
reconnectWifi();
|
||||
|
@ -187,7 +189,7 @@ void LoraPrs::sendToAprsis(String aprsMessage)
|
|||
}
|
||||
}
|
||||
|
||||
void LoraPrs::onAprsisDataAvailable()
|
||||
void Service::onAprsisDataAvailable()
|
||||
{
|
||||
String aprsisData;
|
||||
|
||||
|
@ -210,7 +212,7 @@ void LoraPrs::onAprsisDataAvailable()
|
|||
}
|
||||
}
|
||||
|
||||
bool LoraPrs::sendToLora(const AX25::Payload &payload)
|
||||
bool Service::sendToLora(const AX25::Payload &payload)
|
||||
{
|
||||
byte buf[512];
|
||||
int bytesWritten = payload.ToBinary(buf, sizeof(buf));
|
||||
|
@ -225,7 +227,7 @@ bool LoraPrs::sendToLora(const AX25::Payload &payload)
|
|||
return true;
|
||||
}
|
||||
|
||||
void LoraPrs::onLoraDataAvailable(int packetSize)
|
||||
void Service::onLoraDataAvailable(int packetSize)
|
||||
{
|
||||
int rxBufIndex = 0;
|
||||
byte rxBuf[packetSize];
|
||||
|
@ -292,13 +294,13 @@ void LoraPrs::onLoraDataAvailable(int packetSize)
|
|||
delay(50);
|
||||
}
|
||||
|
||||
void LoraPrs::kissResetState()
|
||||
void Service::kissResetState()
|
||||
{
|
||||
kissCmd_ = KissCmd::NoCmd;
|
||||
kissState_ = KissState::Void;
|
||||
}
|
||||
|
||||
void LoraPrs::onBtDataAvailable()
|
||||
void Service::onBtDataAvailable()
|
||||
{
|
||||
while (serialBt_.available()) {
|
||||
byte txByte = serialBt_.read();
|
||||
|
@ -355,3 +357,5 @@ void LoraPrs::onBtDataAvailable()
|
|||
}
|
||||
delay(20);
|
||||
}
|
||||
|
||||
} // LoraPrs
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef LORAPRS_H
|
||||
#define LORAPRS_H
|
||||
#ifndef LORAPRS_SEVICE_H
|
||||
#define LORAPRS_SERVICE_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <SPI.h>
|
||||
|
@ -8,46 +8,16 @@
|
|||
|
||||
#include "BluetoothSerial.h"
|
||||
#include "ax25_payload.h"
|
||||
#include "loraprs_config.h"
|
||||
|
||||
struct LoraPrsConfig
|
||||
{
|
||||
bool IsClientMode;
|
||||
|
||||
long LoraFreq;
|
||||
int LoraBw;
|
||||
byte LoraSf;
|
||||
byte LoraCodingRate;
|
||||
byte LoraSync;
|
||||
byte LoraPower;
|
||||
namespace LoraPrs {
|
||||
|
||||
int AprsPort;
|
||||
String AprsHost;
|
||||
String AprsLogin;
|
||||
String AprsPass;
|
||||
String AprsFilter;
|
||||
String AprsRawBeacon;
|
||||
int AprsRawBeaconPeriodMinutes;
|
||||
|
||||
String BtName;
|
||||
|
||||
String WifiSsid;
|
||||
String WifiKey;
|
||||
|
||||
bool EnableSignalReport;
|
||||
bool EnableAutoFreqCorrection;
|
||||
bool EnablePersistentAprsConnection;
|
||||
bool EnableRfToIs;
|
||||
bool EnableIsToRf;
|
||||
bool EnableRepeater;
|
||||
bool EnableBeacon;
|
||||
};
|
||||
|
||||
class LoraPrs
|
||||
class Service
|
||||
{
|
||||
public:
|
||||
LoraPrs();
|
||||
Service();
|
||||
|
||||
void setup(const LoraPrsConfig &conf);
|
||||
void setup(const Config &conf);
|
||||
void loop();
|
||||
|
||||
private:
|
||||
|
@ -132,4 +102,6 @@ private:
|
|||
WiFiClient aprsisConn_;
|
||||
};
|
||||
|
||||
#endif // LORAPRS_H
|
||||
} // LoraPrs
|
||||
|
||||
#endif // LORAPRS_SERVICE_H
|
Ładowanie…
Reference in New Issue