eive-obsw/linux/devices/startracker/StarTrackerHandler.cpp
2022-02-11 15:09:45 +01:00

2498 lines
102 KiB
C++

#include "StarTrackerHandler.h"
#include <fsfw/globalfunctions/CRC.h>
#include <fsfw/ipc/QueueFactory.h>
#include <mission/memory/NVMParameterBase.h>
#include <fstream>
#include "OBSWConfig.h"
#include "StarTrackerJsonCommands.h"
extern "C" {
#include <thirdparty/arcsec_star_tracker/client/generated/actionreq.h>
#include <thirdparty/arcsec_star_tracker/client/generated/parameter.h>
#include <thirdparty/arcsec_star_tracker/client/generated/telemetry.h>
#include "common/misc.h"
}
using json = nlohmann::json;
StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
StrHelper* strHelper)
: DeviceHandlerBase(objectId, comIF, comCookie),
temperatureSet(this),
versionSet(this),
powerSet(this),
interfaceSet(this),
timeSet(this),
solutionSet(this),
histogramSet(this),
contrastSet(this),
checksumSet(this),
downloadCentroidSet(this),
downloadMatchedStar(this),
downloadDbImage(this),
downloadBlobPixel(this),
cameraSet(this),
limitsSet(this),
loglevelSet(this),
mountingSet(this),
imageProcessorSet(this),
centroidingSet(this),
lisaSet(this),
matchingSet(this),
trackingSet(this),
validationSet(this),
algoSet(this),
subscriptionSet(this),
logSubscriptionSet(this),
debugCameraSet(this),
strHelper(strHelper) {
if (comCookie == nullptr) {
sif::error << "StarTrackerHandler: Invalid com cookie" << std::endl;
}
if (strHelper == nullptr) {
sif::error << "StarTrackerHandler: Invalid str image loader" << std::endl;
}
eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5);
}
StarTrackerHandler::~StarTrackerHandler() {}
ReturnValue_t StarTrackerHandler::initialize() {
ReturnValue_t result = RETURN_OK;
result = DeviceHandlerBase::initialize();
if (result != RETURN_OK) {
return result;
}
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
if (manager == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "StarTrackerHandler::initialize: Invalid event manager" << std::endl;
#endif
return ObjectManagerIF::CHILD_INIT_FAILED;
;
}
result = manager->registerListener(eventQueue->getId());
if (result != RETURN_OK) {
return result;
}
result = manager->subscribeToEventRange(eventQueue->getId(),
event::getEventId(StrHelper::IMAGE_UPLOAD_FAILED),
event::getEventId(StrHelper::FPGA_UPLOAD_FAILED));
if (result != RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "StarTrackerHandler::initialize: Failed to subscribe to events from "
" str helper"
<< std::endl;
#endif
return ObjectManagerIF::CHILD_INIT_FAILED;
}
result = strHelper->setComIF(communicationInterface);
if (result != RETURN_OK) {
return ObjectManagerIF::CHILD_INIT_FAILED;
}
strHelper->setComCookie(comCookie);
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) {
ReturnValue_t result = RETURN_OK;
switch (actionId) {
case (startrackerSTOP_IMAGE_LOADER): {
strHelper->stopProcess();
return EXECUTION_FINISHED;
}
case (startrackerSET_JSON_FILE_NAME): {
if (size > MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG;
}
paramJsonFile = std::string(reinterpret_cast<const char*>(data), size);
return EXECUTION_FINISHED;
}
default:
break;
}
if (strHelperExecuting == true) {
return STR_HELPER_EXECUTING;
}
result = checkMode(actionId);
if (result != RETURN_OK) {
return result;
}
// Intercept image loader commands which do not follow the common DHB communication flow
switch (actionId) {
case (startrackerUPLOAD_IMAGE): {
result = DeviceHandlerBase::acceptExternalDeviceCommands();
if (result != RETURN_OK) {
return result;
}
if (size > MAX_PATH_SIZE + MAX_FILE_NAME) {
return FILE_PATH_TOO_LONG;
}
result = strHelper->startImageUpload(std::string(reinterpret_cast<const char*>(data), size));
if (result != RETURN_OK) {
return result;
}
strHelperExecuting = true;
return EXECUTION_FINISHED;
}
case (startrackerDOWNLOAD_IMAGE): {
result = DeviceHandlerBase::acceptExternalDeviceCommands();
if (result != RETURN_OK) {
return result;
}
if (size > MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG;
}
result =
strHelper->startImageDownload(std::string(reinterpret_cast<const char*>(data), size));
if (result != RETURN_OK) {
return result;
}
strHelperExecuting = true;
return EXECUTION_FINISHED;
}
case (startrackerWRITE): {
result = DeviceHandlerBase::acceptExternalDeviceCommands();
if (result != RETURN_OK) {
return result;
}
result = executeWriteCommand(data, size);
if (result != RETURN_OK) {
return result;
}
strHelperExecuting = true;
return EXECUTION_FINISHED;
}
case (startrackerREAD): {
result = DeviceHandlerBase::acceptExternalDeviceCommands();
if (result != RETURN_OK) {
return result;
}
result = executeReadCommand(data, size);
if (result != RETURN_OK) {
return result;
}
strHelperExecuting = true;
return EXECUTION_FINISHED;
}
case (startrackerCHANGE_DOWNLOAD_FILE): {
if (size > MAX_FILE_NAME) {
return FILENAME_TOO_LONG;
}
strHelper->setDownloadImageName(std::string(reinterpret_cast<const char*>(data), size));
return EXECUTION_FINISHED;
}
case (startrackerCHANGE_FPGA_DOWNLOAD_FILE): {
if (size > MAX_FILE_NAME) {
return FILENAME_TOO_LONG;
}
strHelper->setDownloadFpgaImage(std::string(reinterpret_cast<const char*>(data), size));
return EXECUTION_FINISHED;
}
case (startrackerSET_READ_FILENAME): {
if (size > MAX_FILE_NAME) {
return FILENAME_TOO_LONG;
}
strHelper->setDownloadImageName(std::string(reinterpret_cast<const char*>(data), size));
return EXECUTION_FINISHED;
}
case (startrackerDOWNLOAD_FPGA_IMAGE): {
result = DeviceHandlerBase::acceptExternalDeviceCommands();
if (result != RETURN_OK) {
return result;
}
if (size > MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG;
}
result = executeFpgaDownloadCommand(data, size);
if (result != RETURN_OK) {
return result;
}
strHelperExecuting = true;
return EXECUTION_FINISHED;
}
case (startrackerUPLOAD_FPGA_IMAGE): {
result = DeviceHandlerBase::acceptExternalDeviceCommands();
if (result != RETURN_OK) {
return result;
}
if (size > MAX_PATH_SIZE + MAX_FILE_NAME) {
return FILE_PATH_TOO_LONG;
}
result = strHelper->startFpgaUpload(std::string(reinterpret_cast<const char*>(data), size));
if (result != RETURN_OK) {
return result;
}
strHelperExecuting = true;
return EXECUTION_FINISHED;
}
default:
break;
}
return DeviceHandlerBase::executeAction(actionId, commandedBy, data, size);
}
void StarTrackerHandler::performOperationHook() {
EventMessage event;
for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == RETURN_OK;
result = eventQueue->receiveMessage(&event)) {
switch (event.getMessageId()) {
case EventMessage::EVENT_MESSAGE:
handleEvent(&event);
break;
default:
sif::debug << "CCSDSHandler::checkEvents: Did not subscribe to this event message"
<< std::endl;
break;
}
}
}
void StarTrackerHandler::doStartUp() {
switch (startupState) {
case StartupState::IDLE:
startupState = StartupState::CHECK_BOOT_STATE;
return;
case StartupState::BOOT_DELAY:
if (bootCountdown.hasTimedOut()) {
startupState = StartupState::LOGLEVEL;
}
return;
case StartupState::DONE:
startupState = StartupState::IDLE;
break;
default:
return;
}
setMode(_MODE_TO_ON);
}
void StarTrackerHandler::doShutDown() {
// If star tracker is shutdown also stop all running processes in the image loader task
strHelper->stopProcess();
setMode(_MODE_POWER_DOWN);
}
void StarTrackerHandler::doOffActivity() { startupState = StartupState::IDLE; }
ReturnValue_t StarTrackerHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) {
switch (internalState) {
case InternalState::TEMPERATURE_REQUEST:
*id = startrackerREQ_TEMPERATURE;
break;
default:
sif::debug << "StarTrackerHandler::buildNormalDeviceCommand: Invalid internal step"
<< std::endl;
break;
}
return buildCommandFromCommand(*id, NULL, 0);
}
ReturnValue_t StarTrackerHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) {
if (mode != _MODE_START_UP) {
return NOTHING_TO_SEND;
}
switch (startupState) {
case StartupState::CHECK_BOOT_STATE:
*id = startrackerREQ_VERSION;
startupState = StartupState::WAIT_FOR_EXECUTION;
return buildCommandFromCommand(*id, nullptr, 0);
case StartupState::BOOT:
*id = startrackerBOOT;
bootCountdown.setTimeout(BOOT_TIMEOUT);
startupState = StartupState::BOOT_DELAY;
return buildCommandFromCommand(*id, nullptr, 0);
case StartupState::LOGLEVEL:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerLOGLEVEL;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::LIMITS:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerLIMITS;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::TRACKING:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerTRACKING;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::MOUNTING:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerMOUNTING;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::IMAGE_PROCESSOR:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerIMAGE_PROCESSOR;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::CAMERA:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerCAMERA;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::CENTROIDING:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerCENTROIDING;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::LISA:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerLISA;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::MATCHING:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerMATCHING;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::VALIDATION:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerVALIDATION;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::ALGO:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerALGO;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::LOG_SUBSCRIPTION:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerLOGSUBSCRIPTION;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case StartupState::DEBUG_CAMERA:
startupState = StartupState::WAIT_FOR_EXECUTION;
*id = startrackerDEBUG_CAMERA;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
default:
break;
}
return NOTHING_TO_SEND;
}
ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
switch (deviceCommand) {
case (startrackerPING_REQUEST): {
preparePingRequest();
return RETURN_OK;
}
case (startrackerREQ_TIME): {
prepareTimeRequest();
return RETURN_OK;
}
case (startrackerBOOT): {
prepareBootCommand();
return RETURN_OK;
}
case (startrackerREQ_VERSION): {
prepareVersionRequest();
return RETURN_OK;
}
case (startrackerREQ_INTERFACE): {
prepareInterfaceRequest();
return RETURN_OK;
}
case (startrackerREQ_POWER): {
preparePowerRequest();
return RETURN_OK;
}
case (startrackerSWITCH_TO_BOOTLOADER_PROGRAM): {
prepareRebootCommand();
return RETURN_OK;
}
case (startrackerTAKE_IMAGE): {
prepareTakeImageCommand(commandData);
return RETURN_OK;
}
case (startrackerSUBSCRIPTION): {
Subscription subscription;
result = prepareParamCommand(commandData, commandDataLen, subscription);
return RETURN_OK;
}
case (startrackerREQ_SOLUTION): {
prepareSolutionRequest();
return RETURN_OK;
}
case (startrackerREQ_TEMPERATURE): {
prepareTemperatureRequest();
return RETURN_OK;
}
case (startrackerREQ_HISTOGRAM): {
prepareHistogramRequest();
return RETURN_OK;
}
case (startrackerREQ_CONTRAST): {
prepareContrastRequest();
return RETURN_OK;
}
case (startrackerRESET_ERROR): {
prepareErrorResetRequest();
return RETURN_OK;
}
case (startrackerLIMITS): {
Limits limits;
result = prepareParamCommand(commandData, commandDataLen, limits);
return result;
}
case (startrackerMOUNTING): {
Mounting mounting;
result = prepareParamCommand(commandData, commandDataLen, mounting);
return result;
}
case (startrackerIMAGE_PROCESSOR): {
ImageProcessor imageProcessor;
result = prepareParamCommand(commandData, commandDataLen, imageProcessor);
return result;
}
case (startrackerCAMERA): {
Camera camera;
result = prepareParamCommand(commandData, commandDataLen, camera);
return result;
}
case (startrackerCENTROIDING): {
Centroiding centroiding;
result = prepareParamCommand(commandData, commandDataLen, centroiding);
return result;
}
case (startrackerLISA): {
Lisa lisa;
result = prepareParamCommand(commandData, commandDataLen, lisa);
return result;
}
case (startrackerMATCHING): {
Matching matching;
result = prepareParamCommand(commandData, commandDataLen, matching);
return result;
}
case (startrackerVALIDATION): {
Validation validation;
result = prepareParamCommand(commandData, commandDataLen, validation);
return result;
}
case (startrackerALGO): {
Algo algo;
result = prepareParamCommand(commandData, commandDataLen, algo);
return result;
}
case (startrackerTRACKING): {
Tracking tracking;
result = prepareParamCommand(commandData, commandDataLen, tracking);
return result;
}
case (startrackerLOGLEVEL): {
LogLevel logLevel;
result = prepareParamCommand(commandData, commandDataLen, logLevel);
return result;
}
case (startrackerLOGSUBSCRIPTION): {
LogSubscription logSubscription;
result = prepareParamCommand(commandData, commandDataLen, logSubscription);
return result;
}
case (startrackerDEBUG_CAMERA): {
DebugCamera debugCamera;
result = prepareParamCommand(commandData, commandDataLen, debugCamera);
return result;
}
case (startrackerERASE): {
result = prepareEraseCommand(commandData, commandDataLen);
return result;
}
case (startrackerUNLOCK): {
result = prepareUnlockCommand(commandData, commandDataLen);
return result;
}
case (startrackerCHECKSUM): {
result = prepareChecksumCommand(commandData, commandDataLen);
return result;
}
case (startrackerSET_TIME): {
result = prepareSetTimeCommand(commandData, commandDataLen);
return result;
}
case (startrackerDOWNLOAD_CENTROID): {
result = prepareDownloadCentroidCommand(commandData, commandDataLen);
return result;
}
case (startrackerUPLOAD_CENTROID): {
result = prepareUploadCentroidCommand(commandData, commandDataLen);
return result;
}
case (startrackerDOWNLOAD_MATCHED_STAR): {
result = prepareDownloadMatchedStarCommand(commandData, commandDataLen);
return result;
}
case (startrackerDOWNLOAD_DBIMAGE): {
result = prepareDownloadDbImageCommand(commandData, commandDataLen);
return result;
}
case (startrackerDOWNLOAD_BLOBPIXEL): {
result = prepareDownloadBlobPixelCommand(commandData, commandDataLen);
return result;
}
case (startrackerFPGA_ACTION): {
result = prepareFpgaActionCommand(commandData, commandDataLen);
return result;
}
case (startrackerREQ_CAMERA): {
result = prepareRequestCameraParams();
return result;
}
case (startrackerREQ_LIMITS): {
result = prepareRequestLimitsParams();
return result;
}
case (startrackerREQ_LOG_LEVEL): {
result = prepareRequestLogLevelParams();
return result;
}
case (startrackerREQ_MOUNTING): {
result = prepareRequestMountingParams();
return result;
}
case (startrackerREQ_IMAGE_PROCESSOR): {
result = prepareRequestImageProcessorParams();
return result;
}
case (startrackerREQ_CENTROIDING): {
result = prepareRequestCentroidingParams();
return result;
}
case (startrackerREQ_LISA): {
result = prepareRequestLisaParams();
return result;
}
case (startrackerREQ_MATCHING): {
result = prepareRequestMatchingParams();
return result;
}
case (startrackerREQ_TRACKING): {
result = prepareRequestTrackingParams();
return result;
}
case (startrackerREQ_VALIDATION): {
result = prepareRequestValidationParams();
return result;
}
case (startrackerREQ_ALGO): {
result = prepareRequestAlgoParams();
return result;
}
case (startrackerREQ_SUBSCRIPTION): {
result = prepareRequestSubscriptionParams();
return result;
}
case (startrackerREQ_LOG_SUBSCRIPTION): {
result = prepareRequestLogSubscriptionParams();
return result;
}
case (startrackerREQ_DEBUG_CAMERA): {
result = prepareRequestDebugCameraParams();
return result;
}
default:
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
return HasReturnvaluesIF::RETURN_FAILED;
}
void StarTrackerHandler::fillCommandAndReplyMap() {
/** Reply lengths are unknown because of the slip encoding. Thus always maximum reply size
* is specified */
this->insertInCommandAndReplyMap(startrackerPING_REQUEST, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandMap(startrackerBOOT);
this->insertInCommandAndReplyMap(startrackerREQ_VERSION, 3, &versionSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_TIME, 3, &timeSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandMap(startrackerUPLOAD_IMAGE);
this->insertInCommandMap(startrackerDOWNLOAD_IMAGE);
this->insertInCommandAndReplyMap(startrackerREQ_POWER, 3, &powerSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_INTERFACE, 3, &interfaceSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
// Reboot has no reply. Star tracker reboots immediately
this->insertInCommandMap(startrackerSWITCH_TO_BOOTLOADER_PROGRAM);
this->insertInCommandAndReplyMap(startrackerSUBSCRIPTION, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_SOLUTION, 3, &solutionSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_TEMPERATURE, 3, &temperatureSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_HISTOGRAM, 3, &histogramSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_CONTRAST, 3, &contrastSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerLOGLEVEL, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerLOGSUBSCRIPTION, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerDEBUG_CAMERA, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerLIMITS, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerMOUNTING, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerIMAGE_PROCESSOR, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerCAMERA, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerCAMERA, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerCENTROIDING, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerLISA, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerMATCHING, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerTRACKING, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerVALIDATION, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerALGO, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerTAKE_IMAGE, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerRESET_ERROR, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerERASE, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerUNLOCK, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerCHECKSUM, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerSET_TIME, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerDOWNLOAD_CENTROID, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerUPLOAD_CENTROID, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerDOWNLOAD_MATCHED_STAR, 3, &downloadMatchedStar,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerDOWNLOAD_DBIMAGE, 3, &downloadDbImage,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerDOWNLOAD_BLOBPIXEL, 3, &downloadBlobPixel,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerFPGA_ACTION, 3, nullptr,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_CAMERA, 3, &cameraSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_LIMITS, 3, &limitsSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_LOG_LEVEL, 3, &loglevelSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_MOUNTING, 3, &mountingSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_IMAGE_PROCESSOR, 3, &imageProcessorSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_CENTROIDING, 3, &centroidingSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_LISA, 3, &lisaSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_MATCHING, 3, &matchingSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_TRACKING, 3, &trackingSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_VALIDATION, 3, &validationSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_ALGO, 3, &algoSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_SUBSCRIPTION, 3, &subscriptionSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_LOG_SUBSCRIPTION, 3, &logSubscriptionSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(startrackerREQ_DEBUG_CAMERA, 3, &debugCameraSet,
startrackerMAX_FRAME_SIZE * 2 + 2);
}
ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
ReturnValue_t result = RETURN_OK;
size_t bytesLeft = 0;
result = dataLinkLayer.decodeFrame(start, remainingSize, &bytesLeft);
switch (result) {
case ArcsecDatalinkLayer::DEC_IN_PROGRESS: {
remainingSize = bytesLeft;
// Need a second doSendRead pass to reaa in whole packet
return IGNORE_REPLY_DATA;
}
case RETURN_OK: {
break;
}
default:
remainingSize = bytesLeft;
return result;
}
switch (dataLinkLayer.getReplyFrameType()) {
case TMTC_ACTIONREPLY: {
*foundLen = remainingSize - bytesLeft;
result = scanForActionReply(foundId);
break;
}
case TMTC_SETPARAMREPLY: {
*foundLen = remainingSize - bytesLeft;
result = scanForSetParameterReply(foundId);
break;
}
case TMTC_PARAMREPLY: {
*foundLen = remainingSize - bytesLeft;
result = scanForGetParameterReply(foundId);
break;
}
case TMTC_TELEMETRYREPLYA:
case TMTC_TELEMETRYREPLY: {
*foundLen = remainingSize - bytesLeft;
result = scanForTmReply(foundId);
break;
}
default: {
sif::debug << "StarTrackerHandler::scanForReply: Reply has invalid type id" << std::endl;
result = RETURN_FAILED;
}
}
remainingSize = bytesLeft;
return result;
}
ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t* packet) {
ReturnValue_t result = RETURN_OK;
switch (id) {
case (startrackerREQ_TIME): {
result = handleTm(timeSet, startrackerTimeSet::SIZE);
break;
}
case (startrackerPING_REQUEST): {
result = handlePingReply();
break;
}
case (startrackerBOOT):
case (startrackerTAKE_IMAGE):
case (startrackerRESET_ERROR):
case (startrackerUNLOCK):
case (startrackerSET_TIME):
case (startrackerFPGA_ACTION): {
result = handleActionReply();
break;
}
case (startrackerDOWNLOAD_CENTROID): {
result = handleActionReplySet(downloadCentroidSet, startrackerDownloadCentroidSet::SIZE);
break;
}
case (startrackerDOWNLOAD_MATCHED_STAR): {
result = handleActionReplySet(downloadMatchedStar, startrackerDownloadMatchedStar::SIZE);
break;
}
case (startrackerDOWNLOAD_DBIMAGE): {
result = handleActionReplySet(downloadDbImage, startrackerDownloadDBImage::SIZE);
break;
}
case (startrackerDOWNLOAD_BLOBPIXEL): {
result = handleActionReplySet(downloadBlobPixel, startrackerDownloadBlobPixel::SIZE);
break;
}
case (startrackerUPLOAD_CENTROID): {
result = handleUploadCentroidReply();
break;
}
case (startrackerERASE): {
result = handleEraseReply();
break;
}
case (startrackerCHECKSUM): {
result = handleChecksumReply();
break;
}
case (startrackerREQ_VERSION): {
result = handleTm(versionSet, startrackerVersionSet::SIZE);
if (result != RETURN_OK) {
return result;
}
result = checkProgram();
if (result != RETURN_OK) {
return result;
}
break;
}
case (startrackerREQ_INTERFACE): {
result = handleTm(interfaceSet, startrackerInterfaceSet::SIZE);
break;
}
case (startrackerREQ_POWER): {
result = handleTm(powerSet, startrackerPowerSet::SIZE);
break;
}
case (startrackerREQ_SOLUTION): {
result = handleTm(solutionSet, startrackerSolutionSet::SIZE);
break;
}
case (startrackerREQ_TEMPERATURE): {
result = handleTm(temperatureSet, startrackerTemperatureSet::SIZE);
break;
}
case (startrackerREQ_HISTOGRAM): {
result = handleTm(histogramSet, startrackerHistogramSet::SIZE);
break;
}
case (startrackerREQ_CONTRAST): {
result = handleTm(contrastSet, startrackerContrastSet::SIZE);
break;
}
case (startrackerSUBSCRIPTION):
case (startrackerLOGLEVEL):
case (startrackerLOGSUBSCRIPTION):
case (startrackerDEBUG_CAMERA):
case (startrackerLIMITS):
case (startrackerMOUNTING):
case (startrackerCAMERA):
case (startrackerCENTROIDING):
case (startrackerLISA):
case (startrackerMATCHING):
case (startrackerTRACKING):
case (startrackerVALIDATION):
case (startrackerIMAGE_PROCESSOR):
case (startrackerALGO): {
result = handleSetParamReply();
break;
}
case (startrackerREQ_CAMERA): {
handleParamRequest(cameraSet, startrackerCameraSet::SIZE);
break;
}
case (startrackerREQ_LIMITS): {
handleParamRequest(limitsSet, startrackerLimitsSet::SIZE);
break;
}
case (startrackerREQ_LOG_LEVEL): {
handleParamRequest(loglevelSet, startrackerLogLevelSet::SIZE);
break;
}
case (startrackerREQ_MOUNTING): {
handleParamRequest(mountingSet, startrackerMountingSet::SIZE);
break;
}
case (startrackerREQ_IMAGE_PROCESSOR): {
handleParamRequest(imageProcessorSet, startrackerImageProcessorSet::SIZE);
break;
}
case (startrackerREQ_CENTROIDING): {
handleParamRequest(centroidingSet, startrackerCentroidingSet::SIZE);
break;
}
case (startrackerREQ_LISA): {
handleParamRequest(lisaSet, startrackerLisaSet::SIZE);
break;
}
case (startrackerREQ_MATCHING): {
handleParamRequest(matchingSet, startrackerMatchingSet::SIZE);
break;
}
case (startrackerREQ_TRACKING): {
handleParamRequest(trackingSet, startrackerTrackingSet::SIZE);
break;
}
case (startrackerREQ_VALIDATION): {
handleParamRequest(validationSet, startrackerValidationSet::SIZE);
break;
}
case (startrackerREQ_ALGO): {
handleParamRequest(algoSet, startrackerAlgoSet::SIZE);
break;
}
case (startrackerREQ_SUBSCRIPTION): {
handleParamRequest(subscriptionSet, startrackerSubscriptionSet::SIZE);
break;
}
case (startrackerREQ_LOG_SUBSCRIPTION): {
handleParamRequest(logSubscriptionSet, startrackerLogSubscriptionSet::SIZE);
break;
}
case (startrackerREQ_DEBUG_CAMERA): {
handleParamRequest(debugCameraSet, startrackerDebugCameraSet::SIZE);
break;
}
default: {
sif::debug << "StarTrackerHandler::interpretDeviceReply: Unknown device reply id:" << id
<< std::endl;
result = DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return result;
}
void StarTrackerHandler::setNormalDatapoolEntriesInvalid() {}
uint32_t StarTrackerHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 20000; }
ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(startrackerTICKS_TIME_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTIME_TIME_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startrackerRUN_TIME, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerUNIX_TIME, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startrackerTICKS_VERSION_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTIME_VERSION_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startrackerPROGRAM, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerMAJOR, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerMINOR, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerTICKS_INTERFACE_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTIME_INTERFACE_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startrackerFRAME_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCHECKSUM_ERROR_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerSET_PARAM_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerSET_PARAM_REPLY_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerPARAM_REQUEST_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerPARAM_REPLY_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerREQ_TM_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTM_REPLY_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerACTION_REQ_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerACTION_REPLY_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTICKS_POWER_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTIME_POWER_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startrackerMCU_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMCU_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerFPGA_CORE_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerFPGA_CORE_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerFPGA_18_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerFPGA_18_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerFPGA_25_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerFPGA_25_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCMV_21_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCMV_21_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCMV_PIX_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCMV_PIX_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCMV_33_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCMV_33_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCMV_RES_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCMV_RES_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTICKS_TEMPERATURE_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTIME_TEMPERATURE_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startrackerMCU_TEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCMOS_TEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerFPGA_TEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTICKS_SOLUTION_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTIME_SOLUTION_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startrackerCALI_QW, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCALI_QX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCALI_QY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCALI_QZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACK_CONFIDENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACK_QW, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACK_QX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACK_QY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACK_QZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACK_REMOVED, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSTARS_CENTROIDED, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSTARS_MATCHED_DATABASE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLISA_QW, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_QX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_QY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_QZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_PERC_CLOSE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_NR_CLOSE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerTRUST_WORTHY, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSTABLE_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerSOLUTION_STRATEGY, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerTICKS_HISTOGRAM_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTIME_HISTOGRAM_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINA0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINA1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINA2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINA3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINA4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINA5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINA6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINA7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINA8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINB0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINB1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINB2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINB3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINB4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINB5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINB6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINB7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINB8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINC0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINC1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINC2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINC3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINC4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINC5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINC6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINC7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BINC8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BIND0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BIND1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BIND2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BIND3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BIND4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BIND5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BIND6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BIND7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerHISTOGRAM_BIND8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTICKS_CONTRAST_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerTIME_CONTRAST_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINA0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINA1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINA2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINA3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINA4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINA5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINA6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINA7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINA8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINB0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINB1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINB2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINB3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINB4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINB5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINB6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINB7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINB8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BINC8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BIND0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BIND1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BIND2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BIND3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BIND4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BIND5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BIND6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BIND7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCONTRAST_BIND8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCHKSUM, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerDWL_ID, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerDWL_PIXX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerDWL_PIXY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerDWL_X_UNCORRECTED, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerDWL_Y_UNCORRECTED, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerDWL_X_CORRECTED, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerDWL_Y_CORRECTED, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerDWL_MAGNITUDE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerDWL_CXA, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerDWL_CYA, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerDWL_QUALITY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_ID, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_CAMFPX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_CAMFPY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_CAMCARTX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_CAMCARTY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_CAMCARTZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_CAMMAGNITUDE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_DBFPX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_DBFPY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_DBCARTX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_DBCARTY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_DBCARTZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_DBMAGNITUDE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHEDSTR_CATALOGID, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerBLOBPIX_ID, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerBLOBPIX_X, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerBLOBPIX_Y, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerBLOBPIX_TOT_VAL, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerBLOBPIX_IN_USE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerBLOBPIX_BRIGHT_NEIGHBOURS, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerBLOBPIX_REGION, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerCAMERA_MODE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerFOCALLENGTH, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerEXPOSURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerINTERVAL, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCAMERA_OFFSET, new PoolEntry<int16_t>({0}));
localDataPoolMap.emplace(startrackerPGAGAIN, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerADCGAIN, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_REG1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_VAL1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_REG2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_VAL2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_REG3, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_VAL3, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_REG4, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_VAL4, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_REG5, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_VAL5, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_REG6, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_VAL6, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_REG7, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_VAL7, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_REG8, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_VAL8, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCAM_FREQ_1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLIMITS_ACTION, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLIMITS_FPGA18CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLIMITS_FPGA25CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLIMITS_FPGA10CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLIMITS_MCUCURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLIMITS_CMOS21CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLIMITS_CMOSPIXCURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLIMITS_CMOS33CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLIMITS_CMOSVRESCURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLIMITS_CMOSTEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL3, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL4, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL5, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL6, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL7, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL8, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL9, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL10, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL11, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL12, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL13, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL14, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL15, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOGLEVEL16, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerMOUNTING_QW, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMOUNTING_QX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMOUNTING_QY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMOUNTING_QZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerIMAGE_PROCESSOR_MODE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerIMAGE_PROCESSOR_STORE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerIMAGE_PROCESSOR_SIGNALTHRESHOLD, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(startrackerIMAGE_PROCESSOR_DARKTHRESHOLD, new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(startrackerIMAGE_PROCESSOR_BACKGROUNDCOMPENSATION, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_ENABLE_FILTER, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_MAX_QUALITY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_DARK_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_MIN_QUALITY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_MAX_INTENSITY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_MIN_INTENSITY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_MAX_MAGNITUDE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_GAUSSIAN_CMAX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_GAUSSIAN_CMIN, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_TRANSMATRIX00, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_TRANSMATRIX01, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_TRANSMATRIX10, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerCENTROIDING_TRANSMATRIX11, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_MODE, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerLISA_PREFILTER_DIST_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_PREFILTER_ANGLE_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_FOV_WIDTH, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_FOV_HEIGHT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_FLOAT_STAR_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_CLOSE_STAR_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_RATING_WEIGHT_CLOSE_STAR_COUNT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_RATING_WEIGHT_FRACTION_CLOSE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_RATING_WEIGHT_MEAN_SUM, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_RATING_WEIGHT_DB_STAR_COUNT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerLISA_MAX_COMBINATIONS, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLISA_NR_STARS_STOP, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLISA_FRACTION_CLOSE_STOP, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHING_SQUARED_DISTANCE_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerMATCHING_SQUARED_SHIFT_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACKING_THIN_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACKING_OUTLIER_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACKING_OUTLIER_THRESHOLD_QUEST, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerTRACKING_TRACKER_CHOICE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerVALIDATION_STABLE_COUNT, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerVALIDATION_MAX_DIFFERENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerVALIDATION_MIN_TRACKER_CONFIDENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerVALIDATION_MIN_MATCHED_STARS, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerALGO_MODE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerALGO_I2T_MIN_CONFIDENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerALGO_I2T_MIN_MATCHED, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerALGO_I2L_MIN_CONFIDENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startrackerALGO_I2L_MIN_MATCHED, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM3, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM4, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM5, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM6, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM7, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM8, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM9, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM10, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM11, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM12, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM13, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM14, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM15, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerSUBSCRIPTION_TM16, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOG_SUBSCRIPTION_LEVEL1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOG_SUBSCRIPTION_MODULE1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOG_SUBSCRIPTION_LEVEL2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerLOG_SUBSCRIPTION_MODULE2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startrackerDEBUG_CAMERA_TIMING, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startrackerDEBUG_CAMERA_TEST, new PoolEntry<uint32_t>({0}));
return RETURN_OK;
}
size_t StarTrackerHandler::getNextReplyLength(DeviceCommandId_t commandId) {
return startrackerMAX_FRAME_SIZE;
}
ReturnValue_t StarTrackerHandler::doSendReadHook() {
// Prevent DHB from polling UART during commands executed by the image loader task
if (strHelperExecuting) {
return RETURN_FAILED;
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::checkMode(ActionId_t actionId) {
switch (actionId) {
case startrackerUPLOAD_IMAGE:
case startrackerDOWNLOAD_IMAGE: {
return DeviceHandlerBase::acceptExternalDeviceCommands();
default:
break;
}
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::scanForActionReply(DeviceCommandId_t* foundId) {
const uint8_t* reply = dataLinkLayer.getReply();
switch (*reply) {
case (startrackerID::PING): {
*foundId = startrackerPING_REQUEST;
break;
}
case (startrackerID::WRITE): {
*foundId = startrackerWRITE;
break;
}
case (startrackerID::BOOT): {
*foundId = startrackerBOOT;
break;
}
case (startrackerID::TAKE_IMAGE): {
*foundId = startrackerTAKE_IMAGE;
break;
}
case (startrackerID::UPLOAD_IMAGE): {
*foundId = startrackerUPLOAD_IMAGE;
break;
}
case (startrackerID::ERROR_RESET): {
*foundId = startrackerRESET_ERROR;
break;
}
case (startrackerID::ERASE): {
*foundId = startrackerERASE;
break;
}
case (startrackerID::UNLOCK): {
*foundId = startrackerUNLOCK;
break;
}
case (startrackerID::CHECKSUM): {
*foundId = startrackerCHECKSUM;
break;
}
case (startrackerID::SET_TIME): {
*foundId = startrackerSET_TIME;
break;
}
case (startrackerID::DOWNLOAD_CENTROID): {
*foundId = startrackerDOWNLOAD_CENTROID;
break;
}
case (startrackerID::UPLOAD_CENTROID): {
*foundId = startrackerUPLOAD_CENTROID;
break;
}
case (startrackerID::DOWNLOAD_MATCHED_STAR): {
*foundId = startrackerDOWNLOAD_MATCHED_STAR;
break;
}
case (startrackerID::DOWNLOAD_DBIMAGE): {
*foundId = startrackerDOWNLOAD_DBIMAGE;
break;
}
case (startrackerID::DOWNLOAD_BLOBPIXEL): {
*foundId = startrackerDOWNLOAD_BLOBPIXEL;
break;
}
case (startrackerID::FPGA_ACTION): {
*foundId = startrackerFPGA_ACTION;
break;
}
default:
sif::warning << "StarTrackerHandler::scanForActionReply: Unknown parameter reply id"
<< std::endl;
return RETURN_FAILED;
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::scanForSetParameterReply(DeviceCommandId_t* foundId) {
const uint8_t* reply = dataLinkLayer.getReply();
switch (*reply) {
case (startrackerID::SUBSCRIPTION): {
*foundId = startrackerSUBSCRIPTION;
break;
}
case (startrackerID::LIMITS): {
*foundId = startrackerLIMITS;
break;
}
case (startrackerID::MOUNTING): {
*foundId = startrackerMOUNTING;
break;
}
case (startrackerID::IMAGE_PROCESSOR): {
*foundId = startrackerIMAGE_PROCESSOR;
break;
}
case (startrackerID::CAMERA): {
*foundId = startrackerCAMERA;
break;
}
case (startrackerID::CENTROIDING): {
*foundId = startrackerCENTROIDING;
break;
}
case (startrackerID::LISA): {
*foundId = startrackerLISA;
break;
}
case (startrackerID::MATCHING): {
*foundId = startrackerMATCHING;
break;
}
case (startrackerID::TRACKING): {
*foundId = startrackerTRACKING;
break;
}
case (startrackerID::VALIDATION): {
*foundId = startrackerVALIDATION;
break;
}
case (startrackerID::ALGO): {
*foundId = startrackerALGO;
break;
}
case (startrackerID::LOG_LEVEL): {
*foundId = startrackerLOGLEVEL;
break;
}
case (startrackerID::DEBUG_CAMERA): {
*foundId = startrackerDEBUG_CAMERA;
break;
}
case (startrackerID::LOG_SUBSCRIPTION): {
*foundId = startrackerLOGSUBSCRIPTION;
break;
}
default:
sif::debug << "StarTrackerHandler::scanForParameterReply: Unknown parameter reply id"
<< std::endl;
return RETURN_FAILED;
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::scanForGetParameterReply(DeviceCommandId_t* foundId) {
const uint8_t* reply = dataLinkLayer.getReply();
switch (*reply) {
case (startrackerID::CAMERA): {
*foundId = startrackerREQ_CAMERA;
break;
}
case (startrackerID::LIMITS): {
*foundId = startrackerREQ_LIMITS;
break;
}
case (startrackerID::LOG_LEVEL): {
*foundId = startrackerREQ_LOG_LEVEL;
break;
}
case (startrackerID::MOUNTING): {
*foundId = startrackerREQ_MOUNTING;
break;
}
case (startrackerID::IMAGE_PROCESSOR): {
*foundId = startrackerREQ_IMAGE_PROCESSOR;
break;
}
case (startrackerID::CENTROIDING): {
*foundId = startrackerREQ_CENTROIDING;
break;
}
case (startrackerID::LISA): {
*foundId = startrackerREQ_LISA;
break;
}
case (startrackerID::MATCHING): {
*foundId = startrackerREQ_MATCHING;
break;
}
case (startrackerID::TRACKING): {
*foundId = startrackerREQ_TRACKING;
break;
}
case (startrackerID::VALIDATION): {
*foundId = startrackerREQ_VALIDATION;
break;
}
case (startrackerID::ALGO): {
*foundId = startrackerREQ_ALGO;
break;
}
case (startrackerID::SUBSCRIPTION): {
*foundId = startrackerREQ_SUBSCRIPTION;
break;
}
case (startrackerID::LOG_SUBSCRIPTION): {
*foundId = startrackerREQ_LOG_SUBSCRIPTION;
break;
}
case (startrackerID::DEBUG_CAMERA): {
*foundId = startrackerREQ_DEBUG_CAMERA;
break;
}
default: {
sif::warning << "tarTrackerHandler::scanForGetParameterReply: UnkNown ID" << std::endl;
return RETURN_FAILED;
break;
}
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::scanForTmReply(DeviceCommandId_t* foundId) {
const uint8_t* reply = dataLinkLayer.getReply();
switch (*reply) {
case (startrackerID::VERSION): {
*foundId = startrackerREQ_VERSION;
break;
}
case (startrackerID::INTERFACE): {
*foundId = startrackerREQ_INTERFACE;
break;
}
case (startrackerID::POWER): {
*foundId = startrackerREQ_POWER;
break;
}
case (startrackerID::TEMPERATURE): {
*foundId = startrackerREQ_TEMPERATURE;
break;
}
case (startrackerID::HISTOGRAM): {
*foundId = startrackerREQ_HISTOGRAM;
break;
}
case (startrackerID::CONTRAST): {
*foundId = startrackerREQ_CONTRAST;
break;
}
case (startrackerID::TIME): {
*foundId = startrackerREQ_TIME;
break;
}
case (startrackerID::SOLUTION): {
*foundId = startrackerREQ_SOLUTION;
break;
}
default: {
sif::debug << "StarTrackerHandler::scanForTmReply: Reply contains invalid reply id: "
<< static_cast<unsigned int>(*reply) << std::endl;
return RETURN_FAILED;
break;
}
}
return RETURN_OK;
}
void StarTrackerHandler::handleEvent(EventMessage* eventMessage) {
object_id_t objectId = eventMessage->getReporter();
switch (objectId) {
case objects::STR_HELPER: {
// All events from image loader signal either that the operation was successful or that it
// failed
strHelperExecuting = false;
break;
}
default:
sif::debug << "StarTrackerHandler::handleEvent: Did not subscribe to this event" << std::endl;
break;
}
}
ReturnValue_t StarTrackerHandler::executeWriteCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
if (commandDataLen < WriteCmd::MIN_LENGTH) {
sif::warning << "StarTrackerHandler::executeWriteCommand: Command too short" << std::endl;
return COMMAND_TOO_SHORT;
}
uint8_t region = *(commandData);
uint32_t address;
size_t size = sizeof(address);
const uint8_t* addressPtr = commandData + WriteCmd::ADDRESS_OFFSET;
result = SerializeAdapter::deSerialize(&address, addressPtr, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::executeWriteCommand: Deserialization of address failed"
<< std::endl;
return result;
}
if (commandDataLen - sizeof(address) - sizeof(region) > MAX_PATH_SIZE) {
sif::warning << "StarTrackerHandler::executeWriteCommand: Received command with invalid"
<< " path and filename" << std::endl;
return FILE_PATH_TOO_LONG;
}
const uint8_t* filePtr = commandData + WriteCmd::FILE_OFFSET;
std::string fullname = std::string(reinterpret_cast<const char*>(filePtr),
commandDataLen - sizeof(address) - sizeof(region));
result = strHelper->startFlashWrite(fullname, region, address);
if (result != RETURN_OK) {
return result;
}
return result;
}
ReturnValue_t StarTrackerHandler::executeFpgaDownloadCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
if (commandDataLen < FpgaDownloadCmd::MIN_LENGTH) {
sif::warning << "StarTrackerHandler::executeFpgaDownloadCommand: Command too short"
<< std::endl;
return COMMAND_TOO_SHORT;
}
uint32_t position;
size_t size = sizeof(position);
result =
SerializeAdapter::deSerialize(&position, &commandData, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::executeWriteCommand: Deserialization of position failed"
<< std::endl;
return result;
}
uint32_t length;
size = sizeof(length);
result =
SerializeAdapter::deSerialize(&length, &commandData, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::executeWriteCommand: Deserialization of length failed"
<< std::endl;
return result;
}
if (commandDataLen - sizeof(position) - sizeof(length) > MAX_PATH_SIZE) {
sif::warning << "StarTrackerHandler::executeFpgaDownloadCommand: Received command with "
" invalid path and filename"
<< std::endl;
return FILE_PATH_TOO_LONG;
}
std::string fullname = std::string(reinterpret_cast<const char*>(commandData),
commandDataLen - sizeof(position) - sizeof(length));
result = strHelper->startFpgaDownload(fullname, position, length);
if (result != RETURN_OK) {
return result;
}
return result;
}
ReturnValue_t StarTrackerHandler::executeReadCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
if (commandDataLen < ReadCmd::MIN_LENGTH) {
sif::warning << "StarTrackerHandler::executeReadCommand: Command too short" << std::endl;
return COMMAND_TOO_SHORT;
}
uint8_t region = *(commandData);
uint32_t address;
size_t size = sizeof(address);
const uint8_t* addressPtr = commandData + ReadCmd::ADDRESS_OFFSET;
result = SerializeAdapter::deSerialize(&address, addressPtr, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::executeReadCommand: Deserialization of address failed"
<< std::endl;
return result;
}
uint32_t length;
size = sizeof(length);
const uint8_t* lengthPtr = commandData + ReadCmd::LENGTH_OFFSET;
result = SerializeAdapter::deSerialize(&length, lengthPtr, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::executeReadCommand: Deserialization of length failed"
<< std::endl;
return result;
}
if (commandDataLen - sizeof(address) - sizeof(region) - sizeof(length) > MAX_PATH_SIZE) {
sif::warning << "StarTrackerHandler::executeReadCommand: Received command with invalid"
<< " path and filename" << std::endl;
return FILE_PATH_TOO_LONG;
}
const uint8_t* filePtr = commandData + ReadCmd::FILE_OFFSET;
std::string fullname =
std::string(reinterpret_cast<const char*>(filePtr),
commandDataLen - sizeof(address) - sizeof(region) - sizeof(length));
result = strHelper->startFlashRead(fullname, region, address, length);
if (result != RETURN_OK) {
return result;
}
return result;
}
void StarTrackerHandler::prepareBootCommand() {
uint32_t length = 0;
struct BootActionRequest bootRequest = {BOOT_REGION_ID};
arc_pack_boot_action_req(&bootRequest, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
ReturnValue_t StarTrackerHandler::prepareEraseCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
if (commandDataLen != EraseCmd::LENGTH) {
return INVALID_LENGTH;
}
uint32_t length = 0;
struct EraseActionRequest req;
req.region = *commandData;
arc_pack_erase_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
eraseCmd.rememberRegion = req.region;
return result;
}
ReturnValue_t StarTrackerHandler::prepareUnlockCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
uint32_t length = 0;
struct UnlockActionRequest req;
req.region = *commandData;
size_t size = sizeof(req.code);
const uint8_t* codePtr = commandData + UnlockCmd::CODE_OFFSET;
result = SerializeAdapter::deSerialize(&req.code, &codePtr, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
return result;
}
arc_pack_unlock_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return result;
}
ReturnValue_t StarTrackerHandler::prepareChecksumCommand(const uint8_t* commandData,
size_t commandDataLen) {
struct ChecksumActionRequest req;
ReturnValue_t result = RETURN_OK;
if (commandDataLen != ChecksumCmd::LENGTH) {
sif::warning << "StarTrackerHandler::prepareChecksumCommand: Invalid length" << std::endl;
return INVALID_LENGTH;
}
req.region = *(commandData);
size_t size = sizeof(req.address);
const uint8_t* addressPtr = commandData + ChecksumCmd::ADDRESS_OFFSET;
result =
SerializeAdapter::deSerialize(&req.address, addressPtr, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::prepareChecksumCommand: Deserialization of address "
<< "failed" << std::endl;
return result;
}
size = sizeof(req.length);
const uint8_t* lengthPtr = commandData + ChecksumCmd::LENGTH_OFFSET;
result =
SerializeAdapter::deSerialize(&req.length, lengthPtr, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::prepareChecksumCommand: Deserialization of length failed"
<< std::endl;
return result;
}
uint32_t rawCmdLength = 0;
arc_pack_checksum_action_req(&req, commandBuffer, &rawCmdLength);
dataLinkLayer.encodeFrame(commandBuffer, rawCmdLength);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
checksumCmd.rememberRegion = req.region;
checksumCmd.rememberAddress = req.address;
checksumCmd.rememberLength = req.length;
return result;
}
ReturnValue_t StarTrackerHandler::prepareSetTimeCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
struct SetTimeActionRequest req;
if (commandDataLen != SetTimeCmd::LENGTH) {
sif::warning << "StarTrackerHandler::prepareSetTimeCommand: Invalid length" << std::endl;
return INVALID_LENGTH;
}
size_t size = sizeof(req.unixTime);
result = SerializeAdapter::deSerialize(&req.unixTime, commandData, &size,
SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::prepareSetTimeCommand: Deserialization failed" << std::endl;
return result;
}
uint32_t length = 0;
arc_pack_settime_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return result;
}
ReturnValue_t StarTrackerHandler::prepareDownloadCentroidCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
struct DownloadCentroidActionRequest req;
if (commandDataLen != DownloadCentroidCmd::LENGTH) {
sif::warning << "StarTrackerHandler::prepareDownloadCentroidCommand: Invalid length"
<< std::endl;
return INVALID_LENGTH;
}
req.id = *commandData;
uint32_t length = 0;
arc_pack_downloadcentroid_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return result;
}
ReturnValue_t StarTrackerHandler::prepareUploadCentroidCommand(const uint8_t* commandData,
size_t commandDataLen) {
if (commandDataLen > MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG;
}
ReturnValue_t result = RETURN_OK;
struct UploadCentroidActionRequest req;
std::string jsonFileName =
std::string(reinterpret_cast<const char*>(commandData), commandDataLen);
NVMParameterBase j(jsonFileName);
result = j.readJsonFile();
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: " << jsonFileName
<< " does not exist" << std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::id, &req.id);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::id << " does not exist" << std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::pixx, &req.pixx);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::pixx << " does not exist" << std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::pixy, &req.pixy);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::pixy << " does not exist" << std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::x_uncorrected, &req.x_uncorrected);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::x_uncorrected << " does not exist"
<< std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::y_uncorrected, &req.y_uncorrected);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::y_uncorrected << " does not exist"
<< std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::x_corrected, &req.x_corrected);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::x_corrected << " does not exist" << std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::y_corrected, &req.y_corrected);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::y_corrected << " does not exist" << std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::magnitude, &req.magnitude);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::magnitude << " does not exist" << std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::cxa, &req.cxa);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::cxa << " does not exist" << std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::cya, &req.cya);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::cya << " does not exist" << std::endl;
return result;
}
result = j.getValue(startrackerUploadCentroidKeys::quality, &req.quality);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startrackerUploadCentroidKeys::quality << " does not exist" << std::endl;
return result;
}
uint32_t length = 0;
arc_pack_uploadcentroid_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
uploadCentroid.rememberId = req.id;
return result;
}
void StarTrackerHandler::prepareTimeRequest() {
uint32_t length = 0;
arc_tm_pack_time_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::preparePingRequest() {
uint32_t length = 0;
struct PingActionRequest pingRequest = {PING_ID};
arc_pack_ping_action_req(&pingRequest, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::prepareVersionRequest() {
uint32_t length = 0;
arc_tm_pack_version_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::prepareInterfaceRequest() {
uint32_t length = 0;
arc_tm_pack_interface_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::preparePowerRequest() {
uint32_t length = 0;
arc_tm_pack_power_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::prepareRebootCommand() {
uint32_t length = 0;
struct RebootActionRequest rebootReq;
arc_pack_reboot_action_req(&rebootReq, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::prepareTakeImageCommand(const uint8_t* commandData) {
uint32_t length = 0;
struct CameraActionRequest camReq;
camReq.actionid = *commandData;
arc_pack_camera_action_req(&camReq, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::prepareSolutionRequest() {
uint32_t length = 0;
arc_tm_pack_solution_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::prepareTemperatureRequest() {
uint32_t length = 0;
arc_tm_pack_temperature_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::prepareHistogramRequest() {
uint32_t length = 0;
arc_tm_pack_histogram_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::prepareContrastRequest() {
uint32_t length = 0;
arc_tm_pack_contrast_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
void StarTrackerHandler::prepareErrorResetRequest() {
uint32_t length = 0;
struct ResetErrorSignalActionRequest req;
arc_pack_reseterrorsignal_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
}
ReturnValue_t StarTrackerHandler::prepareParamCommand(const uint8_t* commandData,
size_t commandDataLen,
ArcsecJsonParamBase& paramSet) {
ReturnValue_t result = RETURN_OK;
if (commandDataLen > MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG;
}
std::string fullName(reinterpret_cast<const char*>(commandData), commandDataLen);
result = paramSet.create(fullName, commandBuffer);
if (result != RETURN_OK) {
return result;
}
dataLinkLayer.encodeFrame(commandBuffer, paramSet.getSize());
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareDownloadMatchedStarCommand(const uint8_t* commandData,
size_t commandDataLen) {
if (commandDataLen != DownloadMatchedStarCmd::LENGTH) {
return INVALID_LENGTH;
}
struct DownloadMatchedStarActionRequest req;
req.id = *commandData;
uint32_t length = 0;
arc_pack_downloadmatchedstar_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareDownloadDbImageCommand(const uint8_t* commandData,
size_t commandDataLen) {
if (commandDataLen != DownloadDbImageCmd::LENGTH) {
return INVALID_LENGTH;
}
struct DownloadDBImageActionRequest req;
req.id = *commandData;
uint32_t length = 0;
arc_pack_downloaddbimage_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareDownloadBlobPixelCommand(const uint8_t* commandData,
size_t commandDataLen) {
if (commandDataLen != DownloadBlobPixCmd::LENGTH) {
return INVALID_LENGTH;
}
struct DownloadBlobPixelActionRequest req;
req.id = *commandData;
req.type = *(commandData + 1);
if ((req.type != DownloadBlobPixCmd::NORMAL) && (req.type != DownloadBlobPixCmd::FAST)) {
return INVALID_TYPE;
}
uint32_t length = 0;
arc_pack_downloadblobpixel_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareFpgaActionCommand(const uint8_t* commandData,
size_t commandDataLen) {
if (commandDataLen != FpgaActionCmd::LENGTH) {
return INVALID_LENGTH;
}
struct FPGAActionActionRequest req;
req.id = *commandData;
if (req.id != FpgaActionCmd::ID) {
return INVALID_ID;
}
uint32_t length = 0;
arc_pack_fpgaaction_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestCameraParams() {
uint32_t length = 0;
arc_pack_camera_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestLimitsParams() {
uint32_t length = 0;
arc_pack_limits_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestLogLevelParams() {
uint32_t length = 0;
arc_pack_loglevel_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestMountingParams() {
uint32_t length = 0;
arc_pack_mounting_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestImageProcessorParams() {
uint32_t length = 0;
arc_pack_imageprocessor_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestCentroidingParams() {
uint32_t length = 0;
arc_pack_centroiding_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestLisaParams() {
uint32_t length = 0;
arc_pack_lisa_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestMatchingParams() {
uint32_t length = 0;
arc_pack_matching_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestTrackingParams() {
uint32_t length = 0;
arc_pack_tracking_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestValidationParams() {
uint32_t length = 0;
arc_pack_validation_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestAlgoParams() {
uint32_t length = 0;
arc_pack_algo_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestSubscriptionParams() {
uint32_t length = 0;
arc_pack_subscription_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestLogSubscriptionParams() {
uint32_t length = 0;
arc_pack_logsubscription_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::prepareRequestDebugCameraParams() {
uint32_t length = 0;
arc_pack_debugcamera_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::handleSetParamReply() {
const uint8_t* reply = dataLinkLayer.getReply();
uint8_t status = *(reply + STATUS_OFFSET);
if (status != startrackerSTATUS_OK) {
sif::warning << "StarTrackerHandler::handleSetParamReply: Failed to execute parameter set "
" command with parameter ID"
<< static_cast<unsigned int>(*(reply + PARAMETER_ID_OFFSET)) << std::endl;
if (startupState != StartupState::IDLE) {
startupState = StartupState::IDLE;
}
return SET_PARAM_FAILED;
}
if (startupState != StartupState::IDLE) {
handleStartup(reply + PARAMETER_ID_OFFSET);
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::handleActionReply() {
const uint8_t* reply = dataLinkLayer.getReply();
uint8_t status = *(reply + STATUS_OFFSET);
if (status != startrackerSTATUS_OK) {
sif::warning << "StarTrackerHandler::handleActionReply: Failed to execute action "
<< "command with action ID "
<< static_cast<unsigned int>(*(reply + ACTION_ID_OFFSET)) << " and status "
<< static_cast<unsigned int>(status) << std::endl;
return ACTION_FAILED;
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::handleUploadCentroidReply() {
ReturnValue_t result = RETURN_OK;
result = handleActionReply();
if (result != RETURN_OK) {
return result;
}
const uint8_t* reply = dataLinkLayer.getReply();
if (*(reply + ACTION_DATA_OFFSET) != uploadCentroid.rememberId) {
return UPLOAD_CENTROID_ID_MISMATCH;
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::handleEraseReply() {
ReturnValue_t result = RETURN_OK;
result = handleActionReply();
if (result != RETURN_OK) {
return result;
}
const uint8_t* replyData = dataLinkLayer.getReply() + ACTION_DATA_OFFSET;
startrackerEraseReply eraseReply(replyData);
if (eraseReply.getRegion() != eraseCmd.rememberRegion) {
sif::warning << "StarTrackerHandler::handleEraseReply: Region mismatch" << std::endl;
return REGION_MISMATCH;
}
return result;
}
ReturnValue_t StarTrackerHandler::handleChecksumReply() {
ReturnValue_t result = RETURN_OK;
result = handleActionReply();
if (result != RETURN_OK) {
return result;
}
const uint8_t* replyData = dataLinkLayer.getReply() + ACTION_DATA_OFFSET;
startrackerChecksumReply checksumReply(replyData);
if (checksumReply.getRegion() != checksumCmd.rememberRegion) {
sif::warning << "StarTrackerHandler::handleChecksumReply: Region mismatch" << std::endl;
return REGION_MISMATCH;
}
if (checksumReply.getAddress() != checksumCmd.rememberAddress) {
sif::warning << "StarTrackerHandler::handleChecksumReply: Address mismatch" << std::endl;
return ADDRESS_MISMATCH;
}
if (checksumReply.getLength() != checksumCmd.rememberLength) {
sif::warning << "StarTrackerHandler::handleChecksumReply: Length mismatch" << std::endl;
return LENGTH_MISSMATCH;
}
PoolReadGuard rg(&checksumSet);
checksumSet.checksum = checksumReply.getChecksum();
handleDeviceTM(&checksumSet, startrackerCHECKSUM);
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1
checksumReply.printChecksum();
#endif /* OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1 */
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::handleParamRequest(LocalPoolDataSetBase& dataset, size_t size) {
ReturnValue_t result = RETURN_OK;
result = dataset.read(TIMEOUT_TYPE, MUTEX_TIMEOUT);
if (result != RETURN_OK) {
return result;
}
const uint8_t* reply = dataLinkLayer.getReply() + PARAMS_OFFSET;
dataset.setValidityBufferGeneration(false);
result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::handleParamRequest Deserialization failed" << std::endl;
}
dataset.setValidityBufferGeneration(true);
dataset.setValidity(true, true);
result = dataset.commit(TIMEOUT_TYPE, MUTEX_TIMEOUT);
if (result != RETURN_OK) {
return result;
}
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1
dataset.printSet();
#endif
return result;
}
ReturnValue_t StarTrackerHandler::handlePingReply() {
ReturnValue_t result = RETURN_OK;
uint32_t pingId = 0;
const uint8_t* reply = dataLinkLayer.getReply();
uint8_t status = dataLinkLayer.getStatusField();
const uint8_t* buffer = reply + ACTION_DATA_OFFSET;
size_t size = sizeof(pingId);
SerializeAdapter::deSerialize(&pingId, &buffer, &size, SerializeIF::Endianness::LITTLE);
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1
sif::info << "StarTracker: Ping status: " << static_cast<unsigned int>(status) << std::endl;
sif::info << "Ping id: 0x" << std::hex << pingId << std::endl;
#endif /* OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1 */
if (status != startrackerSTATUS_OK || pingId != PING_ID) {
sif::warning << "StarTrackerHandler::handlePingReply: Ping failed" << std::endl;
result = PING_FAILED;
} else {
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1
sif::info << "StarTracker: Ping successful" << std::endl;
#endif
}
return result;
}
ReturnValue_t StarTrackerHandler::checkProgram() {
PoolReadGuard pg(&versionSet);
switch (versionSet.program.value) {
case startrackerProgram::BOOTLOADER:
// Star tracker currently in bootloader program. Need to send boot command to switch to
// firmware program
if (startupState != StartupState::IDLE) {
startupState = StartupState::BOOT;
}
break;
case startrackerProgram::FIRMWARE:
// Firmware already booted
if (startupState != StartupState::IDLE) {
startupState = StartupState::LIMITS;
}
break;
default:
sif::warning << "StarTrackerHandler::checkProgram: Version set has invalid program ID"
<< std::endl;
return INVALID_PROGRAM;
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::handleTm(LocalPoolDataSetBase& dataset, size_t size) {
ReturnValue_t result = RETURN_OK;
uint8_t status = *(dataLinkLayer.getReply() + STATUS_OFFSET);
if (status != startrackerSTATUS_OK) {
sif::warning << "StarTrackerHandler::handleTm: Reply error: "
<< static_cast<unsigned int>(status) << std::endl;
return REPLY_ERROR;
}
result = dataset.read(TIMEOUT_TYPE, MUTEX_TIMEOUT);
if (result != RETURN_OK) {
return result;
}
const uint8_t* reply = dataLinkLayer.getReply() + TICKS_OFFSET;
dataset.setValidityBufferGeneration(false);
result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::handleTm: Deserialization failed" << std::endl;
}
dataset.setValidityBufferGeneration(true);
dataset.setValidity(true, true);
result = dataset.commit(TIMEOUT_TYPE, MUTEX_TIMEOUT);
if (result != RETURN_OK) {
return result;
}
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1
dataset.printSet();
#endif
return result;
}
ReturnValue_t StarTrackerHandler::handleActionReplySet(LocalPoolDataSetBase& dataset, size_t size) {
ReturnValue_t result = RETURN_OK;
uint8_t status = *(dataLinkLayer.getReply() + STATUS_OFFSET);
if (status != startrackerSTATUS_OK) {
sif::warning << "StarTrackerHandler::handleActionReplySet: Reply error: "
<< static_cast<unsigned int>(status) << std::endl;
return REPLY_ERROR;
}
result = dataset.read(TIMEOUT_TYPE, MUTEX_TIMEOUT);
if (result != RETURN_OK) {
return result;
}
const uint8_t* reply = dataLinkLayer.getReply() + ACTION_DATA_OFFSET;
dataset.setValidityBufferGeneration(false);
result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE);
if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::handleActionReplySet Deserialization failed" << std::endl;
}
dataset.setValidityBufferGeneration(true);
dataset.setValidity(true, true);
result = dataset.commit(TIMEOUT_TYPE, MUTEX_TIMEOUT);
if (result != RETURN_OK) {
return result;
}
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1
dataset.printSet();
#endif
return result;
}
void StarTrackerHandler::handleStartup(const uint8_t* parameterId) {
switch (*parameterId) {
case (startrackerID::LOG_LEVEL): {
startupState = StartupState::LIMITS;
break;
}
case (startrackerID::LIMITS): {
startupState = StartupState::TRACKING;
break;
}
case (startrackerID::TRACKING): {
startupState = StartupState::MOUNTING;
break;
}
case (startrackerID::MOUNTING): {
startupState = StartupState::IMAGE_PROCESSOR;
break;
}
case (startrackerID::IMAGE_PROCESSOR): {
startupState = StartupState::CAMERA;
break;
}
case (startrackerID::CAMERA): {
startupState = StartupState::CENTROIDING;
break;
}
case (startrackerID::CENTROIDING): {
startupState = StartupState::LISA;
break;
}
case (startrackerID::LISA): {
startupState = StartupState::MATCHING;
break;
}
case (startrackerID::MATCHING): {
startupState = StartupState::VALIDATION;
break;
}
case (startrackerID::VALIDATION): {
startupState = StartupState::ALGO;
break;
}
case (startrackerID::ALGO): {
startupState = StartupState::LOG_SUBSCRIPTION;
break;
}
case (startrackerID::LOG_SUBSCRIPTION): {
startupState = StartupState::DEBUG_CAMERA;
break;
}
case (startrackerID::DEBUG_CAMERA): {
startupState = StartupState::DONE;
break;
}
default: {
sif::debug << "StarTrackerHandler::handleStartup: Received parameter reply with unexpected"
<< " parameter ID" << std::endl;
break;
}
}
}