add uart reception handler
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2023-03-21 20:35:28 +01:00
parent 24fb8e34f2
commit 0256824e37
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
14 changed files with 490 additions and 422 deletions

View File

@ -4,6 +4,7 @@
#include <linux/devices/AcsBoardPolling.h> #include <linux/devices/AcsBoardPolling.h>
#include <linux/devices/ImtqPollingTask.h> #include <linux/devices/ImtqPollingTask.h>
#include <linux/devices/RwPollingTask.h> #include <linux/devices/RwPollingTask.h>
#include <linux/devices/startracker/StrComHandler.h>
#include <mission/devices/GyrL3gCustomHandler.h> #include <mission/devices/GyrL3gCustomHandler.h>
#include <mission/devices/MgmLis3CustomHandler.h> #include <mission/devices/MgmLis3CustomHandler.h>
#include <mission/devices/MgmRm3100CustomHandler.h> #include <mission/devices/MgmRm3100CustomHandler.h>
@ -45,7 +46,6 @@
#include "linux/devices/ploc/PlocMemoryDumper.h" #include "linux/devices/ploc/PlocMemoryDumper.h"
#include "linux/devices/ploc/PlocSupervisorHandler.h" #include "linux/devices/ploc/PlocSupervisorHandler.h"
#include "linux/devices/startracker/StarTrackerHandler.h" #include "linux/devices/startracker/StarTrackerHandler.h"
#include "linux/devices/startracker/StrHelper.h"
#include "linux/ipcore/AxiPtmeConfig.h" #include "linux/ipcore/AxiPtmeConfig.h"
#include "linux/ipcore/PapbVcInterface.h" #include "linux/ipcore/PapbVcInterface.h"
#include "linux/ipcore/PdecHandler.h" #include "linux/ipcore/PdecHandler.h"
@ -934,7 +934,7 @@ void ObjectFactory::createStrComponents(PowerSwitchIF* pwrSwitcher) {
new SerialCookie(objects::STAR_TRACKER, q7s::UART_STAR_TRACKER_DEV, uart::STAR_TRACKER_BAUD, new SerialCookie(objects::STAR_TRACKER, q7s::UART_STAR_TRACKER_DEV, uart::STAR_TRACKER_BAUD,
startracker::MAX_FRAME_SIZE * 2 + 2, UartModes::NON_CANONICAL); startracker::MAX_FRAME_SIZE * 2 + 2, UartModes::NON_CANONICAL);
starTrackerCookie->setNoFixedSizeReply(); starTrackerCookie->setNoFixedSizeReply();
StrHelper* strHelper = new StrHelper(objects::STR_HELPER); StrComHandler* strHelper = new StrComHandler(objects::STR_HELPER);
const char* paramJsonFile = nullptr; const char* paramJsonFile = nullptr;
#ifdef EGSE #ifdef EGSE

2
fsfw

@ -1 +1 @@
Subproject commit 227524a21da755d125bcb1a5ff67bcbc452f8cf9 Subproject commit 341437df1387aaf0128dd5304b5c0cc8ad734e69

View File

@ -148,8 +148,7 @@ ReturnValue_t ScexUartReader::sendMessage(CookieIF *cookie, const uint8_t *sendD
} }
size_t bytesWritten = write(serialPort, cmdbuf.data(), encodedLen); size_t bytesWritten = write(serialPort, cmdbuf.data(), encodedLen);
if (bytesWritten != encodedLen) { if (bytesWritten != encodedLen) {
sif::warning << "ScexUartReader::sendMessage: Sending ping command to solar experiment failed" sif::warning << "ScexUartReader::sendMessage: Sending command failed" << std::endl;
<< std::endl;
return FAILED; return FAILED;
} }

View File

