- remove NtripReconnect from Autopilot and CaptureRoute

- shiftet moveControl States in the class namespace
- added auto reconeect to NtripClient
- a lot of refactor
This commit is contained in:
2023-05-30 23:40:05 +02:00
parent 98b65c4aec
commit 22eb6788c3
18 changed files with 369 additions and 280 deletions
+55 -31
View File
@@ -29,27 +29,14 @@ NTRIPClient::~NTRIPClient() {
}
void NTRIPClient::loop() {
this->pushGPGGA();
if (millis() - this->lastLoopTime < this->delayTime)
return;
this->lastLoopTime = millis();
if (millis() - this->lastGPGGAPushTime > this->pushGPGGATime && this->activated) {
this->lastGPGGAPushTime = millis();
// std::cout << "Try to push GPGGA data." << std::endl;
NMEA_GGA_data_t *data = new NMEA_GGA_data_t;
DebugTimes requestGpsData;
uint8_t res = this->gps->getLatestNMEAGPGGA(data);
requestGpsData.stopConsol("RequestGpsData", 5);
if (res == 2)
this->pushGPGGA(data);
delete data;
}
switch (this->state) {
case NTRIPClientStates::openConnection:
if (millis() - this->lastNtripConnectTime < this->tryReconnectTime)
break;
if (!this->activated) {
this->state = NTRIPClientStates::closeConnection;
break;
@@ -60,10 +47,9 @@ void NTRIPClient::loop() {
std::cout << "Connected to the NTRIP caster!" << std::endl;
this->state = NTRIPClientStates::pushData;
} else {
uint8_t seconds = this->tryReconnectTime / 1000;
std::cout << "Could not connect to the caster. Trying again in "
<< (int) seconds << " seconds." << std::endl;
this->lastNtripConnectTime = millis();
std::cout << "Failed!" << std::endl;
this->state = NTRIPClientStates::wait;
this->activated = false;
}
break;
@@ -81,9 +67,8 @@ void NTRIPClient::loop() {
case NTRIPClientStates::wait:
if (this->activated)
this->state = NTRIPClientStates::openConnection;
if (this->activated) {
// std::cout << "state is openConnection" << std::endl;
}
else
this->checkAutoReconnect();
break;
case NTRIPClientStates::notAvailable:
@@ -105,16 +90,27 @@ void NTRIPClient::gpsConfiguration() {
this->gps->enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_SPI, 10);
}
bool NTRIPClient::setActivated(bool b) {
bool NTRIPClient::setActivated(bool state) {
// std::cout << "NTRIPClient::setActivated: b - " << b << std::endl;
if (b && this->state != NTRIPClientStates::notAvailable)
if (state && this->state != NTRIPClientStates::notAvailable)
this->activated = true;
else if (b)
else if (state)
return false;
else
else {
this->activated = false;
this->autoReconnect = false;
}
return true;
}
void NTRIPClient::setAutoReconnect(bool state) {
if (state) {
this->reconnectAttemps = 0;
this->autoReconnect = true;
return;
}
this->autoReconnect = false;
}
bool NTRIPClient::beginClient() {
@@ -252,11 +248,39 @@ bool NTRIPClient::processConnection() {
return true;
}
void NTRIPClient::pushGPGGA(NMEA_GGA_data_t *nmeaData) {
if (this->ntripClient->connected() && this->transmitLocation)
this->ntripClient->print((const char *)nmeaData->nmea);
else
std::cout << "Failed to pushing GGA to server: " << (const char *)nmeaData->nmea << std::endl;
void NTRIPClient::checkAutoReconnect() {
if (!this->autoReconnect)
return;
if (millis() - this->lastReconnectTime < this->reconnectDelayTime)
return;
this->lastReconnectTime = millis();
if (this->reconnectAttemps >= this->maxReconnectAttemps) {
this->autoReconnect = false;
return;
}
this->activated = true;
this->reconnectAttemps++;
}
void NTRIPClient::pushGPGGA() {
if (!this->transmitLocation && !this->activated)
return;
if (millis() - this->lastGPGGAPushTime < this->pushGPGGATime)
return;
this->lastGPGGAPushTime = millis();
if (!this->ntripClient->connected())
std::cout << "Failed to pushing GGA to server: " << std::endl;
NMEA_GGA_data_t *data = new NMEA_GGA_data_t;
uint8_t res = this->gps->getLatestNMEAGPGGA(data);
if (res == 2)
this->ntripClient->print((const char *)data);
delete data;
}
bool NTRIPClient::isConnected() {