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

79 lines
2.1 KiB
C++
Raw Normal View History

2021-12-02 08:05:33 +01:00
#include "ArcsecDatalinkLayer.h"
ArcsecDatalinkLayer::ArcsecDatalinkLayer() {
slipInit();
}
ArcsecDatalinkLayer::~ArcsecDatalinkLayer() {
}
void ArcsecDatalinkLayer::slipInit() {
slipInfo.buffer = rxBuffer;
slipInfo.maxlength = StarTracker::MAX_FRAME_SIZE;
slipInfo.length = 0;
slipInfo.unescape_next = 0;
slipInfo.prev_state = SLIP_COMPLETE;
}
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,
decodedFrame, &decFrameSize);
2021-12-06 19:36:21 +01:00
*bytesLeft = rawDataSize - bytePos - 1;
2021-12-02 08:05:33 +01:00
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;
2021-12-06 19:36:21 +01:00
return RETURN_OK;
2021-12-02 08:05:33 +01:00
}
default:
sif::debug << "ArcsecDatalinkLayer::decodeFrame: Unknown result code" << std::endl;
break;
2021-12-06 19:36:21 +01:00
return RETURN_FAILED;
2021-12-02 08:05:33 +01:00
}
}
2021-12-06 19:36:21 +01:00
return RETURN_FAILED;
2021-12-02 08:05:33 +01:00
}
uint8_t ArcsecDatalinkLayer::getReplyFrameType() {
return decodedFrame[0];
}
const uint8_t* ArcsecDatalinkLayer::getReply() {
return &decodedFrame[1];
}
void ArcsecDatalinkLayer::encodeFrame(const uint8_t* data, uint32_t length) {
2021-12-06 19:36:21 +01:00
arc_transport_encode_body(data, length, encBuffer, &encFrameSize);
2021-12-02 08:05:33 +01:00
}
uint8_t* ArcsecDatalinkLayer::getEncodedFrame() {
return encBuffer;
}
uint32_t ArcsecDatalinkLayer::getEncodedLength() {
return encFrameSize;
}
2021-12-06 19:36:21 +01:00
uint8_t ArcsecDatalinkLayer::getStatusField() {
return *(decodedFrame + STATUS_OFFSET);
}
uint8_t ArcsecDatalinkLayer::getId() {
return *(decodedFrame + ID_OFFSET);
}