tmp1075 handler, wip
This commit is contained in:
@ -125,17 +125,21 @@ void InitMission::initTasks(){
|
||||
sif::error << "Object add component failed" << std::endl;
|
||||
}
|
||||
|
||||
// PeriodicTaskIF* P60DockTask = TaskFactory::instance()->
|
||||
// createPeriodicTask("P60Dock Task", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE*4,
|
||||
// 1.6, nullptr);
|
||||
// result = P60DockTask->addComponent(objects::P60DOCK_HANDLER);
|
||||
// if(result!=HasReturnvaluesIF::RETURN_OK){
|
||||
// sif::error << "Object add component failed" << std::endl;
|
||||
// }
|
||||
//TODO: Add handling of missed deadlines
|
||||
/* Polling Sequence Table Default */
|
||||
FixedTimeslotTaskIF * PollingSequenceTableTaskDefault =
|
||||
TaskFactory::instance()->createFixedTimeslotTask("PST_TASK_DEFAULT",
|
||||
50, PeriodicTaskIF::MINIMUM_STACK_SIZE*4, 3.0,
|
||||
nullptr);
|
||||
result = pst::pollingSequenceInitDefault(PollingSequenceTableTaskDefault);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "InitMission::initTasks: Creating PST failed!"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
FixedTimeslotTaskIF* GomSpacePstTask = TaskFactory::instance()->
|
||||
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);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::error << "InitMission::initTasks: GomSpace PST initialization "
|
||||
@ -161,7 +165,8 @@ void InitMission::initTasks(){
|
||||
UdpBridgeTask->startTask();
|
||||
UdpPollingTask->startTask();
|
||||
|
||||
GomSpacePstTask->startTask();
|
||||
// GomSpacePstTask->startTask();
|
||||
PollingSequenceTableTaskDefault->startTask();
|
||||
|
||||
PusVerification->startTask();
|
||||
PusEvents->startTask();
|
||||
@ -169,8 +174,6 @@ void InitMission::initTasks(){
|
||||
PusMedPrio->startTask();
|
||||
PusLowPrio->startTask();
|
||||
|
||||
// P60DockTask->startTask();
|
||||
|
||||
#if OBSW_ADD_TEST_CODE == 1
|
||||
// TestTimeslotTask->startTask();
|
||||
#endif
|
||||
|
@ -13,12 +13,15 @@
|
||||
|
||||
#include <mission/core/GenericFactory.h>
|
||||
#include <mission/devices/GomspaceDeviceHandler.h>
|
||||
#include <mission/devices/Tmp1075Handler.h>
|
||||
#include <mission/devices/devicedefinitions/GomSpacePackets.h>
|
||||
#include <mission/devices/devicedefinitions/GomspaceDefinitions.h>
|
||||
#include <mission/utility/TmFunnel.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/I2cComIF.h>
|
||||
|
||||
void Factory::setStaticFrameworkObjectIds() {
|
||||
PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR;
|
||||
@ -52,9 +55,12 @@ void ObjectFactory::produce(){
|
||||
addresses::PDU2);
|
||||
CspCookie* acuCspCookie = new CspCookie(ACU::MAX_REPLY_LENGTH,
|
||||
addresses::ACU);
|
||||
I2cCookie* i2cCookieTmp1075tcs1 = new I2cCookie(addresses::TMP1075_TCS_1,
|
||||
TMP1075::MAX_REPLY_LENGTH, std::string("/dev/i2c-1"));
|
||||
|
||||
/* Communication interfaces */
|
||||
new CspComIF(objects::CSP_COM_IF);
|
||||
new I2cComIF(objects::I2C_COM_IF);
|
||||
|
||||
/* Device Handler */
|
||||
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,
|
||||
acuCspCookie, ACU::MAX_CONFIGTABLE_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,
|
||||
objects::CCSDS_PACKET_DISTRIBUTOR,
|
||||
|
@ -1,6 +1,8 @@
|
||||
target_sources(${TARGET_NAME} PRIVATE
|
||||
cookies/CspCookie.cpp
|
||||
cookies/I2cCookie.cpp
|
||||
CspComIF.cpp
|
||||
I2cComIF.cpp
|
||||
)
|
||||
|
||||
|
||||
|
158
bsp_q7s/comIF/I2cComIF.cpp
Normal file
158
bsp_q7s/comIF/I2cComIF.cpp
Normal 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
49
bsp_q7s/comIF/I2cComIF.h
Normal 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_ */
|
21
bsp_q7s/comIF/cookies/I2cCookie.cpp
Normal file
21
bsp_q7s/comIF/cookies/I2cCookie.cpp
Normal 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() {}
|
37
bsp_q7s/comIF/cookies/I2cCookie.h
Normal file
37
bsp_q7s/comIF/cookies/I2cCookie.h
Normal 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
|
Reference in New Issue
Block a user