#include "StarTrackerHandler.h" #include #include #include #include #include "OBSWConfig.h" #include "StarTrackerJsonCommands.h" extern "C" { #include #include #include #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(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::FIRMWARE_UPDATE_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 (startracker::STOP_IMAGE_LOADER): { strHelper->stopProcess(); return EXECUTION_FINISHED; } case (startracker::SET_JSON_FILE_NAME): { if (size > MAX_PATH_SIZE) { return FILE_PATH_TOO_LONG; } paramJsonFile = std::string(reinterpret_cast(data), size); return EXECUTION_FINISHED; } case (startracker::DISABLE_TIMESTAMP_GENERATION): strHelper->disableTimestamping(); break; case (startracker::ENABLE_TIMESTAMP_GENERATION): strHelper->enableTimestamping(); break; default: break; } if (strHelperExecuting == true) { return STR_HELPER_EXECUTING; } result = checkMode(actionId); if (result != RETURN_OK) { return result; } result = checkCommand(actionId); if (result != RETURN_OK) { return result; } // Intercept image loader commands which do not follow the common DHB communication flow switch (actionId) { case (startracker::UPLOAD_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(data), size)); if (result != RETURN_OK) { return result; } strHelperExecuting = true; return EXECUTION_FINISHED; } case (startracker::DOWNLOAD_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(data), size)); if (result != RETURN_OK) { return result; } strHelperExecuting = true; return EXECUTION_FINISHED; } case (startracker::FLASH_READ): { result = DeviceHandlerBase::acceptExternalDeviceCommands(); if (result != RETURN_OK) { return result; } result = executeFlashReadCommand(data, size); if (result != RETURN_OK) { return result; } strHelperExecuting = true; return EXECUTION_FINISHED; } case (startracker::CHANGE_DOWNLOAD_FILE): { if (size > MAX_FILE_NAME) { return FILENAME_TOO_LONG; } strHelper->setDownloadImageName(std::string(reinterpret_cast(data), size)); return EXECUTION_FINISHED; } case (startracker::SET_READ_FILENAME): { if (size > MAX_FILE_NAME) { return FILENAME_TOO_LONG; } strHelper->setDownloadImageName(std::string(reinterpret_cast(data), size)); return EXECUTION_FINISHED; } case (startracker::FIRMWARE_UPDATE): { result = DeviceHandlerBase::acceptExternalDeviceCommands(); if (result != RETURN_OK) { return result; } if (size > MAX_PATH_SIZE + MAX_FILE_NAME) { return FILE_PATH_TOO_LONG; } result = strHelper->startFirmwareUpdate(std::string(reinterpret_cast(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; } } } Submode_t StarTrackerHandler::getInitialSubmode() { return SUBMODE_BOOTLOADER; } void StarTrackerHandler::doStartUp() { switch (startupState) { case StartupState::IDLE: startupState = StartupState::CHECK_PROGRAM; return; case StartupState::BOOT_BOOTLOADER: // This step is required in case the star tracker is already in firmware mode to harmonize // the device handler's submode to the star tracker's mode return; case StartupState::DONE: submode = SUBMODE_BOOTLOADER; startupState = StartupState::IDLE; break; default: return; } setMode(_MODE_TO_ON); } void StarTrackerHandler::doShutDown() { // If the 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; internalState = InternalState::IDLE; } ReturnValue_t StarTrackerHandler::buildNormalDeviceCommand(DeviceCommandId_t* id) { switch (normalState) { case NormalState::TEMPERATURE_REQUEST: *id = startracker::REQ_TEMPERATURE; break; default: sif::debug << "StarTrackerHandler::buildNormalDeviceCommand: Invalid normal step" << std::endl; break; } return buildCommandFromCommand(*id, NULL, 0); } ReturnValue_t StarTrackerHandler::buildTransitionDeviceCommand(DeviceCommandId_t* id) { switch (internalState) { case InternalState::BOOT: *id = startracker::BOOT; bootCountdown.setTimeout(BOOT_TIMEOUT); internalState = InternalState::BOOT_DELAY; return buildCommandFromCommand(*id, nullptr, 0); case InternalState::REQ_VERSION: internalState = InternalState::VERIFY_BOOT; // Again read program to check if firmware boot was successful *id = startracker::REQ_VERSION; return buildCommandFromCommand(*id, nullptr, 0); case InternalState::LOGLEVEL: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::LOGLEVEL; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::LIMITS: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::LIMITS; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::TRACKING: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::TRACKING; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::MOUNTING: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::MOUNTING; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::IMAGE_PROCESSOR: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::IMAGE_PROCESSOR; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::CAMERA: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::CAMERA; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::CENTROIDING: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::CENTROIDING; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::LISA: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::LISA; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::MATCHING: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::MATCHING; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::VALIDATION: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::VALIDATION; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::ALGO: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::ALGO; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::LOG_SUBSCRIPTION: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::LOGSUBSCRIPTION; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::DEBUG_CAMERA: internalState = InternalState::WAIT_FOR_EXECUTION; *id = startracker::DEBUG_CAMERA; return buildCommandFromCommand(*id, reinterpret_cast(paramJsonFile.c_str()), paramJsonFile.size()); case InternalState::BOOT_BOOTLOADER: internalState = InternalState::BOOTLOADER_CHECK; *id = startracker::SWITCH_TO_BOOTLOADER_PROGRAM; return buildCommandFromCommand(*id, nullptr, 0); case InternalState::BOOTLOADER_CHECK: *id = startracker::REQ_VERSION; return buildCommandFromCommand(*id, nullptr, 0); default: break; } switch (startupState) { case StartupState::CHECK_PROGRAM: startupState = StartupState::WAIT_CHECK_PROGRAM; *id = startracker::REQ_VERSION; return buildCommandFromCommand(*id, nullptr, 0); break; case StartupState::BOOT_BOOTLOADER: startupState = StartupState::CHECK_PROGRAM; *id = startracker::SWITCH_TO_BOOTLOADER_PROGRAM; return buildCommandFromCommand(*id, nullptr, 0); break; 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 (startracker::PING_REQUEST): { preparePingRequest(); return RETURN_OK; } case (startracker::REQ_TIME): { prepareTimeRequest(); return RETURN_OK; } case (startracker::BOOT): { prepareBootCommand(); return RETURN_OK; } case (startracker::REQ_VERSION): { prepareVersionRequest(); return RETURN_OK; } case (startracker::REQ_INTERFACE): { prepareInterfaceRequest(); return RETURN_OK; } case (startracker::REQ_POWER): { preparePowerRequest(); return RETURN_OK; } case (startracker::SWITCH_TO_BOOTLOADER_PROGRAM): { prepareRebootCommand(); return RETURN_OK; } case (startracker::TAKE_IMAGE): { prepareTakeImageCommand(commandData); return RETURN_OK; } case (startracker::SUBSCRIPTION): { Subscription subscription; result = prepareParamCommand(commandData, commandDataLen, subscription); return RETURN_OK; } case (startracker::REQ_SOLUTION): { prepareSolutionRequest(); return RETURN_OK; } case (startracker::REQ_TEMPERATURE): { prepareTemperatureRequest(); return RETURN_OK; } case (startracker::REQ_HISTOGRAM): { prepareHistogramRequest(); return RETURN_OK; } case (startracker::REQ_CONTRAST): { prepareContrastRequest(); return RETURN_OK; } case (startracker::RESET_ERROR): { prepareErrorResetRequest(); return RETURN_OK; } case (startracker::LIMITS): { Limits limits; result = prepareParamCommand(commandData, commandDataLen, limits); return result; } case (startracker::MOUNTING): { Mounting mounting; result = prepareParamCommand(commandData, commandDataLen, mounting); return result; } case (startracker::IMAGE_PROCESSOR): { ImageProcessor imageProcessor; result = prepareParamCommand(commandData, commandDataLen, imageProcessor); return result; } case (startracker::CAMERA): { Camera camera; result = prepareParamCommand(commandData, commandDataLen, camera); return result; } case (startracker::CENTROIDING): { Centroiding centroiding; result = prepareParamCommand(commandData, commandDataLen, centroiding); return result; } case (startracker::LISA): { Lisa lisa; result = prepareParamCommand(commandData, commandDataLen, lisa); return result; } case (startracker::MATCHING): { Matching matching; result = prepareParamCommand(commandData, commandDataLen, matching); return result; } case (startracker::VALIDATION): { Validation validation; result = prepareParamCommand(commandData, commandDataLen, validation); return result; } case (startracker::ALGO): { Algo algo; result = prepareParamCommand(commandData, commandDataLen, algo); return result; } case (startracker::TRACKING): { Tracking tracking; result = prepareParamCommand(commandData, commandDataLen, tracking); return result; } case (startracker::LOGLEVEL): { LogLevel logLevel; result = prepareParamCommand(commandData, commandDataLen, logLevel); return result; } case (startracker::LOGSUBSCRIPTION): { LogSubscription logSubscription; result = prepareParamCommand(commandData, commandDataLen, logSubscription); return result; } case (startracker::DEBUG_CAMERA): { DebugCamera debugCamera; result = prepareParamCommand(commandData, commandDataLen, debugCamera); return result; } case (startracker::ERASE): { result = prepareEraseCommand(commandData, commandDataLen); return result; } case (startracker::UNLOCK): { result = prepareUnlockCommand(commandData, commandDataLen); return result; } case (startracker::CHECKSUM): { result = prepareChecksumCommand(commandData, commandDataLen); return result; } case (startracker::SET_TIME): { result = prepareSetTimeCommand(commandData, commandDataLen); return result; } case (startracker::DOWNLOAD_CENTROID): { result = prepareDownloadCentroidCommand(commandData, commandDataLen); return result; } case (startracker::UPLOAD_CENTROID): { result = prepareUploadCentroidCommand(commandData, commandDataLen); return result; } case (startracker::DOWNLOAD_MATCHED_STAR): { result = prepareDownloadMatchedStarCommand(commandData, commandDataLen); return result; } case (startracker::DOWNLOAD_DBIMAGE): { result = prepareDownloadDbImageCommand(commandData, commandDataLen); return result; } case (startracker::DOWNLOAD_BLOBPIXEL): { result = prepareDownloadBlobPixelCommand(commandData, commandDataLen); return result; } case (startracker::REQ_CAMERA): { result = prepareRequestCameraParams(); return result; } case (startracker::REQ_LIMITS): { result = prepareRequestLimitsParams(); return result; } case (startracker::REQ_LOG_LEVEL): { result = prepareRequestLogLevelParams(); return result; } case (startracker::REQ_MOUNTING): { result = prepareRequestMountingParams(); return result; } case (startracker::REQ_IMAGE_PROCESSOR): { result = prepareRequestImageProcessorParams(); return result; } case (startracker::REQ_CENTROIDING): { result = prepareRequestCentroidingParams(); return result; } case (startracker::REQ_LISA): { result = prepareRequestLisaParams(); return result; } case (startracker::REQ_MATCHING): { result = prepareRequestMatchingParams(); return result; } case (startracker::REQ_TRACKING): { result = prepareRequestTrackingParams(); return result; } case (startracker::REQ_VALIDATION): { result = prepareRequestValidationParams(); return result; } case (startracker::REQ_ALGO): { result = prepareRequestAlgoParams(); return result; } case (startracker::REQ_SUBSCRIPTION): { result = prepareRequestSubscriptionParams(); return result; } case (startracker::REQ_LOG_SUBSCRIPTION): { result = prepareRequestLogSubscriptionParams(); return result; } case (startracker::REQ_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(startracker::PING_REQUEST, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandMap(startracker::BOOT); this->insertInCommandAndReplyMap(startracker::REQ_VERSION, 3, &versionSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_TIME, 3, &timeSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandMap(startracker::UPLOAD_IMAGE); this->insertInCommandMap(startracker::DOWNLOAD_IMAGE); this->insertInCommandAndReplyMap(startracker::REQ_POWER, 3, &powerSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_INTERFACE, 3, &interfaceSet, startracker::MAX_FRAME_SIZE * 2 + 2); // Reboot has no reply. Star tracker reboots immediately this->insertInCommandMap(startracker::SWITCH_TO_BOOTLOADER_PROGRAM); this->insertInCommandAndReplyMap(startracker::SUBSCRIPTION, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_SOLUTION, 3, &solutionSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_TEMPERATURE, 3, &temperatureSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_HISTOGRAM, 3, &histogramSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_CONTRAST, 3, &contrastSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::LOGLEVEL, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::LOGSUBSCRIPTION, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::DEBUG_CAMERA, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::LIMITS, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::MOUNTING, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::IMAGE_PROCESSOR, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::CAMERA, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::CAMERA, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::CENTROIDING, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::LISA, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::MATCHING, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::TRACKING, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::VALIDATION, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::ALGO, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::TAKE_IMAGE, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::RESET_ERROR, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::ERASE, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::UNLOCK, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::CHECKSUM, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::SET_TIME, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::DOWNLOAD_CENTROID, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::UPLOAD_CENTROID, 3, nullptr, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::DOWNLOAD_MATCHED_STAR, 3, &downloadMatchedStar, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::DOWNLOAD_DBIMAGE, 3, &downloadDbImage, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::DOWNLOAD_BLOBPIXEL, 3, &downloadBlobPixel, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_CAMERA, 3, &cameraSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_LIMITS, 3, &limitsSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_LOG_LEVEL, 3, &loglevelSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_MOUNTING, 3, &mountingSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_IMAGE_PROCESSOR, 3, &imageProcessorSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_CENTROIDING, 3, ¢roidingSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_LISA, 3, &lisaSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_MATCHING, 3, &matchingSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_TRACKING, 3, &trackingSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_VALIDATION, 3, &validationSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_ALGO, 3, &algoSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_SUBSCRIPTION, 3, &subscriptionSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_LOG_SUBSCRIPTION, 3, &logSubscriptionSet, startracker::MAX_FRAME_SIZE * 2 + 2); this->insertInCommandAndReplyMap(startracker::REQ_DEBUG_CAMERA, 3, &debugCameraSet, startracker::MAX_FRAME_SIZE * 2 + 2); } ReturnValue_t StarTrackerHandler::isModeCombinationValid(Mode_t mode, Submode_t submode) { if (this->mode == MODE_NORMAL && mode == MODE_ON) { return TRANS_NOT_ALLOWED; } switch (mode) { case MODE_OFF: case MODE_NORMAL: case MODE_RAW: if (submode == SUBMODE_NONE) { return RETURN_OK; } else { return INVALID_SUBMODE; } case MODE_ON: if (submode == SUBMODE_BOOTLOADER || submode == SUBMODE_FIRMWARE) { return RETURN_OK; } else { return INVALID_SUBMODE; } default: return HasModesIF::INVALID_MODE; } } void StarTrackerHandler::doTransition(Mode_t modeFrom, Submode_t subModeFrom) { switch (mode) { case _MODE_TO_ON: doOnTransition(subModeFrom); break; case _MODE_TO_RAW: setMode(MODE_RAW); break; case _MODE_TO_NORMAL: doNormalTransition(modeFrom, subModeFrom); break; case _MODE_POWER_DOWN: internalState = InternalState::IDLE; startupState = StartupState::IDLE; break; default: break; } } void StarTrackerHandler::doOnTransition(Submode_t subModeFrom) { if (submode == SUBMODE_BOOTLOADER && subModeFrom == SUBMODE_FIRMWARE) { bootBootloader(); } else if (submode == SUBMODE_FIRMWARE && subModeFrom == SUBMODE_FIRMWARE) { setMode(MODE_ON); } else if (submode == SUBMODE_FIRMWARE && subModeFrom == SUBMODE_BOOTLOADER) { bootFirmware(MODE_ON); } else if (submode == SUBMODE_BOOTLOADER && subModeFrom == SUBMODE_BOOTLOADER) { setMode(MODE_ON); } else if (submode == SUBMODE_BOOTLOADER && subModeFrom == SUBMODE_NONE) { setMode(MODE_ON); } else if (submode == SUBMODE_FIRMWARE && subModeFrom == SUBMODE_NONE) { setMode(MODE_ON); } } void StarTrackerHandler::doNormalTransition(Mode_t modeFrom, Submode_t subModeFrom) { if (subModeFrom == SUBMODE_FIRMWARE) { setMode(MODE_NORMAL); } else if (subModeFrom == SUBMODE_BOOTLOADER) { bootFirmware(MODE_NORMAL); } else if (modeFrom == MODE_NORMAL && subModeFrom == SUBMODE_NONE) { // Device handler already in mode normal setMode(MODE_NORMAL); } } void StarTrackerHandler::bootFirmware(Mode_t toMode) { switch (internalState) { case InternalState::IDLE: internalState = InternalState::BOOT; break; case InternalState::BOOT_DELAY: if (bootCountdown.hasTimedOut()) { internalState = InternalState::REQ_VERSION; } break; case InternalState::FAILED_FIRMWARE_BOOT: internalState = InternalState::IDLE; break; case InternalState::DONE: setMode(toMode); internalState = InternalState::IDLE; break; default: return; } } void StarTrackerHandler::bootBootloader() { if (internalState == InternalState::IDLE) { internalState = InternalState::BOOT_BOOTLOADER; } else if (internalState == InternalState::BOOTING_BOOTLOADER_FAILED) { internalState = InternalState::IDLE; } else if (internalState == InternalState::DONE) { internalState = InternalState::IDLE; setMode(MODE_ON); } } 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 (startracker::REQ_TIME): { result = handleTm(timeSet, startracker::TimeSet::SIZE); break; } case (startracker::PING_REQUEST): { result = handlePingReply(); break; } case (startracker::BOOT): case (startracker::TAKE_IMAGE): case (startracker::RESET_ERROR): case (startracker::UNLOCK): case (startracker::SET_TIME): break; case (startracker::DOWNLOAD_CENTROID): { result = handleActionReplySet(downloadCentroidSet, startracker::DownloadCentroidSet::SIZE); break; } case (startracker::DOWNLOAD_MATCHED_STAR): { result = handleActionReplySet(downloadMatchedStar, startracker::DownloadMatchedStar::SIZE); break; } case (startracker::DOWNLOAD_DBIMAGE): { result = handleActionReplySet(downloadDbImage, startracker::DownloadDBImage::SIZE); break; } case (startracker::DOWNLOAD_BLOBPIXEL): { result = handleActionReplySet(downloadBlobPixel, startracker::DownloadBlobPixel::SIZE); break; } case (startracker::UPLOAD_CENTROID): { result = handleUploadCentroidReply(); break; } case (startracker::ERASE): { result = handleEraseReply(); break; } case (startracker::CHECKSUM): { result = handleChecksumReply(); break; } case (startracker::REQ_VERSION): { result = handleTm(versionSet, startracker::VersionSet::SIZE); if (result != RETURN_OK) { return result; } result = checkProgram(); if (result != RETURN_OK) { return result; } break; } case (startracker::REQ_INTERFACE): { result = handleTm(interfaceSet, startracker::InterfaceSet::SIZE); break; } case (startracker::REQ_POWER): { result = handleTm(powerSet, startracker::PowerSet::SIZE); break; } case (startracker::REQ_SOLUTION): { result = handleTm(solutionSet, startracker::SolutionSet::SIZE); break; } case (startracker::REQ_TEMPERATURE): { result = handleTm(temperatureSet, startracker::TemperatureSet::SIZE); break; } case (startracker::REQ_HISTOGRAM): { result = handleTm(histogramSet, startracker::HistogramSet::SIZE); break; } case (startracker::REQ_CONTRAST): { result = handleTm(contrastSet, startracker::ContrastSet::SIZE); break; } case (startracker::SUBSCRIPTION): case (startracker::LOGLEVEL): case (startracker::LOGSUBSCRIPTION): case (startracker::DEBUG_CAMERA): case (startracker::LIMITS): case (startracker::MOUNTING): case (startracker::CAMERA): case (startracker::CENTROIDING): case (startracker::LISA): case (startracker::MATCHING): case (startracker::TRACKING): case (startracker::VALIDATION): case (startracker::IMAGE_PROCESSOR): case (startracker::ALGO): { result = handleSetParamReply(); break; } case (startracker::REQ_CAMERA): { handleParamRequest(cameraSet, startracker::CameraSet::SIZE); break; } case (startracker::REQ_LIMITS): { handleParamRequest(limitsSet, startracker::LimitsSet::SIZE); break; } case (startracker::REQ_LOG_LEVEL): { handleParamRequest(loglevelSet, startracker::LogLevelSet::SIZE); break; } case (startracker::REQ_MOUNTING): { handleParamRequest(mountingSet, startracker::MountingSet::SIZE); break; } case (startracker::REQ_IMAGE_PROCESSOR): { handleParamRequest(imageProcessorSet, startracker::ImageProcessorSet::SIZE); break; } case (startracker::REQ_CENTROIDING): { handleParamRequest(centroidingSet, startracker::CentroidingSet::SIZE); break; } case (startracker::REQ_LISA): { handleParamRequest(lisaSet, startracker::LisaSet::SIZE); break; } case (startracker::REQ_MATCHING): { handleParamRequest(matchingSet, startracker::MatchingSet::SIZE); break; } case (startracker::REQ_TRACKING): { handleParamRequest(trackingSet, startracker::TrackingSet::SIZE); break; } case (startracker::REQ_VALIDATION): { handleParamRequest(validationSet, startracker::ValidationSet::SIZE); break; } case (startracker::REQ_ALGO): { handleParamRequest(algoSet, startracker::AlgoSet::SIZE); break; } case (startracker::REQ_SUBSCRIPTION): { handleParamRequest(subscriptionSet, startracker::SubscriptionSet::SIZE); break; } case (startracker::REQ_LOG_SUBSCRIPTION): { handleParamRequest(logSubscriptionSet, startracker::LogSubscriptionSet::SIZE); break; } case (startracker::REQ_DEBUG_CAMERA): { handleParamRequest(debugCameraSet, startracker::DebugCameraSet::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) { // if (modeTo == MODE_ON && (submode == SUBMODE_NONE || submode == SUBMODE_BOOTLOADER)) { // return BOOTLOADER_TRANSITION_DELAY; // } else if (modeTo == MODE_ON && submode == SUBMODE_FIRMWARE && modeFrom == MODE_) { // return FIRMWARE_TRANSITION_DELAY; // } return DEFAULT_TRANSITION_DELAY; } ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { localDataPoolMap.emplace(startracker::TICKS_TIME_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TIME_TIME_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::RUN_TIME, new PoolEntry({0})); localDataPoolMap.emplace(startracker::UNIX_TIME, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TICKS_VERSION_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TIME_VERSION_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::PROGRAM, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MAJOR, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MINOR, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TICKS_INTERFACE_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TIME_INTERFACE_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::FRAME_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CHECKSUM_ERROR_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SET_PARAM_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SET_PARAM_REPLY_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::PARAM_REQUEST_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::PARAM_REPLY_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::REQ_TM_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TM_REPLY_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::ACTION_REQ_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::ACTION_REPLY_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TICKS_POWER_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TIME_POWER_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MCU_CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MCU_VOLTAGE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::FPGA_CORE_CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::FPGA_CORE_VOLTAGE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::FPGA_18_CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::FPGA_18_VOLTAGE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::FPGA_25_CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::FPGA_25_VOLTAGE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CMV_21_CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CMV_21_VOLTAGE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CMV_PIX_CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CMV_PIX_VOLTAGE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CMV_33_CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CMV_33_VOLTAGE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CMV_RES_CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CMV_RES_VOLTAGE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TICKS_TEMPERATURE_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TIME_TEMPERATURE_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MCU_TEMPERATURE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CMOS_TEMPERATURE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::FPGA_TEMPERATURE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TICKS_SOLUTION_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TIME_SOLUTION_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CALI_QW, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CALI_QX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CALI_QY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CALI_QZ, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACK_CONFIDENCE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACK_QW, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACK_QX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACK_QY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACK_QZ, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACK_REMOVED, new PoolEntry({0})); localDataPoolMap.emplace(startracker::STARS_CENTROIDED, new PoolEntry({0})); localDataPoolMap.emplace(startracker::STARS_MATCHED_DATABASE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_QW, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_QX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_QY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_QZ, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_PERC_CLOSE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_NR_CLOSE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRUST_WORTHY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::STABLE_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SOLUTION_STRATEGY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TICKS_HISTOGRAM_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TIME_HISTOGRAM_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINA0, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINA1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINA2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINA3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINA4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINA5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINA6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINA7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINA8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINB0, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINB1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINB2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINB3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINB4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINB5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINB6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINB7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINB8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINC0, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINC1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINC2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINC3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINC4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINC5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINC6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINC7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BINC8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BIND0, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BIND1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BIND2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BIND3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BIND4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BIND5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BIND6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BIND7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::HISTOGRAM_BIND8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TICKS_CONTRAST_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TIME_CONTRAST_SET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINA0, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINA1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINA2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINA3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINA4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINA5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINA6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINA7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINA8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINB0, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINB1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINB2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINB3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINB4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINB5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINB6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINB7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINB8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC0, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BINC8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BIND0, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BIND1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BIND2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BIND3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BIND4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BIND5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BIND6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BIND7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CONTRAST_BIND8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CHKSUM, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_ID, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_PIXX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_PIXY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_X_UNCORRECTED, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_Y_UNCORRECTED, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_X_CORRECTED, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_Y_CORRECTED, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_MAGNITUDE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_CXA, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_CYA, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DWL_QUALITY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_ID, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_CAMFPX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_CAMFPY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_CAMCARTX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_CAMCARTY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_CAMCARTZ, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_CAMMAGNITUDE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_DBFPX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_DBFPY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_DBCARTX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_DBCARTY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_DBCARTZ, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_DBMAGNITUDE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHEDSTR_CATALOGID, new PoolEntry({0})); localDataPoolMap.emplace(startracker::BLOBPIX_ID, new PoolEntry({0})); localDataPoolMap.emplace(startracker::BLOBPIX_X, new PoolEntry({0})); localDataPoolMap.emplace(startracker::BLOBPIX_Y, new PoolEntry({0})); localDataPoolMap.emplace(startracker::BLOBPIX_TOT_VAL, new PoolEntry({0})); localDataPoolMap.emplace(startracker::BLOBPIX_IN_USE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::BLOBPIX_BRIGHT_NEIGHBOURS, new PoolEntry({0})); localDataPoolMap.emplace(startracker::BLOBPIX_REGION, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAMERA_MODE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::FOCALLENGTH, new PoolEntry({0})); localDataPoolMap.emplace(startracker::EXPOSURE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::INTERVAL, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAMERA_OFFSET, new PoolEntry({0})); localDataPoolMap.emplace(startracker::PGAGAIN, new PoolEntry({0})); localDataPoolMap.emplace(startracker::ADCGAIN, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_REG1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_VAL1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_REG2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_VAL2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_REG3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_VAL3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_REG4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_VAL4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_REG5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_VAL5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_REG6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_VAL6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_REG7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_VAL7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_REG8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_VAL8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CAM_FREQ_1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_ACTION, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_FPGA18CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_FPGA25CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_FPGA10CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_MCUCURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_CMOS21CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_CMOSPIXCURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_CMOS33CURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_CMOSVRESCURRENT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LIMITS_CMOSTEMPERATURE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL9, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL10, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL11, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL12, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL13, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL14, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL15, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOGLEVEL16, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MOUNTING_QW, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MOUNTING_QX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MOUNTING_QY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MOUNTING_QZ, new PoolEntry({0})); localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_MODE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_STORE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_SIGNALTHRESHOLD, new PoolEntry({0})); localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_DARKTHRESHOLD, new PoolEntry({0})); localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_BACKGROUNDCOMPENSATION, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_ENABLE_FILTER, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_MAX_QUALITY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_DARK_THRESHOLD, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_MIN_QUALITY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_MAX_INTENSITY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_MIN_INTENSITY, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_MAX_MAGNITUDE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_GAUSSIAN_CMAX, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_GAUSSIAN_CMIN, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_TRANSMATRIX00, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_TRANSMATRIX01, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_TRANSMATRIX10, new PoolEntry({0})); localDataPoolMap.emplace(startracker::CENTROIDING_TRANSMATRIX11, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_MODE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_PREFILTER_DIST_THRESHOLD, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_PREFILTER_ANGLE_THRESHOLD, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_FOV_WIDTH, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_FOV_HEIGHT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_FLOAT_STAR_LIMIT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_CLOSE_STAR_LIMIT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_CLOSE_STAR_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_FRACTION_CLOSE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_MEAN_SUM, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_DB_STAR_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_MAX_COMBINATIONS, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_NR_STARS_STOP, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LISA_FRACTION_CLOSE_STOP, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHING_SQUARED_DISTANCE_LIMIT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::MATCHING_SQUARED_SHIFT_LIMIT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACKING_THIN_LIMIT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACKING_OUTLIER_THRESHOLD, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACKING_OUTLIER_THRESHOLD_QUEST, new PoolEntry({0})); localDataPoolMap.emplace(startracker::TRACKING_TRACKER_CHOICE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::VALIDATION_STABLE_COUNT, new PoolEntry({0})); localDataPoolMap.emplace(startracker::VALIDATION_MAX_DIFFERENCE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::VALIDATION_MIN_TRACKER_CONFIDENCE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::VALIDATION_MIN_MATCHED_STARS, new PoolEntry({0})); localDataPoolMap.emplace(startracker::ALGO_MODE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::ALGO_I2T_MIN_CONFIDENCE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::ALGO_I2T_MIN_MATCHED, new PoolEntry({0})); localDataPoolMap.emplace(startracker::ALGO_I2L_MIN_CONFIDENCE, new PoolEntry({0})); localDataPoolMap.emplace(startracker::ALGO_I2L_MIN_MATCHED, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM3, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM4, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM5, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM6, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM7, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM8, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM9, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM10, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM11, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM12, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM13, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM14, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM15, new PoolEntry({0})); localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM16, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOG_SUBSCRIPTION_LEVEL1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOG_SUBSCRIPTION_MODULE1, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOG_SUBSCRIPTION_LEVEL2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::LOG_SUBSCRIPTION_MODULE2, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DEBUG_CAMERA_TIMING, new PoolEntry({0})); localDataPoolMap.emplace(startracker::DEBUG_CAMERA_TEST, new PoolEntry({0})); return RETURN_OK; } size_t StarTrackerHandler::getNextReplyLength(DeviceCommandId_t commandId) { return startracker::MAX_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 startracker::UPLOAD_IMAGE: case startracker::DOWNLOAD_IMAGE: case startracker::FLASH_READ: case startracker::FIRMWARE_UPDATE: { return DeviceHandlerBase::acceptExternalDeviceCommands(); default: break; } } return RETURN_OK; } ReturnValue_t StarTrackerHandler::scanForActionReply(DeviceCommandId_t* foundId) { const uint8_t* reply = dataLinkLayer.getReply(); switch (*reply) { case (startracker::ID::PING): { *foundId = startracker::PING_REQUEST; break; } case (startracker::ID::BOOT): { *foundId = startracker::BOOT; break; } case (startracker::ID::TAKE_IMAGE): { *foundId = startracker::TAKE_IMAGE; break; } case (startracker::ID::UPLOAD_IMAGE): { *foundId = startracker::UPLOAD_IMAGE; break; } case (startracker::ID::ERROR_RESET): { *foundId = startracker::RESET_ERROR; break; } case (startracker::ID::ERASE): { *foundId = startracker::ERASE; break; } case (startracker::ID::UNLOCK): { *foundId = startracker::UNLOCK; break; } case (startracker::ID::CHECKSUM): { *foundId = startracker::CHECKSUM; break; } case (startracker::ID::SET_TIME): { *foundId = startracker::SET_TIME; break; } case (startracker::ID::DOWNLOAD_CENTROID): { *foundId = startracker::DOWNLOAD_CENTROID; break; } case (startracker::ID::UPLOAD_CENTROID): { *foundId = startracker::UPLOAD_CENTROID; break; } case (startracker::ID::DOWNLOAD_MATCHED_STAR): { *foundId = startracker::DOWNLOAD_MATCHED_STAR; break; } case (startracker::ID::DOWNLOAD_DBIMAGE): { *foundId = startracker::DOWNLOAD_DBIMAGE; break; } case (startracker::ID::DOWNLOAD_BLOBPIXEL): { *foundId = startracker::DOWNLOAD_BLOBPIXEL; 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 (startracker::ID::SUBSCRIPTION): { *foundId = startracker::SUBSCRIPTION; break; } case (startracker::ID::LIMITS): { *foundId = startracker::LIMITS; break; } case (startracker::ID::MOUNTING): { *foundId = startracker::MOUNTING; break; } case (startracker::ID::IMAGE_PROCESSOR): { *foundId = startracker::IMAGE_PROCESSOR; break; } case (startracker::ID::CAMERA): { *foundId = startracker::CAMERA; break; } case (startracker::ID::CENTROIDING): { *foundId = startracker::CENTROIDING; break; } case (startracker::ID::LISA): { *foundId = startracker::LISA; break; } case (startracker::ID::MATCHING): { *foundId = startracker::MATCHING; break; } case (startracker::ID::TRACKING): { *foundId = startracker::TRACKING; break; } case (startracker::ID::VALIDATION): { *foundId = startracker::VALIDATION; break; } case (startracker::ID::ALGO): { *foundId = startracker::ALGO; break; } case (startracker::ID::LOG_LEVEL): { *foundId = startracker::LOGLEVEL; break; } case (startracker::ID::DEBUG_CAMERA): { *foundId = startracker::DEBUG_CAMERA; break; } case (startracker::ID::LOG_SUBSCRIPTION): { *foundId = startracker::LOGSUBSCRIPTION; 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 (startracker::ID::CAMERA): { *foundId = startracker::REQ_CAMERA; break; } case (startracker::ID::LIMITS): { *foundId = startracker::REQ_LIMITS; break; } case (startracker::ID::LOG_LEVEL): { *foundId = startracker::REQ_LOG_LEVEL; break; } case (startracker::ID::MOUNTING): { *foundId = startracker::REQ_MOUNTING; break; } case (startracker::ID::IMAGE_PROCESSOR): { *foundId = startracker::REQ_IMAGE_PROCESSOR; break; } case (startracker::ID::CENTROIDING): { *foundId = startracker::REQ_CENTROIDING; break; } case (startracker::ID::LISA): { *foundId = startracker::REQ_LISA; break; } case (startracker::ID::MATCHING): { *foundId = startracker::REQ_MATCHING; break; } case (startracker::ID::TRACKING): { *foundId = startracker::REQ_TRACKING; break; } case (startracker::ID::VALIDATION): { *foundId = startracker::REQ_VALIDATION; break; } case (startracker::ID::ALGO): { *foundId = startracker::REQ_ALGO; break; } case (startracker::ID::SUBSCRIPTION): { *foundId = startracker::REQ_SUBSCRIPTION; break; } case (startracker::ID::LOG_SUBSCRIPTION): { *foundId = startracker::REQ_LOG_SUBSCRIPTION; break; } case (startracker::ID::DEBUG_CAMERA): { *foundId = startracker::REQ_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 (startracker::ID::VERSION): { *foundId = startracker::REQ_VERSION; break; } case (startracker::ID::INTERFACE): { *foundId = startracker::REQ_INTERFACE; break; } case (startracker::ID::POWER): { *foundId = startracker::REQ_POWER; break; } case (startracker::ID::TEMPERATURE): { *foundId = startracker::REQ_TEMPERATURE; break; } case (startracker::ID::HISTOGRAM): { *foundId = startracker::REQ_HISTOGRAM; break; } case (startracker::ID::CONTRAST): { *foundId = startracker::REQ_CONTRAST; break; } case (startracker::ID::TIME): { *foundId = startracker::REQ_TIME; break; } case (startracker::ID::SOLUTION): { *foundId = startracker::REQ_SOLUTION; break; } default: { sif::debug << "StarTrackerHandler::scanForTmReply: Reply contains invalid reply id: " << static_cast(*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::executeFlashReadCommand(const uint8_t* commandData, size_t commandDataLen) { ReturnValue_t result = RETURN_OK; if (commandDataLen < ReadCmd::MIN_LENGTH) { sif::warning << "StarTrackerHandler::executeFlashReadCommand: Command too short" << std::endl; return COMMAND_TOO_SHORT; } uint8_t startRegion = *(commandData); uint32_t length; size_t size = sizeof(length); const uint8_t* lengthPtr = commandData + sizeof(startRegion); result = SerializeAdapter::deSerialize(&length, lengthPtr, &size, SerializeIF::Endianness::BIG); if (result != RETURN_OK) { sif::debug << "StarTrackerHandler::executeFlashReadCommand: Deserialization of length failed" << std::endl; return result; } if (commandDataLen - sizeof(startRegion) - sizeof(length) > MAX_PATH_SIZE) { sif::warning << "StarTrackerHandler::executeFlashReadCommand: Received command with invalid" << " path and filename" << std::endl; return FILE_PATH_TOO_LONG; } const uint8_t* filePtr = commandData + sizeof(startRegion) + sizeof(length); std::string fullname = std::string(reinterpret_cast(filePtr), commandDataLen - sizeof(startRegion) - sizeof(length)); result = strHelper->startFlashRead(fullname, startRegion, 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(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(startracker::UploadCentroidKeys::id, &req.id); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::id << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::pixx, &req.pixx); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::pixx << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::pixy, &req.pixy); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::pixy << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::x_uncorrected, &req.x_uncorrected); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::x_uncorrected << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::y_uncorrected, &req.y_uncorrected); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::y_uncorrected << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::x_corrected, &req.x_corrected); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::x_corrected << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::y_corrected, &req.y_corrected); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::y_corrected << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::magnitude, &req.magnitude); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::magnitude << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::cxa, &req.cxa); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::cxa << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::cya, &req.cya); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::cya << " does not exist" << std::endl; return result; } result = j.getValue(startracker::UploadCentroidKeys::quality, &req.quality); if (result != RETURN_OK) { sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " << startracker::UploadCentroidKeys::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(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 != startracker::STATUS_OK) { sif::warning << "StarTrackerHandler::handleSetParamReply: Failed to execute parameter set " " command with parameter ID" << static_cast(*(reply + PARAMETER_ID_OFFSET)) << std::endl; if (internalState != InternalState::IDLE) { internalState = InternalState::IDLE; } return SET_PARAM_FAILED; } if (internalState != InternalState::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 != startracker::STATUS_OK) { sif::warning << "StarTrackerHandler::handleActionReply: Failed to execute action " << "command with action ID " << static_cast(*(reply + ACTION_ID_OFFSET)) << " and status " << static_cast(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; startracker::EraseReply 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; startracker::ChecksumReply 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, startracker::CHECKSUM); #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(status) << std::endl; sif::info << "Ping id: 0x" << std::hex << pingId << std::endl; #endif /* OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1 */ if (status != startracker::STATUS_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 startracker::Program::BOOTLOADER: if (startupState == StartupState::WAIT_CHECK_PROGRAM) { startupState = StartupState::DONE; } if (internalState == InternalState::VERIFY_BOOT) { sif::warning << "StarTrackerHandler::checkProgram: Failed to boot firmware" << std::endl; // Device handler will run into timeout and fall back to transition source mode triggerEvent(BOOTING_FIRMWARE_FAILED); internalState = InternalState::FAILED_FIRMWARE_BOOT; } else if (internalState == InternalState::BOOTLOADER_CHECK) { internalState = InternalState::DONE; } break; case startracker::Program::FIRMWARE: if (startupState == StartupState::WAIT_CHECK_PROGRAM) { startupState = StartupState::BOOT_BOOTLOADER; } if (internalState == InternalState::VERIFY_BOOT) { internalState = InternalState::LOGLEVEL; } else if (internalState == InternalState::BOOTLOADER_CHECK) { triggerEvent(BOOTING_BOOTLOADER_FAILED); internalState = InternalState::BOOTING_BOOTLOADER_FAILED; } 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 != startracker::STATUS_OK) { sif::warning << "StarTrackerHandler::handleTm: Reply error: " << static_cast(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 != startracker::STATUS_OK) { sif::warning << "StarTrackerHandler::handleActionReplySet: Reply error: " << static_cast(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 (startracker::ID::LOG_LEVEL): { internalState = InternalState::LIMITS; break; } case (startracker::ID::LIMITS): { internalState = InternalState::TRACKING; break; } case (startracker::ID::TRACKING): { internalState = InternalState::MOUNTING; break; } case (startracker::ID::MOUNTING): { internalState = InternalState::IMAGE_PROCESSOR; break; } case (startracker::ID::IMAGE_PROCESSOR): { internalState = InternalState::CAMERA; break; } case (startracker::ID::CAMERA): { internalState = InternalState::CENTROIDING; break; } case (startracker::ID::CENTROIDING): { internalState = InternalState::LISA; break; } case (startracker::ID::LISA): { internalState = InternalState::MATCHING; break; } case (startracker::ID::MATCHING): { internalState = InternalState::VALIDATION; break; } case (startracker::ID::VALIDATION): { internalState = InternalState::ALGO; break; } case (startracker::ID::ALGO): { internalState = InternalState::LOG_SUBSCRIPTION; break; } case (startracker::ID::LOG_SUBSCRIPTION): { internalState = InternalState::DEBUG_CAMERA; break; } case (startracker::ID::DEBUG_CAMERA): { internalState = InternalState::DONE; break; } default: { sif::debug << "StarTrackerHandler::handleStartup: Received parameter reply with unexpected" << " parameter ID" << std::endl; break; } } } ReturnValue_t StarTrackerHandler::checkCommand(ActionId_t actionId) { switch (actionId) { case startracker::REQ_INTERFACE: case startracker::REQ_TIME: case startracker::SWITCH_TO_BOOTLOADER_PROGRAM: case startracker::DOWNLOAD_IMAGE: case startracker::UPLOAD_IMAGE: case startracker::REQ_POWER: case startracker::TAKE_IMAGE: case startracker::DOWNLOAD_CENTROID: case startracker::UPLOAD_CENTROID: case startracker::REQ_SOLUTION: case startracker::REQ_TEMPERATURE: case startracker::REQ_HISTOGRAM: case startracker::REQ_CONTRAST: case startracker::DOWNLOAD_MATCHED_STAR: case startracker::DOWNLOAD_DBIMAGE: case startracker::DOWNLOAD_BLOBPIXEL: if (!(mode == MODE_ON && submode == startracker::Program::FIRMWARE)) { return STARTRACKER_RUNNING_BOOTLOADER; } break; case startracker::FIRMWARE_UPDATE: if (!(mode == MODE_ON && submode == startracker::Program::BOOTLOADER)) { return STARTRACKER_RUNNING_FIRMWARE; } break; default: break; } return RETURN_OK; }