2020-12-22 00:32:11 +01:00
|
|
|
#include "GPSHandler.h"
|
2021-06-15 17:07:47 +02:00
|
|
|
#include "devicedefinitions/GPSDefinitions.h"
|
2020-12-22 00:32:11 +01:00
|
|
|
|
2021-06-16 17:19:14 +02:00
|
|
|
#include "lwgps/lwgps.h"
|
|
|
|
|
2020-12-22 00:32:11 +01:00
|
|
|
GPSHandler::GPSHandler(object_id_t objectId, object_id_t deviceCommunication,
|
|
|
|
CookieIF *comCookie):
|
|
|
|
DeviceHandlerBase(objectId, deviceCommunication, comCookie) {
|
2021-06-16 17:19:14 +02:00
|
|
|
lwgps_init(&gpsData);
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GPSHandler::~GPSHandler() {}
|
|
|
|
|
|
|
|
void GPSHandler::doStartUp() {
|
2021-06-15 16:44:31 +02:00
|
|
|
if(internalState == InternalStates::NONE) {
|
|
|
|
commandExecuted = false;
|
|
|
|
internalState = InternalStates::WAIT_FIRST_MESSAGE;
|
|
|
|
}
|
2020-12-22 00:32:11 +01:00
|
|
|
|
2021-06-15 16:44:31 +02:00
|
|
|
if(internalState == InternalStates::WAIT_FIRST_MESSAGE) {
|
|
|
|
if(commandExecuted) {
|
|
|
|
internalState = InternalStates::IDLE;
|
|
|
|
setMode(MODE_ON);
|
|
|
|
commandExecuted = false;
|
|
|
|
}
|
|
|
|
}
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPSHandler::doShutDown() {
|
2021-06-15 16:44:31 +02:00
|
|
|
internalState = InternalStates::NONE;
|
|
|
|
commandExecuted = false;
|
|
|
|
setMode(MODE_OFF);
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t GPSHandler::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t GPSHandler::buildNormalDeviceCommand(DeviceCommandId_t *id) {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t GPSHandler::buildCommandFromCommand(
|
|
|
|
DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
|
|
|
size_t commandDataLen) {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t GPSHandler::scanForReply(const uint8_t *start, size_t len,
|
|
|
|
DeviceCommandId_t *foundId, size_t *foundLen) {
|
2021-06-16 17:19:14 +02:00
|
|
|
// Pass data to GPS library
|
2021-06-23 15:18:31 +02:00
|
|
|
if(len > 0) {
|
2021-06-24 08:50:46 +02:00
|
|
|
sif::info << "GPSHandler::scanForReply: Received " << len << " bytes" << std::endl;
|
|
|
|
if (internalState == InternalStates::WAIT_FIRST_MESSAGE) {
|
|
|
|
// TODO: Check whether data is valid by chcking whether NMEA start string is valid
|
|
|
|
commandExecuted = true;
|
|
|
|
}
|
2021-06-23 15:18:31 +02:00
|
|
|
int result = lwgps_process(&gpsData, start, len);
|
2021-06-24 08:50:46 +02:00
|
|
|
if(result != 1) {
|
2021-06-23 15:18:31 +02:00
|
|
|
sif::warning << "GPSHandler::scanForReply: Issue processing GPS data with lwgps"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2021-06-24 08:50:46 +02:00
|
|
|
else {
|
|
|
|
sif::info << "GPS Data" << std::endl;
|
|
|
|
// Print messages
|
|
|
|
printf("Valid status: %d\n", gpsData.is_valid);
|
|
|
|
printf("Latitude: %f degrees\n", gpsData.latitude);
|
|
|
|
printf("Longitude: %f degrees\n", gpsData.longitude);
|
|
|
|
printf("Altitude: %f meters\n", gpsData.altitude);
|
|
|
|
}
|
|
|
|
*foundLen = len;
|
2021-06-16 17:19:14 +02:00
|
|
|
}
|
2020-12-22 00:32:11 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2021-06-16 17:19:14 +02:00
|
|
|
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t GPSHandler::interpretDeviceReply(DeviceCommandId_t id,
|
|
|
|
const uint8_t *packet) {
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t GPSHandler::getTransitionDelayMs(Mode_t from, Mode_t to) {
|
|
|
|
return 5000;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t GPSHandler::initializeLocalDataPool(
|
2021-01-14 11:37:32 +01:00
|
|
|
localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) {
|
2020-12-22 00:32:11 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPSHandler::fillCommandAndReplyMap() {
|
2021-06-15 17:07:47 +02:00
|
|
|
// Reply length does not matter, packets should always arrive periodically
|
|
|
|
insertInReplyMap(GpsHyperion::GPS_REPLY, 4, nullptr, 0, true);
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GPSHandler::modeChanged() {
|
2021-06-15 17:07:47 +02:00
|
|
|
internalState = InternalStates::NONE;
|
2020-12-22 00:32:11 +01:00
|
|
|
}
|