StarTrackerHandler wip

This commit is contained in:
Jakob.Meier 2021-07-07 12:12:01 +02:00
parent 9f6378f001
commit 4148a8c0bd
13 changed files with 433 additions and 9 deletions

3
.gitmodules vendored
View File

@ -19,3 +19,6 @@
[submodule "generators/fsfwgen"]
path = generators/fsfwgen
url = https://egit.irs.uni-stuttgart.de/fsfw/fsfw-generators.git
[submodule "arcsec-start-tracker"]
path = arcsec-start-tracker
url = https://egit.irs.uni-stuttgart.de/eive/arcsec-start-tracker.git

1
arcsec-start-tracker Submodule

@ -0,0 +1 @@
Subproject commit 7103370d15c19a843e40dc880a29ace51f348f92

View File

@ -33,12 +33,14 @@
#include <mission/devices/PlocHandler.h>
#include <mission/devices/RadiationSensorHandler.h>
#include <mission/devices/RwHandler.h>
#include <mission/devices/StarTrackerHandler.h>
#include <mission/devices/devicedefinitions/GomspaceDefinitions.h>
#include <mission/devices/devicedefinitions/SyrlinksDefinitions.h>
#include <mission/devices/devicedefinitions/PlocDefinitions.h>
#include <mission/devices/devicedefinitions/RadSensorDefinitions.h>
#include <mission/devices/devicedefinitions/Max31865Definitions.h>
#include <mission/devices/devicedefinitions/RwDefinitions.h>
#include <mission/devices/devicedefinitions/StarTrackerDefinitions.h>
#include <mission/utility/TmFunnel.h>
#include <linux/obc/CCSDSIPCoreBridge.h>
@ -619,6 +621,11 @@ void ObjectFactory::produce(void* args){
gpioIds::EN_RW4);
rw4SpiCookie->setCallbackArgs(rwHandler4);
UartCookie* starTrackerCookie = new UartCookie(objects::START_TRACKER, std::string("/dev/ttyUL3"),
UartModes::NON_CANONICAL, 115200, StartTracker::MAX_FRAME_SIZE* 2 + 2);
starTrackerCookie->setNoFixedSizeReply();
new StarTrackerHandler(objects::START_TRACKER, objects::UART_COM_IF, starTrackerCookie);
#endif /* TE0720 == 0 */
new UdpTmTcBridge(objects::UDP_BRIDGE, objects::CCSDS_PACKET_DISTRIBUTOR);

View File

@ -14,6 +14,7 @@ enum commonClassIds: uint8_t {
SYRLINKS_HANDLER, //SYRLINKS
IMTQ_HANDLER, //IMTQ
RW_HANDLER, //Reaction Wheels
STR_HANDLER, //Star tracker
PLOC_HANDLER, //PLOC
SUS_HANDLER, //SUSS
CCSDS_IP_CORE_BRIDGE, // IP Core interface

View File

@ -73,10 +73,12 @@ enum commonObjects: uint32_t {
GPS0_HANDLER = 0x44130045,
GPS1_HANDLER = 0x44130146,
RW1 = 0x44210001,
RW2 = 0x44210002,
RW3 = 0x44210003,
RW4 = 0x44210004
RW1 = 0x44120001,
RW2 = 0x44120002,
RW3 = 0x44120003,
RW4 = 0x44120004,
START_TRACKER = 0x44130001
};
}

View File

@ -14,6 +14,7 @@ enum: uint8_t {
PLOC_HANDLER = 111,
IMTQ_HANDLER = 112,
RW_HANDLER = 113,
STR_HANDLER = 114,
COMMON_SUBSYSTEM_ID_END
};
}

View File

@ -44,7 +44,8 @@ debugging. */
#define DEBUG_SUS 1
#define DEBUG_RTD 1
#define IMTQ_DEBUG 1
#define RW_DEBUG 1
#define RW_DEBUG 0
#define START_TRACKER_DEBUG 1
// Leave at one as the BSP is linux. Used by the ADIS16507 device handler
#define OBSW_ADIS16507_LINUX_COM_IF 1

