flash read request
This commit is contained in:
parent
8a104c4af2
commit
1331c9e7e9
@ -127,12 +127,15 @@ void initmission::initTasks() {
|
|||||||
initmission::printAddObjectError("FILE_SYSTEM_TASK", objects::FILE_SYSTEM_HANDLER);
|
initmission::printAddObjectError("FILE_SYSTEM_TASK", objects::FILE_SYSTEM_HANDLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if OBSW_ADD_STAR_TRACKER == 1
|
||||||
PeriodicTaskIF* strImgLoaderTask = factory->createPeriodicTask(
|
PeriodicTaskIF* strImgLoaderTask = factory->createPeriodicTask(
|
||||||
"FILE_SYSTEM_TASK", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc);
|
"FILE_SYSTEM_TASK", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc);
|
||||||
result = strImgLoaderTask->addComponent(objects::STR_HELPER);
|
result = strImgLoaderTask->addComponent(objects::STR_HELPER);
|
||||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
initmission::printAddObjectError("FILE_SYSTEM_TASK", objects::STR_HELPER);
|
initmission::printAddObjectError("FILE_SYSTEM_TASK", objects::STR_HELPER);
|
||||||
}
|
}
|
||||||
|
#endif /* OBSW_ADD_STAR_TRACKER == 1 */
|
||||||
|
|
||||||
#endif /* BOARD_TE0720 */
|
#endif /* BOARD_TE0720 */
|
||||||
|
|
||||||
#if OBSW_TEST_CCSDS_BRIDGE == 1
|
#if OBSW_TEST_CCSDS_BRIDGE == 1
|
||||||
@ -194,7 +197,9 @@ void initmission::initTasks() {
|
|||||||
|
|
||||||
#if BOARD_TE0720 == 0
|
#if BOARD_TE0720 == 0
|
||||||
fsTask->startTask();
|
fsTask->startTask();
|
||||||
|
#if OBSW_ADD_STAR_TRACKER == 1
|
||||||
strImgLoaderTask->startTask();
|
strImgLoaderTask->startTask();
|
||||||
|
#endif /* OBSW_ADD_STAR_TRACKER == 1 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sif::info << "Tasks started.." << std::endl;
|
sif::info << "Tasks started.." << std::endl;
|
||||||
|
@ -202,6 +202,7 @@ static const DeviceCommandId_t STOP_IMAGE_LOADER = 55;
|
|||||||
static const DeviceCommandId_t RESET_ERROR = 56;
|
static const DeviceCommandId_t RESET_ERROR = 56;
|
||||||
static const DeviceCommandId_t CHANGE_DOWNLOAD_FILE = 57;
|
static const DeviceCommandId_t CHANGE_DOWNLOAD_FILE = 57;
|
||||||
static const DeviceCommandId_t SET_JSON_FILE_NAME = 58;
|
static const DeviceCommandId_t SET_JSON_FILE_NAME = 58;
|
||||||
|
static const DeviceCommandId_t SET_READ_FILENAME = 59;
|
||||||
static const DeviceCommandId_t NONE = 0xFFFFFFFF;
|
static const DeviceCommandId_t NONE = 0xFFFFFFFF;
|
||||||
|
|
||||||
static const uint32_t VERSION_SET_ID = REQ_VERSION;
|
static const uint32_t VERSION_SET_ID = REQ_VERSION;
|
||||||
|
@ -145,6 +145,18 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
|
|||||||
strHelperExecuting = true;
|
strHelperExecuting = true;
|
||||||
return EXECUTION_FINISHED;
|
return EXECUTION_FINISHED;
|
||||||
}
|
}
|
||||||
|
case(StarTracker::READ): {
|
||||||
|
result = DeviceHandlerBase::acceptExternalDeviceCommands();
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
result = executeReadCommand(data, size);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
strHelperExecuting = true;
|
||||||
|
return EXECUTION_FINISHED;
|
||||||
|
}
|
||||||
case(StarTracker::CHANGE_DOWNLOAD_FILE): {
|
case(StarTracker::CHANGE_DOWNLOAD_FILE): {
|
||||||
if (size > MAX_FILE_NAME) {
|
if (size > MAX_FILE_NAME) {
|
||||||
return FILENAME_TOO_LONG;
|
return FILENAME_TOO_LONG;
|
||||||
@ -153,6 +165,14 @@ ReturnValue_t StarTrackerHandler::executeAction(ActionId_t actionId, MessageQueu
|
|||||||
std::string(reinterpret_cast<const char*>(data), size));
|
std::string(reinterpret_cast<const char*>(data), size));
|
||||||
return EXECUTION_FINISHED;
|
return EXECUTION_FINISHED;
|
||||||
}
|
}
|
||||||
|
case(StarTracker::SET_READ_FILENAME): {
|
||||||
|
if (size > MAX_FILE_NAME) {
|
||||||
|
return FILENAME_TOO_LONG;
|
||||||
|
}
|
||||||
|
strHelper->setDownloadImageName(
|
||||||
|
std::string(reinterpret_cast<const char*>(data), size));
|
||||||
|
return EXECUTION_FINISHED;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -396,6 +416,10 @@ ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t devi
|
|||||||
result = prepareParamCommand(commandData, commandDataLen, tracking);
|
result = prepareParamCommand(commandData, commandDataLen, tracking);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
case (StarTracker::UNLOCK): {
|
||||||
|
result = prepareUnlockCommand(commandData, commandDataLen);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
@ -454,6 +478,8 @@ void StarTrackerHandler::fillCommandAndReplyMap() {
|
|||||||
StarTracker::MAX_FRAME_SIZE * 2 + 2);
|
StarTracker::MAX_FRAME_SIZE * 2 + 2);
|
||||||
this->insertInCommandAndReplyMap(StarTracker::RESET_ERROR, 3, nullptr,
|
this->insertInCommandAndReplyMap(StarTracker::RESET_ERROR, 3, nullptr,
|
||||||
StarTracker::MAX_FRAME_SIZE * 2 + 2);
|
StarTracker::MAX_FRAME_SIZE * 2 + 2);
|
||||||
|
this->insertInCommandAndReplyMap(StarTracker::UNLOCK, 3, nullptr,
|
||||||
|
StarTracker::MAX_FRAME_SIZE * 2 + 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t *start, size_t remainingSize,
|
ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t *start, size_t remainingSize,
|
||||||
@ -522,15 +548,10 @@ ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id, con
|
|||||||
result = handlePingReply();
|
result = handlePingReply();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case (StarTracker::BOOT): {
|
case (StarTracker::BOOT):
|
||||||
result = handleActionReply();
|
case (StarTracker::TAKE_IMAGE):
|
||||||
break;
|
case (StarTracker::RESET_ERROR):
|
||||||
}
|
case (StarTracker::UNLOCK): {
|
||||||
case (StarTracker::RESET_ERROR): {
|
|
||||||
result = handleActionReply();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case (StarTracker::TAKE_IMAGE): {
|
|
||||||
result = handleActionReply();
|
result = handleActionReply();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -809,6 +830,10 @@ ReturnValue_t StarTrackerHandler::scanForActionReply(DeviceCommandId_t *foundId)
|
|||||||
*foundId = StarTracker::RESET_ERROR;
|
*foundId = StarTracker::RESET_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case (StarTracker::ID::UNLOCK): {
|
||||||
|
*foundId = StarTracker::UNLOCK;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
sif::warning << "StarTrackerHandler::scanForParameterReply: Unknown parameter reply id"
|
sif::warning << "StarTrackerHandler::scanForParameterReply: Unknown parameter reply id"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@ -966,6 +991,49 @@ ReturnValue_t StarTrackerHandler::executeWriteCommand(const uint8_t* commandData
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t StarTrackerHandler::executeReadCommand(const uint8_t* commandData,
|
||||||
|
size_t commandDataLen) {
|
||||||
|
ReturnValue_t result = RETURN_OK;
|
||||||
|
if (commandDataLen < ReadCmd::MIN_LENGTH) {
|
||||||
|
sif::warning << "StarTrackerHandler::executeReadCommand: Command too short" << std::endl;
|
||||||
|
return COMMAND_TOO_SHORT;
|
||||||
|
}
|
||||||
|
uint8_t region = *(commandData);
|
||||||
|
uint32_t address;
|
||||||
|
size_t size = sizeof(address);
|
||||||
|
const uint8_t* addressPtr = commandData + ReadCmd::ADDRESS_OFFSET;
|
||||||
|
result = SerializeAdapter::deSerialize(&address, addressPtr, &size,
|
||||||
|
SerializeIF::Endianness::LITTLE);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
sif::debug << "StarTrackerHandler::executeReadCommand: Deserialization of address failed"
|
||||||
|
<< std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
uint16_t length;
|
||||||
|
size = sizeof(length);
|
||||||
|
const uint8_t* lengthPtr = commandData + ReadCmd::LENGTH_OFFSET;
|
||||||
|
result = SerializeAdapter::deSerialize(&address, lengthPtr, &size,
|
||||||
|
SerializeIF::Endianness::LITTLE);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
sif::debug << "StarTrackerHandler::executeReadCommand: Deserialization of length failed"
|
||||||
|
<< std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (commandDataLen - sizeof(address) - sizeof(region) - sizeof(length) > MAX_PATH_SIZE) {
|
||||||
|
sif::warning << "StarTrackerHandler::executeReadCommand: Received command with invalid"
|
||||||
|
<< " path and filename" << std::endl;
|
||||||
|
return FILE_PATH_TOO_LONG;
|
||||||
|
}
|
||||||
|
const uint8_t* filePtr = commandData + ReadCmd::FILE_OFFSET;
|
||||||
|
std::string fullname = std::string(reinterpret_cast<const char*>(filePtr),
|
||||||
|
commandDataLen - sizeof(address) - sizeof(region) - sizeof(length));
|
||||||
|
result = strHelper->startFlashRead(fullname, region, address, length);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void StarTrackerHandler::prepareBootCommand() {
|
void StarTrackerHandler::prepareBootCommand() {
|
||||||
uint32_t length = 0;
|
uint32_t length = 0;
|
||||||
struct BootActionRequest bootRequest = {BOOT_REGION_ID};
|
struct BootActionRequest bootRequest = {BOOT_REGION_ID};
|
||||||
@ -975,6 +1043,25 @@ void StarTrackerHandler::prepareBootCommand() {
|
|||||||
rawPacketLen = dataLinkLayer.getEncodedLength();
|
rawPacketLen = dataLinkLayer.getEncodedLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t StarTrackerHandler::prepareUnlockCommand(const uint8_t* commandData, size_t commandDataLen) {
|
||||||
|
ReturnValue_t result = RETURN_OK;
|
||||||
|
uint32_t length = 0;
|
||||||
|
struct UnlockActionRequest req;
|
||||||
|
req.region = *commandData;
|
||||||
|
size_t size = sizeof(req.code);
|
||||||
|
const uint8_t* codePtr = commandData + UnlockCmd::CODE_OFFSET;
|
||||||
|
result = SerializeAdapter::deSerialize(&req.code, &codePtr, &size,
|
||||||
|
SerializeIF::Endianness::BIG);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
arc_pack_unlock_action_req(&req, commandBuffer, &length);
|
||||||
|
dataLinkLayer.encodeFrame(commandBuffer, length);
|
||||||
|
rawPacket = dataLinkLayer.getEncodedFrame();
|
||||||
|
rawPacketLen = dataLinkLayer.getEncodedLength();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void StarTrackerHandler::prepareTimeRequest() {
|
void StarTrackerHandler::prepareTimeRequest() {
|
||||||
uint32_t length = 0;
|
uint32_t length = 0;
|
||||||
arc_tm_pack_time_req(commandBuffer, &length);
|
arc_tm_pack_time_req(commandBuffer, &length);
|
||||||
|
@ -147,6 +147,20 @@ private:
|
|||||||
static const size_t MIN_LENGTH = 7;
|
static const size_t MIN_LENGTH = 7;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ReadCmd {
|
||||||
|
public:
|
||||||
|
static const uint8_t ADDRESS_OFFSET = 1;
|
||||||
|
static const uint8_t LENGTH_OFFSET = 5;
|
||||||
|
static const uint8_t FILE_OFFSET = 7;
|
||||||
|
// Minimum length of a read command (region, address, length and filename)
|
||||||
|
static const size_t MIN_LENGTH = 9;
|
||||||
|
};
|
||||||
|
|
||||||
|
class UnlockCmd {
|
||||||
|
public:
|
||||||
|
static const uint8_t CODE_OFFSET = 1;
|
||||||
|
};
|
||||||
|
|
||||||
MessageQueueIF* eventQueue = nullptr;
|
MessageQueueIF* eventQueue = nullptr;
|
||||||
|
|
||||||
ArcsecDatalinkLayer dataLinkLayer;
|
ArcsecDatalinkLayer dataLinkLayer;
|
||||||
@ -245,12 +259,28 @@ private:
|
|||||||
*/
|
*/
|
||||||
ReturnValue_t executeWriteCommand(const uint8_t* commandData, size_t commandDataLen);
|
ReturnValue_t executeWriteCommand(const uint8_t* commandData, size_t commandDataLen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Extracts information for flash-read-command from TC data and starts execution of
|
||||||
|
* flash-read-procedure
|
||||||
|
*
|
||||||
|
* @param commandData Pointer to received command data
|
||||||
|
* @param commandDataLen Size of received command data
|
||||||
|
*
|
||||||
|
* @return RETURN_OK if start of execution was successful, otherwise error return value
|
||||||
|
*/
|
||||||
|
ReturnValue_t executeReadCommand(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
|
||||||
* in bootloader mode).
|
* in bootloader mode).
|
||||||
*/
|
*/
|
||||||
void prepareBootCommand();
|
void prepareBootCommand();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fills command buffer with command to unlock flash region
|
||||||
|
*/
|
||||||
|
ReturnValue_t prepareUnlockCommand(const uint8_t* commandData, size_t commandDataLen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Fills the command buffer with the command to take an image.
|
* @brief Fills the command buffer with the command to take an image.
|
||||||
*/
|
*/
|
||||||
|
@ -63,6 +63,17 @@ ReturnValue_t StrHelper::performOperation(uint8_t operationCode) {
|
|||||||
internalState = InternalState::IDLE;
|
internalState = InternalState::IDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case InternalState::FLASH_READ: {
|
||||||
|
result = performFlashRead();
|
||||||
|
if (result == RETURN_OK){
|
||||||
|
triggerEvent(FLASH_READ_SUCCESSFUL);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
triggerEvent(FLASH_READ_FAILED);
|
||||||
|
}
|
||||||
|
internalState = InternalState::IDLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
sif::debug << "StrHelper::performOperation: Invalid state" << std::endl;
|
sif::debug << "StrHelper::performOperation: Invalid state" << std::endl;
|
||||||
break;
|
break;
|
||||||
@ -121,8 +132,12 @@ void StrHelper::setDownloadImageName(std::string image) {
|
|||||||
downloadImage = image;
|
downloadImage = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StrHelper::setFlashReadFilename(std::string filename) {
|
||||||
|
flashReadFile = filename;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnValue_t StrHelper::startFlashWrite(std::string flashWriteFile_, uint8_t region,
|
ReturnValue_t StrHelper::startFlashWrite(std::string flashWriteFile_, uint8_t region,
|
||||||
uint32_t flashWriteAddress) {
|
uint32_t address) {
|
||||||
ReturnValue_t result = checkPath(flashWriteFile_);
|
ReturnValue_t result = checkPath(flashWriteFile_);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
@ -131,12 +146,33 @@ ReturnValue_t StrHelper::startFlashWrite(std::string flashWriteFile_, uint8_t re
|
|||||||
if(not std::filesystem::exists(flashWriteFile)) {
|
if(not std::filesystem::exists(flashWriteFile)) {
|
||||||
return FILE_NOT_EXISTS;
|
return FILE_NOT_EXISTS;
|
||||||
}
|
}
|
||||||
|
flashWriteAddress = address;
|
||||||
|
flashWriteRegion = region;
|
||||||
internalState = InternalState::FLASH_WRITE;
|
internalState = InternalState::FLASH_WRITE;
|
||||||
semaphore.release();
|
semaphore.release();
|
||||||
terminate = false;
|
terminate = false;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReturnValue_t StrHelper::startFlashRead(std::string flashReadFile_, uint8_t region,
|
||||||
|
uint32_t address, uint16_t length) {
|
||||||
|
ReturnValue_t result = checkPath(flashReadFile_);
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
flashReadFile = flashReadFile_;
|
||||||
|
if(not std::filesystem::exists(flashReadFile)) {
|
||||||
|
return FILE_NOT_EXISTS;
|
||||||
|
}
|
||||||
|
flashReadAddress = address;
|
||||||
|
flashReadRegion = region;
|
||||||
|
flashReadSize = length;
|
||||||
|
internalState = InternalState::FLASH_READ;
|
||||||
|
semaphore.release();
|
||||||
|
terminate = false;
|
||||||
|
return RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnValue_t StrHelper::performImageDownload() {
|
ReturnValue_t StrHelper::performImageDownload() {
|
||||||
ReturnValue_t result;
|
ReturnValue_t result;
|
||||||
struct DownloadActionRequest downloadReq;
|
struct DownloadActionRequest downloadReq;
|
||||||
@ -184,7 +220,7 @@ ReturnValue_t StrHelper::performImageDownload() {
|
|||||||
file.close();
|
file.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + DATA_OFFSET),
|
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + IMAGE_DATA_OFFSET),
|
||||||
IMAGE_DATA_SIZE);
|
IMAGE_DATA_SIZE);
|
||||||
downloadReq.position++;
|
downloadReq.position++;
|
||||||
retries = 0;
|
retries = 0;
|
||||||
@ -274,7 +310,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
|
|||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
result = checkFlashWriteReply(req);
|
result = checkFlashActionReply(req.region, req.address, req.length);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -288,7 +324,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
|
|||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
result = checkFlashWriteReply(req);
|
result = checkFlashActionReply(req.region, req.address, req.length);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -302,13 +338,12 @@ 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 file = flashReadPath + "/" + timestamp.str() + flashReadFile ;
|
std::string fullname = flashReadPath + "/" + timestamp.str() + flashReadFile ;
|
||||||
std::ofstream file(file, 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(file)) {
|
if (not std::filesystem::exists(fullname)) {
|
||||||
return FILE_CREATION_FAILED;
|
return FILE_CREATION_FAILED;
|
||||||
}
|
}
|
||||||
req.region = flashReadRegion;
|
req.region = flashReadRegion;
|
||||||
req.address = flashReadAddress;
|
|
||||||
while(bytesRead < flashReadSize) {
|
while(bytesRead < flashReadSize) {
|
||||||
if (terminate) {
|
if (terminate) {
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
@ -319,12 +354,9 @@ ReturnValue_t StrHelper::performFlashRead() {
|
|||||||
else {
|
else {
|
||||||
req.length = MAX_FLASH_DATA;
|
req.length = MAX_FLASH_DATA;
|
||||||
}
|
}
|
||||||
arc_pack_read_action_req(&req, commandBuffer, static_cast<uint32_t>(req.length));
|
req.address = flashReadAddress + bytesRead;
|
||||||
|
arc_pack_read_action_req(&req, commandBuffer, &size);
|
||||||
|
result = sendAndRead(size, req.address);
|
||||||
|
|
||||||
|
|
||||||
result = sendAndRead(size, downloadReq.position);
|
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||||
uartComIF->flushUartRxBuffer(comCookie);
|
uartComIF->flushUartRxBuffer(comCookie);
|
||||||
@ -344,7 +376,7 @@ ReturnValue_t StrHelper::performFlashRead() {
|
|||||||
file.close();
|
file.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = checkReplyPosition(downloadReq.position);
|
result = checkFlashActionReply(req.region, req.address, req.length);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||||
uartComIF->flushUartRxBuffer(comCookie);
|
uartComIF->flushUartRxBuffer(comCookie);
|
||||||
@ -354,9 +386,9 @@ ReturnValue_t StrHelper::performFlashRead() {
|
|||||||
file.close();
|
file.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + DATA_OFFSET),
|
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + FLASH_READ_DATA_OFFSET),
|
||||||
IMAGE_DATA_SIZE);
|
req.length);
|
||||||
downloadReq.position++;
|
bytesRead += req.length;
|
||||||
retries = 0;
|
retries = 0;
|
||||||
}
|
}
|
||||||
file.close();
|
file.close();
|
||||||
@ -446,8 +478,13 @@ ReturnValue_t StrHelper::checkReplyPosition(uint32_t expectedPosition) {
|
|||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t StrHelper::checkFlashWriteReply(struct WriteActionRequest& req) {
|
ReturnValue_t StrHelper::checkFlashActionReply(uint8_t region_, uint32_t address_,
|
||||||
|
uint16_t length_) {
|
||||||
ReturnValue_t result = RETURN_OK;
|
ReturnValue_t result = RETURN_OK;
|
||||||
|
result = checkReply();
|
||||||
|
if (result != RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
const uint8_t* data = datalinkLayer.getReply();
|
const uint8_t* data = datalinkLayer.getReply();
|
||||||
uint8_t region = *(data + REGION_OFFSET);
|
uint8_t region = *(data + REGION_OFFSET);
|
||||||
uint32_t address;
|
uint32_t address;
|
||||||
@ -456,7 +493,7 @@ ReturnValue_t StrHelper::checkFlashWriteReply(struct WriteActionRequest& req) {
|
|||||||
result = SerializeAdapter::deSerialize(&address, &addressData, &size,
|
result = SerializeAdapter::deSerialize(&address, &addressData, &size,
|
||||||
SerializeIF::Endianness::LITTLE);
|
SerializeIF::Endianness::LITTLE);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
sif::warning << "StrHelper::checkFlashWriteReply: Deserialization of address failed"
|
sif::warning << "StrHelper::checkFlashActionReply: Deserialization of address failed"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
uint16_t length;
|
uint16_t length;
|
||||||
@ -465,16 +502,16 @@ ReturnValue_t StrHelper::checkFlashWriteReply(struct WriteActionRequest& req) {
|
|||||||
result = SerializeAdapter::deSerialize(&length, lengthData, &size,
|
result = SerializeAdapter::deSerialize(&length, lengthData, &size,
|
||||||
SerializeIF::Endianness::LITTLE);
|
SerializeIF::Endianness::LITTLE);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
sif::warning << "StrHelper::checkFlashWriteReply: Deserialization of length failed"
|
sif::warning << "StrHelper::checkFlashActionReply: Deserialization of length failed"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
if (region != req.region) {
|
if (region != region_) {
|
||||||
return REGION_MISMATCH;
|
return REGION_MISMATCH;
|
||||||
}
|
}
|
||||||
if (address != req.address) {
|
if (address != address_) {
|
||||||
return ADDRESS_MISMATCH;
|
return ADDRESS_MISMATCH;
|
||||||
}
|
}
|
||||||
if (region != req.length) {
|
if (region != length_) {
|
||||||
return LENGTH_MISMATCH;
|
return LENGTH_MISMATCH;
|
||||||
}
|
}
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
|
@ -103,10 +103,21 @@ public:
|
|||||||
*
|
*
|
||||||
* @param flashWriteFile_ Full name including absolute path of file to write to flash
|
* @param flashWriteFile_ Full name including absolute path of file to write to flash
|
||||||
* @param region Region ID of flash region to write to
|
* @param region Region ID of flash region to write to
|
||||||
* @param flashWriteAddress Start address of flash write procedure
|
* @param address Start address of flash write procedure
|
||||||
*/
|
*/
|
||||||
ReturnValue_t startFlashWrite(std::string flashWriteFile_, uint8_t region,
|
ReturnValue_t startFlashWrite(std::string flashWriteFile_, uint8_t region,
|
||||||
uint32_t flashWriteAddress);
|
uint32_t address);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Starts the flash read procedure
|
||||||
|
*
|
||||||
|
* @param flashWriteFile_ Full name including absolute path of file to write to flash
|
||||||
|
* @param region Region ID of flash region to read from
|
||||||
|
* @param flashWriteAddress Start address of flash section to read
|
||||||
|
* @param length Number of bytes to read from flash
|
||||||
|
*/
|
||||||
|
ReturnValue_t startFlashRead(std::string flashReadFile_, uint8_t region,
|
||||||
|
uint32_t address, uint16_t length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Can be used to interrupt a running data transfer.
|
* @brief Can be used to interrupt a running data transfer.
|
||||||
@ -118,6 +129,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setDownloadImageName(std::string image);
|
void setDownloadImageName(std::string image);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the name of the file which will be created to store the data read from flash
|
||||||
|
*/
|
||||||
|
void setFlashReadFilename(std::string filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static const uint8_t INTERFACE_ID = CLASS_ID::STR_HELPER;
|
static const uint8_t INTERFACE_ID = CLASS_ID::STR_HELPER;
|
||||||
@ -145,7 +161,8 @@ private:
|
|||||||
static const uint32_t MAX_POLLS = 10000;
|
static const uint32_t MAX_POLLS = 10000;
|
||||||
|
|
||||||
static const uint8_t POS_OFFSET = 2;
|
static const uint8_t POS_OFFSET = 2;
|
||||||
static const uint8_t DATA_OFFSET = 5;
|
static const uint8_t IMAGE_DATA_OFFSET = 5;
|
||||||
|
static const uint8_t FLASH_READ_DATA_OFFSET = 8;
|
||||||
static const uint8_t REGION_OFFSET = 2;
|
static const uint8_t REGION_OFFSET = 2;
|
||||||
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;
|
||||||
@ -232,6 +249,12 @@ private:
|
|||||||
*/
|
*/
|
||||||
ReturnValue_t performFlashWrite();
|
ReturnValue_t performFlashWrite();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sends a sequence of commands to the star tracker to read larger parts from the
|
||||||
|
* flash memory.
|
||||||
|
*/
|
||||||
|
ReturnValue_t performFlashRead();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sends packet to the star tracker and reads reply by using the communication
|
* @brief Sends packet to the star tracker and reads reply by using the communication
|
||||||
* interface
|
* interface
|
||||||
@ -260,12 +283,12 @@ private:
|
|||||||
ReturnValue_t checkReplyPosition(uint32_t expectedPosition);
|
ReturnValue_t checkReplyPosition(uint32_t expectedPosition);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks the region, address and length value of a flash write reply.
|
* @brief Checks the region, address and length value of a flash write or read reply.
|
||||||
*
|
*
|
||||||
* @return RETURN_OK if values match expected values, otherwise appropriate error return
|
* @return RETURN_OK if values match expected values, otherwise appropriate error return
|
||||||
* value.
|
* value.
|
||||||
*/
|
*/
|
||||||
ReturnValue_t checkFlashWriteReply(struct WriteActionRequest& req);
|
ReturnValue_t checkFlashActionReply(uint8_t region_, uint32_t address_, uint16_t length_);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks if a path points to an sd card and whether the SD card is monuted.
|
* @brief Checks if a path points to an sd card and whether the SD card is monuted.
|
||||||
|
Loading…
Reference in New Issue
Block a user