tmp1075 handler, wip

This commit is contained in:
Jakob Meier 2021-01-08 09:34:43 +01:00
parent 06231a71cc
commit d6eb4ebb07
20 changed files with 663 additions and 41 deletions

View File

@ -125,17 +125,21 @@ void InitMission::initTasks(){
sif::error << "Object add component failed" << std::endl; sif::error << "Object add component failed" << std::endl;
} }
// PeriodicTaskIF* P60DockTask = TaskFactory::instance()-> //TODO: Add handling of missed deadlines
// createPeriodicTask("P60Dock Task", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE*4, /* Polling Sequence Table Default */
// 1.6, nullptr); FixedTimeslotTaskIF * PollingSequenceTableTaskDefault =
// result = P60DockTask->addComponent(objects::P60DOCK_HANDLER); TaskFactory::instance()->createFixedTimeslotTask("PST_TASK_DEFAULT",
// if(result!=HasReturnvaluesIF::RETURN_OK){ 50, PeriodicTaskIF::MINIMUM_STACK_SIZE*4, 3.0,
// sif::error << "Object add component failed" << std::endl; nullptr);
// } result = pst::pollingSequenceInitDefault(PollingSequenceTableTaskDefault);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "InitMission::initTasks: Creating PST failed!"
<< std::endl;
}
FixedTimeslotTaskIF* GomSpacePstTask = TaskFactory::instance()-> FixedTimeslotTaskIF* GomSpacePstTask = TaskFactory::instance()->
createFixedTimeslotTask("GS_PST_TASK", 50, createFixedTimeslotTask("GS_PST_TASK", 50,
PeriodicTaskIF::MINIMUM_STACK_SIZE*4, 1.0, nullptr); PeriodicTaskIF::MINIMUM_STACK_SIZE*4, 3.0, nullptr);
result = pst::gomspacePstInit(GomSpacePstTask); result = pst::gomspacePstInit(GomSpacePstTask);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "InitMission::initTasks: GomSpace PST initialization " sif::error << "InitMission::initTasks: GomSpace PST initialization "
@ -161,7 +165,8 @@ void InitMission::initTasks(){
UdpBridgeTask->startTask(); UdpBridgeTask->startTask();
UdpPollingTask->startTask(); UdpPollingTask->startTask();
GomSpacePstTask->startTask(); // GomSpacePstTask->startTask();
PollingSequenceTableTaskDefault->startTask();
PusVerification->startTask(); PusVerification->startTask();
PusEvents->startTask(); PusEvents->startTask();
@ -169,8 +174,6 @@ void InitMission::initTasks(){
PusMedPrio->startTask(); PusMedPrio->startTask();
PusLowPrio->startTask(); PusLowPrio->startTask();
// P60DockTask->startTask();
#if OBSW_ADD_TEST_CODE == 1 #if OBSW_ADD_TEST_CODE == 1
// TestTimeslotTask->startTask(); // TestTimeslotTask->startTask();
#endif #endif

View File

@ -13,12 +13,15 @@
#include <mission/core/GenericFactory.h> #include <mission/core/GenericFactory.h>
#include <mission/devices/GomspaceDeviceHandler.h> #include <mission/devices/GomspaceDeviceHandler.h>
#include <mission/devices/Tmp1075Handler.h>
#include <mission/devices/devicedefinitions/GomSpacePackets.h> #include <mission/devices/devicedefinitions/GomSpacePackets.h>
#include <mission/devices/devicedefinitions/GomspaceDefinitions.h> #include <mission/devices/devicedefinitions/GomspaceDefinitions.h>
#include <mission/utility/TmFunnel.h> #include <mission/utility/TmFunnel.h>
#include <bsp_q7s/comIF/cookies/CspCookie.h> #include <bsp_q7s/comIF/cookies/CspCookie.h>
#include <bsp_q7s/comIF/cookies/I2cCookie.h>
#include <bsp_q7s/comIF/CspComIF.h> #include <bsp_q7s/comIF/CspComIF.h>
#include <bsp_q7s/comIF/I2cComIF.h>
void Factory::setStaticFrameworkObjectIds() { void Factory::setStaticFrameworkObjectIds() {
PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR; PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR;
@ -52,9 +55,12 @@ void ObjectFactory::produce(){
addresses::PDU2); addresses::PDU2);
CspCookie* acuCspCookie = new CspCookie(ACU::MAX_REPLY_LENGTH, CspCookie* acuCspCookie = new CspCookie(ACU::MAX_REPLY_LENGTH,
addresses::ACU); addresses::ACU);
I2cCookie* i2cCookieTmp1075tcs1 = new I2cCookie(addresses::TMP1075_TCS_1,
TMP1075::MAX_REPLY_LENGTH, std::string("/dev/i2c-1"));
/* Communication interfaces */ /* Communication interfaces */
new CspComIF(objects::CSP_COM_IF); new CspComIF(objects::CSP_COM_IF);
new I2cComIF(objects::I2C_COM_IF);
/* Device Handler */ /* Device Handler */
new GomspaceDeviceHandler(objects::P60DOCK_HANDLER, objects::CSP_COM_IF, new GomspaceDeviceHandler(objects::P60DOCK_HANDLER, objects::CSP_COM_IF,
@ -69,6 +75,11 @@ void ObjectFactory::produce(){
new GomspaceDeviceHandler(objects::ACU_HANDLER, objects::CSP_COM_IF, new GomspaceDeviceHandler(objects::ACU_HANDLER, objects::CSP_COM_IF,
acuCspCookie, ACU::MAX_CONFIGTABLE_ADDRESS, acuCspCookie, ACU::MAX_CONFIGTABLE_ADDRESS,
ACU::MAX_HKTABLE_ADDRESS); ACU::MAX_HKTABLE_ADDRESS);
Tmp1075Handler* tmp1075Handler_1 = new Tmp1075Handler(
objects::TMP1075_HANDLER_1, objects::I2C_COM_IF,
i2cCookieTmp1075tcs1);
tmp1075Handler_1->setStartUpImmediately();
new TmTcUnixUdpBridge(objects::UDP_BRIDGE, new TmTcUnixUdpBridge(objects::UDP_BRIDGE,
objects::CCSDS_PACKET_DISTRIBUTOR, objects::CCSDS_PACKET_DISTRIBUTOR,

View File

@ -1,6 +1,8 @@
target_sources(${TARGET_NAME} PRIVATE target_sources(${TARGET_NAME} PRIVATE
cookies/CspCookie.cpp cookies/CspCookie.cpp
cookies/I2cCookie.cpp
CspComIF.cpp CspComIF.cpp
I2cComIF.cpp
) )

158
bsp_q7s/comIF/I2cComIF.cpp Normal file
View File

@ -0,0 +1,158 @@
#include <bsp_q7s/comIF/I2cComIF.h>
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <errno.h>
#include <string.h>
I2cComIF::I2cComIF(object_id_t objectId): SystemObject(objectId){
}
I2cComIF::~I2cComIF() {}
ReturnValue_t I2cComIF::initializeInterface(CookieIF * cookie) {
if(cookie == nullptr) {
return NULLPOINTER;
}
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if(i2cCookie == nullptr) {
sif::error << "I2cComIF: Invalid I2C Cookie!"
<< std::endl;
return NULLPOINTER;
}
address_t i2cAddress = i2cCookie->getAddress();
int fd;
std::string deviceFile = i2cCookie->getDeviceFile();
/* Opening i2c device in non-blocking mode */
fd = open("/dev/i2c-0", O_RDWR);
if (fd < 0) {
sif::error << "I2cComIF: Opening i2c device failed with error code "
<< errno << ". Error description: " << strerror(errno)
<< std::endl;
}
if (ioctl(fd, I2C_SLAVE, i2cAddress) < 0) {
sif::error << "I2cComIF: Specifying target device failed with error "
<< "code " << errno << ". Error description "
<< strerror(errno) << std::endl;
}
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if(i2cDeviceMapIter == i2cDeviceMap.end()) {
size_t maxReplyLen = i2cCookie->getMaxReplyLen();
I2cInstance_t i2cInstance = {fd, std::vector<uint8_t>(maxReplyLen), 0};
i2cDeviceMap.emplace(i2cAddress, i2cInstance);
}
else {
sif::error << "I2cComIF: Device with address " << i2cAddress
<< "already in use" << std::endl;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,
const uint8_t *sendData, size_t sendLen) {
if(sendData == nullptr) {
sif::error << "I2cComIF::sendMessage: Send Data is nullptr"
<< std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
if(sendLen == 0) {
return HasReturnvaluesIF::RETURN_OK;
}
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if(i2cCookie == nullptr) {
sif::error << "I2cComIF::sendMessasge: Invalid I2C Cookie!"
<< std::endl;
return NULLPOINTER;
}
address_t i2cAddress = i2cCookie->getAddress();
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
sif::error << "I2cComIF::sendMessage: i2cAddress of Cookie not "
<< "registered in i2cDeviceMap" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
int fd = i2cDeviceMapIter->second.fileDescriptor;
if (write(fd, sendData, sendLen) != (int)sendLen) {
sif::error << "I2cComIF::sendMessage: Failed to send data to I2C "
"device with error code " << errno << ". Error description: "
<< strerror(errno) << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t I2cComIF::getSendSuccess(CookieIF *cookie) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
size_t requestLen) {
if (requestLen == 0) {
return HasReturnvaluesIF::RETURN_OK;
}
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if(i2cCookie == nullptr) {
sif::error << "I2cComIF::sendMessage: Invalid I2C Cookie!"
<< std::endl;
return NULLPOINTER;
}
address_t i2cAddress = i2cCookie->getAddress();
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
sif::error << "I2cComIF::requestReceiveMessage: i2cAddress of Cookie not "
<< "registered in i2cDeviceMap" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
int fd = i2cDeviceMapIter->second.fileDescriptor;
uint8_t* replyBuffer = i2cDeviceMapIter->second.replyBuffer.data();
if (read(fd, replyBuffer, requestLen) != (int)requestLen) {
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C "
<< "device failed with error code " << errno <<". Description"
<< " of error: " << strerror(errno) << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
i2cDeviceMapIter->second.replyLen = requestLen;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie,
uint8_t **buffer, size_t* size) {
I2cCookie* i2cCookie = dynamic_cast<I2cCookie*>(cookie);
if(i2cCookie == nullptr) {
sif::error << "I2cComIF::readReceivedMessage: Invalid I2C Cookie!"
<< std::endl;
return NULLPOINTER;
}
address_t i2cAddress = i2cCookie->getAddress();
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if (i2cDeviceMapIter == i2cDeviceMap.end()) {
sif::error << "I2cComIF::getReplyBuffer: i2cAddress of Cookie not "
<< "registered in i2cDeviceMap" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
*buffer = i2cDeviceMapIter->second.replyBuffer.data();
*size = i2cDeviceMapIter->second.replyLen;
return HasReturnvaluesIF::RETURN_OK;
}

49
bsp_q7s/comIF/I2cComIF.h Normal file
View File

@ -0,0 +1,49 @@
#ifndef BSP_Q7S_COMIF_I2COMIF_H_
#define BSP_Q7S_COMIF_I2COMIF_H_
#include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/devicehandlers/DeviceCommunicationIF.h>
#include <bsp_q7s/comIF/cookies/I2cCookie.h>
#include <unordered_map>
#include <vector>
/**
* @brief This is the communication interface for i2c devices connected
* to a system running a linux OS.
*
* @author J. Meier
*/
class I2cComIF: public DeviceCommunicationIF, public SystemObject {
public:
I2cComIF(object_id_t objectId);
virtual ~I2cComIF();
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;
private:
typedef struct I2cInstance {
int fileDescriptor;
std::vector<uint8_t> replyBuffer;
size_t replyLen;
} I2cInstance_t;
using I2cDeviceMap = std::unordered_map<address_t, I2cInstance_t>;
using I2cDeviceMapIter = I2cDeviceMap::iterator;
/* In this map all i2c devices will be registered with their address and
* the appropriate file descriptor will be stored */
I2cDeviceMap i2cDeviceMap;
I2cDeviceMapIter i2cDeviceMapIter;
};
#endif /* BSP_Q7S_COMIF_I2COMIF_H_ */

View File

@ -0,0 +1,21 @@
#include <bsp_q7s/comIF/cookies/I2cCookie.h>
I2cCookie::I2cCookie(address_t i2cAddress_, size_t maxReplyLen_,
std::string deviceFile_) :
i2cAddress(i2cAddress_), maxReplyLen(maxReplyLen_), deviceFile(
deviceFile_) {
}
address_t I2cCookie::getAddress() const {
return i2cAddress;
}
size_t I2cCookie::getMaxReplyLen() const {
return maxReplyLen;
}
std::string I2cCookie::getDeviceFile() const {
return deviceFile;
}
I2cCookie::~I2cCookie() {}

View File

@ -0,0 +1,37 @@
#ifndef SAM9G20_COMIF_COOKIES_I2C_COOKIE_H_
#define SAM9G20_COMIF_COOKIES_I2C_COOKIE_H_
#include <fsfw/devicehandlers/CookieIF.h>
#include <string>
/**
* @brief Cookie for the i2cDeviceComIF.
*
* @author J. Meier
*/
class I2cCookie: public CookieIF {
public:
/**
* @brief Constructor for the I2C cookie.
* @param i2cAddress_ The i2c address of the target device.
* @param maxReplyLen The maximum expected length of a reply from the
* target device.
*/
I2cCookie(address_t i2cAddress_, size_t maxReplyLen_,
std::string deviceFile_);
virtual ~I2cCookie();
address_t getAddress() const;
size_t getMaxReplyLen() const;
std::string getDeviceFile() const;
private:
address_t i2cAddress = 0;
size_t maxReplyLen = 0;
std::string deviceFile;
};
#endif

2
etl

@ -1 +1 @@
Subproject commit f6ce3f59bd9da826817d79947165991ca8655b22 Subproject commit 1ac3b77ef40aa783024d15185ee8ff41ae04a73e

2
fsfw

@ -1 +1 @@
Subproject commit 1ac2479b28c1114b0876123e0db4155abfbf06fe Subproject commit bd5cc7ae3ea53040cc832b5d756846d21613d91a

View File

@ -15,6 +15,8 @@ namespace addresses {
enum logicalAddresses: address_t { enum logicalAddresses: address_t {
PCDU, PCDU,
TMP1075_TCS_1 = 72,
TMP1075_TCS_2 = 73,
/* Dummy and Test Addresses */ /* Dummy and Test Addresses */
DUMMY_ECHO = 129, DUMMY_ECHO = 129,
DUMMY_GPS0 = 130, DUMMY_GPS0 = 130,

View File

@ -31,12 +31,15 @@ namespace objects {
/* 0x49 ('I') for Communication Interfaces **/ /* 0x49 ('I') for Communication Interfaces **/
ARDUINO_COM_IF = 0x49000001, ARDUINO_COM_IF = 0x49000001,
CSP_COM_IF = 0x49000002, CSP_COM_IF = 0x49000002,
I2C_COM_IF = 0x49000003,
/* 0x44 ('D') for device handlers */ /* 0x44 ('D') for device handlers */
P60DOCK_HANDLER = 0x44000001, P60DOCK_HANDLER = 0x44000001,
PDU1_HANDLER = 0x44000002, PDU1_HANDLER = 0x44000002,
PDU2_HANDLER = 0x44000003, PDU2_HANDLER = 0x44000003,
ACU_HANDLER = 0x44000004 ACU_HANDLER = 0x44000004,
TMP1075_HANDLER_1 = 0x44000005,
TMP1075_HANDLER_2 = 0x44000006
}; };
} }

View File

@ -10,14 +10,16 @@ ReturnValue_t pst::pollingSequenceInitDefault(FixedTimeslotTaskIF *thisSequence)
/* Length of a communication cycle */ /* Length of a communication cycle */
uint32_t length = thisSequence->getPeriodMs(); uint32_t length = thisSequence->getPeriodMs();
thisSequence->addSlot(objects::DUMMY_HANDLER, thisSequence->addSlot(objects::TMP1075_HANDLER_1,
length * 0, DeviceHandlerIF::SEND_WRITE); length * 0, DeviceHandlerIF::PERFORM_OPERATION);
thisSequence->addSlot(objects::DUMMY_HANDLER, thisSequence->addSlot(objects::TMP1075_HANDLER_1,
length * 0.25, DeviceHandlerIF::GET_WRITE); length * 0.2, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::DUMMY_HANDLER, thisSequence->addSlot(objects::TMP1075_HANDLER_1,
length * 0.5, DeviceHandlerIF::SEND_READ); length * 0.4, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::DUMMY_HANDLER, thisSequence->addSlot(objects::TMP1075_HANDLER_1,
length * 0.75, DeviceHandlerIF::GET_READ); length * 0.6, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::TMP1075_HANDLER_1,
length * 0.8, DeviceHandlerIF::GET_READ);
if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
@ -42,40 +44,40 @@ ReturnValue_t pst::gomspacePstInit(FixedTimeslotTaskIF *thisSequence){
length * 0, DeviceHandlerIF::PERFORM_OPERATION); length * 0, DeviceHandlerIF::PERFORM_OPERATION);
thisSequence->addSlot(objects::P60DOCK_HANDLER, thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE); length * 0.2, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::PDU1_HANDLER, thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE); length * 0.2, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::PDU2_HANDLER, thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE); length * 0.2, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::ACU_HANDLER, thisSequence->addSlot(objects::ACU_HANDLER,
length * 0, DeviceHandlerIF::SEND_WRITE); length * 0.2, DeviceHandlerIF::SEND_WRITE);
thisSequence->addSlot(objects::P60DOCK_HANDLER, thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE); length * 0.4, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::PDU1_HANDLER, thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE); length * 0.4, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::PDU2_HANDLER, thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE); length * 0.4, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::ACU_HANDLER, thisSequence->addSlot(objects::ACU_HANDLER,
length * 0.25, DeviceHandlerIF::GET_WRITE); length * 0.4, DeviceHandlerIF::GET_WRITE);
thisSequence->addSlot(objects::P60DOCK_HANDLER, thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ); length * 0.6, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::PDU1_HANDLER, thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ); length * 0.6, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::PDU2_HANDLER, thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ); length * 0.6, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::ACU_HANDLER, thisSequence->addSlot(objects::ACU_HANDLER,
length * 0.5, DeviceHandlerIF::SEND_READ); length * 0.6, DeviceHandlerIF::SEND_READ);
thisSequence->addSlot(objects::P60DOCK_HANDLER, thisSequence->addSlot(objects::P60DOCK_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ); length * 0.8, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::PDU1_HANDLER, thisSequence->addSlot(objects::PDU1_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ); length * 0.8, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::PDU2_HANDLER, thisSequence->addSlot(objects::PDU2_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ); length * 0.8, DeviceHandlerIF::GET_READ);
thisSequence->addSlot(objects::ACU_HANDLER, thisSequence->addSlot(objects::ACU_HANDLER,
length * 0.75, DeviceHandlerIF::GET_READ); length * 0.8, DeviceHandlerIF::GET_READ);
if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) { if (thisSequence->checkSequence() == HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;

View File

@ -0,0 +1,49 @@
#include "ThermalController.h"
#include <mission/devices/devicedefinitions/ThermalSensorPacket.h>
ThermalController::ThermalController(object_id_t objectId):
ExtendedControllerBase(objectId, objects::NO_OBJECT),
thermalControllerSet(objectId) {
}
ReturnValue_t ThermalController::handleCommandMessage(
CommandMessage *message) {
return HasReturnvaluesIF::RETURN_OK;
}
void ThermalController::performControlOperation() {
}
void ThermalController::handleChangedDataset(sid_t sid,
store_address_t storeId) {
if(sid == sid_t(TSensorDefinitions::ObjIds::TEST_HKB_HANDLER,
TSensorDefinitions::THERMAL_SENSOR_SET_ID)) {
sif::info << "Update registered!" << std::endl;
}
}
ReturnValue_t ThermalController::initializeAfterTaskCreation() {
ReturnValue_t result =
ExtendedControllerBase::initializeAfterTaskCreation();
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "ThermalController::initializeAfterTaskCreation: Base"
<< " class initialization failed!" << std::endl;
}
HasLocalDataPoolIF* testHkbHandler = objectManager->get<HasLocalDataPoolIF>(
TSensorDefinitions::ObjIds::TEST_HKB_HANDLER);
if(testHkbHandler == nullptr) {
sif::warning << "ThermalController::initializeAfterTaskCreation: Test"
<< " HKB Handler invalid!" << std::endl;
}
// Test normal notifications without data packet first.
testHkbHandler->getHkManagerHandle()->subscribeForSetUpdateMessages(
TSensorDefinitions::THERMAL_SENSOR_SET_ID,
this->getObjectId(), commandQueue->getId(), false);
return result;
}
ReturnValue_t ThermalController::checkModeCommand(Mode_t mode,
Submode_t submode, uint32_t *msToReachTheMode) {
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -0,0 +1,33 @@
#ifndef MISSION_CONTROLLER_THERMALCONTROLLER_H_
#define MISSION_CONTROLLER_THERMALCONTROLLER_H_
#include <fsfw/controller/ExtendedControllerBase.h>
#include "ctrldefinitions/ThermalCtrlPackets.h"
class ThermalController: public ExtendedControllerBase {
public:
ThermalController(object_id_t objectId);
private:
// TODO: Add stubs for thermal components. Each device / assembly with one
// or multiple redundant sensors will have a thermal component.
/** ExtendedControllerBase overrides */
virtual ReturnValue_t handleCommandMessage(
CommandMessage *message) override;
virtual void performControlOperation() override;
virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode) override;
ReturnValue_t initializeAfterTaskCreation() override;
void handleChangedDataset(sid_t sid, store_address_t storeId) override;
ThermalCtrl::ThermalControllerTemperatureSet thermalControllerSet;
};
#endif /* MISSION_CONTROLLER_THERMALCONTROLLER_H_ */

View File

@ -4,6 +4,7 @@ target_sources(${TARGET_NAME} PUBLIC
MGMHandlerLIS3MDL.cpp MGMHandlerLIS3MDL.cpp
MGMHandlerRM3100.cpp MGMHandlerRM3100.cpp
GomspaceDeviceHandler.cpp GomspaceDeviceHandler.cpp
Tmp1075Handler.cpp
) )

View File

@ -70,9 +70,9 @@ ReturnValue_t GomspaceDeviceHandler::buildCommandFromCommand(
} }
} }
default: default:
break; return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_FAILED;
} }
void GomspaceDeviceHandler::fillCommandAndReplyMap(){ void GomspaceDeviceHandler::fillCommandAndReplyMap(){

View File

@ -0,0 +1,134 @@
#include <mission/devices/Tmp1075Handler.h>
#include <mission/devices/devicedefinitions/Tmp1075Definitions.h>
Tmp1075Handler::Tmp1075Handler(object_id_t objectId, object_id_t comIF,
CookieIF * comCookie) :
DeviceHandlerBase(objectId, comIF, comCookie), dataset(
this) {
if (comCookie == NULL) {
sif::error << "Tmp1075Handler: Invalid com cookie" << std::endl;
}
}
Tmp1075Handler::~Tmp1075Handler() {
}
void Tmp1075Handler::doStartUp(){
if(mode == _MODE_START_UP){
setMode(MODE_NORMAL);
}
}
void Tmp1075Handler::doShutDown(){
}
ReturnValue_t Tmp1075Handler::buildNormalDeviceCommand(
DeviceCommandId_t * id) {
if(communicationStep == CommunicationStep::START_ADC_CONVERSION) {
*id = TMP1075::START_ADC_CONVERSION;
communicationStep = CommunicationStep::GET_TEMPERATURE;
return buildCommandFromCommand(*id, NULL, 0);
}
else {
*id = TMP1075::GET_TEMP;
communicationStep = CommunicationStep::START_ADC_CONVERSION;
return buildCommandFromCommand(*id, NULL, 0);
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Tmp1075Handler::buildTransitionDeviceCommand(
DeviceCommandId_t * id){
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Tmp1075Handler::buildCommandFromCommand(
DeviceCommandId_t deviceCommand, const uint8_t * commandData,
size_t commandDataLen) {
switch(deviceCommand) {
case(TMP1075::START_ADC_CONVERSION): {
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
prepareAdcConversionCommand();
rawPacket = cmdBuffer;
rawPacketLen = TMP1075::CFGR_CMD_SIZE;
return RETURN_OK;
}
case(TMP1075::GET_TEMP): {
std::memset(cmdBuffer, 0, sizeof(cmdBuffer));
prepareGetTempCommand();
rawPacket = cmdBuffer;
rawPacketLen = TMP1075::POINTER_REG_SIZE;
rememberCommandId = TMP1075::GET_TEMP;
return RETURN_OK;
}
default:
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
return HasReturnvaluesIF::RETURN_FAILED;
}
void Tmp1075Handler::fillCommandAndReplyMap(){
this->insertInCommandMap(TMP1075::START_ADC_CONVERSION);
this->insertInCommandAndReplyMap(TMP1075::GET_TEMP, 1, &dataset,
TMP1075::GET_TEMP_REPLY_SIZE);
}
ReturnValue_t Tmp1075Handler::scanForReply(const uint8_t *start,
size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) {
switch(rememberCommandId) {
case(TMP1075::GET_TEMP):
*foundId = TMP1075::GET_TEMP;
*foundLen = TMP1075::GET_TEMP_REPLY_SIZE;
rememberCommandId = TMP1075::NONE;
break;
default:
return IGNORE_REPLY_DATA;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Tmp1075Handler::interpretDeviceReply(DeviceCommandId_t id,
const uint8_t *packet) {
switch (id) {
case TMP1075::GET_TEMP: {
int16_t tempValueRaw = packet[1] << 8 | packet[0] >> 4;
float tempValue = ((static_cast<float>(tempValueRaw)) * 0.0625);
#if OBSW_ENHANCED_PRINTOUT == 1
sif::info << "Tmp1075: Temperature: " << tempValue<< " °C" << std::endl;
#endif
ReturnValue_t result = dataset.read(20);
if(result == HasReturnvaluesIF::RETURN_OK) {
dataset.temperatureCelcius = tempValue;
dataset.commit(20);
}
break;
}
default: {
return DeviceHandlerIF::UNKNOWN_DEVICE_REPLY;
}
}
return HasReturnvaluesIF::RETURN_OK;
}
void Tmp1075Handler::setNormalDatapoolEntriesInvalid(){
}
void Tmp1075Handler::prepareAdcConversionCommand(){
cmdBuffer[0] = TMP1075::CFGR_ADDR;
cmdBuffer[1] = TMP1075::ONE_SHOT_MODE >> 8;
cmdBuffer[2] = TMP1075::ONE_SHOT_MODE & 0xFF;
}
void Tmp1075Handler::prepareGetTempCommand(){
cmdBuffer[0] = TMP1075::TEMP_REG_ADDR;
}
uint32_t Tmp1075Handler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo){
return 0;
}

View File

@ -0,0 +1,66 @@
#ifndef MISSION_DEVICES_TMP1075HANDLER_H_
#define MISSION_DEVICES_TMP1075HANDLER_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <mission/devices/devicedefinitions/Tmp1075Definitions.h>
/**
* @brief This is the device handler class for the tmp1075 temperature sensor.
*
* @details The tmp1075 communicates via I2C. After the address byte and the
* read and write bit, a pointer address must be sent to the device.
* This pointer address is stored in the pointer register of the
* tmp1075 and defines to which address following data bytes will
* be written or from which address data will be read.
*
* @author J. Meier
*/
class Tmp1075Handler: public DeviceHandlerBase {
public:
Tmp1075Handler(object_id_t objectId, object_id_t comIF,
CookieIF * comCookie);
virtual ~Tmp1075Handler();
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;
private:
/**
* @brief Function fills cmdBuffer with command to start the adc
* conversion for a new temperature value.
*/
void prepareAdcConversionCommand();
void prepareGetTempCommand();
enum class CommunicationStep {
START_ADC_CONVERSION,
GET_TEMPERATURE
};
TMP1075::Tmp1075Dataset dataset;
static const uint8_t MAX_CMD_LEN = 3;
uint8_t rememberRequestedSize = 0;
uint8_t rememberCommandId = TMP1075::NONE;
uint8_t cmdBuffer[MAX_CMD_LEN];
CommunicationStep communicationStep =
CommunicationStep::START_ADC_CONVERSION;
};
#endif /* MISSION_DEVICES_TMP1075HANDLER_H_ */

View File

@ -0,0 +1,51 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_TMP1075DEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_TMP1075DEFINITIONS_H_
namespace TMP1075 {
static const uint8_t TEMP_REG_ADDR = 0x0;
static const uint8_t CFGR_ADDR = 0x1;
/* Writing this information to the configuration register sets the tmp1075
* to shutdown mode and starts a single temperature conversion */
static const uint16_t ONE_SHOT_MODE = 0x8100;
static const DeviceCommandId_t NONE = 0x0; // Set when no command is pending
static const DeviceCommandId_t GET_TEMP = 0x1;
static const DeviceCommandId_t START_ADC_CONVERSION = 0x2;
static const uint8_t GET_TEMP_REPLY_SIZE = 2;
static const uint8_t CFGR_CMD_SIZE = 3;
static const uint8_t POINTER_REG_SIZE = 1;
static const lp_id_t TEMPERATURE_C = GET_TEMP;
static const uint32_t DATA_SET_ID = 0x0;
static const uint8_t MAX_REPLY_LENGTH = GET_TEMP_REPLY_SIZE;
class Tmp1075Dataset:
public StaticLocalDataSet<sizeof(float)> {
public:
/**
* Constructor used by owner and data creators like device handlers.
* @param owner
* @param setId
*/
Tmp1075Dataset(HasLocalDataPoolIF* owner):
StaticLocalDataSet(owner, DATA_SET_ID) {
}
/**
* Constructor used by data users like controllers.
* @param sid
*/
Tmp1075Dataset(object_id_t objectId):
StaticLocalDataSet(sid_t(objectId, DATA_SET_ID)) {
}
lp_var_t<float> temperatureCelcius = lp_var_t<float>(hkManager->getOwner(),
TEMPERATURE_C, this);
};
}
#endif /* MISSION_DEVICES_DEVICEDEFINITIONS_TMP1075DEFINITIONS_H_ */

2
tmtc

@ -1 +1 @@
Subproject commit b1dc449ccfd7de558a87ebc7aae77b1eaf32c934 Subproject commit eb9deae5abd5d6d6f016f7864dc37c9825aabb43