Skip to content

Commit

Permalink
Digirepeater Mode Added
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed Nov 8, 2023
1 parent 0c4d748 commit 82862b1
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 149 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ ____________________________________________________
____________________________________________________
## Timeline (Versions):

- 2023.11.07 DigiRepeater Mode added in Emergency Menu.
- 2023.10.23 COMPLETE New Menu for Keyboard add-on.
- 2023.10.22 Added Keyboard Support over I2C (CARDKB from https://m5stack.com)
- 2023.10.07 Screen Brightness control added.
Expand Down
121 changes: 52 additions & 69 deletions lib/APRSPacketLib/APRSPacketLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,23 @@ namespace APRSPacketLib {
packet.path.replace("WIDE1-" + hop , callsign + "*,WIDE1-" + String(hop.toInt()-1));
}
String repeatedPacket = packet.sender + ">" + packet.tocall + "," + packet.path;
if (packet.type == "gps") {
repeatedPacket += ":!";
} else if (packet.type == "status") {
repeatedPacket += ":>";
} else if (packet.type == "telemetry") {
repeatedPacket += ":T#";
} else if (packet.type == "message") {
for(int i = packet.addressee.length(); i < 9; i++) {
packet.addressee += ' ';
}
repeatedPacket += "::" + packet.addressee + ":";
}
switch (packet.type) {
case 0: // gps
repeatedPacket += ":!";
break;
case 1: // message
for(int i = packet.addressee.length(); i < 9; i++) {
packet.addressee += ' ';
}
repeatedPacket += "::" + packet.addressee + ":";
break;
case 2: // status
repeatedPacket += ":>";
break;
case 3: // telemetry
repeatedPacket += ":T#";
break;
}
return repeatedPacket + packet.message;
} else {
return "X";
Expand Down Expand Up @@ -121,34 +126,23 @@ namespace APRSPacketLib {
return packet;
}

float decodeEncodedLatitude(String receivedPacket) {
String packet = receivedPacket.substring(receivedPacket.indexOf(":!")+3);
String encodedLatitude = packet.substring(0,4);
float decodeEncodedLatitude(String encodedLatitude) {
int Y1 = int(encodedLatitude[0]);
int Y2 = int(encodedLatitude[1]);
int Y3 = int(encodedLatitude[2]);
int Y4 = int(encodedLatitude[3]);
return (90.0 - ((((Y1-33) * pow(91,3)) + ((Y2-33) * pow(91,2)) + ((Y3-33) * 91) + Y4-33) / 380926.0));
}

float decodeEncodedLongitude(String receivedPacket) {
String packet = receivedPacket.substring(receivedPacket.indexOf(":!")+3);
String encodedLongtitude = packet.substring(4,8);
int X1 = int(encodedLongtitude[0]);
int X2 = int(encodedLongtitude[1]);
int X3 = int(encodedLongtitude[2]);
int X4 = int(encodedLongtitude[3]);
float decodeEncodedLongitude(String encodedLongitude) {
int X1 = int(encodedLongitude[0]);
int X2 = int(encodedLongitude[1]);
int X3 = int(encodedLongitude[2]);
int X4 = int(encodedLongitude[3]);
return (-180.0 + ((((X1-33) * pow(91,3)) + ((X2-33) * pow(91,2)) + ((X3-33) * 91) + X4-33) / 190463.0));
}

float decodeLatitude(String receivedPacket) {
String gpsData;
if (receivedPacket.indexOf(":!") > 10) {
gpsData = receivedPacket.substring(receivedPacket.indexOf(":!")+2);
} else if (receivedPacket.indexOf(":=") > 10) {
gpsData = receivedPacket.substring(receivedPacket.indexOf(":=")+2);
}
String Latitude = gpsData.substring(0,8);
float decodeLatitude(String Latitude) {
String firstLatPart = Latitude.substring(0,2);
String secondLatPart = Latitude.substring(2,4);
String thirdLatPart = Latitude.substring(Latitude.indexOf(".")+1,Latitude.indexOf(".")+3);
Expand All @@ -161,14 +155,7 @@ namespace APRSPacketLib {
}
}

float decodeLongitude(String receivedPacket) {
String gpsData;
if (receivedPacket.indexOf(":!") > 10) {
gpsData = receivedPacket.substring(receivedPacket.indexOf(":!")+2);
} else if (receivedPacket.indexOf(":=") > 10) {
gpsData = receivedPacket.substring(receivedPacket.indexOf(":=")+2);
}
String Longitude = gpsData.substring(9,18);
float decodeLongitude(String Longitude) {
String firstLngPart = Longitude.substring(0,3);
String secondLngPart = Longitude.substring(3,5);
String thirdLngPart = Longitude.substring(Longitude.indexOf(".")+1,Longitude.indexOf(".")+3);
Expand All @@ -182,6 +169,11 @@ namespace APRSPacketLib {
}

APRSPacket processReceivedPacket(String receivedPacket) {
/* Packet type:
gps = 0
message = 1
status = 2
telemetry = 3 */
APRSPacket aprsPacket;
aprsPacket.sender = receivedPacket.substring(0,receivedPacket.indexOf(">"));
String temp00 = receivedPacket.substring(receivedPacket.indexOf(">")+1,receivedPacket.indexOf(":"));
Expand All @@ -192,50 +184,41 @@ namespace APRSPacketLib {
aprsPacket.tocall = temp00;
aprsPacket.path = "";
}
if (receivedPacket.indexOf("::") > 10) {
aprsPacket.type = "message";
if (receivedPacket.indexOf(":!") > 10 || receivedPacket.indexOf(":=") > 10 ) {
aprsPacket.type = 0;
aprsPacket.addressee = "";
String gpsChar = "";
if (receivedPacket.indexOf(":!") > 10) {
gpsChar = ":!";
} else {
gpsChar = ":=";
}
int encodedBytePosition = receivedPacket.indexOf(gpsChar) + 14;
aprsPacket.message = receivedPacket.substring(receivedPacket.indexOf(gpsChar)+2);
if (String(receivedPacket[encodedBytePosition]) == "G" || String(receivedPacket[encodedBytePosition]) == "Q" || String(receivedPacket[encodedBytePosition]) == "[" || String(receivedPacket[encodedBytePosition]) == "H") {
aprsPacket.latitude = decodeEncodedLatitude(receivedPacket.substring(receivedPacket.indexOf(gpsChar)+3, receivedPacket.indexOf(gpsChar)+7));
aprsPacket.longitude = decodeEncodedLongitude(receivedPacket.substring(receivedPacket.indexOf(gpsChar)+7, receivedPacket.indexOf(gpsChar)+11));
} else {
aprsPacket.latitude = decodeLatitude(receivedPacket.substring(receivedPacket.indexOf(gpsChar)+2,receivedPacket.indexOf(gpsChar)+10));
aprsPacket.longitude = decodeLongitude(receivedPacket.substring(receivedPacket.indexOf(gpsChar)+11,receivedPacket.indexOf(gpsChar)+20));
}
} else if (receivedPacket.indexOf("::") > 10) {
aprsPacket.type = 1;
String temp1 = receivedPacket.substring(receivedPacket.indexOf("::")+2);
String temp2 = temp1.substring(0,temp1.indexOf(":"));
temp2.trim();
aprsPacket.addressee = temp2;
aprsPacket.message = temp1.substring(temp1.indexOf(":")+1);
aprsPacket.latitude = 0;
aprsPacket.longitude = 0;
} else if (receivedPacket.indexOf(":!") > 10 || receivedPacket.indexOf(":=") > 10 ) {
aprsPacket.type = "gps";
aprsPacket.addressee = "";
int encodedBytePosition = 0;
if (receivedPacket.indexOf(":!") > 10) {
encodedBytePosition = receivedPacket.indexOf(":!") + 14;
aprsPacket.message = receivedPacket.substring(receivedPacket.indexOf(":!")+2);
}
if (receivedPacket.indexOf(":=") > 10) {
encodedBytePosition = receivedPacket.indexOf(":=") + 14;
aprsPacket.message = receivedPacket.substring(receivedPacket.indexOf(":=")+2);
}
if (encodedBytePosition != 0) {
if (String(receivedPacket[encodedBytePosition]) == "G" || String(receivedPacket[encodedBytePosition]) == "Q" || String(receivedPacket[encodedBytePosition]) == "[" || String(receivedPacket[encodedBytePosition]) == "H") {
aprsPacket.latitude = decodeEncodedLatitude(receivedPacket);
aprsPacket.longitude = decodeEncodedLongitude(receivedPacket);
} else {
aprsPacket.latitude = decodeLatitude(receivedPacket);
aprsPacket.longitude = decodeLongitude(receivedPacket);
}
//
Serial.print(aprsPacket.sender);
Serial.print(" GPS : ");
Serial.print(aprsPacket.latitude); Serial.print(" N ");
Serial.print(aprsPacket.longitude);Serial.println(" E");
//
}
} else if (receivedPacket.indexOf(":>") > 10) {
aprsPacket.type = "status";
aprsPacket.type = 2;
aprsPacket.addressee = "";
aprsPacket.message = receivedPacket.substring(receivedPacket.indexOf(":>")+2);
aprsPacket.latitude = 0;
aprsPacket.longitude = 0;
} else if (receivedPacket.indexOf(":T#") >= 10 && receivedPacket.indexOf(":=/") == -1) {
aprsPacket.type = "telemetry";
aprsPacket.type = 3;
aprsPacket.addressee = "";
aprsPacket.message = receivedPacket.substring(receivedPacket.indexOf(":T#")+3);
aprsPacket.latitude = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/APRSPacketLib/APRSPacketLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct APRSPacket {
String path;
String addressee;
String message;
String type;
int type;
float latitude;
float longitude;
};
Expand Down
3 changes: 2 additions & 1 deletion src/LoRa_APRS_Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ uint32_t keyboardTime = millis();
String messageCallsign = "";
String messageText = "";

bool digirepeaterActive = false; // defaul = false (needs to be activated in the EMERGENCY of the Tracker MENU)
bool digirepeaterActive = false;
bool sosActive = false;

logging::Logger logger;

Expand Down
26 changes: 21 additions & 5 deletions src/keyboard_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extern int messagesIterator;
extern bool messageLed;
extern String messageCallsign;
extern String messageText;
extern bool digirepeaterActive;
extern bool sosActive;

namespace KEYBOARD_Utils {

Expand Down Expand Up @@ -218,12 +220,26 @@ namespace KEYBOARD_Utils {
else if (menuDisplay == 6) {
menuDisplay = 60;
} else if (menuDisplay == 60) {
show_display("EMERGENCY_", "Digirepeater still", "on development..", 2000); /////////////////////////
if (digirepeaterActive) {
show_display("EMERGENCY_", ""," DigiRepeater"," Status --> OFF","", 2000); /////////////////////////
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "%s", "DigiRepeater OFF");
digirepeaterActive = false;
} else {
show_display("EMERGENCY_", ""," DigiRepeater"," Status --> ON","", 2000); /////////////////////////
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "%s", "DigiRepeater ON");
digirepeaterActive = true;
}
} else if (menuDisplay == 61) {
show_display("EMERGENCY_", "S.O.S. still", "on development..", 2000); /////////////////////////
}


if (sosActive) {
show_display("EMERGENCY_", ""," S.O.S."," Status --> OFF","", 2000);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "%s", "S.O.S Mode OFF");
sosActive = false;
} else {
show_display("EMERGENCY_", ""," S.O.S."," Status --> ON","", 2000);
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Main", "%s", "S.O.S Mode ON");
sosActive = true;
}
}
}

void processPressedKey(char key) {
Expand Down
30 changes: 27 additions & 3 deletions src/menu_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ extern int lowBatteryPercent;
extern bool keyDetected;
extern String messageCallsign;
extern String messageText;
extern bool digirepeaterActive;
extern bool sosActive;

String digi, sos;

namespace MENU_Utils {

Expand Down Expand Up @@ -171,12 +175,32 @@ namespace MENU_Utils {
break;

case 60: // 6. Emergency ---> Digirepeater
show_display("EMERGENCY_", "", "> Digirepeater", " S.O.S.","",lastLine);
if (digirepeaterActive) {
digi = "ON";
} else {
digi = "OFF";
}
if (sosActive) {
sos = "ON";
} else {
sos = "OFF";
}
show_display("EMERGENCY_", "", "> Digirepeater (" + digi + ")", " S.O.S. (" + sos + ")","",lastLine);
break;
case 61: // 6. Emergency ---> S.O.S.
show_display("EMERGENCY_", "", " Digirepeater", "> S.O.S.","",lastLine);
if (digirepeaterActive) {
digi = "ON";
} else {
digi = "OFF";
}
if (sosActive) {
sos = "ON";
} else {
sos = "OFF";
}
show_display("EMERGENCY_", "", " Digirepeater (" + digi + ")", "> S.O.S. (" + sos + ")","",lastLine);
break;

case 0: ///////////// MAIN MENU //////////////
String hdopState, firstRowMainMenu, secondRowMainMenu, thirdRowMainMenu, fourthRowMainMenu, fifthRowMainMenu, sixthRowMainMenu;

Expand Down
Loading

0 comments on commit 82862b1

Please sign in to comment.