@ -42,6 +42,15 @@ ReturnValue_t ArcsecDatalinkLayer::checkRingBufForFrame(const uint8_t** decodedF
return DEC_IN_PROGRESS; return DEC_IN_PROGRESS;
} }
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);
}
void ArcsecDatalinkLayer::slipInit() { void ArcsecDatalinkLayer::slipInit() {
slipInfo.buffer = rxBuffer; slipInfo.buffer = rxBuffer;
slipInfo.maxlength = startracker::MAX_FRAME_SIZE; slipInfo.maxlength = startracker::MAX_FRAME_SIZE;
@ -50,51 +59,43 @@ void ArcsecDatalinkLayer::slipInit() {
slipInfo.prev_state = SLIP_COMPLETE; slipInfo.prev_state = SLIP_COMPLETE;
} }
ReturnValue_t ArcsecDatalinkLayer::decodeFrame(const uint8_t* rawData, size_t rawDataSize, // ReturnValue_t ArcsecDatalinkLayer::decodeFrame(const uint8_t* rawData, size_t rawDataSize,
size_t* bytesLeft) { // size_t* bytesLeft) {
size_t bytePos = 0; // size_t bytePos = 0;
for (bytePos = 0; bytePos < rawDataSize; bytePos++) { // for (bytePos = 0; bytePos < rawDataSize; bytePos++) {
enum arc_dec_result decResult = // enum arc_dec_result decResult =
arc_transport_decode_body(*(rawData + bytePos), &slipInfo, decodedRxFrame, &rxFrameSize); // arc_transport_decode_body(*(rawData + bytePos), &slipInfo, decodedRxFrame, &rxFrameSize);
*bytesLeft = rawDataSize - bytePos - 1; // *bytesLeft = rawDataSize - bytePos - 1;
switch (decResult) { // switch (decResult) {
case ARC_DEC_INPROGRESS: { // case ARC_DEC_INPROGRESS: {
if (bytePos == rawDataSize - 1) { // if (bytePos == rawDataSize - 1) {
return DEC_IN_PROGRESS; // return DEC_IN_PROGRESS;
} // }
continue; // continue;
} // }
case ARC_DEC_ERROR_FRAME_SHORT: // case ARC_DEC_ERROR_FRAME_SHORT:
return REPLY_TOO_SHORT; // return REPLY_TOO_SHORT;
case ARC_DEC_ERROR_CHECKSUM: // case ARC_DEC_ERROR_CHECKSUM:
return CRC_FAILURE; // return CRC_FAILURE;
case ARC_DEC_ASYNC: // case ARC_DEC_ASYNC:
case ARC_DEC_SYNC: { // case ARC_DEC_SYNC: {
// Reset length of SLIP struct for next frame // // Reset length of SLIP struct for next frame
slipInfo.length = 0; // slipInfo.length = 0;
return returnvalue::OK; // return returnvalue::OK;
} // }
default: // default:
sif::debug << "ArcsecDatalinkLayer::decodeFrame: Unknown result code" << std::endl; // sif::debug << "ArcsecDatalinkLayer::decodeFrame: Unknown result code" << std::endl;
break; // break;
return returnvalue::FAILED; // return returnvalue::FAILED;
} // }
} // }
return returnvalue::FAILED; // return returnvalue::FAILED;
} // }
uint8_t ArcsecDatalinkLayer::getReplyFrameType() { return decodedRxFrame[0]; } void ArcsecDatalinkLayer::encodeFrame(const uint8_t* data, size_t length, const uint8_t** txFrame,
const uint8_t* ArcsecDatalinkLayer::getReply() { return &decodedRxFrame[1]; }
void ArcsecDatalinkLayer::encodeFrame(const uint8_t* data, size_t length, uint8_t** txFrame,
size_t& size) { size_t& size) {
arc_transport_encode_body(data, length, txEncoded, &size); arc_transport_encode_body(data, length, txEncoded, &size);
if (txFrame != nullptr) { if (txFrame != nullptr) {
*txFrame = txEncoded; *txFrame = txEncoded;
} }
} }
uint8_t ArcsecDatalinkLayer::getStatusField() { return *(decodedRxFrame + STATUS_OFFSET); }
uint8_t ArcsecDatalinkLayer::getId() { return *(decodedRxFrame + ID_OFFSET); }

View File

@ -2,15 +2,13 @@
#define BSP_Q7S_DEVICES_ARCSECDATALINKLAYER_H_ #define BSP_Q7S_DEVICES_ARCSECDATALINKLAYER_H_
#include <fsfw/container/SimpleRingBuffer.h> #include <fsfw/container/SimpleRingBuffer.h>
#include <fsfw/devicehandlers/CookieIF.h>
#include "arcsec/common/misc.h"
#include "eive/resultClassIds.h" #include "eive/resultClassIds.h"
#include "fsfw/returnvalues/returnvalue.h" #include "fsfw/returnvalues/returnvalue.h"
#include "linux/devices/devicedefinitions/StarTrackerDefinitions.h" #include "linux/devices/devicedefinitions/StarTrackerDefinitions.h"
extern "C" {
#include "common/misc.h"
}
/** /**
* @brief Helper class to handle the datalinklayer of replies from the star tracker of arcsec. * @brief Helper class to handle the datalinklayer of replies from the star tracker of arcsec.
*/ */
@ -47,7 +45,7 @@ class ArcsecDatalinkLayer {
* @param rawDataSize Size of raw data stream * @param rawDataSize Size of raw data stream
* @param remainingBytes Number of bytes left * @param remainingBytes Number of bytes left
*/ */
ReturnValue_t decodeFrame(const uint8_t* rawData, size_t rawDataSize, size_t* bytesLeft); // ReturnValue_t decodeFrame(const uint8_t* rawData, size_t rawDataSize, size_t* bytesLeft);
/** /**
* @brief SLIP encodes data pointed to by data pointer. * @brief SLIP encodes data pointed to by data pointer.
@ -55,27 +53,7 @@ class ArcsecDatalinkLayer {
* @param data Pointer to data to encode * @param data Pointer to data to encode
* @param length Length of buffer to encode * @param length Length of buffer to encode
*/ */
void encodeFrame(const uint8_t* data, size_t length, uint8_t** txFrame, size_t& frameLen); void encodeFrame(const uint8_t* data, size_t length, const uint8_t** txFrame, size_t& frameLen);
/**
* @brief Returns the frame type field of a decoded frame.
*/
uint8_t getReplyFrameType();
/**
* @brief Returns pointer to reply packet (first entry normally action ID, telemetry ID etc.)
*/
const uint8_t* getReply();
/**
* @brief Returns status of reply
*/
uint8_t getStatusField();
/**
* @brief Returns ID of reply
*/
uint8_t getId();
private: private:
static const uint8_t ID_OFFSET = 1; static const uint8_t ID_OFFSET = 1;

View File

@ -5,15 +5,12 @@
#include <fstream> #include <fstream>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "arcsec/common/generated/tmtcstructs.h"
#include "arcsec/common/genericstructs.h"
#include "eive/resultClassIds.h" #include "eive/resultClassIds.h"
#include "fsfw/returnvalues/returnvalue.h" #include "fsfw/returnvalues/returnvalue.h"
#include "linux/devices/devicedefinitions/StarTrackerDefinitions.h" #include "linux/devices/devicedefinitions/StarTrackerDefinitions.h"
extern "C" {
#include "thirdparty/arcsec_star_tracker/common/generated/tmtcstructs.h"
#include "thirdparty/arcsec_star_tracker/common/genericstructs.h"
}
using json = nlohmann::json; using json = nlohmann::json;
/** /**

View File

@ -1,4 +1,5 @@
target_sources( target_sources(
${OBSW_NAME} ${OBSW_NAME}
PRIVATE StarTrackerHandler.cpp StarTrackerJsonCommands.cpp PRIVATE StarTrackerHandler.cpp StarTrackerJsonCommands.cpp
ArcsecDatalinkLayer.cpp ArcsecJsonParamBase.cpp StrHelper.cpp) ArcsecDatalinkLayer.cpp ArcsecJsonParamBase.cpp StrComHandler.cpp
helpers.cpp)

View File

@ -1,5 +1,8 @@
#include "StarTrackerHandler.h" #include "StarTrackerHandler.h"
#include <arcsec/client/generated/actionreq.h>
#include <arcsec/client/generated/parameter.h>
#include <arcsec/client/generated/telemetry.h>
#include <fsfw/ipc/QueueFactory.h> #include <fsfw/ipc/QueueFactory.h>
#include <fsfw/timemanager/Stopwatch.h> #include <fsfw/timemanager/Stopwatch.h>
@ -9,18 +12,13 @@
#include "OBSWConfig.h" #include "OBSWConfig.h"
#include "StarTrackerJsonCommands.h" #include "StarTrackerJsonCommands.h"
extern "C" { #include "arcsec/common/misc.h"
#include <thirdparty/arcsec_star_tracker/client/generated/actionreq.h> #include "helpers.h"
#include <thirdparty/arcsec_star_tracker/client/generated/parameter.h>
#include <thirdparty/arcsec_star_tracker/client/generated/telemetry.h>
#include "common/misc.h"
}
std::atomic_bool JCFG_DONE(false); std::atomic_bool JCFG_DONE(false);
StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
const char* jsonFileStr, StrHelper* strHelper, const char* jsonFileStr, StrComHandler* strHelper,
power::Switch_t powerSwitch) power::Switch_t powerSwitch)
: DeviceHandlerBase(objectId, comIF, comCookie), : DeviceHandlerBase(objectId, comIF, comCookie),
temperatureSet(this), temperatureSet(this),
@ -84,8 +82,8 @@ ReturnValue_t StarTrackerHandler::initialize() {
return result; return result;
} }
result = manager->subscribeToEventRange(eventQueue->getId(), result = manager->subscribeToEventRange(eventQueue->getId(),
event::getEventId(StrHelper::IMAGE_UPLOAD_FAILED), event::getEventId(StrComHandler::IMAGE_UPLOAD_FAILED),
event::getEventId(StrHelper::FIRMWARE_UPDATE_FAILED)); event::getEventId(StrComHandler::FIRMWARE_UPDATE_FAILED));
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "StarTrackerHandler::initialize: Failed to subscribe to events from " sif::warning << "StarTrackerHandler::initialize: Failed to subscribe to events from "
@ -95,11 +93,11 @@ ReturnValue_t StarTrackerHandler::initialize() {
return ObjectManagerIF::CHILD_INIT_FAILED; return ObjectManagerIF::CHILD_INIT_FAILED;
} }
result = strHelper->setComIF(communicationInterface); // result = strHelper->setComIF(communicationInterface);
if (result != returnvalue::OK) { // if (result != returnvalue::OK) {
return ObjectManagerIF::CHILD_INIT_FAILED; // return ObjectManagerIF::CHILD_INIT_FAILED;
} // }
strHelper->setComCookie(comCookie); // strHelper->setComCookie(comCookie);
return returnvalue::OK; return returnvalue::OK;
} }
@ -828,41 +826,36 @@ ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t* start, size_t rema
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
size_t bytesLeft = 0; size_t bytesLeft = 0;
result = dataLinkLayer.decodeFrame(start, remainingSize, &bytesLeft); if (remainingSize == 0) {
switch (result) { *foundLen = remainingSize;
case ArcsecDatalinkLayer::DEC_IN_PROGRESS: { return returnvalue::OK;
remainingSize = bytesLeft;
// Need a second doSendRead pass to reaa in whole packet
return IGNORE_REPLY_DATA;
} }
case returnvalue::OK: { if (remainingSize < 3) {
break; sif::error << "StarTrackerHandler: Reply packet with length less than 3 is invalid"
} << std::endl;
default: return returnvalue::FAILED;
remainingSize = bytesLeft;
return result;
} }
switch (dataLinkLayer.getReplyFrameType()) { switch (str::getReplyFrameType(start)) {
case TMTC_ACTIONREPLY: { case TMTC_ACTIONREPLY: {
*foundLen = remainingSize - bytesLeft; *foundLen = remainingSize - bytesLeft;
result = scanForActionReply(foundId); result = scanForActionReply(str::getId(start), foundId);
break; break;
} }
case TMTC_SETPARAMREPLY: { case TMTC_SETPARAMREPLY: {
*foundLen = remainingSize - bytesLeft; *foundLen = remainingSize - bytesLeft;
result = scanForSetParameterReply(foundId); result = scanForSetParameterReply(str::getId(start), foundId);
break; break;
} }
case TMTC_PARAMREPLY: { case TMTC_PARAMREPLY: {
*foundLen = remainingSize - bytesLeft; *foundLen = remainingSize - bytesLeft;
result = scanForGetParameterReply(foundId); result = scanForGetParameterReply(str::getId(start), foundId);
break; break;
} }
case TMTC_TELEMETRYREPLYA: case TMTC_TELEMETRYREPLYA:
case TMTC_TELEMETRYREPLY: { case TMTC_TELEMETRYREPLY: {
*foundLen = remainingSize - bytesLeft; *foundLen = remainingSize - bytesLeft;
result = scanForTmReply(foundId); result = scanForTmReply(str::getId(start), foundId);
break; break;
} }
default: { default: {
@ -882,22 +875,22 @@ ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id,
switch (id) { switch (id) {
case (startracker::REQ_TIME): { case (startracker::REQ_TIME): {
result = handleTm(timeSet, startracker::TimeSet::SIZE); result = handleTm(packet, timeSet, startracker::TimeSet::SIZE);
break; break;
} }
case (startracker::PING_REQUEST): { case (startracker::PING_REQUEST): {
result = handlePingReply(); result = handlePingReply(packet);
break; break;
} }
case (startracker::BOOT): case (startracker::BOOT):
case (startracker::TAKE_IMAGE): case (startracker::TAKE_IMAGE):
break; break;
case (startracker::CHECKSUM): { case (startracker::CHECKSUM): {
result = handleChecksumReply(); result = handleChecksumReply(packet);
break; break;
} }
case (startracker::REQ_VERSION): { case (startracker::REQ_VERSION): {
result = handleTm(versionSet, startracker::VersionSet::SIZE); result = handleTm(packet, versionSet, startracker::VersionSet::SIZE);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
@ -908,23 +901,23 @@ ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id,
break; break;
} }
case (startracker::REQ_INTERFACE): { case (startracker::REQ_INTERFACE): {
result = handleTm(interfaceSet, startracker::InterfaceSet::SIZE); result = handleTm(packet, interfaceSet, startracker::InterfaceSet::SIZE);
break; break;
} }
case (startracker::REQ_POWER): { case (startracker::REQ_POWER): {
result = handleTm(powerSet, startracker::PowerSet::SIZE); result = handleTm(packet, powerSet, startracker::PowerSet::SIZE);
break; break;
} }
case (startracker::REQ_SOLUTION): { case (startracker::REQ_SOLUTION): {
result = handleTm(solutionSet, startracker::SolutionSet::SIZE); result = handleTm(packet, solutionSet, startracker::SolutionSet::SIZE);
break; break;
} }
case (startracker::REQ_TEMPERATURE): { case (startracker::REQ_TEMPERATURE): {
result = handleTm(temperatureSet, startracker::TemperatureSet::SIZE); result = handleTm(packet, temperatureSet, startracker::TemperatureSet::SIZE);
break; break;
} }
case (startracker::REQ_HISTOGRAM): { case (startracker::REQ_HISTOGRAM): {
result = handleTm(histogramSet, startracker::HistogramSet::SIZE); result = handleTm(packet, histogramSet, startracker::HistogramSet::SIZE);
break; break;
} }
case (startracker::SUBSCRIPTION): case (startracker::SUBSCRIPTION):
@ -941,63 +934,63 @@ ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id,
case (startracker::VALIDATION): case (startracker::VALIDATION):
case (startracker::IMAGE_PROCESSOR): case (startracker::IMAGE_PROCESSOR):
case (startracker::ALGO): { case (startracker::ALGO): {
result = handleSetParamReply(); result = handleSetParamReply(packet);
break; break;
} }
case (startracker::REQ_CAMERA): { case (startracker::REQ_CAMERA): {
handleParamRequest(cameraSet, startracker::CameraSet::SIZE); handleParamRequest(packet, cameraSet, startracker::CameraSet::SIZE);
break; break;
} }
case (startracker::REQ_LIMITS): { case (startracker::REQ_LIMITS): {
handleParamRequest(limitsSet, startracker::LimitsSet::SIZE); handleParamRequest(packet, limitsSet, startracker::LimitsSet::SIZE);
break; break;
} }
case (startracker::REQ_LOG_LEVEL): { case (startracker::REQ_LOG_LEVEL): {
handleParamRequest(loglevelSet, startracker::LogLevelSet::SIZE); handleParamRequest(packet, loglevelSet, startracker::LogLevelSet::SIZE);
break; break;
} }
case (startracker::REQ_MOUNTING): { case (startracker::REQ_MOUNTING): {
handleParamRequest(mountingSet, startracker::MountingSet::SIZE); handleParamRequest(packet, mountingSet, startracker::MountingSet::SIZE);
break; break;
} }
case (startracker::REQ_IMAGE_PROCESSOR): { case (startracker::REQ_IMAGE_PROCESSOR): {
handleParamRequest(imageProcessorSet, startracker::ImageProcessorSet::SIZE); handleParamRequest(packet, imageProcessorSet, startracker::ImageProcessorSet::SIZE);
break; break;
} }
case (startracker::REQ_CENTROIDING): { case (startracker::REQ_CENTROIDING): {
handleParamRequest(centroidingSet, startracker::CentroidingSet::SIZE); handleParamRequest(packet, centroidingSet, startracker::CentroidingSet::SIZE);
break; break;
} }
case (startracker::REQ_LISA): { case (startracker::REQ_LISA): {
handleParamRequest(lisaSet, startracker::LisaSet::SIZE); handleParamRequest(packet, lisaSet, startracker::LisaSet::SIZE);
break; break;
} }
case (startracker::REQ_MATCHING): { case (startracker::REQ_MATCHING): {
handleParamRequest(matchingSet, startracker::MatchingSet::SIZE); handleParamRequest(packet, matchingSet, startracker::MatchingSet::SIZE);
break; break;
} }
case (startracker::REQ_TRACKING): { case (startracker::REQ_TRACKING): {
handleParamRequest(trackingSet, startracker::TrackingSet::SIZE); handleParamRequest(packet, trackingSet, startracker::TrackingSet::SIZE);
break; break;
} }
case (startracker::REQ_VALIDATION): { case (startracker::REQ_VALIDATION): {
handleParamRequest(validationSet, startracker::ValidationSet::SIZE); handleParamRequest(packet, validationSet, startracker::ValidationSet::SIZE);
break; break;
} }
case (startracker::REQ_ALGO): { case (startracker::REQ_ALGO): {
handleParamRequest(algoSet, startracker::AlgoSet::SIZE); handleParamRequest(packet, algoSet, startracker::AlgoSet::SIZE);
break; break;
} }
case (startracker::REQ_SUBSCRIPTION): { case (startracker::REQ_SUBSCRIPTION): {
handleParamRequest(subscriptionSet, startracker::SubscriptionSet::SIZE); handleParamRequest(packet, subscriptionSet, startracker::SubscriptionSet::SIZE);
break; break;
} }
case (startracker::REQ_LOG_SUBSCRIPTION): { case (startracker::REQ_LOG_SUBSCRIPTION): {
handleParamRequest(logSubscriptionSet, startracker::LogSubscriptionSet::SIZE); handleParamRequest(packet, logSubscriptionSet, startracker::LogSubscriptionSet::SIZE);
break; break;
} }
case (startracker::REQ_DEBUG_CAMERA): { case (startracker::REQ_DEBUG_CAMERA): {
handleParamRequest(debugCameraSet, startracker::DebugCameraSet::SIZE); handleParamRequest(packet, debugCameraSet, startracker::DebugCameraSet::SIZE);
break; break;
} }
default: { default: {
@ -1328,9 +1321,8 @@ ReturnValue_t StarTrackerHandler::checkMode(ActionId_t actionId) {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::scanForActionReply(DeviceCommandId_t* foundId) { ReturnValue_t StarTrackerHandler::scanForActionReply(uint8_t replyId, DeviceCommandId_t* foundId) {
const uint8_t* reply = dataLinkLayer.getReply(); switch (replyId) {
switch (*reply) {
case (startracker::ID::PING): { case (startracker::ID::PING): {
*foundId = startracker::PING_REQUEST; *foundId = startracker::PING_REQUEST;
break; break;
@ -1359,9 +1351,9 @@ ReturnValue_t StarTrackerHandler::scanForActionReply(DeviceCommandId_t* foundId)
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::scanForSetParameterReply(DeviceCommandId_t* foundId) { ReturnValue_t StarTrackerHandler::scanForSetParameterReply(uint8_t replyId,
const uint8_t* reply = dataLinkLayer.getReply(); DeviceCommandId_t* foundId) {
switch (*reply) { switch (replyId) {
case (startracker::ID::SUBSCRIPTION): { case (startracker::ID::SUBSCRIPTION): {
*foundId = startracker::SUBSCRIPTION; *foundId = startracker::SUBSCRIPTION;
break; break;
@ -1426,9 +1418,9 @@ ReturnValue_t StarTrackerHandler::scanForSetParameterReply(DeviceCommandId_t* fo
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::scanForGetParameterReply(DeviceCommandId_t* foundId) { ReturnValue_t StarTrackerHandler::scanForGetParameterReply(uint8_t replyId,
const uint8_t* reply = dataLinkLayer.getReply(); DeviceCommandId_t* foundId) {
switch (*reply) { switch (replyId) {
case (startracker::ID::CAMERA): { case (startracker::ID::CAMERA): {
*foundId = startracker::REQ_CAMERA; *foundId = startracker::REQ_CAMERA;
break; break;
@ -1494,9 +1486,8 @@ ReturnValue_t StarTrackerHandler::scanForGetParameterReply(DeviceCommandId_t* fo
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::scanForTmReply(DeviceCommandId_t* foundId) { ReturnValue_t StarTrackerHandler::scanForTmReply(uint8_t replyId, DeviceCommandId_t* foundId) {
const uint8_t* reply = dataLinkLayer.getReply(); switch (replyId) {
switch (*reply) {
case (startracker::ID::VERSION): { case (startracker::ID::VERSION): {
*foundId = startracker::REQ_VERSION; *foundId = startracker::REQ_VERSION;
break; break;
@ -1527,7 +1518,7 @@ ReturnValue_t StarTrackerHandler::scanForTmReply(DeviceCommandId_t* foundId) {
} }
default: { default: {
sif::debug << "StarTrackerHandler::scanForTmReply: Reply contains invalid reply id: " sif::debug << "StarTrackerHandler::scanForTmReply: Reply contains invalid reply id: "
<< static_cast<unsigned int>(*reply) << std::endl; << static_cast<unsigned int>(replyId) << std::endl;
return returnvalue::FAILED; return returnvalue::FAILED;
break; break;
} }
@ -1586,9 +1577,9 @@ void StarTrackerHandler::prepareBootCommand() {
uint32_t length = 0; uint32_t length = 0;
struct BootActionRequest bootRequest = {BOOT_REGION_ID}; struct BootActionRequest bootRequest = {BOOT_REGION_ID};
arc_pack_boot_action_req(&bootRequest, commandBuffer, &length); arc_pack_boot_action_req(&bootRequest, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
ReturnValue_t StarTrackerHandler::prepareChecksumCommand(const uint8_t* commandData, ReturnValue_t StarTrackerHandler::prepareChecksumCommand(const uint8_t* commandData,
@ -1620,9 +1611,9 @@ ReturnValue_t StarTrackerHandler::prepareChecksumCommand(const uint8_t* commandD
} }
uint32_t rawCmdLength = 0; uint32_t rawCmdLength = 0;
arc_pack_checksum_action_req(&req, commandBuffer, &rawCmdLength); arc_pack_checksum_action_req(&req, commandBuffer, &rawCmdLength);
dataLinkLayer.encodeFrame(commandBuffer, rawCmdLength); // dataLinkLayer.encodeFrame(commandBuffer, rawCmdLength);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = rawCmdLength; // dataLinkLayer.getEncodedLength();
checksumCmd.rememberRegion = req.region; checksumCmd.rememberRegion = req.region;
checksumCmd.rememberAddress = req.address; checksumCmd.rememberAddress = req.address;
checksumCmd.rememberLength = req.length; checksumCmd.rememberLength = req.length;
@ -1632,51 +1623,51 @@ ReturnValue_t StarTrackerHandler::prepareChecksumCommand(const uint8_t* commandD
void StarTrackerHandler::prepareTimeRequest() { void StarTrackerHandler::prepareTimeRequest() {
uint32_t length = 0; uint32_t length = 0;
arc_tm_pack_time_req(commandBuffer, &length); arc_tm_pack_time_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
void StarTrackerHandler::preparePingRequest() { void StarTrackerHandler::preparePingRequest() {
uint32_t length = 0; uint32_t length = 0;
struct PingActionRequest pingRequest = {PING_ID}; struct PingActionRequest pingRequest = {PING_ID};
arc_pack_ping_action_req(&pingRequest, commandBuffer, &length); arc_pack_ping_action_req(&pingRequest, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
void StarTrackerHandler::prepareVersionRequest() { void StarTrackerHandler::prepareVersionRequest() {
uint32_t length = 0; uint32_t length = 0;
arc_tm_pack_version_req(commandBuffer, &length); arc_tm_pack_version_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
void StarTrackerHandler::prepareInterfaceRequest() { void StarTrackerHandler::prepareInterfaceRequest() {
uint32_t length = 0; uint32_t length = 0;
arc_tm_pack_interface_req(commandBuffer, &length); arc_tm_pack_interface_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
void StarTrackerHandler::preparePowerRequest() { void StarTrackerHandler::preparePowerRequest() {
uint32_t length = 0; uint32_t length = 0;
arc_tm_pack_power_req(commandBuffer, &length); arc_tm_pack_power_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
void StarTrackerHandler::prepareSwitchToBootloaderCmd() { void StarTrackerHandler::prepareSwitchToBootloaderCmd() {
uint32_t length = 0; uint32_t length = 0;
struct RebootActionRequest rebootReq {}; struct RebootActionRequest rebootReq {};
arc_pack_reboot_action_req(&rebootReq, commandBuffer, &length); arc_pack_reboot_action_req(&rebootReq, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
void StarTrackerHandler::prepareTakeImageCommand(const uint8_t* commandData) { void StarTrackerHandler::prepareTakeImageCommand(const uint8_t* commandData) {
@ -1684,33 +1675,33 @@ void StarTrackerHandler::prepareTakeImageCommand(const uint8_t* commandData) {
struct CameraActionRequest camReq; struct CameraActionRequest camReq;
camReq.actionid = *commandData; camReq.actionid = *commandData;
arc_pack_camera_action_req(&camReq, commandBuffer, &length); arc_pack_camera_action_req(&camReq, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
void StarTrackerHandler::prepareSolutionRequest() { void StarTrackerHandler::prepareSolutionRequest() {
uint32_t length = 0; uint32_t length = 0;
arc_tm_pack_solution_req(commandBuffer, &length); arc_tm_pack_solution_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
void StarTrackerHandler::prepareTemperatureRequest() { void StarTrackerHandler::prepareTemperatureRequest() {
uint32_t length = 0; uint32_t length = 0;
arc_tm_pack_temperature_req(commandBuffer, &length); arc_tm_pack_temperature_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
void StarTrackerHandler::prepareHistogramRequest() { void StarTrackerHandler::prepareHistogramRequest() {
uint32_t length = 0; uint32_t length = 0;
arc_tm_pack_histogram_req(commandBuffer, &length); arc_tm_pack_histogram_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); // dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacket = commandBuffer; // dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = length; // dataLinkLayer.getEncodedLength();
} }
ReturnValue_t StarTrackerHandler::prepareParamCommand(const uint8_t* commandData, ReturnValue_t StarTrackerHandler::prepareParamCommand(const uint8_t* commandData,
@ -1727,176 +1718,159 @@ ReturnValue_t StarTrackerHandler::prepareParamCommand(const uint8_t* commandData
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
dataLinkLayer.encodeFrame(commandBuffer, paramSet.getSize()); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = paramSet.getSize();
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestCameraParams() { ReturnValue_t StarTrackerHandler::prepareRequestCameraParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_camera_parameter_req(commandBuffer, &length); arc_pack_camera_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestLimitsParams() { ReturnValue_t StarTrackerHandler::prepareRequestLimitsParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_limits_parameter_req(commandBuffer, &length); arc_pack_limits_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestLogLevelParams() { ReturnValue_t StarTrackerHandler::prepareRequestLogLevelParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_loglevel_parameter_req(commandBuffer, &length); arc_pack_loglevel_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestMountingParams() { ReturnValue_t StarTrackerHandler::prepareRequestMountingParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_mounting_parameter_req(commandBuffer, &length); arc_pack_mounting_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestImageProcessorParams() { ReturnValue_t StarTrackerHandler::prepareRequestImageProcessorParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_imageprocessor_parameter_req(commandBuffer, &length); arc_pack_imageprocessor_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestCentroidingParams() { ReturnValue_t StarTrackerHandler::prepareRequestCentroidingParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_centroiding_parameter_req(commandBuffer, &length); arc_pack_centroiding_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestLisaParams() { ReturnValue_t StarTrackerHandler::prepareRequestLisaParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_lisa_parameter_req(commandBuffer, &length); arc_pack_lisa_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestMatchingParams() { ReturnValue_t StarTrackerHandler::prepareRequestMatchingParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_matching_parameter_req(commandBuffer, &length); arc_pack_matching_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestTrackingParams() { ReturnValue_t StarTrackerHandler::prepareRequestTrackingParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_tracking_parameter_req(commandBuffer, &length); arc_pack_tracking_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestValidationParams() { ReturnValue_t StarTrackerHandler::prepareRequestValidationParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_validation_parameter_req(commandBuffer, &length); arc_pack_validation_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestAlgoParams() { ReturnValue_t StarTrackerHandler::prepareRequestAlgoParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_algo_parameter_req(commandBuffer, &length); arc_pack_algo_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestSubscriptionParams() { ReturnValue_t StarTrackerHandler::prepareRequestSubscriptionParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_subscription_parameter_req(commandBuffer, &length); arc_pack_subscription_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestLogSubscriptionParams() { ReturnValue_t StarTrackerHandler::prepareRequestLogSubscriptionParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_logsubscription_parameter_req(commandBuffer, &length); arc_pack_logsubscription_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::prepareRequestDebugCameraParams() { ReturnValue_t StarTrackerHandler::prepareRequestDebugCameraParams() {
uint32_t length = 0; uint32_t length = 0;
arc_pack_debugcamera_parameter_req(commandBuffer, &length); arc_pack_debugcamera_parameter_req(commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length); rawPacket = commandBuffer;
rawPacket = dataLinkLayer.getEncodedFrame(); rawPacketLen = length;
rawPacketLen = dataLinkLayer.getEncodedLength();
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::handleSetParamReply() { ReturnValue_t StarTrackerHandler::handleSetParamReply(const uint8_t* rawFrame) {
const uint8_t* reply = dataLinkLayer.getReply(); uint8_t status = str::getStatusField(rawFrame);
uint8_t status = *(reply + STATUS_OFFSET);
if (status != startracker::STATUS_OK) { if (status != startracker::STATUS_OK) {
sif::warning << "StarTrackerHandler::handleSetParamReply: Failed to execute parameter set " sif::warning << "StarTrackerHandler::handleSetParamReply: Failed to execute parameter set "
" command with parameter ID" " command with parameter ID"
<< static_cast<unsigned int>(*(reply + PARAMETER_ID_OFFSET)) << std::endl; << static_cast<unsigned int>(*(rawFrame + PARAMETER_ID_OFFSET)) << std::endl;
if (internalState != InternalState::IDLE) { if (internalState != InternalState::IDLE) {
internalState = InternalState::IDLE; internalState = InternalState::IDLE;
} }
return SET_PARAM_FAILED; return SET_PARAM_FAILED;
} }
if (internalState != InternalState::IDLE) { if (internalState != InternalState::IDLE) {
handleStartup(reply + PARAMETER_ID_OFFSET); handleStartup(rawFrame + 1 + PARAMETER_ID_OFFSET);
} }
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::handleActionReply() { ReturnValue_t StarTrackerHandler::handleActionReply(const uint8_t* rawFrame) {
const uint8_t* reply = dataLinkLayer.getReply(); uint8_t status = str::getStatusField(rawFrame);
uint8_t status = *(reply + STATUS_OFFSET);
if (status != startracker::STATUS_OK) { if (status != startracker::STATUS_OK) {
sif::warning << "StarTrackerHandler::handleActionReply: Failed to execute action " sif::warning << "StarTrackerHandler::handleActionReply: Failed to execute action "
<< "command with action ID " << "command with action ID "
<< static_cast<unsigned int>(*(reply + ACTION_ID_OFFSET)) << " and status " << static_cast<unsigned int>(*(rawFrame + ACTION_ID_OFFSET)) << " and status "
<< static_cast<unsigned int>(status) << std::endl; << static_cast<unsigned int>(status) << std::endl;
return ACTION_FAILED; return ACTION_FAILED;
} }
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::handleChecksumReply() { ReturnValue_t StarTrackerHandler::handleChecksumReply(const uint8_t* rawFrame) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
result = handleActionReply(); result = handleActionReply(rawFrame);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
const uint8_t* replyData = dataLinkLayer.getReply() + ACTION_DATA_OFFSET; const uint8_t* replyData = rawFrame + ACTION_DATA_OFFSET;
startracker::ChecksumReply checksumReply(replyData); startracker::ChecksumReply checksumReply(replyData);
if (checksumReply.getRegion() != checksumCmd.rememberRegion) { if (checksumReply.getRegion() != checksumCmd.rememberRegion) {
sif::warning << "StarTrackerHandler::handleChecksumReply: Region mismatch" << std::endl; sif::warning << "StarTrackerHandler::handleChecksumReply: Region mismatch" << std::endl;
@ -1919,13 +1893,14 @@ ReturnValue_t StarTrackerHandler::handleChecksumReply() {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::handleParamRequest(LocalPoolDataSetBase& dataset, size_t size) { ReturnValue_t StarTrackerHandler::handleParamRequest(const uint8_t* rawFrame,
LocalPoolDataSetBase& dataset, size_t size) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
result = dataset.read(TIMEOUT_TYPE, MUTEX_TIMEOUT); result = dataset.read(TIMEOUT_TYPE, MUTEX_TIMEOUT);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
const uint8_t* reply = dataLinkLayer.getReply() + PARAMS_OFFSET; const uint8_t* reply = rawFrame + PARAMS_OFFSET;
dataset.setValidityBufferGeneration(false); dataset.setValidityBufferGeneration(false);
result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE); result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -1943,25 +1918,20 @@ ReturnValue_t StarTrackerHandler::handleParamRequest(LocalPoolDataSetBase& datas
return result; return result;
} }
ReturnValue_t StarTrackerHandler::handlePingReply() { ReturnValue_t StarTrackerHandler::handlePingReply(const uint8_t* rawFrame) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
uint32_t pingId = 0; uint32_t pingId = 0;
const uint8_t* reply = dataLinkLayer.getReply(); uint8_t status = str::getStatusField(rawFrame);
uint8_t status = dataLinkLayer.getStatusField(); const uint8_t* buffer = rawFrame + ACTION_DATA_OFFSET;
const uint8_t* buffer = reply + ACTION_DATA_OFFSET;
size_t size = sizeof(pingId); size_t size = sizeof(pingId);
SerializeAdapter::deSerialize(&pingId, &buffer, &size, SerializeIF::Endianness::LITTLE); SerializeAdapter::deSerialize(&pingId, &buffer, &size, SerializeIF::Endianness::LITTLE);
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1
sif::info << "StarTracker: Ping status: " << static_cast<unsigned int>(status) << std::endl; sif::info << "StarTracker: Ping status: " << static_cast<unsigned int>(status) << std::endl;
sif::info << "Ping id: 0x" << std::hex << pingId << std::endl; sif::info << "Ping ID: 0x" << std::hex << pingId << std::endl;
#endif /* OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1 */
if (status != startracker::STATUS_OK || pingId != PING_ID) { if (status != startracker::STATUS_OK || pingId != PING_ID) {
sif::warning << "StarTrackerHandler::handlePingReply: Ping failed" << std::endl; sif::warning << "STR: Ping failed" << std::endl;
result = PING_FAILED; result = PING_FAILED;
} else { } else {
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1 sif::info << "STR: Ping OK" << std::endl;
sif::info << "StarTracker: Ping successful" << std::endl;
#endif
} }
return result; return result;
} }
@ -2001,9 +1971,10 @@ ReturnValue_t StarTrackerHandler::checkProgram() {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StarTrackerHandler::handleTm(LocalPoolDataSetBase& dataset, size_t size) { ReturnValue_t StarTrackerHandler::handleTm(const uint8_t* rawFrame, LocalPoolDataSetBase& dataset,
size_t size) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
uint8_t status = *(dataLinkLayer.getReply() + STATUS_OFFSET); uint8_t status = str::getStatusField(rawFrame);
if (status != startracker::STATUS_OK) { if (status != startracker::STATUS_OK) {
sif::warning << "StarTrackerHandler::handleTm: Reply error: " sif::warning << "StarTrackerHandler::handleTm: Reply error: "
<< static_cast<unsigned int>(status) << std::endl; << static_cast<unsigned int>(status) << std::endl;
@ -2013,7 +1984,7 @@ ReturnValue_t StarTrackerHandler::handleTm(LocalPoolDataSetBase& dataset, size_t
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
const uint8_t* reply = dataLinkLayer.getReply() + TICKS_OFFSET; const uint8_t* reply = rawFrame + TICKS_OFFSET;
dataset.setValidityBufferGeneration(false); dataset.setValidityBufferGeneration(false);
result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE); result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -2031,9 +2002,10 @@ ReturnValue_t StarTrackerHandler::handleTm(LocalPoolDataSetBase& dataset, size_t
return result; return result;
} }
ReturnValue_t StarTrackerHandler::handleActionReplySet(LocalPoolDataSetBase& dataset, size_t size) { ReturnValue_t StarTrackerHandler::handleActionReplySet(const uint8_t* rawFrame,
LocalPoolDataSetBase& dataset, size_t size) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
uint8_t status = *(dataLinkLayer.getReply() + STATUS_OFFSET); uint8_t status = str::getStatusField(rawFrame);
if (status != startracker::STATUS_OK) { if (status != startracker::STATUS_OK) {
sif::warning << "StarTrackerHandler::handleActionReplySet: Reply error: " sif::warning << "StarTrackerHandler::handleActionReplySet: Reply error: "
<< static_cast<unsigned int>(status) << std::endl; << static_cast<unsigned int>(status) << std::endl;
@ -2043,7 +2015,7 @@ ReturnValue_t StarTrackerHandler::handleActionReplySet(LocalPoolDataSetBase& dat
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
const uint8_t* reply = dataLinkLayer.getReply() + ACTION_DATA_OFFSET; const uint8_t* reply = rawFrame + ACTION_DATA_OFFSET;
dataset.setValidityBufferGeneration(false); dataset.setValidityBufferGeneration(false);
result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE); result = dataset.deSerialize(&reply, &size, SerializeIF::Endianness::LITTLE);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {

View File

@ -3,19 +3,19 @@
#include <fsfw/datapool/PoolReadGuard.h> #include <fsfw/datapool/PoolReadGuard.h>
#include <linux/devices/startracker/StarTrackerJsonCommands.h> #include <linux/devices/startracker/StarTrackerJsonCommands.h>
#include <linux/devices/startracker/StrComHandler.h>
#include <thread> #include <thread>
#include "ArcsecDatalinkLayer.h" #include "ArcsecDatalinkLayer.h"
#include "ArcsecJsonParamBase.h" #include "ArcsecJsonParamBase.h"
#include "OBSWConfig.h" #include "OBSWConfig.h"
#include "StrHelper.h" #include "arcsec/common/SLIP.h"
#include "devices/powerSwitcherList.h" #include "devices/powerSwitcherList.h"
#include "fsfw/devicehandlers/DeviceHandlerBase.h" #include "fsfw/devicehandlers/DeviceHandlerBase.h"
#include "fsfw/src/fsfw/serialize/SerializeAdapter.h" #include "fsfw/src/fsfw/serialize/SerializeAdapter.h"
#include "fsfw/timemanager/Countdown.h" #include "fsfw/timemanager/Countdown.h"
#include "linux/devices/devicedefinitions/StarTrackerDefinitions.h" #include "linux/devices/devicedefinitions/StarTrackerDefinitions.h"
#include "thirdparty/arcsec_star_tracker/common/SLIP.h"
/** /**
* @brief This is the device handler for the star tracker from arcsec. * @brief This is the device handler for the star tracker from arcsec.
@ -38,7 +38,8 @@ class StarTrackerHandler : public DeviceHandlerBase {
* to high to enable the device. * to high to enable the device.
*/ */
StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie, StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF* comCookie,
const char* jsonFileStr, StrHelper* strHelper, power::Switch_t powerSwitch); const char* jsonFileStr, StrComHandler* strHelper,
power::Switch_t powerSwitch);
virtual ~StarTrackerHandler(); virtual ~StarTrackerHandler();
ReturnValue_t initialize() override; ReturnValue_t initialize() override;
@ -149,14 +150,14 @@ class StarTrackerHandler : public DeviceHandlerBase {
static const size_t MAX_PATH_SIZE = 50; static const size_t MAX_PATH_SIZE = 50;
static const size_t MAX_FILE_NAME = 30; static const size_t MAX_FILE_NAME = 30;
static const uint8_t STATUS_OFFSET = 1; static const uint8_t STATUS_OFFSET = 2;
static const uint8_t PARAMS_OFFSET = 1; static const uint8_t PARAMS_OFFSET = 2;
static const uint8_t TICKS_OFFSET = 2; static const uint8_t TICKS_OFFSET = 3;
static const uint8_t TIME_OFFSET = 6; static const uint8_t TIME_OFFSET = 7;
static const uint8_t TM_DATA_FIELD_OFFSET = 14; static const uint8_t PARAMETER_ID_OFFSET = 1;
static const uint8_t PARAMETER_ID_OFFSET = 0; static const uint8_t ACTION_ID_OFFSET = 1;
static const uint8_t ACTION_ID_OFFSET = 0; static const uint8_t ACTION_DATA_OFFSET = 3;
static const uint8_t ACTION_DATA_OFFSET = 2;
// Ping request will reply ping with this ID (data field) // Ping request will reply ping with this ID (data field)
static const uint32_t PING_ID = 0x55; static const uint32_t PING_ID = 0x55;
static const uint32_t BOOT_REGION_ID = 1; static const uint32_t BOOT_REGION_ID = 1;
@ -184,7 +185,7 @@ class StarTrackerHandler : public DeviceHandlerBase {
MessageQueueIF* eventQueue = nullptr; MessageQueueIF* eventQueue = nullptr;
ArcsecDatalinkLayer dataLinkLayer; // ArcsecDatalinkLayer dataLinkLayer;
startracker::TemperatureSet temperatureSet; startracker::TemperatureSet temperatureSet;
startracker::VersionSet versionSet; startracker::VersionSet versionSet;
@ -210,7 +211,7 @@ class StarTrackerHandler : public DeviceHandlerBase {
startracker::DebugCameraSet debugCameraSet; startracker::DebugCameraSet debugCameraSet;
// Pointer to object responsible for uploading and downloading images to/from the star tracker // Pointer to object responsible for uploading and downloading images to/from the star tracker
StrHelper* strHelper = nullptr; StrComHandler* strHelper = nullptr;
uint8_t commandBuffer[startracker::MAX_FRAME_SIZE]; uint8_t commandBuffer[startracker::MAX_FRAME_SIZE];
@ -312,10 +313,10 @@ class StarTrackerHandler : public DeviceHandlerBase {
*/ */
void slipInit(); void slipInit();
ReturnValue_t scanForActionReply(DeviceCommandId_t* foundId); ReturnValue_t scanForActionReply(uint8_t replyId, DeviceCommandId_t* foundId);
ReturnValue_t scanForSetParameterReply(DeviceCommandId_t* foundId); ReturnValue_t scanForSetParameterReply(uint8_t replyId, DeviceCommandId_t* foundId);
ReturnValue_t scanForGetParameterReply(DeviceCommandId_t* foundId); ReturnValue_t scanForGetParameterReply(uint8_t replyId, DeviceCommandId_t* foundId);
ReturnValue_t scanForTmReply(DeviceCommandId_t* foundId); ReturnValue_t scanForTmReply(uint8_t replyId, DeviceCommandId_t* foundId);
/** /**
* @brief Fills command buffer with data to ping the star tracker * @brief Fills command buffer with data to ping the star tracker
@ -437,12 +438,13 @@ class StarTrackerHandler : public DeviceHandlerBase {
/** /**
* @brief Handles action replies with datasets. * @brief Handles action replies with datasets.
*/ */
ReturnValue_t handleActionReplySet(LocalPoolDataSetBase& dataset, size_t size); ReturnValue_t handleActionReplySet(const uint8_t* rawFrame, LocalPoolDataSetBase& dataset,
size_t size);
/** /**
* @brief Default function to handle action replies * @brief Default function to handle action replies
*/ */
ReturnValue_t handleActionReply(); ReturnValue_t handleActionReply(const uint8_t* rawFrame);
/** /**
* @brief Handles reply to upload centroid command * @brief Handles reply to upload centroid command
@ -452,16 +454,17 @@ class StarTrackerHandler : public DeviceHandlerBase {
/** /**
* @brief Handles reply to checksum command * @brief Handles reply to checksum command
*/ */
ReturnValue_t handleChecksumReply(); ReturnValue_t handleChecksumReply(const uint8_t* rawFrame);
/** /**
* @brief Handles all set parameter replies * @brief Handles all set parameter replies
*/ */
ReturnValue_t handleSetParamReply(); ReturnValue_t handleSetParamReply(const uint8_t* rawFrame);
ReturnValue_t handlePingReply(); ReturnValue_t handlePingReply(const uint8_t* rawFrame);
ReturnValue_t handleParamRequest(LocalPoolDataSetBase& dataset, size_t size); ReturnValue_t handleParamRequest(const uint8_t* rawFrame, LocalPoolDataSetBase& dataset,
size_t size);
/** /**
* @brief Checks the loaded program by means of the version set * @brief Checks the loaded program by means of the version set
@ -481,7 +484,7 @@ class StarTrackerHandler : public DeviceHandlerBase {
* *
* @return returnvalue::OK if successful, otherwise error return value * @return returnvalue::OK if successful, otherwise error return value
*/ */
ReturnValue_t handleTm(LocalPoolDataSetBase& dataset, size_t size); ReturnValue_t handleTm(const uint8_t* rawFrame, LocalPoolDataSetBase& dataset, size_t size);
/** /**
* @brief Checks if star tracker is in valid mode for executing the received command. * @brief Checks if star tracker is in valid mode for executing the received command.

View File

@ -1,6 +1,8 @@
#include "StrHelper.h" #include <fcntl.h>
#include <fsfw/filesystem/HasFileSystemIF.h> #include <fsfw/filesystem/HasFileSystemIF.h>
#include <fsfw/tasks/TaskFactory.h>
#include <linux/devices/startracker/StrComHandler.h>
#include <unistd.h>
#include <filesystem> #include <filesystem>
#include <fstream> #include <fstream>
@ -8,16 +10,19 @@
#include "OBSWConfig.h" #include "OBSWConfig.h"
#include "eive/definitions.h" #include "eive/definitions.h"
#include "fsfw/timemanager/Countdown.h" #include "fsfw/timemanager/Countdown.h"
#include "helpers.h"
#include "linux/devices/devicedefinitions/StarTrackerDefinitions.h" #include "linux/devices/devicedefinitions/StarTrackerDefinitions.h"
#include "mission/utility/Filenaming.h" #include "mission/utility/Filenaming.h"
#include "mission/utility/ProgressPrinter.h" #include "mission/utility/ProgressPrinter.h"
#include "mission/utility/Timestamp.h" #include "mission/utility/Timestamp.h"
StrHelper::StrHelper(object_id_t objectId) : SystemObject(objectId) {} using namespace returnvalue;
StrHelper::~StrHelper() {} StrComHandler::StrComHandler(object_id_t objectId) : SystemObject(objectId) {}
ReturnValue_t StrHelper::initialize() { StrComHandler::~StrComHandler() {}
ReturnValue_t StrComHandler::initialize() {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
sdcMan = SdCardManager::instance(); sdcMan = SdCardManager::instance();
if (sdcMan == nullptr) { if (sdcMan == nullptr) {
@ -28,7 +33,7 @@ ReturnValue_t StrHelper::initialize() {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StrHelper::performOperation(uint8_t operationCode) { ReturnValue_t StrComHandler::performOperation(uint8_t operationCode) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
semaphore.acquire(); semaphore.acquire();
while (true) { while (true) {
@ -84,18 +89,7 @@ ReturnValue_t StrHelper::performOperation(uint8_t operationCode) {
} }
} }
ReturnValue_t StrHelper::setComIF(DeviceCommunicationIF* communicationInterface_) { ReturnValue_t StrComHandler::startImageUpload(std::string fullname) {
uartComIF = dynamic_cast<SerialComIF*>(communicationInterface_);
if (uartComIF == nullptr) {
sif::warning << "StrHelper::initialize: Invalid uart com if" << std::endl;
return returnvalue::FAILED;
}
return returnvalue::OK;
}
void StrHelper::setComCookie(CookieIF* comCookie_) { comCookie = comCookie_; }
ReturnValue_t StrHelper::startImageUpload(std::string fullname) {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
ReturnValue_t result = checkPath(fullname); ReturnValue_t result = checkPath(fullname);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -112,7 +106,7 @@ ReturnValue_t StrHelper::startImageUpload(std::string fullname) {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StrHelper::startImageDownload(std::string path) { ReturnValue_t StrComHandler::startImageDownload(std::string path) {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
ReturnValue_t result = checkPath(path); ReturnValue_t result = checkPath(path);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -129,13 +123,15 @@ ReturnValue_t StrHelper::startImageDownload(std::string path) {
return returnvalue::OK; return returnvalue::OK;
} }
void StrHelper::stopProcess() { terminate = true; } void StrComHandler::stopProcess() { terminate = true; }
void StrHelper::setDownloadImageName(std::string filename) { downloadImage.filename = filename; } void StrComHandler::setDownloadImageName(std::string filename) {
downloadImage.filename = filename;
}
void StrHelper::setFlashReadFilename(std::string filename) { flashRead.filename = filename; } void StrComHandler::setFlashReadFilename(std::string filename) { flashRead.filename = filename; }
ReturnValue_t StrHelper::startFirmwareUpdate(std::string fullname) { ReturnValue_t StrComHandler::startFirmwareUpdate(std::string fullname) {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
ReturnValue_t result = checkPath(fullname); ReturnValue_t result = checkPath(fullname);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -154,7 +150,8 @@ ReturnValue_t StrHelper::startFirmwareUpdate(std::string fullname) {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StrHelper::startFlashRead(std::string path, uint8_t startRegion, uint32_t length) { ReturnValue_t StrComHandler::startFlashRead(std::string path, uint8_t startRegion,
uint32_t length) {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
ReturnValue_t result = checkPath(path); ReturnValue_t result = checkPath(path);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -173,11 +170,11 @@ ReturnValue_t StrHelper::startFlashRead(std::string path, uint8_t startRegion, u
return returnvalue::OK; return returnvalue::OK;
} }
void StrHelper::disableTimestamping() { timestamping = false; } void StrComHandler::disableTimestamping() { timestamping = false; }
void StrHelper::enableTimestamping() { timestamping = true; } void StrComHandler::enableTimestamping() { timestamping = true; }
ReturnValue_t StrHelper::performImageDownload() { ReturnValue_t StrComHandler::performImageDownload() {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) { if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE; return HasFileSystemIF::FILESYSTEM_INACTIVE;
@ -190,6 +187,7 @@ ReturnValue_t StrHelper::performImageDownload() {
struct DownloadActionRequest downloadReq; struct DownloadActionRequest downloadReq;
uint32_t size = 0; uint32_t size = 0;
uint32_t retries = 0; uint32_t retries = 0;
const uint8_t* replyFrame;
std::string image = Filenaming::generateAbsoluteFilename(downloadImage.path, std::string image = Filenaming::generateAbsoluteFilename(downloadImage.path,
downloadImage.filename, timestamping); downloadImage.filename, timestamping);
std::ofstream file(image, std::ios_base::out); std::ofstream file(image, std::ios_base::out);
@ -203,38 +201,37 @@ ReturnValue_t StrHelper::performImageDownload() {
return returnvalue::OK; return returnvalue::OK;
} }
arc_pack_download_action_req(&downloadReq, commandBuffer, &size); arc_pack_download_action_req(&downloadReq, commandBuffer, &size);
result = sendAndRead(size, downloadReq.position); result = sendAndRead(&replyFrame, size, downloadReq.position);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
uartComIF->flushUartRxBuffer(comCookie); uart::flushRxBuf(serialPort);
retries++; retries++;
continue; continue;
} }
file.close(); file.close();
return result; return result;
} }
result = checkActionReply(); result = checkActionReply(replyFrame);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
uartComIF->flushUartRxBuffer(comCookie); uart::flushRxBuf(serialPort);
retries++; retries++;
continue; continue;
} }
file.close(); file.close();
return result; return result;
} }
result = checkReplyPosition(downloadReq.position); result = checkReplyPosition(replyFrame, downloadReq.position);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
uartComIF->flushUartRxBuffer(comCookie); uart::flushRxBuf(serialPort);
retries++; retries++;
continue; continue;
} }
file.close(); file.close();
return result; return result;
} }
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + IMAGE_DATA_OFFSET), file.write(reinterpret_cast<const char*>(replyFrame + IMAGE_DATA_OFFSET), CHUNK_SIZE);
CHUNK_SIZE);
#if OBSW_DEBUG_STARTRACKER == 1 #if OBSW_DEBUG_STARTRACKER == 1
progressPrinter.print(downloadReq.position); progressPrinter.print(downloadReq.position);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */ #endif /* OBSW_DEBUG_STARTRACKER == 1 */
@ -245,10 +242,11 @@ ReturnValue_t StrHelper::performImageDownload() {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StrHelper::performImageUpload() { ReturnValue_t StrComHandler::performImageUpload() {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
uint32_t size = 0; uint32_t size = 0;
uint32_t imageSize = 0; uint32_t imageSize = 0;
const uint8_t* replyFrame;
struct UploadActionRequest uploadReq; struct UploadActionRequest uploadReq;
uploadReq.position = 0; uploadReq.position = 0;
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
@ -282,12 +280,12 @@ ReturnValue_t StrHelper::performImageUpload() {
file.seekg(uploadReq.position * SIZE_IMAGE_PART, file.beg); file.seekg(uploadReq.position * SIZE_IMAGE_PART, file.beg);
file.read(reinterpret_cast<char*>(uploadReq.data), SIZE_IMAGE_PART); file.read(reinterpret_cast<char*>(uploadReq.data), SIZE_IMAGE_PART);
arc_pack_upload_action_req(&uploadReq, commandBuffer, &size); arc_pack_upload_action_req(&uploadReq, commandBuffer, &size);
result = sendAndRead(size, uploadReq.position); result = sendAndRead(&replyFrame, size, uploadReq.position);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
file.close(); file.close();
return returnvalue::FAILED; return returnvalue::FAILED;
} }
result = checkActionReply(); result = checkActionReply(replyFrame);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
file.close(); file.close();
return result; return result;
@ -304,11 +302,11 @@ ReturnValue_t StrHelper::performImageUpload() {
file.close(); file.close();
uploadReq.position++; uploadReq.position++;
arc_pack_upload_action_req(&uploadReq, commandBuffer, &size); arc_pack_upload_action_req(&uploadReq, commandBuffer, &size);
result = sendAndRead(size, uploadReq.position); result = sendAndRead(&replyFrame, size, uploadReq.position);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
result = checkActionReply(); result = checkActionReply(replyFrame);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
@ -318,7 +316,7 @@ ReturnValue_t StrHelper::performImageUpload() {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StrHelper::performFirmwareUpdate() { ReturnValue_t StrComHandler::performFirmwareUpdate() {
using namespace startracker; using namespace startracker;
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
result = unlockAndEraseRegions(static_cast<uint32_t>(startracker::FirmwareRegions::FIRST), result = unlockAndEraseRegions(static_cast<uint32_t>(startracker::FirmwareRegions::FIRST),
@ -330,7 +328,7 @@ ReturnValue_t StrHelper::performFirmwareUpdate() {
return result; return result;
} }
ReturnValue_t StrHelper::performFlashWrite() { ReturnValue_t StrComHandler::performFlashWrite() {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) { if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE; return HasFileSystemIF::FILESYSTEM_INACTIVE;
@ -340,6 +338,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
uint32_t size = 0; uint32_t size = 0;
uint32_t bytesWritten = 0; uint32_t bytesWritten = 0;
uint32_t fileSize = 0; uint32_t fileSize = 0;
const uint8_t* replyFrame;
struct WriteActionRequest req; struct WriteActionRequest req;
if (not std::filesystem::exists(flashWrite.fullname)) { if (not std::filesystem::exists(flashWrite.fullname)) {
triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState)); triggerEvent(STR_HELPER_FILE_NOT_EXISTS, static_cast<uint32_t>(internalState));
@ -373,12 +372,12 @@ ReturnValue_t StrHelper::performFlashWrite() {
} }
req.address = bytesWritten; req.address = bytesWritten;
arc_pack_write_action_req(&req, commandBuffer, &size); arc_pack_write_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address); result = sendAndRead(&replyFrame, size, req.address);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
file.close(); file.close();
return result; return result;
} }
result = checkActionReply(); result = checkActionReply(replyFrame);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
file.close(); file.close();
return result; return result;
@ -400,11 +399,11 @@ ReturnValue_t StrHelper::performFlashWrite() {
req.length = remainingBytes; req.length = remainingBytes;
bytesWritten += remainingBytes; bytesWritten += remainingBytes;
arc_pack_write_action_req(&req, commandBuffer, &size); arc_pack_write_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address); result = sendAndRead(&replyFrame, size, req.address);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
result = checkActionReply(); result = checkActionReply(replyFrame);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
@ -414,7 +413,7 @@ ReturnValue_t StrHelper::performFlashWrite() {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StrHelper::performFlashRead() { ReturnValue_t StrComHandler::performFlashRead() {
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
if (not sdcMan->getActiveSdCard()) { if (not sdcMan->getActiveSdCard()) {
return HasFileSystemIF::FILESYSTEM_INACTIVE; return HasFileSystemIF::FILESYSTEM_INACTIVE;
@ -428,6 +427,7 @@ ReturnValue_t StrHelper::performFlashRead() {
uint32_t bytesRead = 0; uint32_t bytesRead = 0;
uint32_t size = 0; uint32_t size = 0;
uint32_t retries = 0; uint32_t retries = 0;
const uint8_t* replyFrame;
Timestamp timestamp; Timestamp timestamp;
std::string fullname = std::string fullname =
Filenaming::generateAbsoluteFilename(flashRead.path, flashRead.filename, timestamping); Filenaming::generateAbsoluteFilename(flashRead.path, flashRead.filename, timestamping);
@ -447,28 +447,27 @@ ReturnValue_t StrHelper::performFlashRead() {
req.length = CHUNK_SIZE; req.length = CHUNK_SIZE;
} }
arc_pack_read_action_req(&req, commandBuffer, &size); arc_pack_read_action_req(&req, commandBuffer, &size);
result = sendAndRead(size, req.address); result = sendAndRead(&replyFrame, size, req.address);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
uartComIF->flushUartRxBuffer(comCookie); uart::flushRxBuf(serialPort);
retries++; retries++;
continue; continue;
} }
file.close(); file.close();
return result; return result;
} }
result = checkActionReply(); result = checkActionReply(replyFrame);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) { if (retries < CONFIG_MAX_DOWNLOAD_RETRIES) {
uartComIF->flushUartRxBuffer(comCookie); uart::flushRxBuf(serialPort);
retries++; retries++;
continue; continue;
} }
file.close(); file.close();
return result; return result;
} }
file.write(reinterpret_cast<const char*>(datalinkLayer.getReply() + FLASH_READ_DATA_OFFSET), file.write(reinterpret_cast<const char*>(replyFrame + FLASH_READ_DATA_OFFSET), req.length);
req.length);
bytesRead += req.length; bytesRead += req.length;
req.address += req.length; req.address += req.length;
if (req.address >= FLASH_REGION_SIZE) { if (req.address >= FLASH_REGION_SIZE) {
@ -484,72 +483,74 @@ ReturnValue_t StrHelper::performFlashRead() {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StrHelper::sendAndRead(size_t size, uint32_t parameter, uint32_t delayMs) { ReturnValue_t StrComHandler::sendAndRead(const uint8_t** replyFrame, size_t size,
uint32_t failParameter, uint32_t delayMs) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
ReturnValue_t decResult = returnvalue::OK; ReturnValue_t decResult = returnvalue::OK;
size_t receivedDataLen = 0; size_t receivedDataLen = 0;
uint8_t* receivedData = nullptr;
size_t bytesLeft = 0; size_t bytesLeft = 0;
uint32_t missedReplies = 0; uint32_t missedReplies = 0;
uint8_t* sendData; const uint8_t* sendData;
size_t txFrameLen = 0; size_t txFrameLen = 0;
datalinkLayer.encodeFrame(commandBuffer, size, &sendData, txFrameLen); datalinkLayer.encodeFrame(commandBuffer, size, &sendData, txFrameLen);
result = uartComIF->sendMessage(comCookie, sendData, txFrameLen); int writeResult = write(serialPort, sendData, txFrameLen);
if (result != returnvalue::OK) { if (writeResult < 0) {
sif::warning << "StrHelper::sendAndRead: Failed to send packet" << std::endl; sif::warning << "StrHelper::sendAndRead: Failed to send packet" << std::endl;
triggerEvent(STR_HELPER_SENDING_PACKET_FAILED, result, parameter); triggerEvent(STR_HELPER_SENDING_PACKET_FAILED, result, failParameter);
return returnvalue::FAILED; return returnvalue::FAILED;
} }
decResult = ArcsecDatalinkLayer::DEC_IN_PROGRESS;
while (decResult == ArcsecDatalinkLayer::DEC_IN_PROGRESS) {
Countdown delay(delayMs); Countdown delay(delayMs);
while (true) {
delay.resetTimer(); delay.resetTimer();
while (delay.isBusy()) { while (delay.isBusy()) {
TaskFactory::delayTask(10);
} }
result = uartComIF->requestReceiveMessage(comCookie, startracker::MAX_FRAME_SIZE * 2 + 2); // TODO: Read periodically into ring buffer, analyse ring buffer for reply frames periodically.
if (result != returnvalue::OK) { // result = uartComIF->requestReceiveMessage(comCookie, startracker::MAX_FRAME_SIZE * 2 + 2);
sif::warning << "StrHelper::sendAndRead: Failed to request reply" << std::endl; // if (result != returnvalue::OK) {
triggerEvent(STR_HELPER_REQUESTING_MSG_FAILED, result, parameter); // sif::warning << "StrHelper::sendAndRead: Failed to request reply" << std::endl;
return returnvalue::FAILED; // triggerEvent(STR_HELPER_REQUESTING_MSG_FAILED, result, parameter);
} // return returnvalue::FAILED;
result = uartComIF->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); // }
if (result != returnvalue::OK) { // result = uartComIF->readReceivedMessage(comCookie, &receivedData, &receivedDataLen);
sif::warning << "StrHelper::sendAndRead: Failed to read received message" << std::endl; // if (result != returnvalue::OK) {
triggerEvent(STR_HELPER_READING_REPLY_FAILED, result, parameter); // sif::warning << "StrHelper::sendAndRead: Failed to read received message" << std::endl;
return returnvalue::FAILED; // triggerEvent(STR_HELPER_READING_REPLY_FAILED, result, parameter);
} // return returnvalue::FAILED;
// }
if (receivedDataLen == 0 && missedReplies < MAX_POLLS) { if (receivedDataLen == 0 && missedReplies < MAX_POLLS) {
missedReplies++; missedReplies++;
continue; continue;
} else if ((receivedDataLen == 0) && (missedReplies >= MAX_POLLS)) { } else if ((receivedDataLen == 0) && (missedReplies >= MAX_POLLS)) {
triggerEvent(STR_HELPER_NO_REPLY, parameter); triggerEvent(STR_HELPER_NO_REPLY, failParameter);
return returnvalue::FAILED; return returnvalue::FAILED;
} else { } else {
missedReplies = 0; missedReplies = 0;
} }
decResult = datalinkLayer.decodeFrame(receivedData, receivedDataLen, &bytesLeft); // TODO: Use frame detector function here instead.
// decResult = datalinkLayer.decodeFrame(receivedData, receivedDataLen, &bytesLeft);
if (bytesLeft != 0) { if (bytesLeft != 0) {
// This should never happen // This should never happen
sif::warning << "StrHelper::sendAndRead: Bytes left after decoding" << std::endl; sif::warning << "StrHelper::sendAndRead: Bytes left after decoding" << std::endl;
triggerEvent(STR_HELPER_COM_ERROR, result, parameter); triggerEvent(STR_HELPER_COM_ERROR, result, failParameter);
return returnvalue::FAILED; return returnvalue::FAILED;
} }
} }
if (decResult != returnvalue::OK) { if (decResult != returnvalue::OK) {
triggerEvent(STR_HELPER_DEC_ERROR, decResult, parameter); triggerEvent(STR_HELPER_DEC_ERROR, decResult, failParameter);
return returnvalue::FAILED; return returnvalue::FAILED;
} }
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StrHelper::checkActionReply() { ReturnValue_t StrComHandler::checkActionReply(const uint8_t* rawFrame) {
uint8_t type = datalinkLayer.getReplyFrameType(); uint8_t type = str::getReplyFrameType(rawFrame);
if (type != TMTC_ACTIONREPLY) { if (type != TMTC_ACTIONREPLY) {
sif::warning << "StrHelper::checkActionReply: Received reply with invalid type ID" << std::endl; sif::warning << "StrHelper::checkActionReply: Received reply with invalid type ID" << std::endl;
return INVALID_TYPE_ID; return INVALID_TYPE_ID;
} }
uint8_t status = datalinkLayer.getStatusField(); uint8_t status = str::getStatusField(rawFrame);
if (status != ArcsecDatalinkLayer::STATUS_OK) { if (status != ArcsecDatalinkLayer::STATUS_OK) {
sif::warning << "StrHelper::checkActionReply: Status failure: " sif::warning << "StrHelper::checkActionReply: Status failure: "
<< static_cast<unsigned int>(status) << std::endl; << static_cast<unsigned int>(status) << std::endl;
@ -558,9 +559,10 @@ ReturnValue_t StrHelper::checkActionReply() {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t StrHelper::checkReplyPosition(uint32_t expectedPosition) { ReturnValue_t StrComHandler::checkReplyPosition(const uint8_t* rawFrame,
uint32_t expectedPosition) {
uint32_t receivedPosition = 0; uint32_t receivedPosition = 0;
std::memcpy(&receivedPosition, datalinkLayer.getReply() + POS_OFFSET, sizeof(receivedPosition)); std::memcpy(&receivedPosition, rawFrame + POS_OFFSET, sizeof(receivedPosition));
if (receivedPosition != expectedPosition) { if (receivedPosition != expectedPosition) {
triggerEvent(POSITION_MISMATCH, receivedPosition); triggerEvent(POSITION_MISMATCH, receivedPosition);
return returnvalue::FAILED; return returnvalue::FAILED;
@ -569,7 +571,7 @@ ReturnValue_t StrHelper::checkReplyPosition(uint32_t expectedPosition) {
} }
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
ReturnValue_t StrHelper::checkPath(std::string name) { ReturnValue_t StrComHandler::checkPath(std::string name) {
if (name.substr(0, sizeof(config::SD_0_MOUNT_POINT)) == std::string(config::SD_0_MOUNT_POINT)) { if (name.substr(0, sizeof(config::SD_0_MOUNT_POINT)) == std::string(config::SD_0_MOUNT_POINT)) {
if (!sdcMan->isSdCardUsable(sd::SLOT_0)) { if (!sdcMan->isSdCardUsable(sd::SLOT_0)) {
sif::warning << "StrHelper::checkPath: SD card 0 not mounted" << std::endl; sif::warning << "StrHelper::checkPath: SD card 0 not mounted" << std::endl;
@ -586,8 +588,75 @@ ReturnValue_t StrHelper::checkPath(std::string name) {
} }
#endif #endif
ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) { ReturnValue_t StrComHandler::initializeInterface(CookieIF* cookie) {
if (cookie == nullptr) {
return returnvalue::FAILED;
}
SerialCookie* serCookie = dynamic_cast<SerialCookie*>(cookie);
if (serCookie == nullptr) {
return DeviceCommunicationIF::INVALID_COOKIE_TYPE;
}
// comCookie = serCookie;
std::string devname = serCookie->getDeviceFile();
/* Get file descriptor */
serialPort = open(devname.c_str(), O_RDWR);
if (serialPort < 0) {
sif::warning << "StrComHandler: open call failed with error [" << errno << ", "
<< strerror(errno) << std::endl;
return returnvalue::FAILED;
}
// Setting up UART parameters
tty.c_cflag &= ~PARENB; // Clear parity bit
uart::setStopbits(tty, serCookie->getStopBits());
uart::setBitsPerWord(tty, BitsPerWord::BITS_8);
tty.c_cflag &= ~CRTSCTS; // Disable RTS/CTS hardware flow control
uart::enableRead(tty);
uart::ignoreCtrlLines(tty);
// Use non-canonical mode and clear echo flag
tty.c_lflag &= ~(ICANON | ECHO);
// Non-blocking mode, use polling
tty.c_cc[VTIME] = 0;
tty.c_cc[VMIN] = 0;
uart::setBaudrate(tty, serCookie->getBaudrate());
if (tcsetattr(serialPort, TCSANOW, &tty) != 0) {
sif::warning << "ScexUartReader::initializeInterface: tcsetattr call failed with error ["
<< errno << ", " << strerror(errno) << std::endl;
}
// Flush received and unread data
tcflush(serialPort, TCIOFLUSH);
return returnvalue::OK;
}
ReturnValue_t StrComHandler::sendMessage(CookieIF* cookie, const uint8_t* sendData,
size_t sendLen) {
const uint8_t* txFrame;
size_t frameLen;
datalinkLayer.encodeFrame(sendData, sendLen, &txFrame, frameLen);
size_t bytesWritten = write(serialPort, txFrame, frameLen);
if (bytesWritten != frameLen) {
sif::warning << "ScexUartReader::sendMessage: Sending ping command to solar experiment failed"
<< std::endl;
return returnvalue::FAILED;
}
return returnvalue::OK;
}
ReturnValue_t StrComHandler::getSendSuccess(CookieIF* cookie) { return returnvalue::OK; }
ReturnValue_t StrComHandler::requestReceiveMessage(CookieIF* cookie, size_t requestLen) {
return returnvalue::OK;
}
ReturnValue_t StrComHandler::readReceivedMessage(CookieIF* cookie, uint8_t** buffer, size_t* size) {
return returnvalue::OK;
}
ReturnValue_t StrComHandler::unlockAndEraseRegions(uint32_t from, uint32_t to) {
ReturnValue_t result = returnvalue::OK; ReturnValue_t result = returnvalue::OK;
const uint8_t* replyFrame;
#if OBSW_DEBUG_STARTRACKER == 1 #if OBSW_DEBUG_STARTRACKER == 1
ProgressPrinter progressPrinter("Unlock and erase", to - from); ProgressPrinter progressPrinter("Unlock and erase", to - from);
#endif /* OBSW_DEBUG_STARTRACKER == 1 */ #endif /* OBSW_DEBUG_STARTRACKER == 1 */
@ -598,8 +667,8 @@ ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) {
unlockReq.region = idx; unlockReq.region = idx;
unlockReq.code = startracker::region_secrets::secret[idx]; unlockReq.code = startracker::region_secrets::secret[idx];
arc_pack_unlock_action_req(&unlockReq, commandBuffer, &size); arc_pack_unlock_action_req(&unlockReq, commandBuffer, &size);
sendAndRead(size, unlockReq.region); sendAndRead(&replyFrame, size, unlockReq.region);
result = checkActionReply(); result = checkActionReply(replyFrame);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
sif::warning << "StrHelper::unlockAndEraseRegions: Failed to unlock region with id " sif::warning << "StrHelper::unlockAndEraseRegions: Failed to unlock region with id "
<< static_cast<unsigned int>(unlockReq.region) << std::endl; << static_cast<unsigned int>(unlockReq.region) << std::endl;
@ -607,7 +676,7 @@ ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) {
} }
eraseReq.region = idx; eraseReq.region = idx;
arc_pack_erase_action_req(&eraseReq, commandBuffer, &size); arc_pack_erase_action_req(&eraseReq, commandBuffer, &size);
result = sendAndRead(size, eraseReq.region, FLASH_ERASE_DELAY); result = sendAndRead(&replyFrame, size, eraseReq.region, FLASH_ERASE_DELAY);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
sif::warning << "StrHelper::unlockAndEraseRegions: Failed to erase region with id " sif::warning << "StrHelper::unlockAndEraseRegions: Failed to erase region with id "
<< static_cast<unsigned int>(eraseReq.region) << std::endl; << static_cast<unsigned int>(eraseReq.region) << std::endl;
@ -619,3 +688,24 @@ ReturnValue_t StrHelper::unlockAndEraseRegions(uint32_t from, uint32_t to) {
} }
return result; return result;
} }
ReturnValue_t StrComHandler::handleUartReception() {
ssize_t bytesRead = read(serialPort, reinterpret_cast<void*>(recBuf.data()),
static_cast<unsigned int>(recBuf.size()));
if (bytesRead == 0) {
return NO_SERIAL_DATA_READ;
} else if (bytesRead < 0) {
sif::warning << "PlocSupvHelper::performOperation: read call failed with error [" << errno
<< ", " << strerror(errno) << "]" << std::endl;
return FAILED;
} else if (bytesRead >= static_cast<int>(recBuf.size())) {
sif::error << "PlocSupvHelper::performOperation: Receive buffer too small for " << bytesRead
<< " bytes" << std::endl;
return FAILED;
} else if (bytesRead > 0) {
// sif::info << "Received " << bytesRead << " bytes from the PLOC Supervisor:" << std::endl;
// arrayprinter::print(recBuf.data(), bytesRead);
datalinkLayer.feedData(recBuf.data(), bytesRead);
}
return OK;
}

View File

@ -10,6 +10,8 @@
#include "bsp_q7s/fs/SdCardManager.h" #include "bsp_q7s/fs/SdCardManager.h"
#endif #endif
#include "arcsec/client/generated/actionreq.h"
#include "arcsec/common/generated/tmtcstructs.h"
#include "fsfw/devicehandlers/CookieIF.h" #include "fsfw/devicehandlers/CookieIF.h"
#include "fsfw/objectmanager/SystemObject.h" #include "fsfw/objectmanager/SystemObject.h"
#include "fsfw/osal/linux/BinarySemaphore.h" #include "fsfw/osal/linux/BinarySemaphore.h"
@ -17,18 +19,34 @@
#include "fsfw/tasks/ExecutableObjectIF.h" #include "fsfw/tasks/ExecutableObjectIF.h"
#include "fsfw_hal/linux/serial/SerialComIF.h" #include "fsfw_hal/linux/serial/SerialComIF.h"
extern "C" {
#include "thirdparty/arcsec_star_tracker/client/generated/actionreq.h"
#include "thirdparty/arcsec_star_tracker/common/generated/tmtcstructs.h"
}
/** /**
* @brief Helper class for the star tracker handler to accelerate large data transfers. * @brief Helper class for the star tracker handler to accelerate large data transfers.
* *
* @author J. Meier * @author J. Meier
*/ */
class StrHelper : public SystemObject, public ExecutableObjectIF { class StrComHandler : public SystemObject, public DeviceCommunicationIF, public ExecutableObjectIF {
public: public:
static const uint8_t INTERFACE_ID = CLASS_ID::STR_HELPER;
//! [EXPORT] : [COMMENT] SD card specified in path string not mounted
static const ReturnValue_t SD_NOT_MOUNTED = MAKE_RETURN_CODE(0);
//! [EXPORT] : [COMMENT] Specified file does not exist on filesystem
static const ReturnValue_t FILE_NOT_EXISTS = MAKE_RETURN_CODE(1);
//! [EXPORT] : [COMMENT] Specified path does not exist
static const ReturnValue_t PATH_NOT_EXISTS = MAKE_RETURN_CODE(2);
//! [EXPORT] : [COMMENT] Failed to create download image or read flash file
static const ReturnValue_t FILE_CREATION_FAILED = MAKE_RETURN_CODE(3);
//! [EXPORT] : [COMMENT] Region in flash write/read reply does not match expected region
static const ReturnValue_t REGION_MISMATCH = MAKE_RETURN_CODE(4);
//! [EXPORT] : [COMMENT] Address in flash write/read reply does not match expected address
static const ReturnValue_t ADDRESS_MISMATCH = MAKE_RETURN_CODE(5);
//! [EXPORT] : [COMMENT] Length in flash write/read reply does not match expected length
static const ReturnValue_t LENGTH_MISMATCH = MAKE_RETURN_CODE(6);
//! [EXPORT] : [COMMENT] Status field in reply signals error
static const ReturnValue_t STATUS_ERROR = MAKE_RETURN_CODE(7);
//! [EXPORT] : [COMMENT] Reply has invalid type ID (should be of action reply type)
static const ReturnValue_t INVALID_TYPE_ID = MAKE_RETURN_CODE(8);
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::STR_HELPER; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::STR_HELPER;
//! [EXPORT] : [COMMENT] Image upload failed //! [EXPORT] : [COMMENT] Image upload failed
@ -81,15 +99,12 @@ class StrHelper : public SystemObject, public ExecutableObjectIF {
//! failed //! failed
static const Event STR_HELPER_REQUESTING_MSG_FAILED = MAKE_EVENT(16, severity::LOW); static const Event STR_HELPER_REQUESTING_MSG_FAILED = MAKE_EVENT(16, severity::LOW);
StrHelper(object_id_t objectId); StrComHandler(object_id_t objectId);
virtual ~StrHelper(); virtual ~StrComHandler();
ReturnValue_t initialize() override; ReturnValue_t initialize() override;
ReturnValue_t performOperation(uint8_t operationCode = 0) override; ReturnValue_t performOperation(uint8_t operationCode = 0) override;
ReturnValue_t setComIF(DeviceCommunicationIF* communicationInterface_);
void setComCookie(CookieIF* comCookie_);
/** /**
* @brief Starts sequence to upload image to star tracker * @brief Starts sequence to upload image to star tracker
* *
@ -148,26 +163,8 @@ class StrHelper : public SystemObject, public ExecutableObjectIF {
void enableTimestamping(); void enableTimestamping();
private: private:
static const uint8_t INTERFACE_ID = CLASS_ID::STR_HELPER; //! [EXPORT] : [SKIP]
static constexpr ReturnValue_t NO_SERIAL_DATA_READ = MAKE_RETURN_CODE(128);
//! [EXPORT] : [COMMENT] SD card specified in path string not mounted
static const ReturnValue_t SD_NOT_MOUNTED = MAKE_RETURN_CODE(0xA0);
//! [EXPORT] : [COMMENT] Specified file does not exist on filesystem
static const ReturnValue_t FILE_NOT_EXISTS = MAKE_RETURN_CODE(0xA1);
//! [EXPORT] : [COMMENT] Specified path does not exist
static const ReturnValue_t PATH_NOT_EXISTS = MAKE_RETURN_CODE(0xA2);
//! [EXPORT] : [COMMENT] Failed to create download image or read flash file
static const ReturnValue_t FILE_CREATION_FAILED = MAKE_RETURN_CODE(0xA3);
//! [EXPORT] : [COMMENT] Region in flash write/read reply does not match expected region
static const ReturnValue_t REGION_MISMATCH = MAKE_RETURN_CODE(0xA4);
//! [EXPORT] : [COMMENT] Address in flash write/read reply does not match expected address
static const ReturnValue_t ADDRESS_MISMATCH = MAKE_RETURN_CODE(0xA5);
//! [EXPORT] : [COMMENT] Length in flash write/read reply does not match expected length
static const ReturnValue_t LENGTH_MISMATCH = MAKE_RETURN_CODE(0xA6);
//! [EXPORT] : [COMMENT] Status field in reply signals error
static const ReturnValue_t STATUS_ERROR = MAKE_RETURN_CODE(0xA7);
//! [EXPORT] : [COMMENT] Reply has invalid type ID (should be of action reply type)
static const ReturnValue_t INVALID_TYPE_ID = MAKE_RETURN_CODE(0xA8);
// Size of one image part which can be sent per action request // Size of one image part which can be sent per action request
static const size_t SIZE_IMAGE_PART = 1024; static const size_t SIZE_IMAGE_PART = 1024;
@ -179,13 +176,12 @@ class StrHelper : public SystemObject, public ExecutableObjectIF {
static const uint32_t MAX_POLLS = 10000; static const uint32_t MAX_POLLS = 10000;
static const uint8_t ACTION_DATA_OFFSET = 2; static const uint8_t ACTION_DATA_OFFSET = 3;
static const uint8_t POS_OFFSET = 2; static const uint8_t POS_OFFSET = 3;
static const uint8_t IMAGE_DATA_OFFSET = 5; static const uint8_t IMAGE_DATA_OFFSET = 6;
static const uint8_t FLASH_READ_DATA_OFFSET = 8; static const uint8_t FLASH_READ_DATA_OFFSET = 9;
static const uint8_t REGION_OFFSET = 2; static const uint8_t REGION_OFFSET = 3;
static const uint8_t ADDRESS_OFFSET = 3; static const uint8_t ADDRESS_OFFSET = 4;
static const uint8_t LENGTH_OFFSET = 7;
static const size_t CHUNK_SIZE = 1024; static const size_t CHUNK_SIZE = 1024;
static const size_t CONFIG_MAX_DOWNLOAD_RETRIES = 3; static const size_t CONFIG_MAX_DOWNLOAD_RETRIES = 3;
static const uint32_t FLASH_ERASE_DELAY = 500; static const uint32_t FLASH_ERASE_DELAY = 500;
@ -198,6 +194,8 @@ class StrHelper : public SystemObject, public ExecutableObjectIF {
BinarySemaphore semaphore; BinarySemaphore semaphore;
Countdown replyTimeout = Countdown(2000);
struct UploadImage { struct UploadImage {
// Name including absolute path of image to upload // Name including absolute path of image to upload
std::string uploadFile; std::string uploadFile;
@ -242,6 +240,7 @@ class StrHelper : public SystemObject, public ExecutableObjectIF {
#endif #endif
uint8_t commandBuffer[startracker::MAX_FRAME_SIZE]; uint8_t commandBuffer[startracker::MAX_FRAME_SIZE];
std::array<uint8_t, 4096> recBuf{};
bool terminate = false; bool terminate = false;
@ -251,17 +250,20 @@ class StrHelper : public SystemObject, public ExecutableObjectIF {
bool timestamping = true; bool timestamping = true;
#endif #endif
/** int serialPort = 0;
* UART communication object responsible for low level access of star tracker struct termios tty = {};
* Must be set by star tracker handler
*/
SerialComIF* uartComIF = nullptr;
// Communication cookie. Must be set by the star tracker handler
CookieIF* comCookie = nullptr;
// Queue id of raw data receiver // Queue id of raw data receiver
MessageQueueId_t rawDataReceiver = MessageQueueIF::NO_QUEUE; MessageQueueId_t rawDataReceiver = MessageQueueIF::NO_QUEUE;
ReturnValue_t initializeInterface(CookieIF *cookie) override;
ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t *sendData, size_t sendLen) override;
ReturnValue_t getSendSuccess(CookieIF *cookie) override;
ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) override;
ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) override;
ReturnValue_t handleUartReception();
/** /**
* @brief Performs image uploading * @brief Performs image uploading
*/ */
@ -309,14 +311,15 @@ class StrHelper : public SystemObject, public ExecutableObjectIF {
* *
* @return returnvalue::OK if successful, otherwise returnvalue::FAILED * @return returnvalue::OK if successful, otherwise returnvalue::FAILED
*/ */
ReturnValue_t sendAndRead(size_t size, uint32_t parameter, uint32_t delayMs = 0); ReturnValue_t sendAndRead(const uint8_t **replyFrame, size_t size, uint32_t parameter,
uint32_t delayMs = 0);
/** /**
* @brief Checks the header (type id and status fields) of the action reply * @brief Checks the header (type id and status fields) of the action reply
* *
* @return returnvalue::OK if reply confirms success of packet transfer, otherwise REUTRN_FAILED * @return returnvalue::OK if reply confirms success of packet transfer, otherwise REUTRN_FAILED
*/ */
ReturnValue_t checkActionReply(); ReturnValue_t checkActionReply(const uint8_t *rawFrame);
/** /**
* @brief Checks the position field in a star tracker upload/download reply. * @brief Checks the position field in a star tracker upload/download reply.
@ -326,7 +329,7 @@ class StrHelper : public SystemObject, public ExecutableObjectIF {
* @return returnvalue::OK if received position matches expected position, otherwise * @return returnvalue::OK if received position matches expected position, otherwise
* returnvalue::FAILED * returnvalue::FAILED
*/ */
ReturnValue_t checkReplyPosition(uint32_t expectedPosition); ReturnValue_t checkReplyPosition(const uint8_t *rawFrame, uint32_t expectedPosition);
#ifdef XIPHOS_Q7S #ifdef XIPHOS_Q7S
/** /**

View File

@ -0,0 +1,7 @@
#include "helpers.h"
uint8_t str::getReplyFrameType(const uint8_t* rawFrame) { return rawFrame[0]; }
uint8_t str::getId(const uint8_t* rawFrame) { return rawFrame[1]; }
uint8_t str::getStatusField(const uint8_t* rawFrame) { return rawFrame[2]; }

View File

@ -0,0 +1,17 @@
#ifndef LINUX_DEVICES_STARTRACKER_HELPERS_H_
#define LINUX_DEVICES_STARTRACKER_HELPERS_H_
#include "arcsec/common/genericstructs.h"
namespace str {
/**
* @brief Returns the frame type field of a decoded frame.
*/
uint8_t getReplyFrameType(const uint8_t* rawFrame);
uint8_t getId(const uint8_t* rawFrame);
uint8_t getStatusField(const uint8_t* rawFrame);
} // namespace str
#endif /* LINUX_DEVICES_STARTRACKER_HELPERS_H_ */

@ -1 +1 @@
Subproject commit 42907c36c58e7133d3d3cbefbf96c1a8e35b60b7 Subproject commit c535e1494f2fdb54becd7c338fe959c3672298b3