star tracker flash read

This commit is contained in:
Jakob Meier 2022-02-25 14:24:51 +01:00
parent 3593f5ab8c
commit e082f3973a
8 changed files with 2285 additions and 2291 deletions

View File

@ -1,8 +1,6 @@
#include "ObjectFactory.h" #include "ObjectFactory.h"
#include <devConf.h> #include <devConf.h>
#include <fsfw/src/fsfw/osal/common/TcpTmTcBridge.h>
#include <fsfw/src/fsfw/osal/common/TcpTmTcServer.h>
#include <fsfw_hal/linux/uart/UartComIF.h> #include <fsfw_hal/linux/uart/UartComIF.h>
#include <fsfw_hal/linux/uart/UartCookie.h> #include <fsfw_hal/linux/uart/UartCookie.h>
#include <mission/devices/GPSHyperionHandler.h> #include <mission/devices/GPSHyperionHandler.h>

View File

@ -7,7 +7,7 @@
#include "fsfw/tasks/TaskFactory.h" #include "fsfw/tasks/TaskFactory.h"
/** /**
* @brief This is the main program and entry point for the egse (raspberry pi 4) * @brief This is the main program entry point for the egse (raspberry pi 4)
* @return * @return
*/ */
int main(void) { int main(void) {

2
fsfw

@ -1 +1 @@
Subproject commit 3c06d2dbbb0d79608e003a8a3c89ae90cc71f409 Subproject commit 09c1918c1fe36a07ce611a33ff20799187d8d962

View File

@ -371,7 +371,7 @@ static const DeviceCommandId_t TRACKING = 47;
static const DeviceCommandId_t VALIDATION = 48; static const DeviceCommandId_t VALIDATION = 48;
static const DeviceCommandId_t ALGO = 49; static const DeviceCommandId_t ALGO = 49;
static const DeviceCommandId_t CHECKSUM = 50; static const DeviceCommandId_t CHECKSUM = 50;
static const DeviceCommandId_t READ = 51; static const DeviceCommandId_t FLASH_READ = 51;
static const DeviceCommandId_t DOWNLOAD_MATCHED_STAR = 53; static const DeviceCommandId_t DOWNLOAD_MATCHED_STAR = 53;
static const DeviceCommandId_t STOP_IMAGE_LOADER = 55; static const DeviceCommandId_t STOP_IMAGE_LOADER = 55;
static const DeviceCommandId_t RESET_ERROR = 56; static const DeviceCommandId_t RESET_ERROR = 56;

View File

@ -19,14 +19,36 @@ extern "C" {
using json = nlohmann::json; using json = nlohmann::json;
StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
StrHelper* strHelper) : StrHelper* strHelper)
DeviceHandlerBase(objectId, comIF, comCookie), temperatureSet(this), versionSet(this), powerSet( : DeviceHandlerBase(objectId, comIF, comCookie),
this), interfaceSet(this), timeSet(this), solutionSet(this), histogramSet(this), contrastSet( temperatureSet(this),
this), checksumSet(this), downloadCentroidSet(this), downloadMatchedStar(this), downloadDbImage( versionSet(this),
this), downloadBlobPixel(this), cameraSet(this), limitsSet(this), loglevelSet(this), mountingSet( powerSet(this),
this), imageProcessorSet(this), centroidingSet(this), lisaSet(this), matchingSet( interfaceSet(this),
this), trackingSet(this), validationSet(this), algoSet(this), subscriptionSet(this), logSubscriptionSet( timeSet(this),
this), debugCameraSet(this), strHelper(strHelper) { 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) { if (comCookie == nullptr) {
sif::error << "StarTrackerHandler: Invalid com cookie" << std::endl; sif::error << "StarTrackerHandler: Invalid com cookie" << std::endl;
} }
@ -36,8 +58,7 @@ StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF,
eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5); eventQueue = QueueFactory::instance()->createMessageQueue(EventMessage::EVENT_MESSAGE_SIZE * 5);
} }
StarTrackerHandler::~StarTrackerHandler() { StarTrackerHandler::~StarTrackerHandler() {}
}
ReturnValue_t StarTrackerHandler::initialize() { ReturnValue_t StarTrackerHandler::initialize() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
@ -46,13 +67,13 @@ ReturnValue_t StarTrackerHandler::initialize() {
return result; return result;
} }
EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>( EventManagerIF* manager = ObjectManager::instance()->get<EventManagerIF>(objects::EVENT_MANAGER);
objects::EVENT_MANAGER);
if (manager == nullptr) { if (manager == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "StarTrackerHandler::initialize: Invalid event manager" << std::endl; sif::error << "StarTrackerHandler::initialize: Invalid event manager" << std::endl;
#endif #endif
return ObjectManagerIF::CHILD_INIT_FAILED;; return ObjectManagerIF::CHILD_INIT_FAILED;
;
} }
result = manager->registerListener(eventQueue->getId()); result = manager->registerListener(eventQueue->getId());
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -128,8 +149,7 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
if (size > MAX_PATH_SIZE + MAX_FILE_NAME) { if (size > MAX_PATH_SIZE + MAX_FILE_NAME) {
return FILE_PATH_TOO_LONG; return FILE_PATH_TOO_LONG;
} }
result = strHelper->startImageUpload( result = strHelper->startImageUpload(std::string(reinterpret_cast<const char*>(data), size));
std::string(reinterpret_cast<const char*>(data), size));
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
@ -144,20 +164,20 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
if (size > MAX_PATH_SIZE) { if (size > MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG; return FILE_PATH_TOO_LONG;
} }
result = strHelper->startImageDownload( result =
std::string(reinterpret_cast<const char*>(data), size)); strHelper->startImageDownload(std::string(reinterpret_cast<const char*>(data), size));
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
strHelperExecuting = true; strHelperExecuting = true;
return EXECUTION_FINISHED; return EXECUTION_FINISHED;
} }
case (startracker::READ): { case (startracker::FLASH_READ): {
result = DeviceHandlerBase::acceptExternalDeviceCommands(); result = DeviceHandlerBase::acceptExternalDeviceCommands();
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
result = executeReadCommand(data, size); result = executeFlashReadCommand(data, size);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
@ -186,8 +206,8 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
if (size > MAX_PATH_SIZE + MAX_FILE_NAME) { if (size > MAX_PATH_SIZE + MAX_FILE_NAME) {
return FILE_PATH_TOO_LONG; return FILE_PATH_TOO_LONG;
} }
result = strHelper->startFirmwareUpdate( result =
std::string(reinterpret_cast<const char*>(data), size)); strHelper->startFirmwareUpdate(std::string(reinterpret_cast<const char*>(data), size));
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
@ -202,8 +222,8 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
void StarTrackerHandler::performOperationHook() { void StarTrackerHandler::performOperationHook() {
EventMessage event; EventMessage event;
for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == RETURN_OK; result = for (ReturnValue_t result = eventQueue->receiveMessage(&event); result == RETURN_OK;
eventQueue->receiveMessage(&event)) { result = eventQueue->receiveMessage(&event)) {
switch (event.getMessageId()) { switch (event.getMessageId()) {
case EventMessage::EVENT_MESSAGE: case EventMessage::EVENT_MESSAGE:
handleEvent(&event); handleEvent(&event);
@ -216,6 +236,8 @@ void StarTrackerHandler::performOperationHook() {
} }
} }
Submode_t StarTrackerHandler::getInitialSubmode() { return SUBMODE_BOOTLOADER; }
void StarTrackerHandler::doStartUp() { void StarTrackerHandler::doStartUp() {
switch (startupState) { switch (startupState) {
case StartupState::IDLE: case StartupState::IDLE:
@ -242,6 +264,7 @@ void StarTrackerHandler::doShutDown() {
} }
void StarTrackerHandler::doOffActivity() { void StarTrackerHandler::doOffActivity() {
startupState = StartupState::IDLE;
internalState = InternalState::IDLE; internalState = InternalState::IDLE;
} }
@ -363,7 +386,8 @@ ReturnValue_t StarTrackerHandler::buildTransitionDeviceCommand(DeviceCommandId_t
} }
ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand, ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t* commandData, size_t commandDataLen) { const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
switch (deviceCommand) { switch (deviceCommand) {
case (startracker::PING_REQUEST): { case (startracker::PING_REQUEST): {
@ -1015,8 +1039,7 @@ ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id,
return result; return result;
} }
void StarTrackerHandler::setNormalDatapoolEntriesInvalid() { void StarTrackerHandler::setNormalDatapoolEntriesInvalid() {}
}
uint32_t StarTrackerHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { uint32_t StarTrackerHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
// if (modeTo == MODE_ON && (submode == SUBMODE_NONE || submode == SUBMODE_BOOTLOADER)) { // if (modeTo == MODE_ON && (submode == SUBMODE_NONE || submode == SUBMODE_BOOTLOADER)) {
@ -1214,8 +1237,7 @@ ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& l
localDataPoolMap.emplace(startracker::BLOBPIX_Y, new PoolEntry<uint32_t>({0})); localDataPoolMap.emplace(startracker::BLOBPIX_Y, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::BLOBPIX_TOT_VAL, new PoolEntry<uint32_t>({0})); localDataPoolMap.emplace(startracker::BLOBPIX_TOT_VAL, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::BLOBPIX_IN_USE, new PoolEntry<uint8_t>({0})); localDataPoolMap.emplace(startracker::BLOBPIX_IN_USE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::BLOBPIX_BRIGHT_NEIGHBOURS, localDataPoolMap.emplace(startracker::BLOBPIX_BRIGHT_NEIGHBOURS, new PoolEntry<uint32_t>({0}));
new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(startracker::BLOBPIX_REGION, new PoolEntry<uint32_t>({0})); localDataPoolMap.emplace(startracker::BLOBPIX_REGION, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::CAMERA_MODE, new PoolEntry<uint8_t>({0})); localDataPoolMap.emplace(startracker::CAMERA_MODE, new PoolEntry<uint8_t>({0}));
@ -1280,13 +1302,12 @@ ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& l
localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_STORE, new PoolEntry<uint8_t>({0})); localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_STORE, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_SIGNALTHRESHOLD, localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_SIGNALTHRESHOLD,
new PoolEntry<uint16_t>({0})); new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_DARKTHRESHOLD, new PoolEntry<uint16_t>( { localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_DARKTHRESHOLD,
0 })); new PoolEntry<uint16_t>({0}));
localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_BACKGROUNDCOMPENSATION, localDataPoolMap.emplace(startracker::IMAGE_PROCESSOR_BACKGROUNDCOMPENSATION,
new PoolEntry<uint8_t>({0})); new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_ENABLE_FILTER, localDataPoolMap.emplace(startracker::CENTROIDING_ENABLE_FILTER, new PoolEntry<uint8_t>({0}));
new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(startracker::CENTROIDING_MAX_QUALITY, new PoolEntry<float>({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_DARK_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::CENTROIDING_MIN_QUALITY, new PoolEntry<float>({0})); localDataPoolMap.emplace(startracker::CENTROIDING_MIN_QUALITY, new PoolEntry<float>({0}));
@ -1301,43 +1322,37 @@ ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& l
localDataPoolMap.emplace(startracker::CENTROIDING_TRANSMATRIX11, 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_MODE, new PoolEntry<uint32_t>({0}));
localDataPoolMap.emplace(startracker::LISA_PREFILTER_DIST_THRESHOLD, localDataPoolMap.emplace(startracker::LISA_PREFILTER_DIST_THRESHOLD, new PoolEntry<float>({0}));
new PoolEntry<float>( { 0 })); localDataPoolMap.emplace(startracker::LISA_PREFILTER_ANGLE_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_WIDTH, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_FOV_HEIGHT, 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_FLOAT_STAR_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_CLOSE_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, localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_CLOSE_STAR_COUNT,
new PoolEntry<float>({0})); new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_FRACTION_CLOSE, new PoolEntry<float>( { localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_FRACTION_CLOSE,
0 })); new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::LISA_RATING_WEIGHT_MEAN_SUM, 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})); 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_MAX_COMBINATIONS, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::LISA_NR_STARS_STOP, 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::LISA_FRACTION_CLOSE_STOP, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::MATCHING_SQUARED_DISTANCE_LIMIT, localDataPoolMap.emplace(startracker::MATCHING_SQUARED_DISTANCE_LIMIT, new PoolEntry<float>({0}));
new PoolEntry<float>( { 0 })); localDataPoolMap.emplace(startracker::MATCHING_SQUARED_SHIFT_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_THIN_LIMIT, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACKING_OUTLIER_THRESHOLD, new PoolEntry<float>({0})); localDataPoolMap.emplace(startracker::TRACKING_OUTLIER_THRESHOLD, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACKING_OUTLIER_THRESHOLD_QUEST, new PoolEntry<float>( { localDataPoolMap.emplace(startracker::TRACKING_OUTLIER_THRESHOLD_QUEST,
0 })); new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::TRACKING_TRACKER_CHOICE, new PoolEntry<uint8_t>({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_STABLE_COUNT, new PoolEntry<uint8_t>({0}));
localDataPoolMap.emplace(startracker::VALIDATION_MAX_DIFFERENCE, new PoolEntry<float>({0})); localDataPoolMap.emplace(startracker::VALIDATION_MAX_DIFFERENCE, new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::VALIDATION_MIN_TRACKER_CONFIDENCE, new PoolEntry<float>( { localDataPoolMap.emplace(startracker::VALIDATION_MIN_TRACKER_CONFIDENCE,
0 })); new PoolEntry<float>({0}));
localDataPoolMap.emplace(startracker::VALIDATION_MIN_MATCHED_STARS, localDataPoolMap.emplace(startracker::VALIDATION_MIN_MATCHED_STARS, new PoolEntry<uint8_t>({0}));
new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(startracker::ALGO_MODE, 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_CONFIDENCE, new PoolEntry<float>({0}));
@ -1388,7 +1403,7 @@ ReturnValue_t StarTrackerHandler::checkMode(ActionId_t actionId) {
switch (actionId) { switch (actionId) {
case startracker::UPLOAD_IMAGE: case startracker::UPLOAD_IMAGE:
case startracker::DOWNLOAD_IMAGE: case startracker::DOWNLOAD_IMAGE:
case startracker::READ: case startracker::FLASH_READ:
case startracker::FIRMWARE_UPDATE: { case startracker::FIRMWARE_UPDATE: {
return DeviceHandlerBase::acceptExternalDeviceCommands(); return DeviceHandlerBase::acceptExternalDeviceCommands();
default: default:
@ -1655,48 +1670,37 @@ void StarTrackerHandler::handleEvent(EventMessage* eventMessage) {
break; break;
} }
default: default:
sif::debug << "StarTrackerHandler::handleEvent: Did not subscribe to this event" sif::debug << "StarTrackerHandler::handleEvent: Did not subscribe to this event" << std::endl;
<< std::endl;
break; break;
} }
} }
ReturnValue_t StarTrackerHandler::executeReadCommand(const uint8_t* commandData, ReturnValue_t StarTrackerHandler::executeFlashReadCommand(const uint8_t* commandData,
size_t commandDataLen) { size_t commandDataLen) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
if (commandDataLen < ReadCmd::MIN_LENGTH) { if (commandDataLen < ReadCmd::MIN_LENGTH) {
sif::warning << "StarTrackerHandler::executeReadCommand: Command too short" << std::endl; sif::warning << "StarTrackerHandler::executeFlashReadCommand: Command too short" << std::endl;
return COMMAND_TOO_SHORT; return COMMAND_TOO_SHORT;
} }
uint8_t region = *(commandData); uint8_t startRegion = *(commandData);
uint32_t address;
size_t size = sizeof(address);
const uint8_t* addressPtr = commandData + ReadCmd::ADDRESS_OFFSET;
result = SerializeAdapter::deSerialize(&address, addressPtr, &size,
SerializeIF::Endianness::BIG);
if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::executeReadCommand: Deserialization of address failed"
<< std::endl;
return result;
}
uint32_t length; uint32_t length;
size = sizeof(length); size_t size = sizeof(length);
const uint8_t* lengthPtr = commandData + ReadCmd::LENGTH_OFFSET; const uint8_t* lengthPtr = commandData + sizeof(startRegion);
result = SerializeAdapter::deSerialize(&length, lengthPtr, &size, SerializeIF::Endianness::BIG); result = SerializeAdapter::deSerialize(&length, lengthPtr, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::executeReadCommand: Deserialization of length failed" sif::debug << "StarTrackerHandler::executeFlashReadCommand: Deserialization of length failed"
<< std::endl; << std::endl;
return result; return result;
} }
if (commandDataLen - sizeof(address) - sizeof(region) - sizeof(length) > MAX_PATH_SIZE) { if (commandDataLen - sizeof(startRegion) - sizeof(length) > MAX_PATH_SIZE) {
sif::warning << "StarTrackerHandler::executeReadCommand: Received command with invalid" sif::warning << "StarTrackerHandler::executeFlashReadCommand: Received command with invalid"
<< " path and filename" << std::endl; << " path and filename" << std::endl;
return FILE_PATH_TOO_LONG; return FILE_PATH_TOO_LONG;
} }
const uint8_t* filePtr = commandData + ReadCmd::FILE_OFFSET; const uint8_t* filePtr = commandData + sizeof(startRegion) + sizeof(length);
std::string fullname = std::string(reinterpret_cast<const char*>(filePtr), std::string fullname = std::string(reinterpret_cast<const char*>(filePtr),
commandDataLen - sizeof(address) - sizeof(region) - sizeof(length)); commandDataLen - sizeof(startRegion) - sizeof(length));
result = strHelper->startFlashRead(fullname, region, address, length); result = strHelper->startFlashRead(fullname, startRegion, length);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
@ -1737,8 +1741,7 @@ ReturnValue_t StarTrackerHandler::prepareUnlockCommand(const uint8_t* commandDat
req.region = *commandData; req.region = *commandData;
size_t size = sizeof(req.code); size_t size = sizeof(req.code);
const uint8_t* codePtr = commandData + UnlockCmd::CODE_OFFSET; const uint8_t* codePtr = commandData + UnlockCmd::CODE_OFFSET;
result = SerializeAdapter::deSerialize(&req.code, &codePtr, &size, result = SerializeAdapter::deSerialize(&req.code, &codePtr, &size, SerializeIF::Endianness::BIG);
SerializeIF::Endianness::BIG);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
} }
@ -1760,8 +1763,8 @@ ReturnValue_t StarTrackerHandler::prepareChecksumCommand(const uint8_t* commandD
req.region = *(commandData); req.region = *(commandData);
size_t size = sizeof(req.address); size_t size = sizeof(req.address);
const uint8_t* addressPtr = commandData + ChecksumCmd::ADDRESS_OFFSET; const uint8_t* addressPtr = commandData + ChecksumCmd::ADDRESS_OFFSET;
result = SerializeAdapter::deSerialize(&req.address, addressPtr, &size, result =
SerializeIF::Endianness::BIG); SerializeAdapter::deSerialize(&req.address, addressPtr, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::prepareChecksumCommand: Deserialization of address " sif::debug << "StarTrackerHandler::prepareChecksumCommand: Deserialization of address "
<< "failed" << std::endl; << "failed" << std::endl;
@ -1769,8 +1772,8 @@ ReturnValue_t StarTrackerHandler::prepareChecksumCommand(const uint8_t* commandD
} }
size = sizeof(req.length); size = sizeof(req.length);
const uint8_t* lengthPtr = commandData + ChecksumCmd::LENGTH_OFFSET; const uint8_t* lengthPtr = commandData + ChecksumCmd::LENGTH_OFFSET;
result = SerializeAdapter::deSerialize(&req.length, lengthPtr, &size, result =
SerializeIF::Endianness::BIG); SerializeAdapter::deSerialize(&req.length, lengthPtr, &size, SerializeIF::Endianness::BIG);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::prepareChecksumCommand: Deserialization of length failed" sif::debug << "StarTrackerHandler::prepareChecksumCommand: Deserialization of length failed"
<< std::endl; << std::endl;
@ -1799,8 +1802,7 @@ ReturnValue_t StarTrackerHandler::prepareSetTimeCommand(const uint8_t* commandDa
result = SerializeAdapter::deSerialize(&req.unixTime, commandData, &size, result = SerializeAdapter::deSerialize(&req.unixTime, commandData, &size,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::debug << "StarTrackerHandler::prepareSetTimeCommand: Deserialization failed" sif::debug << "StarTrackerHandler::prepareSetTimeCommand: Deserialization failed" << std::endl;
<< std::endl;
return result; return result;
} }
uint32_t length = 0; uint32_t length = 0;
@ -1836,8 +1838,8 @@ ReturnValue_t StarTrackerHandler::prepareUploadCentroidCommand(const uint8_t* co
} }
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
struct UploadCentroidActionRequest req; struct UploadCentroidActionRequest req;
std::string jsonFileName = std::string(reinterpret_cast<const char*>(commandData), std::string jsonFileName =
commandDataLen); std::string(reinterpret_cast<const char*>(commandData), commandDataLen);
NVMParameterBase j(jsonFileName); NVMParameterBase j(jsonFileName);
result = j.readJsonFile(); result = j.readJsonFile();
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -1866,13 +1868,15 @@ ReturnValue_t StarTrackerHandler::prepareUploadCentroidCommand(const uint8_t* co
result = j.getValue(startracker::UploadCentroidKeys::x_uncorrected, &req.x_uncorrected); result = j.getValue(startracker::UploadCentroidKeys::x_uncorrected, &req.x_uncorrected);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startracker::UploadCentroidKeys::x_uncorrected << " does not exist" << std::endl; << startracker::UploadCentroidKeys::x_uncorrected << " does not exist"
<< std::endl;
return result; return result;
} }
result = j.getValue(startracker::UploadCentroidKeys::y_uncorrected, &req.y_uncorrected); result = j.getValue(startracker::UploadCentroidKeys::y_uncorrected, &req.y_uncorrected);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key " sif::warning << "StarTrackerHandler::prepareUploadCentroidCommand: The key "
<< startracker::UploadCentroidKeys::y_uncorrected << " does not exist" << std::endl; << startracker::UploadCentroidKeys::y_uncorrected << " does not exist"
<< std::endl;
return result; return result;
} }
result = j.getValue(startracker::UploadCentroidKeys::x_corrected, &req.x_corrected); result = j.getValue(startracker::UploadCentroidKeys::x_corrected, &req.x_corrected);
@ -2022,7 +2026,8 @@ void StarTrackerHandler::prepareErrorResetRequest() {
} }
ReturnValue_t StarTrackerHandler::prepareParamCommand(const uint8_t* commandData, ReturnValue_t StarTrackerHandler::prepareParamCommand(const uint8_t* commandData,
size_t commandDataLen, ArcsecJsonParamBase& paramSet) { size_t commandDataLen,
ArcsecJsonParamBase& paramSet) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
if (commandDataLen > MAX_PATH_SIZE) { if (commandDataLen > MAX_PATH_SIZE) {
return FILE_PATH_TOO_LONG; return FILE_PATH_TOO_LONG;
@ -2330,8 +2335,7 @@ ReturnValue_t StarTrackerHandler::handleParamRequest(LocalPoolDataSetBase& datas
dataset.setValidityBufferGeneration(false); dataset.setValidityBufferGeneration(false);
result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE); result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::handleParamRequest Deserialization failed" sif::warning << "StarTrackerHandler::handleParamRequest Deserialization failed" << std::endl;
<< std::endl;
} }
dataset.setValidityBufferGeneration(true); dataset.setValidityBufferGeneration(true);
dataset.setValidity(true, true); dataset.setValidity(true, true);
@ -2376,8 +2380,7 @@ ReturnValue_t StarTrackerHandler::checkProgram() {
startupState = StartupState::DONE; startupState = StartupState::DONE;
} }
if (internalState == InternalState::VERIFY_BOOT) { if (internalState == InternalState::VERIFY_BOOT) {
sif::warning << "StarTrackerHandler::checkProgram: Failed to boot firmware" sif::warning << "StarTrackerHandler::checkProgram: Failed to boot firmware" << std::endl;
<< std::endl;
// Device handler will run into timeout and fall back to transition source mode // Device handler will run into timeout and fall back to transition source mode
triggerEvent(BOOTING_FIRMWARE_FAILED); triggerEvent(BOOTING_FIRMWARE_FAILED);
internalState = InternalState::FAILED_FIRMWARE_BOOT; internalState = InternalState::FAILED_FIRMWARE_BOOT;
@ -2450,8 +2453,7 @@ ReturnValue_t StarTrackerHandler::handleActionReplySet(LocalPoolDataSetBase& dat
dataset.setValidityBufferGeneration(false); dataset.setValidityBufferGeneration(false);
result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE); result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE);
if (result != RETURN_OK) { if (result != RETURN_OK) {
sif::warning << "StarTrackerHandler::handleActionReplySet Deserialization failed" sif::warning << "StarTrackerHandler::handleActionReplySet Deserialization failed" << std::endl;
<< std::endl;
} }
dataset.setValidityBufferGeneration(true); dataset.setValidityBufferGeneration(true);
dataset.setValidity(true, true); dataset.setValidity(true, true);

View File

@ -48,6 +48,8 @@ class StarTrackerHandler : public DeviceHandlerBase {
void performOperationHook() override; void performOperationHook() override;
Submode_t getInitialSubmode() override;
static const Submode_t SUBMODE_BOOTLOADER = 1; static const Submode_t SUBMODE_BOOTLOADER = 1;
static const Submode_t SUBMODE_FIRMWARE = 2; static const Submode_t SUBMODE_FIRMWARE = 2;
@ -183,11 +185,8 @@ class StarTrackerHandler : public DeviceHandlerBase {
class ReadCmd { class ReadCmd {
public: public:
static const uint8_t ADDRESS_OFFSET = 1; // Minimum length of a read command (region, length and filename)
static const uint8_t LENGTH_OFFSET = 5; static const size_t MIN_LENGTH = 7;
static const uint8_t FILE_OFFSET = 9;
// Minimum length of a read command (region, address, length and filename)
static const size_t MIN_LENGTH = 11;
}; };
class EraseCmd { class EraseCmd {
@ -408,7 +407,7 @@ class StarTrackerHandler : public DeviceHandlerBase {
* *
* @return RETURN_OK if start of execution was successful, otherwise error return value * @return RETURN_OK if start of execution was successful, otherwise error return value
*/ */
ReturnValue_t executeReadCommand(const uint8_t* commandData, size_t commandDataLen); ReturnValue_t executeFlashReadCommand(const uint8_t* commandData, size_t commandDataLen);
/** /**
* @brief Fills command buffer with data to boot image (works only when star tracker is * @brief Fills command buffer with data to boot image (works only when star tracker is

View File

@ -141,7 +141,6 @@ ReturnValue_t StrHelper::startFirmwareUpdate(std::string fullname) {
if (not std::filesystem::exists(flashWrite.fullname)) { if (not std::filesystem::exists(flashWrite.fullname)) {
return FILE_NOT_EXISTS; return FILE_NOT_EXISTS;
} }
flashWrite.address = 0;
flashWrite.firstRegion = static_cast<uint8_t>(startracker::FirmwareRegions::FIRST); flashWrite.firstRegion = static_cast<uint8_t>(startracker::FirmwareRegions::FIRST);
flashWrite.lastRegion = static_cast<uint8_t>(startracker::FirmwareRegions::LAST); flashWrite.lastRegion = static_cast<uint8_t>(startracker::FirmwareRegions::LAST);
internalState = InternalState::FIRMWARE_UPDATE; internalState = InternalState::FIRMWARE_UPDATE;
@ -150,8 +149,7 @@ ReturnValue_t StrHelper::startFirmwareUpdate(std::string fullname) {
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t StrHelper::startFlashRead(std::string path, uint8_t region, uint32_t address, ReturnValue_t StrHelper::startFlashRead(std::string path, uint8_t startRegion, uint32_t length) {
uint32_t length) {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
ReturnValue_t result = checkPath(path); ReturnValue_t result = checkPath(path);
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -162,8 +160,7 @@ ReturnValue_t StrHelper::startFlashRead(std::string path, uint8_t region, uint32
if (not std::filesystem::exists(flashRead.path)) { if (not std::filesystem::exists(flashRead.path)) {
return FILE_NOT_EXISTS; return FILE_NOT_EXISTS;
} }
flashRead.address = address; flashRead.startRegion = startRegion;
flashRead.region = region;
flashRead.size = length; flashRead.size = length;
internalState = InternalState::FLASH_READ; internalState = InternalState::FLASH_READ;
semaphore.release(); semaphore.release();
@ -184,8 +181,7 @@ ReturnValue_t StrHelper::performImageDownload() {
struct DownloadActionRequest downloadReq; struct DownloadActionRequest downloadReq;
uint32_t size = 0; uint32_t size = 0;
uint32_t retries = 0; uint32_t retries = 0;
std::string image = makeFilename(); std::string image = makeFullFilename(downloadImage.path, downloadImage.filename);
// std::ofstream file(image, std::ios_base::app | std::ios_base::out);
std::ofstream file(image, std::ios_base::out); std::ofstream file(image, std::ios_base::out);
if (not std::filesystem::exists(image)) { if (not std::filesystem::exists(image)) {
return FILE_CREATION_FAILED; return FILE_CREATION_FAILED;
@ -388,12 +384,13 @@ ReturnValue_t StrHelper::performFlashRead() {
uint32_t size = 0; uint32_t size = 0;
uint32_t retries = 0; uint32_t retries = 0;
Timestamp timestamp; Timestamp timestamp;
std::string fullname = flashRead.path + "/" + timestamp.str() + flashRead.filename; std::string fullname = makeFullFilename(flashRead.path, flashRead.filename);
std::ofstream file(fullname, std::ios_base::app | std::ios_base::out); std::ofstream file(fullname, std::ios_base::app | std::ios_base::out);
if (not std::filesystem::exists(fullname)) { if (not std::filesystem::exists(fullname)) {
return FILE_CREATION_FAILED; return FILE_CREATION_FAILED;
} }
req.region = flashRead.region; req.region = flashRead.startRegion;
req.address = 0;
while (bytesRead < flashRead.size) { while (bytesRead < flashRead.size) {
if (terminate) { if (terminate) {
return RETURN_OK; return RETURN_OK;
@ -403,7 +400,6 @@ ReturnValue_t StrHelper::performFlashRead() {
} else { } else {
req.length = CHUNK_SIZE; req.length = CHUNK_SIZE;
} }
req.address = flashRead.address + bytesRead;
arc_pack_read_action_req(&req, commandBuffer, &size); arc_pack_read_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address); result = sendAndRead(size, req.address);
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -425,19 +421,14 @@ ReturnValue_t StrHelper::performFlashRead() {
file.close(); file.close();
return result; return result;
} }
result = checkActionReply();
if (result != RETURN_OK) {
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
uartComIF->flushUartRxBuffer(comCookie);
retries++;
continue;
}
file.close();
return result;
}
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + FLASH_READ_DATA_OFFSET), file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + FLASH_READ_DATA_OFFSET),
req.length); req.length);
bytesRead += req.length; bytesRead += req.length;
req.address += req.length;
if (req.address >= FLASH_REGION_SIZE) {
req.address = 0;
req.region++;
}
retries = 0; retries = 0;
} }
file.close(); file.close();
@ -585,14 +576,14 @@ ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) {
return result; return result;
} }
std::string StrHelper::makeFilename() { std::string StrHelper::makeFullFilename(std::string path, std::string filename) {
std::string image; std::string image;
Timestamp timestamp; Timestamp timestamp;
if (timestamping) { if (timestamping) {
image = downloadImage.path + "/" + timestamp.str() + downloadImage.filename; image = path + "/" + timestamp.str() + filename;
} }
else { else {
image = downloadImage.path + "/" + downloadImage.filename; image = path + "/" + filename;
} }
return image; return image;
} }

View File

@ -118,11 +118,10 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
* @brief Starts the flash read procedure * @brief Starts the flash read procedure
* *
* @param path Path where file with read flash data will be created * @param path Path where file with read flash data will be created
* @param region Region ID of flash region to read from * @param startRegion Region form where to start reading
* @param address Start address of flash section to read
* @param length Number of bytes to read from flash * @param length Number of bytes to read from flash
*/ */
ReturnValue_t startFlashRead(std::string path, uint8_t region, uint32_t address, uint32_t length); ReturnValue_t startFlashRead(std::string path, uint8_t startRegion, uint32_t length);
/** /**
* @brief Can be used to interrupt a running data transfer. * @brief Can be used to interrupt a running data transfer.
@ -191,7 +190,7 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
static const uint8_t ADDRESS_OFFSET = 3; static const uint8_t ADDRESS_OFFSET = 3;
static const uint8_t LENGTH_OFFSET = 7; static const uint8_t LENGTH_OFFSET = 7;
static const size_t CHUNK_SIZE = 1024; static const size_t CHUNK_SIZE = 1024;
static const size_t CONFIG_MAX_DOWNLOAD_RETRIES = 2000; static const size_t CONFIG_MAX_DOWNLOAD_RETRIES = 3;
static const uint32_t FLASH_ERASE_DELAY = 500; static const uint32_t FLASH_ERASE_DELAY = 500;
enum class InternalState { enum class InternalState {
@ -245,10 +244,7 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
// Default name of file containing the data read from flash, can be changed via command // Default name of file containing the data read from flash, can be changed via command
std::string filename = "flashread.bin"; std::string filename = "flashread.bin";
// Will be set with the flash read command // Will be set with the flash read command
uint8_t region = 0; uint8_t startRegion = 0;
// Will be set with the flash read command and specifies the start address of the flash section
// to read
uint32_t address = 0;
// Number of bytes to read from flash // Number of bytes to read from flash
uint32_t size = 0; uint32_t size = 0;
}; };
@ -372,7 +368,15 @@ class StrHelper : public SystemObject, public ExecutableObjectIF, public HasRetu
*/ */
ReturnValue_t unlockAndEraseRegions(uint32_t from, uint32_t to); ReturnValue_t unlockAndEraseRegions(uint32_t from, uint32_t to);
std::string makeFilename(); /**
* @brief Creates full filename either with timestamp or without
*
* @param path Path where to create the file
* @param filename Name fo the file
*
* @return Full filename
*/
std::string makeFullFilename(std::string path, std::string filename);
}; };
#endif /* BSP_Q7S_DEVICES_STRHELPER_H_ */ #endif /* BSP_Q7S_DEVICES_STRHELPER_H_ */