View File

@ -504,6 +504,12 @@ ReturnValue_t pst::pstUart(FixedTimeslotTaskIF *thisSequence) {
DeviceHandlerIF::GET_READ);
#endif
thisSequence->addSlot(objects::START_TRACKER, length * 0, DeviceHandlerIF::PERFORM_OPERATION);
thisSequence->addSlot(objects::START_TRACKER, length * 0.2, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::START_TRACKER, length * 0.4, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::START_TRACKER, length * 0.6, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::START_TRACKER, length * 0.8, DeviceHandlerIF::GET_READ);
if (thisSequence->checkSequence() != HasReturnvaluesIF::RETURN_OK) {
sif::error << "UART PST initialization failed" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;

View File

@ -60,7 +60,7 @@ ReturnValue_t RwHandler::buildNormalDeviceCommand(DeviceCommandId_t * id) {
internalState = InternalState::GET_RESET_STATUS;
break;
default:
sif::debug << "RwHandler::buildNormalDeviceCommand: Invalid communication step"
sif::debug << "RwHandler::buildNormalDeviceCommand: Invalid internal step"
<< std::endl;
break;
}
@ -176,8 +176,7 @@ ReturnValue_t RwHandler::scanForReply(const uint8_t *start, size_t remainingSize
break;
}
case (static_cast<uint8_t>(RwDefinitions::GET_TM)): {
// *foundLen = RwDefinitions::SIZE_GET_TELEMETRY_REPLY;
*foundLen = 91;
*foundLen = RwDefinitions::SIZE_GET_TELEMETRY_REPLY;
*foundId = RwDefinitions::GET_TM;
break;
}

View File

@ -0,0 +1,238 @@
#include "StarTrackerHandler.h"
#include "OBSWConfig.h"
#include <fsfw/globalfunctions/CRC.h>
#include <fsfw/datapool/PoolReadGuard.h>
#include <arcsec-start-tracker/client/generated/telemetry.h>
StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF,
CookieIF * comCookie, LinuxLibgpioIF* gpioComIF, gpioId_t enableGpio) :
DeviceHandlerBase(objectId, comIF, comCookie), temperatureSet(this) {
if (comCookie == NULL) {
sif::error << "StarTrackerHandler: Invalid com cookie" << std::endl;
}
slipInit();
}
StarTrackerHandler::~StarTrackerHandler() {
}
void StarTrackerHandler::doStartUp() {
#if OBSW_SWITCH_TO_NORMAL_MODE_AFTER_STARTUP == 1
setMode(MODE_NORMAL);
#else
setMode(_MODE_TO_ON);
#endif
}
void StarTrackerHandler::doShutDown() {
}
ReturnValue_t StarTrackerHandler::buildNormalDeviceCommand(DeviceCommandId_t * id) {
switch (internalState) {
case InternalState::TEMPERATURE_REQUEST:
*id = StartTracker::REQ_TEMPERATURE;
break;
default:
sif::debug << "StarTrackerHandler::buildNormalDeviceCommand: Invalid internal step"
<< std::endl;
break;
}
return buildCommandFromCommand(*id, NULL, 0);
}
ReturnValue_t StarTrackerHandler::buildTransitionDeviceCommand(DeviceCommandId_t * id) {
return NOTHING_TO_SEND;
}
ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t * commandData, size_t commandDataLen) {
switch (deviceCommand) {
case (StartTracker::REQ_TEMPERATURE): {
prepareTemperatureRequest();
return RETURN_OK;
}
default:
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
return HasReturnvaluesIF::RETURN_FAILED;
}
void StarTrackerHandler::fillCommandAndReplyMap() {
/** Reply lengths are unknown because of the slip encoding. Thus always maximum reply size
* is specified */
this->insertInCommandAndReplyMap(StartTracker::REQ_TEMPERATURE, 1, &temperatureSet,
sStartTracker::MAX_FRAME_SIZE * 2 + 2);
}
ReturnValue_t StarTrackerHandler::scanForReply(const uint8_t *start, size_t remainingSize,
DeviceCommandId_t *foundId, size_t *foundLen) {
uint32_t decodedLength = 0;
for (int i = 0; i < remainingSize; i++) {
enum arc_dec_result decResult = arc_transport_decode_body(*(start + i), &slipInfo,
decodedFrame, &decodedLength);
switch (decResult) {
case ARC_DEC_INPROGRESS: {
continue;
}
case ARC_DEC_ASYNC: {
sif::debug << "StarTrackerHandler::scanForReply: Received asychronous tm" << std::endl;
/** No asynchronous replies are expected as of now */
return RETURN_FAILED;
}
case ARC_DEC_ERROR_FRAME_SHORT:
return REPLY_TOO_SHORT;
case ARC_DEC_ERROR_CHECKSUM:
return CRC_FAILURE;
case ARC_DEC_SYNC: {
/** Reset length of SLIP struct for next frame */
slipInfo.length = 0;
break;
}
default:
sif::debug << "StarTrackerHandler::scanForReply: Unknown result code" << std::endl;
break;
}
}
switch (*(decodedFrame[1])) {
case (static_cast<uint8_t>(StartTracker::REQ_TEMPERATURE)): {
*foundLen = decodedLength;
*foundId = StartTracker::REQ_TEMPERATURE;
break;
}
default: {
sif::debug << "StarTrackerHandler::scanForReply: Reply contains invalid reply id"
<< std::endl;
return RETURN_FAILED;
break;
}
}
return RETURN_OK;
}
ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
switch (id) {
case (StartTracker::REQ_TEMPERATURE): {
handleTemperatureTm();
break;
}
default: {
sif::debug << "StarTrackerHandler::interpretDeviceReply: Unknown device reply id" << std::endl;
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return RETURN_OK;
}
void StarTrackerHandler::setNormalDatapoolEntriesInvalid() {
}
uint32_t StarTrackerHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
return 5000;
}
ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) {
localDataPoolMap.emplace(RwDefinitions::TEMPERATURE_C, new PoolEntry<int32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::CURR_SPEED, new PoolEntry<int32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::REFERENCE_SPEED, new PoolEntry<int32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::STATE, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::CLC_MODE, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::LAST_RESET_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::CURRRENT_RESET_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::TM_LAST_RESET_STATUS, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::TM_MCU_TEMPERATURE, new PoolEntry<int32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::TM_RW_STATE, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::TM_CLC_MODE, new PoolEntry<uint8_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::TM_RW_CURR_SPEED, new PoolEntry<int32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::TM_RW_REF_SPEED, new PoolEntry<int32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::INVALID_CRC_PACKETS, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::INVALID_LEN_PACKETS, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::INVALID_CMD_PACKETS, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::EXECUTED_REPLIES, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::COMMAND_REPLIES, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::UART_BYTES_WRITTEN, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::UART_BYTES_READ, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::UART_PARITY_ERRORS, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::UART_NOISE_ERRORS, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::UART_FRAME_ERRORS, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::UART_REG_OVERRUN_ERRORS, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::UART_TOTAL_ERRORS, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::SPI_BYTES_WRITTEN, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::SPI_BYTES_READ, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::SPI_REG_OVERRUN_ERRORS, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(RwDefinitions::SPI_TOTAL_ERRORS, new PoolEntry<uint32_t>( { 0 }));
return RETURN_OK;
}
size_t StarTrackerHandler::getNextReplyLength(DeviceCommandId_t commandId){
return StarTracker::MAX_FRAME_SIZE;
}
void StarTrackerHandler::slipInit() {
slipInfo.buffer = rxBuffer;
slipInfo.maxlength = StartTracker::MAX_FRAME_SIZE;
slipInfo.length = 0;
slipInfo.unescape_next = 0;
slipInfo.prev_state = SLIP_COMPLETE;
}
void StarTrackerHandler::prepareTemperatureRequest() {
uint32_t length = 0;
arc_tm_pack_temperature_req(commandBuffer);
uint32_t encLength = 0;
arc_transport_encode_body(commandBuffer, length, encBuffer, &encLength);
rawPacket = encBuffer;
rawPacketLen = encLength;
}
void StarTrackerHandler::handleTemperatureTm() {
PoolReadGuard rg(&temperatureSet);
uint32_t offset = 1;
temperatureSet.status = *(decodedFrame + offset);
offset += 1;
if(temperatureSet.status.value != 0) {
sif::warning << "StarTrackerHandler::handleTemperatureTm: Reply error: "
<< static_const<unsigned int>(temperatureSet.status.value) << std::endl;
triggerEvent(TM_REPLY_ERROR, temperatureSet.status.value);
}
temperatureSet.ticks = *(decodedFrame + offset) << 24
| *(decodedFrame + offset + 1) << 16 | *(decodedFrame + offset + 2) << 8
| *(decodedFrame + offset + 3);
offset += 4;
temperatureSet.time = *(decodedFrame + offset) << 56 | *(decodedFrame + offset + 1) << 48
| *(decodedFrame + offset + 2) << 40 | *(decodedFrame + offset + 3) << 32
| *(decodedFrame + offset + 4) << 24 | *(decodedFrame + offset + 5) << 16
| *(decodedFrame + offset + 6) << 8 | *(decodedFrame + offset + 7);
offset += 8;
temperatureSet.mcuTemperature = *(decodedFrame + offset) << 24
| *(decodedFrame + offset + 1) << 16 | *(decodedFrame + offset + 2) << 8
| *(decodedFrame + offset + 3);
offset += 4;
temperatureSet.cmosTemperature = *(decodedFrame + offset) << 24
| *(decodedFrame + offset + 1) << 16 | *(decodedFrame + offset + 2) << 8
| *(decodedFrame + offset + 3);
#if OBSW_VERBOSE_LEVEL >= 1 && START_TRACKER_DEBUG == 1
sif::info << "StarTrackerHandler::handleTemperatureTm: MCU Temperature: "
<< temperatureSet.mcuTemperature << " °C" << std::endl;
sif::info << "StarTrackerHandler::handleTemperatureTm: CMOS Temperature: "
<< temperatureSet.mcuTemperature << " °C" << std::endl;
#endif
}

View File

@ -0,0 +1,101 @@
#ifndef MISSION_DEVICES_STARTRACKERHANDLER_H_
#define MISSION_DEVICES_STARTRACKERHANDLER_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <mission/devices/devicedefinitions/StarTrackerDefinitions.h>
/**
* @brief This is the device handler for the star tracker from arcsec.
*
* @details Datasheet: https://eive-cloud.irs.uni-stuttgart.de/index.php/apps/files/?dir=/EIVE_IRS/
* Arbeitsdaten/08_Used%20Components/ArcSec_KULeuven_Startracker/
* Sagitta%201.0%20Datapack&fileid=659181
*
* @author J. Meier
*/
class StarTrackerHandler: public DeviceHandlerBase {
public:
/**
* @brief Constructor
*
* @param objectId
* @param comIF
* @param comCookie
* @param gpioComIF Pointer to gpio communication interface
* @param enablePin GPIO connected to the enable pin of the reaction wheels. Must be pulled
* to high to enable the device.
*/
StarTrackerHandler(object_id_t objectId, object_id_t comIF, CookieIF * comCookie);
virtual ~StarTrackerHandler();
protected:
void doStartUp() override;
void doShutDown() override;
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) override;
void fillCommandAndReplyMap() override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t * commandData,size_t commandDataLen) override;
ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize,
DeviceCommandId_t *foundId, size_t *foundLen) override;
ReturnValue_t interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) override;
void setNormalDatapoolEntriesInvalid() override;
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) override;
/**
* @brief Overwritten here to always read all available data from the UartComIF.
*/
virtual size_t getNextReplyLength(DeviceCommandId_t deviceCommand) override;
private:
static const uint8_t INTERFACE_ID = CLASS_ID::STR_HANDLER;
//! [EXPORT] : [COMMENT] Received reply is too short
static const ReturnValue_t REPLY_TOO_SHORT = MAKE_RETURN_CODE(0xB0);
//! [EXPORT] : [COMMENT] Received reply with invalid CRC
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::STR_HANDLER;
//! [EXPORT] : [COMMENT] Result code of tm reply indicates an error
static const ReturnValue_t TM_REPLY_ERROR = MAKE_RETURN_CODE(0xA0);
//! P1: TM id
LinuxLibgpioIF* gpioComIF = nullptr;
gpioId_t enableGpio = gpio::NO_GPIO;
StarTracker::TemperatureSet temperatureSet;
uint8_t commandBuffer[StartTracker::MAX_FRAME_SIZE];
uint8_t rxBuffer[StartTracker::MAX_FRAME_SIZE];
uint8_t decodedFrame[StartTracker::MAX_FRAME_SIZE];
/** Size of buffer derived from the egse source code */
uint8_t encBuffer[StartTracker::MAX_FRAME_SIZE * 2 + 2];
static slip_decode_state slipInfo = {0};
enum class InternalState {
TEMPERATURE_REQUEST
};
InternalState internalState = InternalState::TEMPERATURE_REQUEST;
/**
* @brief This function initializes the serial link ip protocol struct slipInfo.
*/
void slipInit();
void prepareTemperatureRequest(DeviceCommandId_t id);
/**
* @brief This function handles the telemetry reply of a temperature request.
*/
void handleTemperatureTm();
};
#endif /* MISSION_DEVICES_STARTRACKERHANDLER_H_ */

