Skip to content

Commit

Permalink
GPS for iGate
Browse files Browse the repository at this point in the history
  • Loading branch information
richonguzman committed Oct 14, 2024
1 parent c064198 commit 00db358
Show file tree
Hide file tree
Showing 14 changed files with 200 additions and 37 deletions.
30 changes: 30 additions & 0 deletions data_embed/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,36 @@ <h5>
</div>
</div>
</div>
<div class="col-12 mt-3">
<div class="form-check form-switch">
<input
type="checkbox"
name="beacon.gpsActive"
id="beacon.gpsActive"
class="form-check-input"
/>
<label
for="beacon.gpsActive"
class="form-label"
>Send Real GPS Beacon <small>(For Boards with GPS Modules)</small>
</label>
</div>
</div>
<div class="col-12">
<div class="form-check form-switch">
<input
type="checkbox"
name="beacon.gpsAmbiguity"
id="beacon.gpsAmbiguity"
class="form-check-input"
/>
<label
for="beacon.gpsAmbiguity"
class="form-label"
>Send Real GPS Beacon with Ambiguity
</label>
</div>
</div>
</div>
</div>
<hr />
Expand Down
3 changes: 3 additions & 0 deletions data_embed/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ function loadSettings(settings) {
document.getElementById("beacon.sendViaAPRSIS").checked = settings.beacon.sendViaAPRSIS;
document.getElementById("beacon.sendViaRF").checked = settings.beacon.sendViaRF;

document.getElementById("beacon.gpsActive").checked = settings.beacon.gpsActive;
document.getElementById("beacon.gpsAmbiguity").checked = settings.beacon.gpsAmbiguity;

// Digi
document.getElementById("digi.mode").value = settings.digi.mode;
document.getElementById("digi.ecoMode").checked = settings.digi.ecoMode;
Expand Down
8 changes: 8 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ build_flags =
-Werror -Wall
-DHELTEC_WSL_V3
-DHAS_SX1262
-DHAS_GPS
-DGPS_BAUDRATE=115200
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
Expand Down Expand Up @@ -212,6 +214,7 @@ build_flags =
-DTTGO_T_Beam_V1_2
-DHAS_SX1278
-DHAS_AXP2101
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
Expand All @@ -226,6 +229,7 @@ build_flags =
-DTTGO_T_Beam_V1_2_915
-DHAS_SX1276
-DHAS_AXP2101
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
Expand All @@ -240,6 +244,7 @@ build_flags =
-DTTGO_T_Beam_V1_0
-DHAS_SX1278
-DHAS_AXP192
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
Expand All @@ -254,6 +259,7 @@ build_flags =
-DTTGO_T_Beam_V1_0_915
-DHAS_SX1276
-DHAS_AXP192
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
Expand All @@ -268,6 +274,7 @@ build_flags =
-DTTGO_T_Beam_V1_0_SX1268
-DHAS_SX1268
-DHAS_AXP192
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
Expand All @@ -282,6 +289,7 @@ build_flags =
-DTTGO_T_Beam_V1_2_SX1262
-DHAS_SX1262
-DHAS_AXP2101
-DHAS_GPS
-DELEGANTOTA_USE_ASYNC_WEBSERVER=1
lib_deps =
${common.lib_deps}
Expand Down
27 changes: 16 additions & 11 deletions src/LoRa_APRS_iGate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
______________________________________________________________________________________________________________*/

#include <ElegantOTA.h>
#include <TinyGPS++.h>
#include <Arduino.h>
#include <WiFi.h>
#include <vector>
Expand All @@ -39,19 +40,23 @@ ________________________________________________________________________________
#include "A7670_utils.h"
#endif

String versionDate = "2024.10.14";
Configuration Config;
WiFiClient espClient;
String versionDate = "2024.10.14";
Configuration Config;
WiFiClient espClient;
#ifdef HAS_GPS
HardwareSerial gpsSerial(1);
TinyGPSPlus gps;
#endif

uint8_t myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];
uint8_t myWiFiAPIndex = 0;
int myWiFiAPSize = Config.wifiAPs.size();
WiFi_AP *currentWiFi = &Config.wifiAPs[myWiFiAPIndex];

bool isUpdatingOTA = false;
uint32_t lastBatteryCheck = 0;
bool isUpdatingOTA = false;
uint32_t lastBatteryCheck = 0;

bool backUpDigiMode = false;
bool modemLoggedToAPRSIS = false;
bool backUpDigiMode = false;
bool modemLoggedToAPRSIS = false;

