#include #include "configuration.h" #include "gps_utils.h" extern Configuration Config; extern WiFi_AP *currentWiFi; extern int stationMode; namespace GPS_Utils { String double2string(double n, int ndec) { String r = ""; int v = n; r += v; r += '.'; int i; for (i=0;ilatitude); stationLongitude = processLongitudeAPRS(currentWiFi->longitude); beaconPacket = Config.callsign + ">APLRG1,qAC:=" + stationLatitude + "L" + stationLongitude; if (stationMode == 1) { beaconPacket += "&"; } else { beaconPacket += "a"; } beaconPacket += Config.iGateComment; } 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; } return beaconPacket; } double calculateDistanceTo(double latitude, double longitude) { return TinyGPSPlus::distanceBetween(currentWiFi->latitude,currentWiFi->longitude, latitude, longitude) / 1000.0; } String decodeEncodedGPS(String packet) { String GPSPacket = packet.substring(packet.indexOf(":!/")+3); String encodedLatitude = GPSPacket.substring(0,4); String encodedLongtitude = GPSPacket.substring(4,8); int Y1 = int(encodedLatitude[0]); int Y2 = int(encodedLatitude[1]); int Y3 = int(encodedLatitude[2]); int Y4 = int(encodedLatitude[3]); float decodedLatitude = 90.0 - ((((Y1-33) * pow(91,3)) + ((Y2-33) * pow(91,2)) + ((Y3-33) * 91) + Y4-33) / 380926.0); int X1 = int(encodedLongtitude[0]); int X2 = int(encodedLongtitude[1]); int X3 = int(encodedLongtitude[2]); int X4 = int(encodedLongtitude[3]); float decodedLongitude = -180.0 + ((((X1-33) * pow(91,3)) + ((X2-33) * pow(91,2)) + ((X3-33) * 91) + X4-33) / 190463.0); return String(decodedLatitude) + "N / " + String(decodedLongitude) + "E / " + String(calculateDistanceTo(decodedLatitude, decodedLongitude)) + "km"; } String getReceivedGPS(String packet) { String infoGPS; if (packet.indexOf(":!") > 10) { infoGPS = packet.substring(packet.indexOf(":!")+2); } else if (packet.indexOf(":=") > 10) { infoGPS = packet.substring(packet.indexOf(":=")+2); } String Latitude = infoGPS.substring(0,8); String Longitude = infoGPS.substring(9,18); float convertedLatitude, convertedLongitude; String firstLatPart = Latitude.substring(0,2); String secondLatPart = Latitude.substring(2,4); String thirdLatPart = Latitude.substring(Latitude.indexOf(".")+1,Latitude.indexOf(".")+3); String firstLngPart = Longitude.substring(0,3); String secondLngPart = Longitude.substring(3,5); String thirdLngPart = Longitude.substring(Longitude.indexOf(".")+1,Longitude.indexOf(".")+3); convertedLatitude = firstLatPart.toFloat() + (secondLatPart.toFloat()/60) + (thirdLatPart.toFloat()/(60*100)); convertedLongitude = firstLngPart.toFloat() + (secondLngPart.toFloat()/60) + (thirdLngPart.toFloat()/(60*100)); String LatSign = String(Latitude[7]); String LngSign = String(Longitude[8]); if (LatSign == "S") { convertedLatitude = -convertedLatitude; } if (LngSign == "W") { convertedLongitude = -convertedLongitude; } return String(convertedLatitude) + "N / " + String(convertedLongitude) + "E / " + String(calculateDistanceTo(convertedLatitude, convertedLongitude)) + "km"; } String getDistance(String packet) { if (packet.indexOf(":!/") > 10) { return decodeEncodedGPS(packet); } else if (packet.indexOf(":=") > 10 || packet.indexOf(":!") > 10) { return getReceivedGPS(packet); } else { return " _ / _ / _ "; } } }