STR improvements #509

Merged
muellerr merged 10 commits from refactoring_str_use_ring_buff_for_rx into develop 2023-03-23 18:37:19 +01:00
5 changed files with 46 additions and 54 deletions
Showing only changes of commit d824f8ba9e - Show all commits

View File

@ -20,6 +20,20 @@ will consitute of a breaking change warranting a new major release:
- Bugfix for STR: Some action commands wrongfully declined. - Bugfix for STR: Some action commands wrongfully declined.
- STR: No normal command handling while a special request like an image upload is active. - STR: No normal command handling while a special request like an image upload is active.
- STR: Fix weird issues on datalink layer data reception which sometimes occur.
## Changed
- STR: Move datalink layer to `StrComHandler` completely. DLL is now completely hidden from
device handler.
- STR: Is now scheduled twice in ACS PST.
- `StrHelper` renamed to `StrComHandler`, is now a `DeviceHandlerIF` directly and does not wrap
a separate UART COM interface anymore.
## Added
- Add `reset` function for `ArcsecDatalinkLayer` and use it in `StrComHandler` before going to sleep
to ensure consistent state of reply reception.
# [v1.39.0] 2023-03-21 # [v1.39.0] 2023-03-21

View File

@ -1,16 +1,16 @@
#include "ArcsecDatalinkLayer.h" #include "ArcsecDatalinkLayer.h"
ArcsecDatalinkLayer::ArcsecDatalinkLayer() : decodeRingBuf(4096, true) { slipInit(); } ArcsecDatalinkLayer::ArcsecDatalinkLayer() : decodeRingBuf(BUFFER_LENGTHS, true) { slipInit(); }
ArcsecDatalinkLayer::~ArcsecDatalinkLayer() {} ArcsecDatalinkLayer::~ArcsecDatalinkLayer() {}
ReturnValue_t ArcsecDatalinkLayer::checkRingBufForFrame(const uint8_t** decodedFrame, ReturnValue_t ArcsecDatalinkLayer::checkRingBufForFrame(const uint8_t** decodedFrame,
size_t& frameLen) { size_t& frameLen) {
size_t currentLen = decodeRingBuf.getAvailableReadData(); size_t currentLen = decodeRingBuf.getAvailableReadData();
decodeRingBuf.readData(decodedRxFrame, currentLen); decodeRingBuf.readData(rxAnalysisBuffer, currentLen);
for (size_t idx = 0; idx < currentLen; idx++) { for (size_t idx = 0; idx < currentLen; idx++) {
enum arc_dec_result decResult = enum arc_dec_result decResult =
arc_transport_decode_body(decodedRxFrame[idx], &slipInfo, decodedRxFrame, &rxFrameSize); arc_transport_decode_body(rxAnalysisBuffer[idx], &slipInfo, decodedRxFrame, &rxFrameSize);
switch (decResult) { switch (decResult) {
case ARC_DEC_INPROGRESS: { case ARC_DEC_INPROGRESS: {
break; break;
@ -52,46 +52,14 @@ ReturnValue_t ArcsecDatalinkLayer::feedData(const uint8_t* rawData, size_t rawDa
return decodeRingBuf.writeData(rawData, rawDataLen); return decodeRingBuf.writeData(rawData, rawDataLen);
} }
void ArcsecDatalinkLayer::slipInit() { void ArcsecDatalinkLayer::reset() {
slipInfo.buffer = rxBuffer; slipInit();
slipInfo.maxlength = startracker::MAX_FRAME_SIZE; decodeRingBuf.clear();
slipInfo.length = 0;
slipInfo.unescape_next = 0;
slipInfo.prev_state = SLIP_COMPLETE;
} }
// ReturnValue_t ArcsecDatalinkLayer::decodeFrame(const uint8_t* rawData, size_t rawDataSize, void ArcsecDatalinkLayer::slipInit() {
// size_t* bytesLeft) { slip_decode_init(rxBufferArc, sizeof(rxBufferArc), &slipInfo);
// size_t bytePos = 0; }
// for (bytePos = 0; bytePos < rawDataSize; bytePos++) {
// enum arc_dec_result decResult =
// arc_transport_decode_body(*(rawData + bytePos), &slipInfo, decodedRxFrame, &rxFrameSize);
// *bytesLeft = rawDataSize - bytePos - 1;
// switch (decResult) {
// case ARC_DEC_INPROGRESS: {
// if (bytePos == rawDataSize - 1) {
// return DEC_IN_PROGRESS;
// }
// continue;
// }
// case ARC_DEC_ERROR_FRAME_SHORT:
// return REPLY_TOO_SHORT;
// case ARC_DEC_ERROR_CHECKSUM:
// return CRC_FAILURE;
// case ARC_DEC_ASYNC:
// case ARC_DEC_SYNC: {
// // Reset length of SLIP struct for next frame
// slipInfo.length = 0;
// return returnvalue::OK;
// }
// default:
// sif::debug << "ArcsecDatalinkLayer::decodeFrame: Unknown result code" << std::endl;
// break;
// return returnvalue::FAILED;
// }
// }
// return returnvalue::FAILED;
// }
void ArcsecDatalinkLayer::encodeFrame(const uint8_t* data, size_t length, const uint8_t** txFrame, void ArcsecDatalinkLayer::encodeFrame(const uint8_t* data, size_t length, const uint8_t** txFrame,
size_t& size) { size_t& size) {

View File

@ -25,6 +25,8 @@ class ArcsecDatalinkLayer {
static const uint8_t STATUS_OK = 0; static const uint8_t STATUS_OK = 0;
static constexpr size_t BUFFER_LENGTHS = 4096;
ArcsecDatalinkLayer(); ArcsecDatalinkLayer();
virtual ~ArcsecDatalinkLayer(); virtual ~ArcsecDatalinkLayer();
@ -36,16 +38,17 @@ class ArcsecDatalinkLayer {
*/ */
ReturnValue_t feedData(const uint8_t* rawData, size_t rawDataLen); ReturnValue_t feedData(const uint8_t* rawData, size_t rawDataLen);
ReturnValue_t checkRingBufForFrame(const uint8_t** decodedFrame, size_t& frameLen);
/** /**
* @brief Applies decoding to data referenced by rawData pointer * Runs the arcsec datalink layer decoding algorithm on the data in the ring buffer, decoding
* TODO: To be deleted soon, replaced by proper buffering. * frames in the process.
* @param rawData Pointer to raw data received from star tracker * @param decodedFrame
* @param rawDataSize Size of raw data stream * @param frameLen
* @param remainingBytes Number of bytes left * @return
* - returnvalue::OK if a frame was found
* - DEC_IN_PROGRESS if frame decoding is in progress
* - Anything else is a decoding error
*/ */
// ReturnValue_t decodeFrame(const uint8_t* rawData, size_t rawDataSize, size_t* bytesLeft); ReturnValue_t checkRingBufForFrame(const uint8_t** decodedFrame, size_t& frameLen);
/** /**
* @brief SLIP encodes data pointed to by data pointer. * @brief SLIP encodes data pointed to by data pointer.
@ -55,15 +58,19 @@ class ArcsecDatalinkLayer {
*/ */
void encodeFrame(const uint8_t* data, size_t length, const uint8_t** txFrame, size_t& frameLen); void encodeFrame(const uint8_t* data, size_t length, const uint8_t** txFrame, size_t& frameLen);
void reset();
private: private:
static const uint8_t ID_OFFSET = 1; static const uint8_t ID_OFFSET = 1;
static const uint8_t STATUS_OFFSET = 2; static const uint8_t STATUS_OFFSET = 2;
// Used by arcsec slip decoding function process received data // User to buffer and analyse data and allow feeding and checking for frames asychronously.
uint8_t rxBuffer[startracker::MAX_FRAME_SIZE];
SimpleRingBuffer decodeRingBuf; SimpleRingBuffer decodeRingBuf;
uint8_t rxAnalysisBuffer[4096]; uint8_t rxAnalysisBuffer[BUFFER_LENGTHS];
// Used by arcsec slip decoding function to process received data. This should only be written
// to or read from by arcsec functions!
uint8_t rxBufferArc[startracker::MAX_FRAME_SIZE];
// Decoded frame will be copied to this buffer // Decoded frame will be copied to this buffer
uint8_t decodedRxFrame[startracker::MAX_FRAME_SIZE]; uint8_t decodedRxFrame[startracker::MAX_FRAME_SIZE];
// Size of decoded frame // Size of decoded frame

View File

@ -42,6 +42,7 @@ ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
while (true) { while (true) {
lock->lockMutex(); lock->lockMutex();
state = InternalState::SLEEPING; state = InternalState::SLEEPING;
datalinkLayer.reset();
lock->unlockMutex(); lock->unlockMutex();
semaphore.acquire(); semaphore.acquire();
switch (state) { switch (state) {
@ -154,7 +155,9 @@ ReturnValue_t StrComHandler::startImageDownload(std::string path) {
return returnvalue::OK; return returnvalue::OK;
} }
void StrComHandler::stopProcess() { terminate = true; } void StrComHandler::stopProcess() {
terminate = true;
}
void StrComHandler::setDownloadImageName(std::string filename) { void StrComHandler::setDownloadImageName(std::string filename) {
downloadImage.filename = filename; downloadImage.filename = filename;

@ -1 +1 @@
Subproject commit c535e1494f2fdb54becd7c338fe959c3672298b3 Subproject commit cbb3b24dc1993b727735fd63576088401ba351ec