std::vector<ReceivedPacket> receivedPackets;

Expand All @@ -65,7 +70,7 @@ void setup() {
Utils::setupDisplay();
LoRa_Utils::setup();
Utils::validateFreqs();
GPS_Utils::generateBeacons();
GPS_Utils::setup();

#ifdef STARTUP_DELAY // (TEST) just to wait for WiFi init of Routers
displayShow("", " STARTUP DELAY ...", "", "", 0);
Expand Down
10 changes: 10 additions & 0 deletions src/boards_pinout.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@
#define RADIO_BUSY_PIN 8
#endif

#if defined(TTGO_T_Beam_V1_2) || defined(TTGO_T_Beam_V1_2_915) || defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_0_915) || defined(TTGO_T_Beam_V1_0_SX1268) || defined(TTGO_T_Beam_V1_2_SX1262)
#define GPS_RX 12
#define GPS_TX 34
#endif

#if defined( HELTEC_WIRELESS_TRACKER)
#define GPS_RX 34
#define GPS_TX 33
#endif

/* (Same pins for LILYGO LoRa32 and ESP32 Wroom Dev )
SX1278-------------------> ESP32 ttgo-lora32-v21 and ESP32 WROOM Dev
GND GND
Expand Down
9 changes: 9 additions & 0 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void Configuration::writeFile() {
data["beacon"]["sendViaRF"] = beacon.sendViaRF;
data["beacon"]["path"] = beacon.path;

data["beacon"]["gpsActive"] = beacon.gpsActive;
data["beacon"]["gpsAmbiguity"] = beacon.gpsAmbiguity;

data["digi"]["mode"] = digi.mode;
data["digi"]["ecoMode"] = digi.ecoMode;

Expand Down Expand Up @@ -146,6 +149,9 @@ bool Configuration::readFile() {
beacon.path = data["beacon"]["path"] | "WIDE1-1";
beacon.sendViaAPRSIS = data["beacon"]["sendViaAPRSIS"] | false;
beacon.sendViaRF = data["beacon"]["sendViaRF"] | false;

beacon.gpsActive = data["beacon"]["gpsActive"] | false;
beacon.gpsAmbiguity = data["beacon"]["gpsAmbiguity"] | false;

aprs_is.active = data["aprs_is"]["active"] | false;
aprs_is.passcode = data["aprs_is"]["passcode"] | "XYZWV";
Expand Down Expand Up @@ -253,6 +259,9 @@ void Configuration::init() {
beacon.sendViaAPRSIS = true;
beacon.sendViaRF = false;
beacon.path = "WIDE1-1";

beacon.gpsActive = false;
beacon.gpsAmbiguity = false;

digi.mode = 0;
digi.ecoMode = false;
Expand Down
2 changes: 2 additions & 0 deletions src/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class BEACON {
String path;
bool sendViaRF;
bool sendViaAPRSIS;
bool gpsActive;
bool gpsAmbiguity;
};

class APRS_IS {
Expand Down
78 changes: 58 additions & 20 deletions src/gps_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#include <TinyGPS++.h>
#include <WiFi.h>
#include "configuration.h"
#include "boards_pinout.h"
#include "gps_utils.h"
#include "display.h"
#include "utils.h"

extern Configuration Config;
extern WiFiClient espClient;
String distance, iGateBeaconPacket, iGateLoRaBeaconPacket;
#ifdef GPS_BAUDRATE
#define GPS_BAUD GPS_BAUDRATE
#else
#define GPS_BAUD 9600
#endif

extern Configuration Config;
extern WiFiClient espClient;
extern HardwareSerial gpsSerial;
extern TinyGPSPlus gps;
String distance, iGateBeaconPacket, iGateLoRaBeaconPacket;


namespace GPS_Utils {
Expand All @@ -24,20 +33,32 @@ namespace GPS_Utils {
return(s);
}

float roundToTwoDecimals(float degrees) {
return round(degrees * 100) / 100;
}

String encodeGPS(float latitude, float longitude, const String& overlay, const String& symbol) {
String encodedData = overlay;
uint32_t aprs_lat, aprs_lon;
aprs_lat = 900000000 - latitude * 10000000;

float processedLatitude = latitude;
float processedLongitude = longitude;
if (Config.beacon.gpsActive && Config.beacon.gpsAmbiguity) {
processedLatitude = roundToTwoDecimals(latitude);
processedLongitude = roundToTwoDecimals(longitude);
}

aprs_lat = 900000000 - processedLatitude * 10000000;
aprs_lat = aprs_lat / 26 - aprs_lat / 2710 + aprs_lat / 15384615;
aprs_lon = 900000000 + longitude * 10000000 / 2;
aprs_lon = 900000000 + processedLongitude * 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(processedLatitude < 0) { Ns = "S"; } else { Ns = "N"; }
if(processedLatitude < 0) { processedLatitude = -processedLatitude; }

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

char helper_base91[] = {"0000\0"};
int i;
Expand All @@ -55,28 +76,30 @@ namespace GPS_Utils {
return encodedData;
}

void generateBeacons() {
if (Config.callsign.indexOf("NOCALL-10") != 0 && !Utils::checkValidCallsign(Config.callsign)) {
displayShow("***** ERROR ******", "CALLSIGN = NOT VALID!", "", "Only Rx Mode Active", 3000);
Config.loramodule.txActive = false;
Config.aprs_is.messagesToRF = false;
Config.aprs_is.objectsToRF = false;
Config.beacon.sendViaRF = false;
Config.digi.mode = 0;
Config.backupDigiMode = false;
}
void generateBeaconFirstPart() {
String beaconPacket = Config.callsign;
beaconPacket += ">APLRG1";
if (Config.beacon.path.indexOf("WIDE") == 0) {
beaconPacket += ",";
beaconPacket += Config.beacon.path;
}

iGateBeaconPacket = beaconPacket;
iGateBeaconPacket += ",qAC:!";
iGateLoRaBeaconPacket = beaconPacket;
iGateLoRaBeaconPacket += ":!";
}

void generateBeacons() {
if (Config.callsign.indexOf("NOCALL-10") != 0 && !Utils::checkValidCallsign(Config.callsign)) {
displayShow("***** ERROR ******", "CALLSIGN = NOT VALID!", "", "Only Rx Mode Active", 3000);
Config.loramodule.txActive = false;
Config.aprs_is.messagesToRF = false;
Config.aprs_is.objectsToRF = false;
Config.beacon.sendViaRF = false;
Config.digi.mode = 0;
Config.backupDigiMode = false;
}
generateBeaconFirstPart();
String encodedGPS = encodeGPS(Config.beacon.latitude, Config.beacon.longitude, Config.beacon.overlay, Config.beacon.symbol);
iGateBeaconPacket += encodedGPS;
iGateLoRaBeaconPacket += encodedGPS;
Expand Down Expand Up @@ -184,4 +207,19 @@ namespace GPS_Utils {
}
}

void setup() {
#ifdef HAS_GPS
if (Config.beacon.gpsActive) {
gpsSerial.begin(GPS_BAUD, SERIAL_8N1, GPS_TX, GPS_RX);
}
#endif
generateBeacons();
}

void getData() {
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
}
}

}
7 changes: 5 additions & 2 deletions src/gps_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@


namespace GPS_Utils {

String getiGateLoRaBeaconPacket();
char *ax25_base91enc(char *s, uint8_t n, uint32_t v);
String encodeGPS(float latitude, float longitude, const String& overlay, const String& symbol);
void generateBeaconFirstPart();
void generateBeacons();
//double calculateDistanceCourse(double latitude, double longitude);
String decodeEncodedGPS(const String& packet);
String getReceivedGPS(const String& packet);
String getDistanceAndComment(const String& packet);

void setup();
void getData();

}

#endif
5 changes: 3 additions & 2 deletions src/ntp_utils.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <WiFi.h>
#include "configuration.h"
#include "ntp_utils.h"
#include "time.h"
Expand All @@ -14,15 +15,15 @@ NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 15 * 60 * 1000); // Update in
namespace NTP_Utils {

void setup() {
if (!Config.digi.ecoMode && Config.callsign != "NOCALL-10") {
if (WiFi.status() == WL_CONNECTED && !Config.digi.ecoMode && Config.callsign != "NOCALL-10") {
int gmt = Config.ntp.gmtCorrection * 3600;
timeClient.setTimeOffset(gmt);
timeClient.begin();
}
}

void update() {
if (!Config.digi.ecoMode && Config.callsign != "NOCALL-10") timeClient.update();
if (WiFi.status() == WL_CONNECTED && !Config.digi.ecoMode && Config.callsign != "NOCALL-10") timeClient.update();
}

String getFormatedTime() {
Expand Down
Loading

0 comments on commit 00db358

Please sign in to comment.