rework send and read, simplify
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good
This commit is contained in:
parent
0256824e37
commit
fabb643026
@ -188,6 +188,7 @@ ReturnValue_t StrComHandler::performImageDownload() {
|
|||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
uint32_t retries = 0;
|
uint32_t retries = 0;
|
||||||
const uint8_t* replyFrame;
|
const uint8_t* replyFrame;
|
||||||
|
size_t replySize = 0;
|
||||||
std::string image = Filenaming::generateAbsoluteFilename(downloadImage.path,
|
std::string image = Filenaming::generateAbsoluteFilename(downloadImage.path,
|
||||||
downloadImage.filename, timestamping);
|
downloadImage.filename, timestamping);
|
||||||
std::ofstream file(image, std::ios_base::out);
|
std::ofstream file(image, std::ios_base::out);
|
||||||
@ -201,7 +202,7 @@ ReturnValue_t StrComHandler::performImageDownload() {
|
|||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
arc_pack_download_action_req(&downloadReq, commandBuffer, &size);
|
arc_pack_download_action_req(&downloadReq, commandBuffer, &size);
|
||||||
result = sendAndRead(&replyFrame, size, downloadReq.position);
|
result = sendAndRead(size, downloadReq.position, &replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||||
uart::flushRxBuf(serialPort);
|
uart::flushRxBuf(serialPort);
|
||||||
@ -211,7 +212,7 @@ ReturnValue_t StrComHandler::performImageDownload() {
|
|||||||
file.close();
|
file.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = checkActionReply(replyFrame);
|
result = checkActionReply(replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||||
uart::flushRxBuf(serialPort);
|
uart::flushRxBuf(serialPort);
|
||||||
@ -247,6 +248,7 @@ ReturnValue_t StrComHandler::performImageUpload() {
|
|||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
uint32_t imageSize = 0;
|
uint32_t imageSize = 0;
|
||||||
const uint8_t* replyFrame;
|
const uint8_t* replyFrame;
|
||||||
|
size_t replySize = 0;
|
||||||
struct UploadActionRequest uploadReq;
|
struct UploadActionRequest uploadReq;
|
||||||
uploadReq.position = 0;
|
uploadReq.position = 0;
|
||||||
#ifdef XIPHOS_Q7S
|
#ifdef XIPHOS_Q7S
|
||||||
@ -280,12 +282,12 @@ ReturnValue_t StrComHandler::performImageUpload() {
|
|||||||
file.seekg(uploadReq.position * SIZE_IMAGE_PART, file.beg);
|
file.seekg(uploadReq.position * SIZE_IMAGE_PART, file.beg);
|
||||||
file.read(reinterpret_cast<char*>(uploadReq.data), SIZE_IMAGE_PART);
|
file.read(reinterpret_cast<char*>(uploadReq.data), SIZE_IMAGE_PART);
|
||||||
arc_pack_upload_action_req(&uploadReq, commandBuffer, &size);
|
arc_pack_upload_action_req(&uploadReq, commandBuffer, &size);
|
||||||
result = sendAndRead(&replyFrame, size, uploadReq.position);
|
result = sendAndRead(size, uploadReq.position, &replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
file.close();
|
file.close();
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
result = checkActionReply(replyFrame);
|
result = checkActionReply(replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
file.close();
|
file.close();
|
||||||
return result;
|
return result;
|
||||||
@ -302,11 +304,11 @@ ReturnValue_t StrComHandler::performImageUpload() {
|
|||||||
file.close();
|
file.close();
|
||||||
uploadReq.position++;
|
uploadReq.position++;
|
||||||
arc_pack_upload_action_req(&uploadReq, commandBuffer, &size);
|
arc_pack_upload_action_req(&uploadReq, commandBuffer, &size);
|
||||||
result = sendAndRead(&replyFrame, size, uploadReq.position);
|
result = sendAndRead(size, uploadReq.position, &replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
result = checkActionReply(replyFrame);
|
result = checkActionReply(replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -339,6 +341,8 @@ ReturnValue_t StrComHandler::performFlashWrite() {
|
|||||||
uint32_t bytesWritten = 0;
|
uint32_t bytesWritten = 0;
|
||||||
uint32_t fileSize = 0;
|
uint32_t fileSize = 0;
|
||||||
const uint8_t* replyFrame;
|
const uint8_t* replyFrame;
|
||||||
|
size_t replySize = 0;
|
||||||
|
|
||||||
struct WriteActionRequest req;
|
struct WriteActionRequest req;
|
||||||
if (not std::filesystem::exists(flashWrite.fullname)) {
|
if (not std::filesystem::exists(flashWrite.fullname)) {
|
||||||
triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState));
|
triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState));
|
||||||
@ -372,12 +376,12 @@ ReturnValue_t StrComHandler::performFlashWrite() {
|
|||||||
}
|
}
|
||||||
req.address = bytesWritten;
|
req.address = bytesWritten;
|
||||||
arc_pack_write_action_req(&req, commandBuffer, &size);
|
arc_pack_write_action_req(&req, commandBuffer, &size);
|
||||||
result = sendAndRead(&replyFrame, size, req.address);
|
result = sendAndRead(size, req.address, &replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
file.close();
|
file.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = checkActionReply(replyFrame);
|
result = checkActionReply(replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
file.close();
|
file.close();
|
||||||
return result;
|
return result;
|
||||||
@ -399,11 +403,11 @@ ReturnValue_t StrComHandler::performFlashWrite() {
|
|||||||
req.length = remainingBytes;
|
req.length = remainingBytes;
|
||||||
bytesWritten += remainingBytes;
|
bytesWritten += remainingBytes;
|
||||||
arc_pack_write_action_req(&req, commandBuffer, &size);
|
arc_pack_write_action_req(&req, commandBuffer, &size);
|
||||||
result = sendAndRead(&replyFrame, size, req.address);
|
result = sendAndRead(size, req.address, &replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = checkActionReply(replyFrame);
|
result = checkActionReply(replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -428,6 +432,7 @@ ReturnValue_t StrComHandler::performFlashRead() {
|
|||||||
uint32_t size = 0;
|
uint32_t size = 0;
|
||||||
uint32_t retries = 0;
|
uint32_t retries = 0;
|
||||||
const uint8_t* replyFrame;
|
const uint8_t* replyFrame;
|
||||||
|
size_t replySize = 0;
|
||||||
Timestamp timestamp;
|
Timestamp timestamp;
|
||||||
std::string fullname =
|
std::string fullname =
|
||||||
Filenaming::generateAbsoluteFilename(flashRead.path, flashRead.filename, timestamping);
|
Filenaming::generateAbsoluteFilename(flashRead.path, flashRead.filename, timestamping);
|
||||||
@ -447,7 +452,7 @@ ReturnValue_t StrComHandler::performFlashRead() {
|
|||||||
req.length = CHUNK_SIZE;
|
req.length = CHUNK_SIZE;
|
||||||
}
|
}
|
||||||
arc_pack_read_action_req(&req, commandBuffer, &size);
|
arc_pack_read_action_req(&req, commandBuffer, &size);
|
||||||
result = sendAndRead(&replyFrame, size, req.address);
|
result = sendAndRead(size, req.address, &replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||||
uart::flushRxBuf(serialPort);
|
uart::flushRxBuf(serialPort);
|
||||||
@ -457,7 +462,7 @@ ReturnValue_t StrComHandler::performFlashRead() {
|
|||||||
file.close();
|
file.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = checkActionReply(replyFrame);
|
result = checkActionReply(replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
|
||||||
uart::flushRxBuf(serialPort);
|
uart::flushRxBuf(serialPort);
|
||||||
@ -483,13 +488,11 @@ ReturnValue_t StrComHandler::performFlashRead() {
|
|||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t StrComHandler::sendAndRead(const uint8_t** replyFrame, size_t size,
|
ReturnValue_t StrComHandler::sendAndRead(size_t size,
|
||||||
uint32_t failParameter, uint32_t delayMs) {
|
uint32_t failParameter, const uint8_t** replyFrame,
|
||||||
|
size_t& replyLen) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = returnvalue::OK;
|
||||||
ReturnValue_t decResult = returnvalue::OK;
|
ReturnValue_t decResult = returnvalue::OK;
|
||||||
size_t receivedDataLen = 0;
|
|
||||||
size_t bytesLeft = 0;
|
|
||||||
uint32_t missedReplies = 0;
|
|
||||||
|
|
||||||
const uint8_t* sendData;
|
const uint8_t* sendData;
|
||||||
size_t txFrameLen = 0;
|
size_t txFrameLen = 0;
|
||||||
@ -500,12 +503,8 @@ ReturnValue_t StrComHandler::sendAndRead(const uint8_t** replyFrame, size_t size
|
|||||||
triggerEvent(STR_HELPER_SENDING_PACKET_FAILED, result, failParameter);
|
triggerEvent(STR_HELPER_SENDING_PACKET_FAILED, result, failParameter);
|
||||||
return returnvalue::FAILED;
|
return returnvalue::FAILED;
|
||||||
}
|
}
|
||||||
Countdown delay(delayMs);
|
|
||||||
while (true) {
|
while (true) {
|
||||||
delay.resetTimer();
|
handleSerialReception();
|
||||||
while (delay.isBusy()) {
|
|
||||||
TaskFactory::delayTask(10);
|
|
||||||
}
|
|
||||||
// TODO: Read periodically into ring buffer, analyse ring buffer for reply frames periodically.
|
// TODO: Read periodically into ring buffer, analyse ring buffer for reply frames periodically.
|
||||||
// result = uartComIF->requestReceiveMessage(comCookie, startracker::MAX_FRAME_SIZE * 2 + 2);
|
// result = uartComIF->requestReceiveMessage(comCookie, startracker::MAX_FRAME_SIZE * 2 + 2);
|
||||||
// if (result != returnvalue::OK) {
|
// if (result != returnvalue::OK) {
|
||||||
@ -519,23 +518,25 @@ ReturnValue_t StrComHandler::sendAndRead(const uint8_t** replyFrame, size_t size
|
|||||||
// triggerEvent(STR_HELPER_READING_REPLY_FAILED, result, parameter);
|
// triggerEvent(STR_HELPER_READING_REPLY_FAILED, result, parameter);
|
||||||
// return returnvalue::FAILED;
|
// return returnvalue::FAILED;
|
||||||
// }
|
// }
|
||||||
if (receivedDataLen == 0 && missedReplies < MAX_POLLS) {
|
// if (receivedDataLen == 0 && missedReplies < MAX_POLLS) {
|
||||||
missedReplies++;
|
// missedReplies++;
|
||||||
continue;
|
// continue;
|
||||||
} else if ((receivedDataLen == 0) && (missedReplies >= MAX_POLLS)) {
|
// } else if ((receivedDataLen == 0) && (missedReplies >= MAX_POLLS)) {
|
||||||
triggerEvent(STR_HELPER_NO_REPLY, failParameter);
|
// triggerEvent(STR_HELPER_NO_REPLY, failParameter);
|
||||||
return returnvalue::FAILED;
|
// return returnvalue::FAILED;
|
||||||
} else {
|
// } else {
|
||||||
missedReplies = 0;
|
// missedReplies = 0;
|
||||||
}
|
// }
|
||||||
// TODO: Use frame detector function here instead.
|
// TODO: Use frame detector function here instead.
|
||||||
|
result = datalinkLayer.checkRingBufForFrame(replyFrame, replyLen);
|
||||||
|
//if(result == )
|
||||||
// decResult = datalinkLayer.decodeFrame(receivedData, receivedDataLen, &bytesLeft);
|
// decResult = datalinkLayer.decodeFrame(receivedData, receivedDataLen, &bytesLeft);
|
||||||
if (bytesLeft != 0) {
|
// if (bytesLeft != 0) {
|
||||||
// This should never happen
|
// // This should never happen
|
||||||
sif::warning << "StrHelper::sendAndRead: Bytes left after decoding" << std::endl;
|
// sif::warning << "StrHelper::sendAndRead: Bytes left after decoding" << std::endl;
|
||||||
triggerEvent(STR_HELPER_COM_ERROR, result, failParameter);
|
// triggerEvent(STR_HELPER_COM_ERROR, result, failParameter);
|
||||||
return returnvalue::FAILED;
|
// return returnvalue::FAILED;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
if (decResult != returnvalue::OK) {
|
if (decResult != returnvalue::OK) {
|
||||||
triggerEvent(STR_HELPER_DEC_ERROR, decResult, failParameter);
|
triggerEvent(STR_HELPER_DEC_ERROR, decResult, failParameter);
|
||||||
@ -544,7 +545,7 @@ ReturnValue_t StrComHandler::sendAndRead(const uint8_t** replyFrame, size_t size
|
|||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t StrComHandler::checkActionReply(const uint8_t* rawFrame) {
|
ReturnValue_t StrComHandler::checkActionReply(const uint8_t* rawFrame, size_t replySize) {
|
||||||
uint8_t type = str::getReplyFrameType(rawFrame);
|
uint8_t type = str::getReplyFrameType(rawFrame);
|
||||||
if (type != TMTC_ACTIONREPLY) {
|
if (type != TMTC_ACTIONREPLY) {
|
||||||
sif::warning << "StrHelper::checkActionReply: Received reply with invalid type ID" << std::endl;
|
sif::warning << "StrHelper::checkActionReply: Received reply with invalid type ID" << std::endl;
|
||||||
@ -657,6 +658,7 @@ ReturnValue_t StrComHandler::readReceivedMessage(CookieIF* cookie, uint8_t** buf
|
|||||||
ReturnValue_t StrComHandler::unlockAndEraseRegions(uint32_t from, uint32_t to) {
|
ReturnValue_t StrComHandler::unlockAndEraseRegions(uint32_t from, uint32_t to) {
|
||||||
ReturnValue_t result = returnvalue::OK;
|
ReturnValue_t result = returnvalue::OK;
|
||||||
const uint8_t* replyFrame;
|
const uint8_t* replyFrame;
|
||||||
|
size_t replySize = 0;
|
||||||
#if OBSW_DEBUG_STARTRACKER == 1
|
#if OBSW_DEBUG_STARTRACKER == 1
|
||||||
ProgressPrinter progressPrinter("Unlock and erase", to - from);
|
ProgressPrinter progressPrinter("Unlock and erase", to - from);
|
||||||
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
|
#endif /* OBSW_DEBUG_STARTRACKER == 1 */
|
||||||
@ -667,8 +669,8 @@ ReturnValue_t StrComHandler::unlockAndEraseRegions(uint32_t from, uint32_t to) {
|
|||||||
unlockReq.region = idx;
|
unlockReq.region = idx;
|
||||||
unlockReq.code = startracker::region_secrets::secret[idx];
|
unlockReq.code = startracker::region_secrets::secret[idx];
|
||||||
arc_pack_unlock_action_req(&unlockReq, commandBuffer, &size);
|
arc_pack_unlock_action_req(&unlockReq, commandBuffer, &size);
|
||||||
sendAndRead(&replyFrame, size, unlockReq.region);
|
sendAndRead(size, unlockReq.region, &replyFrame, replySize);
|
||||||
result = checkActionReply(replyFrame);
|
result = checkActionReply(replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
sif::warning << "StrHelper::unlockAndEraseRegions: Failed to unlock region with id "
|
sif::warning << "StrHelper::unlockAndEraseRegions: Failed to unlock region with id "
|
||||||
<< static_cast<unsigned int>(unlockReq.region) << std::endl;
|
<< static_cast<unsigned int>(unlockReq.region) << std::endl;
|
||||||
@ -676,7 +678,7 @@ ReturnValue_t StrComHandler::unlockAndEraseRegions(uint32_t from, uint32_t to) {
|
|||||||
}
|
}
|
||||||
eraseReq.region = idx;
|
eraseReq.region = idx;
|
||||||
arc_pack_erase_action_req(&eraseReq, commandBuffer, &size);
|
arc_pack_erase_action_req(&eraseReq, commandBuffer, &size);
|
||||||
result = sendAndRead(&replyFrame, size, eraseReq.region, FLASH_ERASE_DELAY);
|
result = sendAndRead(size, eraseReq.region, &replyFrame, replySize);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
sif::warning << "StrHelper::unlockAndEraseRegions: Failed to erase region with id "
|
sif::warning << "StrHelper::unlockAndEraseRegions: Failed to erase region with id "
|
||||||
<< static_cast<unsigned int>(eraseReq.region) << std::endl;
|
<< static_cast<unsigned int>(eraseReq.region) << std::endl;
|
||||||
@ -689,7 +691,7 @@ ReturnValue_t StrComHandler::unlockAndEraseRegions(uint32_t from, uint32_t to) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t StrComHandler::handleUartReception() {
|
ReturnValue_t StrComHandler::handleSerialReception() {
|
||||||
ssize_t bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
|
ssize_t bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
|
||||||
static_cast<unsigned int>(recBuf.size()));
|
static_cast<unsigned int>(recBuf.size()));
|
||||||
if (bytesRead == 0) {
|
if (bytesRead == 0) {
|
||||||
|
@ -262,7 +262,7 @@ class StrComHandler : public SystemObject, public DeviceCommunicationIF, public
|
|||||||
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
|
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
|
||||||
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override;
|
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override;
|
||||||
|
|
||||||
ReturnValue_t handleUartReception();
|
ReturnValue_t handleSerialReception();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Performs image uploading
|
* @brief Performs image uploading
|
||||||
@ -311,15 +311,14 @@ class StrComHandler : public SystemObject, public DeviceCommunicationIF, public
|
|||||||
*
|
*
|
||||||
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED
|
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED
|
||||||
*/
|
*/
|
||||||
ReturnValue_t sendAndRead(const uint8_t **replyFrame, size_t size, uint32_t parameter,
|
ReturnValue_t sendAndRead(size_t size, uint32_t parameter,const uint8_t **replyFrame, size_t&replyLen);
|
||||||
uint32_t delayMs = 0);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks the header (type id and status fields) of the action reply
|
* @brief Checks the header (type id and status fields) of the action reply
|
||||||
*
|
*
|
||||||
* @return returnvalue::OK if reply confirms success of packet transfer, otherwise REUTRN_FAILED
|
* @return returnvalue::OK if reply confirms success of packet transfer, otherwise REUTRN_FAILED
|
||||||
*/
|
*/
|
||||||
ReturnValue_t checkActionReply(const uint8_t *rawFrame);
|
ReturnValue_t checkActionReply(const uint8_t *rawFrame, size_t replySize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Checks the position field in a star tracker upload/download reply.
|
* @brief Checks the position field in a star tracker upload/download reply.
|
||||||
|
Loading…
Reference in New Issue
Block a user