eive-obsw/linux/devices/startracker/ArcsecDatalinkLayer.cpp

63 lines
2.0 KiB
C++
Raw Normal View History

2021-12-02 08:05:33 +01:00
#include "ArcsecDatalinkLayer.h"
2022-01-17 15:58:27 +01:00
ArcsecDatalinkLayer::ArcsecDatalinkLayer() { 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
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
}
ReturnValue_t ArcsecDatalinkLayer::decodeFrame(const uint8_t* rawData, size_t rawDataSize,
2022-01-17 15:58:27 +01:00
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, decodedFrame, &decFrameSize);
*bytesLeft = rawDataSize - bytePos - 1;
switch (decResult) {
case ARC_DEC_INPROGRESS: {
if (bytePos == rawDataSize - 1) {
return DEC_IN_PROGRESS;
2021-12-02 08:05:33 +01:00
}
2022-01-17 15:58:27 +01:00
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;
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-01-17 15:58:27 +01:00
}
default:
sif::debug << "ArcsecDatalinkLayer::decodeFrame: Unknown result code" << std::endl;
break;
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2021-12-02 08:05:33 +01:00
}
2022-01-17 15:58:27 +01:00
}
2022-08-24 17:27:47 +02:00
return returnvalue::FAILED;
2021-12-02 08:05:33 +01:00
}
2022-01-17 15:58:27 +01:00
uint8_t ArcsecDatalinkLayer::getReplyFrameType() { return decodedFrame[0]; }
2021-12-02 08:05:33 +01:00
2022-01-17 15:58:27 +01:00
const uint8_t* ArcsecDatalinkLayer::getReply() { return &decodedFrame[1]; }
2021-12-02 08:05:33 +01:00
2023-03-22 10:46:53 +01:00
void ArcsecDatalinkLayer::encodeFrame(const uint8_t* data, uint32_t length) {
2022-01-17 15:58:27 +01:00
arc_transport_encode_body(data, length, encBuffer, &encFrameSize);
2021-12-02 08:05:33 +01:00
}
2022-01-17 15:58:27 +01:00
uint8_t* ArcsecDatalinkLayer::getEncodedFrame() { return encBuffer; }
2021-12-02 08:05:33 +01:00
2022-01-17 15:58:27 +01:00
uint32_t ArcsecDatalinkLayer::getEncodedLength() { return encFrameSize; }
2021-12-02 08:05:33 +01:00
2022-01-17 15:58:27 +01:00
uint8_t ArcsecDatalinkLayer::getStatusField() { return *(decodedFrame + STATUS_OFFSET); }
2021-12-06 19:36:21 +01:00
2022-01-17 15:58:27 +01:00
uint8_t ArcsecDatalinkLayer::getId() { return *(decodedFrame + ID_OFFSET); }