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