eive-obsw/linux/devices/startracker/StarTrackerHandler.cpp
Robin Mueller 32def71502
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit
first version of ACS board ASS working
- Testes transition OFF to NORMAL for A side
- Refactored power switching so it can be used by SUS ass as well
- Generate events for sending switch command
- Generate event if switch state changes
- Deny Q7S switch commanding
2022-03-05 03:02:09 +01:00

2075 lines
83 KiB
C++

#include "StarTrackerHandler.h"
#include <fsfw/ipc/QueueFactory.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"
}
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),
checksumSet(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::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<const char*>(data), size);
return EXECUTION_FINISHED;
}
case (startracker::DISABLE_TIMESTAMP_GENERATION):
strHelper->disableTimestamping();
return EXECUTION_FINISHED;
case (startracker::ENABLE_TIMESTAMP_GENERATION):
strHelper->enableTimestamping();
return EXECUTION_FINISHED;
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<const char*>(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<const char*>(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_IMAGE_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 (startracker::SET_FLASH_READ_FILENAME): {
if (size > MAX_FILE_NAME) {
return FILENAME_TOO_LONG;
}
strHelper->setFlashReadFilename(std::string(reinterpret_cast<const char*>(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<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;
}
}
}
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;
normalState = NormalState::SOLUTION_REQUEST;
break;
case NormalState::SOLUTION_REQUEST:
*id = startracker::REQ_SOLUTION;
normalState = NormalState::TEMPERATURE_REQUEST;
break;
default:
sif::debug << "StarTrackerHandler::buildNormalDeviceCommand: Invalid normal step"
<< std::endl;
return NOTHING_TO_SEND;
}
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<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::LIMITS:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::LIMITS;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::TRACKING:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::TRACKING;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::MOUNTING:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::MOUNTING;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::IMAGE_PROCESSOR:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::IMAGE_PROCESSOR;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::CAMERA:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::CAMERA;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::CENTROIDING:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::CENTROIDING;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::LISA:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::LISA;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::MATCHING:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::MATCHING;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::VALIDATION:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::VALIDATION;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::ALGO:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::ALGO;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::LOG_SUBSCRIPTION:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::LOGSUBSCRIPTION;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(paramJsonFile.c_str()),
paramJsonFile.size());
case InternalState::DEBUG_CAMERA:
internalState = InternalState::WAIT_FOR_EXECUTION;
*id = startracker::DEBUG_CAMERA;
return buildCommandFromCommand(*id, reinterpret_cast<const uint8_t*>(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): {
prepareSwitchToBootloaderCmd();
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::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::CHECKSUM): {
result = prepareChecksumCommand(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::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::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::CHECKSUM, 3, &checksumSet,
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, &centroidingSet,
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_RETVAL;
}
}
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):
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::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) {
return DEFAULT_TRANSITION_DELAY;
}
ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(startracker::TICKS_TIME_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::TIME_TIME_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startracker::RUN_TIME, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::UNIX_TIME, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startracker::TICKS_VERSION_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::TIME_VERSION_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startracker::PROGRAM, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::MAJOR, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::MINOR, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::TICKS_INTERFACE_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::TIME_INTERFACE_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startracker::FRAME_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::CHECKSUM_ERROR_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::SET_PARAM_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::SET_PARAM_REPLY_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::PARAM_REQUEST_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::PARAM_REPLY_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::REQ_TM_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::TM_REPLY_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::ACTION_REQ_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::ACTION_REPLY_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::TICKS_POWER_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::TIME_POWER_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startracker::MCU_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::MCU_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::FPGA_CORE_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::FPGA_CORE_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::FPGA_18_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::FPGA_18_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::FPGA_25_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::FPGA_25_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CMV_21_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CMV_21_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CMV_PIX_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CMV_PIX_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CMV_33_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CMV_33_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CMV_RES_CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CMV_RES_VOLTAGE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TICKS_TEMPERATURE_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::TIME_TEMPERATURE_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startracker::MCU_TEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CMOS_TEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::FPGA_TEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TICKS_SOLUTION_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::TIME_SOLUTION_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startracker::CALI_QW, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CALI_QX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CALI_QY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CALI_QZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACK_CONFIDENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACK_QW, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACK_QX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACK_QY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACK_QZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACK_REMOVED, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::STARS_CENTROIDED, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::STARS_MATCHED_DATABASE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LISA_QW, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_QX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_QY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_QZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_PERC_CLOSE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_NR_CLOSE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::TRUST_WORTHY, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::STABLE_COUNT, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::SOLUTION_STRATEGY, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::TICKS_HISTOGRAM_SET, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::TIME_HISTOGRAM_SET, new PoolEntry<uint64_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINA0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINA1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINA2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINA3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINA4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINA5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINA6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINA7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINA8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINB0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINB1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINB2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINB3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINB4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINB5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINB6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINB7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINB8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINC0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINC1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINC2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINC3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINC4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINC5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINC6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINC7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BINC8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BIND0, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BIND1, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BIND2, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BIND3, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BIND4, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BIND5, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BIND6, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BIND7, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::HISTOGRAM_BIND8, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::CAMERA_MODE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::FOCALLENGTH, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::EXPOSURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::INTERVAL, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CAMERA_OFFSET, new PoolEntry<int16_t>({0}));
localDataPoolMap.emplace(startracker::PGAGAIN, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::ADCGAIN, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_REG1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_VAL1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_REG2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_VAL2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_REG3, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_VAL3, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_REG4, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_VAL4, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_REG5, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_VAL5, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_REG6, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_VAL6, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_REG7, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_VAL7, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_REG8, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_VAL8, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CAM_FREQ_1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LIMITS_ACTION, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LIMITS_FPGA18CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LIMITS_FPGA25CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LIMITS_FPGA10CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LIMITS_MCUCURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LIMITS_CMOS21CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LIMITS_CMOSPIXCURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LIMITS_CMOS33CURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LIMITS_CMOSVRESCURRENT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LIMITS_CMOSTEMPERATURE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL3, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL4, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL5, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL6, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL7, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL8, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL9, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL10, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL11, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL12, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL13, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL14, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL15, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOGLEVEL16, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::MOUNTING_QW, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::MOUNTING_QX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::MOUNTING_QY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::MOUNTING_QZ, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_MODE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_STORE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_SIGNALTHRESHOLD,
new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_DARKTHRESHOLD,
new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_BACKGROUNDCOMPENSATION,
new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_ENABLE_FILTER, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_MAX_QUALITY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_DARK_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_MIN_QUALITY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_MAX_INTENSITY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_MIN_INTENSITY, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_MAX_MAGNITUDE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_GAUSSIAN_CMAX, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_GAUSSIAN_CMIN, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_TRANSMATRIX00, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_TRANSMATRIX01, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_TRANSMATRIX10, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_TRANSMATRIX11, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_MODE, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::LISA_PREFILTER_DIST_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_PREFILTER_ANGLE_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_FOV_WIDTH, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_FOV_HEIGHT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_FLOAT_STAR_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_CLOSE_STAR_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_CLOSE_STAR_COUNT,
new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_FRACTION_CLOSE,
new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_MEAN_SUM, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_DB_STAR_COUNT,
new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_MAX_COMBINATIONS, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LISA_NR_STARS_STOP, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LISA_FRACTION_CLOSE_STOP, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::MATCHING_SQUARED_DISTANCE_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::MATCHING_SQUARED_SHIFT_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACKING_THIN_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACKING_OUTLIER_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACKING_OUTLIER_THRESHOLD_QUEST,
new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACKING_TRACKER_CHOICE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::VALIDATION_STABLE_COUNT, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::VALIDATION_MAX_DIFFERENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::VALIDATION_MIN_TRACKER_CONFIDENCE,
new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::VALIDATION_MIN_MATCHED_STARS, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::ALGO_MODE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::ALGO_I2T_MIN_CONFIDENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::ALGO_I2T_MIN_MATCHED, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::ALGO_I2L_MIN_CONFIDENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::ALGO_I2L_MIN_MATCHED, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM3, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM4, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM5, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM6, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM7, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM8, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM9, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM10, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM11, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM12, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM13, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM14, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM15, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::SUBSCRIPTION_TM16, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOG_SUBSCRIPTION_LEVEL1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOG_SUBSCRIPTION_MODULE1, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOG_SUBSCRIPTION_LEVEL2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LOG_SUBSCRIPTION_MODULE2, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::DEBUG_CAMERA_TIMING, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::DEBUG_CAMERA_TEST, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::CHKSUM, new PoolEntry<uint32_t>({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::CHECKSUM): {
*foundId = startracker::CHECKSUM;
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::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<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::executeFlashReadCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
if (commandDataLen < FlashReadCmd::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<const char*>(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::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;
}
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::prepareSwitchToBootloaderCmd() {
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();
}
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::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<unsigned int>(*(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<unsigned int>(*(reply + ACTION_ID_OFFSET)) << " and status "
<< static_cast<unsigned int>(status) << std::endl;
return ACTION_FAILED;
}
return RETURN_OK;
}
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<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 != 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<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 != startracker::STATUS_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 (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::REQ_SOLUTION:
case startracker::REQ_TEMPERATURE:
case startracker::REQ_HISTOGRAM:
case startracker::REQ_CAMERA:
case startracker::REQ_LIMITS:
case startracker::REQ_LOG_LEVEL:
case startracker::REQ_MOUNTING:
case startracker::REQ_IMAGE_PROCESSOR:
case startracker::REQ_CENTROIDING:
case startracker::REQ_LISA:
case startracker::REQ_MATCHING:
case startracker::REQ_TRACKING:
case startracker::REQ_VALIDATION:
case startracker::REQ_ALGO:
case startracker::REQ_SUBSCRIPTION:
case startracker::REQ_LOG_SUBSCRIPTION:
case startracker::REQ_DEBUG_CAMERA:
if (not(mode == MODE_ON && submode == startracker::Program::FIRMWARE)) {
return STARTRACKER_RUNNING_BOOTLOADER;
}
break;
case startracker::FIRMWARE_UPDATE:
case startracker::FLASH_READ:
if (not(mode == MODE_ON && submode == startracker::Program::BOOTLOADER)) {
return STARTRACKER_RUNNING_FIRMWARE;
}
break;
default:
break;
}
return RETURN_OK;
}