2021-12-02 08:05:33 +01:00
|
|
|
#include "ArcsecDatalinkLayer.h"
|
|
|
|
|
2023-03-21 18:47:42 +01:00
|
|
|
ArcsecDatalinkLayer::ArcsecDatalinkLayer() : decodeRingBuf(4096, true) { slipInit(); }
|
2021-12-02 08:05:33 +01:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
ArcsecDatalinkLayer::~ArcsecDatalinkLayer() {}
|
2021-12-02 08:05:33 +01:00
|
|
|
|
2023-03-21 18:47:42 +01:00
|
|
|
ReturnValue_t ArcsecDatalinkLayer::checkRingBufForFrame(const uint8_t** decodedFrame,
|
|
|
|
size_t& frameLen) {
|
|
|
|
size_t currentLen = decodeRingBuf.getAvailableReadData();
|
|
|
|
decodeRingBuf.readData(decodedRxFrame, currentLen);
|
|
|
|
for (size_t idx = 0; idx < currentLen; idx++) {
|
|
|
|
enum arc_dec_result decResult =
|
|
|
|
arc_transport_decode_body(decodedRxFrame[idx], &slipInfo, decodedRxFrame, &rxFrameSize);
|
|
|
|
switch (decResult) {
|
|
|
|
case ARC_DEC_INPROGRESS: {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ARC_DEC_ERROR_FRAME_SHORT: {
|
|
|
|
decodeRingBuf.deleteData(idx);
|
|
|
|
return REPLY_TOO_SHORT;
|
|
|
|
}
|
|
|
|
case ARC_DEC_ERROR_CHECKSUM:
|
|
|
|
decodeRingBuf.deleteData(idx);
|
|
|
|
return CRC_FAILURE;
|
|
|
|
case ARC_DEC_ASYNC:
|
|
|
|
case ARC_DEC_SYNC: {
|
|
|
|
// Reset length of SLIP struct for next frame
|
|
|
|
slipInfo.length = 0;
|
|
|
|
if (decodedFrame != nullptr) {
|
|
|
|
*decodedFrame = decodedRxFrame;
|
|
|
|
}
|
|
|
|
frameLen = rxFrameSize;
|
|
|
|
decodeRingBuf.deleteData(idx);
|
|
|
|
return returnvalue::OK;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
sif::debug << "ArcsecDatalinkLayer::decodeFrame: Unknown result code" << std::endl;
|
|
|
|
break;
|
|
|
|
return returnvalue::FAILED;
|
|
|
|
}
|
|
|
|
}
|
2023-03-21 20:59:59 +01:00
|
|
|
decodeRingBuf.deleteData(currentLen);
|
2023-03-21 18:47:42 +01:00
|
|
|
return DEC_IN_PROGRESS;
|
|
|
|
}
|
|
|
|
|
2023-03-21 20:35:28 +01:00
|
|
|
ReturnValue_t ArcsecDatalinkLayer::feedData(const uint8_t* rawData, size_t rawDataLen) {
|
|
|
|
if (rawDataLen > 4096) {
|
|
|
|
sif::error << "ArcsecDatalinklayer: Can not write more than 4096 bytes to ring buffer"
|
|
|
|
<< std::endl;
|
|
|
|
return returnvalue::FAILED;
|
|
|
|
}
|
|
|
|
return decodeRingBuf.writeData(rawData, rawDataLen);
|
|
|
|
}
|
|
|
|
|
2021-12-02 08:05:33 +01:00
|
|
|
void ArcsecDatalinkLayer::slipInit() {
|
2022-01-17 15:58:27 +01:00
|
|
|
slipInfo.buffer = rxBuffer;
|
2022-02-14 11:28:15 +01:00
|
|
|
slipInfo.maxlength = startracker::MAX_FRAME_SIZE;
|
2022-01-17 15:58:27 +01:00
|
|
|
slipInfo.length = 0;
|
|
|
|
slipInfo.unescape_next = 0;
|
|
|
|
slipInfo.prev_state = SLIP_COMPLETE;
|
2021-12-02 08:05:33 +01:00
|
|
|
}
|
|
|
|
|
2023-03-21 20:35:28 +01:00
|
|
|
// ReturnValue_t ArcsecDatalinkLayer::decodeFrame(const uint8_t* rawData, size_t rawDataSize,
|
|
|
|
// size_t* bytesLeft) {
|
|
|
|
// 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;
|
|
|
|
// }
|
2021-12-02 08:05:33 +01:00
|
|
|
|
2023-03-21 20:35:28 +01:00
|
|
|
void ArcsecDatalinkLayer::encodeFrame(const uint8_t* data, size_t length, const uint8_t** txFrame,
|
2023-03-21 18:47:42 +01:00
|
|
|
size_t& size) {
|
|
|
|
arc_transport_encode_body(data, length, txEncoded, &size);
|
|
|
|
if (txFrame != nullptr) {
|
|
|
|
*txFrame = txEncoded;
|
|
|
|
}
|
2021-12-02 08:05:33 +01:00
|
|
|
}
|