outputBuffer Created-all LoRa send to Buffer

This commit is contained in:
richonguzman 2024-04-20 09:27:20 -04:00
parent ce058ed424
commit b4f2daca42
11 changed files with 89 additions and 107 deletions

View file

@ -23,35 +23,35 @@
Configuration Config;
WiFiClient espClient;
String versionDate = "2024.04.13";
uint8_t myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
String versionDate = "2024.04.20";
uint8_t myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
bool isUpdatingOTA = false;
bool statusAfterBoot = true;
bool beaconUpdate = true;
uint32_t lastBeaconTx = 0;
uint32_t previousWiFiMillis = 0;
uint32_t lastScreenOn = millis();
bool isUpdatingOTA = false;
bool statusAfterBoot = true;
bool beaconUpdate = true;
uint32_t lastBeaconTx = 0;
uint32_t previousWiFiMillis = 0;
uint32_t lastScreenOn = millis();
uint32_t lastWiFiCheck = 0;
bool WiFiConnect = true;
bool WiFiConnected = false;
uint32_t lastWiFiCheck = 0;
bool WiFiConnect = true;
bool WiFiConnected = false;
bool WiFiAutoAPStarted = false;
long WiFiAutoAPTime = false;
bool WiFiAutoAPStarted = false;
long WiFiAutoAPTime = false;
uint32_t lastBatteryCheck = 0;
uint32_t lastBatteryCheck = 0;
uint32_t bmeLastReading = -60000;
uint32_t bmeLastReading = -60000;
String batteryVoltage;
std::vector<String> lastHeardStation;
std::vector<String> lastHeardStation_temp;
std::vector<String> packetBuffer;
std::vector<String> packetBuffer_temp;
std::vector<String> outputPacketBuffer;
uint32_t lastTxTime = millis();
std::vector<ReceivedPacket> receivedPackets;
@ -199,7 +199,7 @@ void loop() {
}
if (Config.digi.mode == 2) { // If Digi enabled
DIGI_Utils::loop(packet); // Send received packet to Digi
DIGI_Utils::processLoRaPacket(packet); // Send received packet to Digi
}
if (Config.tnc.enableServer) { // If TNC server enabled
@ -215,5 +215,7 @@ void loop() {
APRS_IS_Utils::listenAPRSIS(); // listen received packet from APRSIS
}
STATION_Utils::processOutputPacketBuffer();
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, sixthLine, seventhLine, 0);
}

View file