View File

@ -83,7 +83,7 @@ static const size_t SIZE_GET_RW_STATUS = 14;
static const size_t SIZE_SET_SPEED_REPLY = 4;
static const size_t SIZE_GET_TEMPERATURE_REPLY = 8;
/** Max size when requesting telemetry */
static const size_t SIZE_GET_TELEMETRY_REPLY = 83;
static const size_t SIZE_GET_TELEMETRY_REPLY = 91;
/** Set speed command has maximum size */
static const size_t MAX_CMD_SIZE = 9;

View File

@ -0,0 +1,64 @@
#ifndef MISSION_STARTRACKER_DEFINITIONS_H_
#define MISSION_STARTRACKER_DEFINITIONS_H_
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/datapoollocal/LocalPoolVariable.h>
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
#include "objects/systemObjectList.h"
namespace StarTracker {
/** This is the address of the star tracker */
static const uint8_t ADDRESS = 33;
enum PoolIds: lp_id_t {
STATUS,
TICKS,
TIME,
MCU_TEMPERATURE,
CMOS_TEMPERATURE
};
static const DeviceCommandId_t REQ_TEMPERATURE = 25;
static const uint32_t TEMPERATURE_SET_ID = REQ_TEMPERATURE;
/** Max size of unencoded frame */
static const size_t MAX_FRAME_SIZE = 1200;
static const uint8_t TEMPERATURE_SET_ENTRIES = 2;
/**
* @brief This dataset can be used to store the temperature of a reaction wheel.
*/
class TemperatureSet:
public StaticLocalDataSet<TEMPERATURE_SET_ENTRIES> {
public:
TemperatureSet(HasLocalDataPoolIF* owner):
StaticLocalDataSet(owner, TEMPERATURE_SET_ID) {
}
TemperatureSet(object_id_t objectId):
StaticLocalDataSet(sid_t(objectId, TEMPERATURE_SET_ID)) {
}
lp_var_t<uint8_t> status = lp_var_t<uint8_t>(sid.objectId,
PoolIds::STATUS, this);
lp_var_t<uint32_t> ticks = lp_var_t<uint32_t>(sid.objectId,
PoolIds::TICKS, this);
/** Unix time in microseconds */
lp_var_t<uint64_t> ticks = lp_var_t<uint64_t>(sid.objectId,
PoolIds::TIME, this);
lp_var_t<float> mcuTemperature = lp_var_t<float>(sid.objectId,
PoolIds::MCU_TEMPERATURE, this);
lp_var_t<float> cmosTemperature = lp_var_t<float>(sid.objectId,
PoolIds::CMOS_TEMPERATURE, this);
};
}
#endif /* MISSION_STARTRACKER_DEFINITIONS_H_ */