Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman authored Mar 23, 2024
1 parent cb7e9f3 commit ed9d80f
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions src/lora_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ namespace LoRa_Utils {
#ifdef HAS_SX126X
int state = radio.transmit("\x3c\xff\x01" + newPacket);
if (state == RADIOLIB_ERR_NONE) {
if (Config.syslog.active && WiFi.status() == WL_CONNECTED) {
SYSLOG_Utils::log("Tx", newPacket, 0, 0, 0);
}
Utils::print("---> LoRa Packet Tx : ");
Utils::println(newPacket);
//Serial.println(F("success!"));
}
else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Expand All @@ -152,11 +157,6 @@ namespace LoRa_Utils {
#ifdef HAS_INTERNAL_LED
digitalWrite(internalLedPin, LOW);
#endif
SYSLOG_Utils::log("Tx", newPacket, 0, 0, 0);

Utils::print("---> LoRa Packet Tx : ");
Utils::println(newPacket);

if (Config.loramodule.txFreq != Config.loramodule.rxFreq) {
changeFreqRx();
}
Expand Down Expand Up @@ -195,6 +195,19 @@ namespace LoRa_Utils {
rssi = LoRa.packetRssi();
snr = LoRa.packetSnr();
freqError = LoRa.packetFrequencyError();
if ((loraPacket.indexOf("\0") != -1) || (loraPacket.indexOf("\r") != -1) || (loraPacket.indexOf("\n") != -1)) {
loraPacket = packetSanitization(loraPacket);
}

if (loraPacket != "") {
Utils::println("<--- LoRa Packet Rx : " + loraPacket);
Utils::println("(RSSI:" + String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")");
if (Config.syslog.active && WiFi.status() == WL_CONNECTED && loraPacket != "") {
SYSLOG_Utils::log("Rx", loraPacket, rssi, snr, freqError);
}
return loraPacket;
}
return loraPacket;
}
#endif
#ifdef HAS_SX126X
Expand All @@ -203,36 +216,34 @@ namespace LoRa_Utils {
radio.startReceive();
int state = radio.readData(loraPacket);
if (state == RADIOLIB_ERR_NONE) {
rssi = radio.getRSSI();
snr = radio.getSNR();
freqError = radio.getFrequencyError();
if (loraPacket != "") {
rssi = radio.getRSSI();
snr = radio.getSNR();
freqError = radio.getFrequencyError();
Utils::println("<--- LoRa Packet Rx : " + loraPacket);
Utils::println("(RSSI:" + String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")");
if (Config.syslog.active && WiFi.status() == WL_CONNECTED && loraPacket != "") {
SYSLOG_Utils::log("Rx", loraPacket, rssi, snr, freqError);
}
return loraPacket;
}
}
else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
}
else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
Serial.println(F("CRC error!"));
if (Config.syslog.active && WiFi.status() == WL_CONNECTED) {
SYSLOG_Utils::log("Rx", "RADIOLIB_ERR_CRC_MISMATCH", 0,0,0);
}
}
else {
Serial.print(F("failed, code "));
Serial.println(state);
}
}
#endif

if ((loraPacket.indexOf("\0") != -1) || (loraPacket.indexOf("\r") != -1) || (loraPacket.indexOf("\n") != -1)) {
loraPacket = packetSanitization(loraPacket);
}

if (loraPacket != "") {
Utils::println("<--- LoRa Packet Rx : " + loraPacket);
Utils::println("(RSSI:" + String(rssi) + " / SNR:" + String(snr) + " / FreqErr:" + String(freqError) + ")");
}

if (Config.syslog.active && WiFi.status() == WL_CONNECTED && loraPacket != "") {
SYSLOG_Utils::log("Rx", loraPacket, rssi, snr, freqError);
}
return loraPacket;
#endif
}

}

0 comments on commit ed9d80f

Please sign in to comment.