@ -4,21 +4,23 @@
#include "station_utils.h"
#include "syslog_utils.h"
#include "query_utils.h"
#include "lora_utils.h"
//#include "lora_utils.h"
#include "digi_utils.h"
#include "display.h"
#include "utils.h"
extern Configuration Config;
extern WiFiClient espClient;
extern uint32_t lastScreenOn;
extern String firstLine;
extern String secondLine;
extern String thirdLine;
extern String fourthLine;
extern String fifthLine;
extern String sixthLine;
extern String seventhLine;
extern Configuration Config;
extern WiFiClient espClient;
extern uint32_t lastScreenOn;
extern String firstLine;
extern String secondLine;
extern String thirdLine;
extern String fourthLine;
extern String fifthLine;
extern String sixthLine;
extern String seventhLine;
extern std::vector<String> outputPacketBuffer;
namespace APRS_IS_Utils {
@ -89,7 +91,7 @@ namespace APRS_IS_Utils {
secondLine = "WiFi: " + wifiState + " APRS-IS: " + aprsisState;
}
String createPacket(String packet) {
String buildPacketToUpload(String packet) {
if (!(Config.aprs_is.active && Config.digi.mode == 0)) { // Check if NOT only IGate
return packet.substring(3, packet.indexOf(":")) + ",qAR," + Config.callsign + packet.substring(packet.indexOf(":"));
}
@ -98,24 +100,33 @@ namespace APRS_IS_Utils {
}
}
String buildPacketToTx(String aprsisPacket) {
String firstPart, messagePart;
aprsisPacket.trim();
firstPart = aprsisPacket.substring(0, aprsisPacket.indexOf(","));
messagePart = aprsisPacket.substring(aprsisPacket.indexOf("::") + 2);
return firstPart + ",TCPIP,WIDE1-1," + Config.callsign + "::" + messagePart;
}
bool processReceivedLoRaMessage(String sender, String packet) {
String ackMessage, receivedMessage;
if (packet.indexOf("{") > 0) { // ack?
ackMessage = "ack" + packet.substring(packet.indexOf("{") + 1);
ackMessage.trim();
delay(4000);
//Serial.println(ackMessage);
for (int i = sender.length(); i < 9; i++) {
sender += ' ';
}
if (Config.beacon.path == "") {
LoRa_Utils::sendNewPacket("APRS", Config.callsign + ">APLRG1,RFONLY::" + sender + ":" + ackMessage);
STATION_Utils::addToOutputPacketBuffer(Config.callsign + ">APLRG1,RFONLY::" + sender + ":" + ackMessage);
//LoRa_Utils::sendNewPacket(Config.callsign + ">APLRG1,RFONLY::" + sender + ":" + ackMessage);
} else {
LoRa_Utils::sendNewPacket("APRS", Config.callsign + ">APLRG1,RFONLY," + Config.beacon.path + "::" + sender + ":" + ackMessage);
STATION_Utils::addToOutputPacketBuffer(Config.callsign + ">APLRG1,RFONLY," + Config.beacon.path + "::" + sender + ":" + ackMessage);
//LoRa_Utils::sendNewPacket(Config.callsign + ">APLRG1,RFONLY," + Config.beacon.path + "::" + sender + ":" + ackMessage);
}
receivedMessage = packet.substring(packet.indexOf(":") + 1, packet.indexOf("{"));
}
else {
} else {
receivedMessage = packet.substring(packet.indexOf(":") + 1);
}
if (receivedMessage.indexOf("?") == 0) {
@ -123,7 +134,8 @@ namespace APRS_IS_Utils {
if (!Config.display.alwaysOn) {
display_toggle(true);
}
LoRa_Utils::sendNewPacket("APRS", QUERY_Utils::process(receivedMessage, sender, "LoRa"));
STATION_Utils::addToOutputPacketBuffer(QUERY_Utils::process(receivedMessage, sender, "LoRa"));
//LoRa_Utils::sendNewPacket(QUERY_Utils::process(receivedMessage, sender, "LoRa"));
lastScreenOn = millis();
show_display(firstLine, secondLine, thirdLine, fourthLine, fifthLine, "Callsign = " + sender, "TYPE --> QUERY", 0);
return true;
@ -141,7 +153,6 @@ namespace APRS_IS_Utils {
if ((packet.substring(0, 3) == "\x3c\xff\x01") && (packet.indexOf("TCPIP") == -1) && (packet.indexOf("NOGATE") == -1) && (packet.indexOf("RFONLY") == -1)) {
Sender = packet.substring(3, packet.indexOf(">"));
STATION_Utils::updateLastHeard(Sender);
//STATION_Utils::updatePacketBuffer(packet);
Utils::typeOfPacket(aprsPacket, "LoRa-APRS");
if (Sender != Config.callsign) { // avoid listening yourself by digirepeating
AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2);
@ -152,7 +163,7 @@ namespace APRS_IS_Utils {
queryMessage = processReceivedLoRaMessage(Sender, AddresseeAndMessage);
}
if (!queryMessage) {
aprsPacket = createPacket(packet);
aprsPacket = buildPacketToUpload(packet);
if (!Config.display.alwaysOn) {
display_toggle(true);
}
@ -214,7 +225,8 @@ namespace APRS_IS_Utils {
Utils::print("Received from APRS-IS : " + packet);
if (Config.aprs_is.toRF && STATION_Utils::wasHeard(Addressee)) {
LoRa_Utils::sendNewPacket("APRS", LoRa_Utils::generatePacket(packet));
STATION_Utils::addToOutputPacketBuffer(buildPacketToTx(packet));
//LoRa_Utils::sendNewPacket(buildPacketToTx(packet));
display_toggle(true);
lastScreenOn = millis();
Utils::typeOfPacket(packet, "APRS-LoRa");

View file

@ -9,7 +9,8 @@ namespace APRS_IS_Utils {
void upload(String line);
void connect();
void checkStatus();
String createPacket(String unprocessedPacket);
String buildPacketToUpload(String unprocessedPacket);
String buildPacketToTx(String aprsisPacket);
bool processReceivedLoRaMessage(String sender, String packet);
void processLoRaPacket(String packet);
void processAPRSISPacket(String packet);

View file

@ -3,7 +3,7 @@
#include "station_utils.h"
#include "aprs_is_utils.h"
#include "query_utils.h"
#include "lora_utils.h"
//#include "lora_utils.h"
#include "digi_utils.h"
#include "wifi_utils.h"
#include "gps_utils.h"
@ -21,6 +21,8 @@ extern String fifthLine;
extern String sixthLine;
extern String seventhLine;
extern std::vector<String> outputPacketBuffer;
namespace DIGI_Utils {
@ -56,7 +58,7 @@ namespace DIGI_Utils {
}
}
void processPacket(String packet) {
void processLoRaPacket(String packet) {
bool queryMessage = false;
String loraPacket, Sender, AddresseeAndMessage, Addressee;
if (packet != "") {
@ -64,7 +66,6 @@ namespace DIGI_Utils {
Sender = packet.substring(3, packet.indexOf(">"));
if (Sender != Config.callsign) {
STATION_Utils::updateLastHeard(Sender);
// STATION_Utils::updatePacketBuffer(packet);
Utils::typeOfPacket(packet.substring(3), "Digi");
AddresseeAndMessage = packet.substring(packet.indexOf("::") + 2);
Addressee = AddresseeAndMessage.substring(0, AddresseeAndMessage.indexOf(":"));
@ -75,8 +76,9 @@ namespace DIGI_Utils {
if (!queryMessage && packet.indexOf("WIDE1-") > 10 && Config.digi.mode == 2) { // If should repeat packet (WIDE1 Digi)
loraPacket = generateDigiRepeatedPacket(packet.substring(3), Config.callsign);
if (loraPacket != "") {
delay(500);
LoRa_Utils::sendNewPacket("APRS", loraPacket);
STATION_Utils::addToOutputPacketBuffer(loraPacket);
//delay(500);
//LoRa_Utils::sendNewPacket(loraPacket);
display_toggle(true);
lastScreenOn = millis();
}
@ -86,8 +88,4 @@ namespace DIGI_Utils {
}
}
void loop(String packet) {
processPacket(packet);
}
}

View file

@ -7,8 +7,7 @@
namespace DIGI_Utils {
String generateDigiRepeatedPacket(String packet, String callsign);
void processPacket(String packet);
void loop(String packet);
void processLoRaPacket(String packet);
}

View file

@ -92,7 +92,7 @@ namespace LoRa_Utils {
radio.setFrequency(freq);
}
void sendNewPacket(const String& typeOfMessage, const String& newPacket) {
void sendNewPacket(const String& newPacket) {
if (!Config.loramodule.txActive) return;
if (Config.loramodule.txFreq != Config.loramodule.rxFreq) {
@ -127,14 +127,6 @@ namespace LoRa_Utils {
//ignorePacket = true;
}
String generatePacket(String aprsisPacket) {
String firstPart, messagePart;
aprsisPacket.trim();
firstPart = aprsisPacket.substring(0, aprsisPacket.indexOf(","));
messagePart = aprsisPacket.substring(aprsisPacket.indexOf("::") + 2);
return firstPart + ",TCPIP,WIDE1-1," + Config.callsign + "::" + messagePart;
}
String packetSanitization(String packet) {
if (packet.indexOf("\0") > 0) {
packet.replace("\0", "");

View file

@ -7,8 +7,7 @@
namespace LoRa_Utils {
void setup();
void sendNewPacket(const String &typeOfMessage, const String &newPacket);
String generatePacket(String aprsisPacket);
void sendNewPacket(const String &newPacket);
String packetSanitization(String packet);
String receivePacket();
void changeFreqTx();

View file

@ -1,14 +1,15 @@
#include "station_utils.h"
#include "aprs_is_utils.h"
#include "configuration.h"
#include "lora_utils.h"
#include "utils.h"
#include <vector>
extern Configuration Config;
extern std::vector<String> lastHeardStation;
extern std::vector<String> lastHeardStation_temp;
extern std::vector<String> packetBuffer;
extern std::vector<String> packetBuffer_temp;
extern std::vector<String> outputPacketBuffer;
extern uint32_t lastTxTime;
extern String fourthLine;
@ -47,13 +48,6 @@ namespace STATION_Utils {
fourthLine += " ";
}
fourthLine += String(lastHeardStation.size());
// DEBUG ONLY
// Serial.print("Stations Near (last " + String(Config.rememberStationTime) + " minutes): ");
// for (int k=0; k<lastHeardStation.size(); k++) {
// Serial.print(lastHeardStation[k].substring(0,lastHeardStation[k].indexOf(","))); Serial.print(" ");
// }
// Serial.println("");
}
bool wasHeard(String station) {
@ -68,37 +62,19 @@ namespace STATION_Utils {
return false;
}
void checkBuffer() {
for (int i = 0; i < packetBuffer.size(); i++) {
String deltaTimeString = packetBuffer[i].substring(0, packetBuffer[i].indexOf(","));
uint32_t deltaTime = deltaTimeString.toInt();
if ((millis() - deltaTime) < 60 * 1000) { // cambiar a 15 segundos?
packetBuffer_temp.push_back(packetBuffer[i]);
}
void processOutputPacketBuffer() {
uint32_t lastTx = millis() - lastTxTime;
if (outputPacketBuffer.size() == 0 || lastTx < 5 * 1000) { // 5 segs between packet tx ???
return;
} else {
LoRa_Utils::sendNewPacket(outputPacketBuffer[0]);
outputPacketBuffer.erase(outputPacketBuffer.begin());
lastTxTime = millis();
}
packetBuffer.clear();
for (int j = 0; j < packetBuffer_temp.size(); j++) {
packetBuffer.push_back(packetBuffer_temp[j]);
}
packetBuffer_temp.clear();
// DEBUG ONLY
// for (int i=0; i<packetBuffer.size(); i++) {
// Serial.println(packetBuffer[i]);
// }
}
void updatePacketBuffer(String packet) {
if ((packet.indexOf(":!") == -1) && (packet.indexOf(":=") == -1) && (packet.indexOf(":>") == -1) && (packet.indexOf(":`") == -1)) {
String sender = packet.substring(3, packet.indexOf(">"));
String tempAddressee = packet.substring(packet.indexOf("::") + 2);
String addressee = tempAddressee.substring(0, tempAddressee.indexOf(":"));
addressee.trim();
String message = tempAddressee.substring(tempAddressee.indexOf(":") + 1);
//Serial.println(String(millis()) + "," + sender + "," + addressee + "," + message);
packetBuffer.push_back(String(millis()) + "," + sender + "," + addressee + "," + message);
checkBuffer();
}
void addToOutputPacketBuffer(String packet) {
outputPacketBuffer.push_back(packet);
}
}

View file

@ -9,8 +9,8 @@ namespace STATION_Utils {
void deleteNotHeard();
void updateLastHeard(String station);
bool wasHeard(String station);
void checkBuffer();
void updatePacketBuffer(String packet);
void processOutputPacketBuffer();
void addToOutputPacketBuffer(String packet);
}

View file

@ -1,11 +1,13 @@
#include <WiFi.h>
#include "kiss_utils.h"
#include "kiss_protocol.h"
#include "lora_utils.h"
//#include "lora_utils.h"
#include "configuration.h"
#include "station_utils.h"
#include "utils.h"
extern Configuration Config;
extern std::vector<String> outputPacketBuffer;
#define MAX_CLIENTS 4
#define INPUT_BUFFER_SIZE (2 + MAX_CLIENTS)
@ -74,7 +76,8 @@ namespace TNC_Utils {
String sender = frame.substring(0,frame.indexOf(">"));
if (Config.tnc.acceptOwn || sender != Config.callsign) {
LoRa_Utils::sendNewPacket("APRS", frame);
STATION_Utils::addToOutputPacketBuffer(frame);
//LoRa_Utils::sendNewPacket(frame);
} else {
Utils::println("Ignored own frame from KISS");
}

View file

@ -53,7 +53,7 @@ namespace Utils {
if (statusAfterBoot && !Config.beacon.sendViaAPRSIS && Config.beacon.sendViaRF) {
delay(2000);
status += ":>https://github.com/richonguzman/LoRa_APRS_iGate " + versionDate;
LoRa_Utils::sendNewPacket("APRS", status);
LoRa_Utils::sendNewPacket(status);
statusAfterBoot = false;
}
}
@ -141,7 +141,7 @@ namespace Utils {
seventhLine = " listening...";
LoRa_Utils::sendNewPacket("APRS", secondaryBeaconPacket);
LoRa_Utils::sendNewPacket(secondaryBeaconPacket);
}
lastBeaconTx = millis();