Skip to content

Commit

Permalink
new Compressed GPS data instead of classic NMEA
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed Apr 9, 2024
1 parent 3ce5d08 commit a6ce44f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/LoRa_APRS_iGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Configuration Config;
WiFiClient espClient;

String versionDate = "2024.03.28";
String versionDate = "2024.04.09";
uint8_t myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
Expand Down
106 changes: 33 additions & 73 deletions src/gps_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,94 +10,54 @@ String distance;

namespace GPS_Utils {

String double2string(double n, int ndec) {
String r = "";
if (n>-1 && n<0) {
r = "-";
}
int v = n;
r += v;
r += '.';
for (int i = 0; i < ndec; i++) {
n -= v;
n = 10 * abs(n);
v = n;
r += v;
char *ax25_base91enc(char *s, uint8_t n, uint32_t v) {
for(s += n, *s = '\0'; n; n--) {
*(--s) = v % 91 + 33;
v /= 91;
}
return r;
return(s);
}

String processLatitudeAPRS(double lat) {
String degrees = double2string(lat,6);
String north_south, latitude, convDeg3;
float convDeg, convDeg2;

if (abs(degrees.toFloat()) < 10) {
latitude += "0";
String encodeGPS(float latitude, float longitude, String overlay, String symbol) {
String encodedData = overlay;
uint32_t aprs_lat, aprs_lon;
aprs_lat = 900000000 - latitude * 10000000;
aprs_lat = aprs_lat / 26 - aprs_lat / 2710 + aprs_lat / 15384615;
aprs_lon = 900000000 + longitude * 10000000 / 2;
aprs_lon = aprs_lon / 26 - aprs_lon / 2710 + aprs_lon / 15384615;

String Ns, Ew, helper;
if(latitude < 0) { Ns = "S"; } else { Ns = "N"; }
if(latitude < 0) { latitude= -latitude; }

if(longitude < 0) { Ew = "W"; } else { Ew = "E"; }
if(longitude < 0) { longitude= -longitude; }

char helper_base91[] = {"0000\0"};
int i;
ax25_base91enc(helper_base91, 4, aprs_lat);
for (i = 0; i < 4; i++) {
encodedData += helper_base91[i];
}
if (degrees.indexOf("-") == 0) {
north_south = "S";
latitude += degrees.substring(1,degrees.indexOf("."));
} else {
north_south = "N";
latitude += degrees.substring(0,degrees.indexOf("."));
ax25_base91enc(helper_base91, 4, aprs_lon);
for (i = 0; i < 4; i++) {
encodedData += helper_base91[i];
}
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;
}

String processLongitudeAPRS(double lon) {
String degrees = double2string(lon,6);
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;
encodedData += symbol + " x" + "\x47";
return encodedData;
}

String generateBeacon() {
String stationLatitude = processLatitudeAPRS(Config.beacon.latitude);
String stationLongitude = processLongitudeAPRS(Config.beacon.longitude);

String beaconPacket = Config.callsign + ">APLRG1," + Config.beacon.path;

if (Config.aprs_is.active && Config.digi.mode == 0) { // If APRSIS enabled and Digi disabled
beaconPacket += ",qAC";
} else {}

beaconPacket += ":=" + stationLatitude + Config.beacon.overlay + stationLongitude + Config.beacon.symbol;

return beaconPacket;
}
return beaconPacket + ":!" + encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);;
}

String generateiGateLoRaBeacon() {
String stationLatitude = processLatitudeAPRS(Config.beacon.latitude);
String stationLongitude = processLongitudeAPRS(Config.beacon.longitude);

String beaconPacket = Config.callsign + ">APLRG1," + Config.beacon.path + ":=" + stationLatitude + Config.beacon.overlay + stationLongitude + Config.beacon.symbol;

return beaconPacket;
return Config.callsign + ">APLRG1," + Config.beacon.path + ":!" + encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);
}

double calculateDistanceTo(double latitude, double longitude) {
Expand Down
5 changes: 2 additions & 3 deletions src/gps_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@

namespace GPS_Utils {

String double2string(double n, int ndec);
String processLatitudeAPRS();
String processLongitudeAPRS();
char *ax25_base91enc(char *s, uint8_t n, uint32_t v);
String encodeGPS(float latitude, float longitude, String overlay, String symbol);
String generateBeacon();
String generateiGateLoRaBeacon();
double calculateDistanceCourse(double latitude, double longitude);
Expand Down

0 comments on commit a6ce44f

Please sign in to comment.