LoRa_APRS_iGate/src/gps_utils.cpp

95 lines
2.8 KiB
C++
Raw Normal View History

2023-06-06 18:19:56 +02:00
#include "configuration.h"
2023-06-08 06:58:10 +02:00
#include "gps_utils.h"
2023-06-06 18:19:56 +02:00
extern Configuration Config;
extern WiFi_AP *currentWiFi;
2023-06-07 23:25:50 +02:00
extern int stationMode;
2023-06-06 18:19:56 +02:00
namespace GPS_Utils {
String double2string(double n, int ndec) {
String r = "";
int v = n;
r += v;
r += '.';
int i;
for (i=0;i<ndec;i++) {
n -= v;
n = 10 * abs(n);
v = n;
r += v;
}
return r;
}
2023-06-09 01:31:27 +02:00
String processLatitudeAPRS(double lat) {
String degrees = double2string(lat,6);
2023-06-06 18:19:56 +02:00
String north_south, latitude, convDeg3;
float convDeg, convDeg2;
if (abs(degrees.toFloat()) < 10) {
latitude += "0";
}
Serial.println(latitude);
if (degrees.indexOf("-") == 0) {
north_south = "S";
latitude += degrees.substring(1,degrees.indexOf("."));
} else {
north_south = "N";
latitude += degrees.substring(0,degrees.indexOf("."));
}
convDeg = abs(degrees.toFloat()) - abs(int(degrees.toFloat()));
convDeg2 = (convDeg * 60)/100;
convDeg3 = String(convDeg2,6);
latitude += convDeg3.substring(convDeg3.indexOf(".")+1,convDeg3.indexOf(".")+3) + "." + convDeg3.substring(convDeg3.indexOf(".")+3,convDeg3.indexOf(".")+5);
latitude += north_south;
return latitude;
}
2023-06-09 01:31:27 +02:00
String processLongitudeAPRS(double lon) {
String degrees = double2string(lon,6);
2023-06-06 18:19:56 +02:00
String east_west, longitude, convDeg3;
float convDeg, convDeg2;
if (abs(degrees.toFloat()) < 100) {
longitude += "0";
}
if (abs(degrees.toFloat()) < 10) {
longitude += "0";
}
if (degrees.indexOf("-") == 0) {
east_west = "W";
longitude += degrees.substring(1,degrees.indexOf("."));
} else {
east_west = "E";
longitude += degrees.substring(0,degrees.indexOf("."));
}
convDeg = abs(degrees.toFloat()) - abs(int(degrees.toFloat()));
convDeg2 = (convDeg * 60)/100;
convDeg3 = String(convDeg2,6);
longitude += convDeg3.substring(convDeg3.indexOf(".")+1,convDeg3.indexOf(".")+3) + "." + convDeg3.substring(convDeg3.indexOf(".")+3,convDeg3.indexOf(".")+5);
longitude += east_west;
return longitude;
}
String generateBeacon() {
2023-06-09 01:31:27 +02:00
String stationLatitude, stationLongitude, beaconPacket;
if (stationMode==1 || stationMode==2) {
stationLatitude = processLatitudeAPRS(currentWiFi->latitude);
stationLongitude = processLongitudeAPRS(currentWiFi->longitude);
beaconPacket = Config.callsign + ">APLRG1,qAC:=" + stationLatitude + "L" + stationLongitude;
if (stationMode == 1) {
beaconPacket += "&";
} else {
beaconPacket += "a";
}
2023-06-08 01:34:18 +02:00
beaconPacket += Config.iGateComment;
2023-06-09 01:31:27 +02:00
} else { //stationMode 3 y 4
stationLatitude = processLatitudeAPRS(Config.digi.latitude);
stationLongitude = processLongitudeAPRS(Config.digi.longitude);
beaconPacket = Config.callsign + ">APLRG1:=" + stationLatitude + "L" + stationLongitude + "#" + Config.digi.comment;
2023-06-06 18:19:56 +02:00
}
return beaconPacket;
}
}