tmp1075handler and I2cComIF complete

This commit is contained in:
Jakob Meier 2021-01-12 10:39:24 +01:00
parent adef6eb188
commit fd41c3b4db
6 changed files with 86 additions and 138 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ __pycache__
!misc/eclipse/**/.cproject !misc/eclipse/**/.cproject
!misc/eclipse/**/.project !misc/eclipse/**/.project
/eive_obsw cmake debug/

View File

@ -14,6 +14,10 @@ I2cComIF::I2cComIF(object_id_t objectId): SystemObject(objectId){
I2cComIF::~I2cComIF() {} I2cComIF::~I2cComIF() {}
ReturnValue_t I2cComIF::initializeInterface(CookieIF * cookie) { ReturnValue_t I2cComIF::initializeInterface(CookieIF * cookie) {
address_t i2cAddress;
std::string deviceFile;
if(cookie == nullptr) { if(cookie == nullptr) {
return NULLPOINTER; return NULLPOINTER;
} }
@ -24,40 +28,40 @@ ReturnValue_t I2cComIF::initializeInterface(CookieIF * cookie) {
return NULLPOINTER; return NULLPOINTER;
} }
address_t i2cAddress = i2cCookie->getAddress(); i2cAddress = i2cCookie->getAddress();
int fd;
std::string deviceFile = i2cCookie->getDeviceFile();
fd = open(deviceFile.c_str(), 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); i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if(i2cDeviceMapIter == i2cDeviceMap.end()) { if(i2cDeviceMapIter == i2cDeviceMap.end()) {
size_t maxReplyLen = i2cCookie->getMaxReplyLen(); size_t maxReplyLen = i2cCookie->getMaxReplyLen();
I2cInstance_t i2cInstance = {fd, std::vector<uint8_t>(maxReplyLen), 0}; I2cInstance_t i2cInstance = {std::vector<uint8_t>(maxReplyLen), 0};
i2cDeviceMap.emplace(i2cAddress, i2cInstance); std::pair status = i2cDeviceMap.emplace(i2cAddress, i2cInstance);
if (status.second == false) {
sif::error << "I2cComIF::initializeInterface: Failed to insert "
<< "device with address " << i2cAddress << "to I2C device "
<< "map" << std::endl;
return HasReturnvaluesIF::RETURN_OK;
}
} }
else { else {
sif::error << "I2cComIF: Device with address " << i2cAddress sif::error << "I2cComIF: Device with address " << i2cAddress
<< "already in use" << std::endl; << "already in use" << std::endl;
} }
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if(i2cDeviceMapIter == i2cDeviceMap.end()) {
sif::error << "Failure" << std::endl;
}
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie, ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,
const uint8_t *sendData, size_t sendLen) { const uint8_t *sendData, size_t sendLen) {
ReturnValue_t result;
int fd;
std::string deviceFile;
if(sendData == nullptr) { if(sendData == nullptr) {
sif::error << "I2cComIF::sendMessage: Send Data is nullptr" sif::error << "I2cComIF::sendMessage: Send Data is nullptr"
<< std::endl; << std::endl;
@ -82,15 +86,21 @@ ReturnValue_t I2cComIF::sendMessage(CookieIF *cookie,
<< "registered in i2cDeviceMap" << std::endl; << "registered in i2cDeviceMap" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
int fd = i2cDeviceMapIter->second.fileDescriptor;
deviceFile = i2cCookie->getDeviceFile();
result = openDevice(deviceFile, i2cAddress, &fd);
if (result != HasReturnvaluesIF::RETURN_OK){
return result;
}
if (write(fd, sendData, sendLen) != (int)sendLen) { if (write(fd, sendData, sendLen) != (int)sendLen) {
sif::error << "I2cComIF::sendMessage: Failed to send data to I2C " sif::error << "I2cComIF::sendMessage: Failed to send data to I2C "
"device with error code " << errno << ". Error description: " "device with error code " << errno << ". Error description: "
<< strerror(errno) << std::endl; << strerror(errno) << std::endl;
close(fd);
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
close(fd);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -101,6 +111,10 @@ ReturnValue_t I2cComIF::getSendSuccess(CookieIF *cookie) {
ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie, ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
size_t requestLen) { size_t requestLen) {
ReturnValue_t result;
int fd;
std::string deviceFile;
if (requestLen == 0) { if (requestLen == 0) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -109,6 +123,7 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
if(i2cCookie == nullptr) { if(i2cCookie == nullptr) {
sif::error << "I2cComIF::sendMessage: Invalid I2C Cookie!" sif::error << "I2cComIF::sendMessage: Invalid I2C Cookie!"
<< std::endl; << std::endl;
i2cDeviceMapIter->second.replyLen = 0;
return NULLPOINTER; return NULLPOINTER;
} }
@ -117,20 +132,32 @@ ReturnValue_t I2cComIF::requestReceiveMessage(CookieIF *cookie,
if (i2cDeviceMapIter == i2cDeviceMap.end()) { if (i2cDeviceMapIter == i2cDeviceMap.end()) {
sif::error << "I2cComIF::requestReceiveMessage: i2cAddress of Cookie not " sif::error << "I2cComIF::requestReceiveMessage: i2cAddress of Cookie not "
<< "registered in i2cDeviceMap" << std::endl; << "registered in i2cDeviceMap" << std::endl;
i2cDeviceMapIter->second.replyLen = 0;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
int fd = i2cDeviceMapIter->second.fileDescriptor;
deviceFile = i2cCookie->getDeviceFile();
result = openDevice(deviceFile, i2cAddress, &fd);
if (result != HasReturnvaluesIF::RETURN_OK){
i2cDeviceMapIter->second.replyLen = 0;
return result;
}
uint8_t* replyBuffer = i2cDeviceMapIter->second.replyBuffer.data(); uint8_t* replyBuffer = i2cDeviceMapIter->second.replyBuffer.data();
if (read(fd, replyBuffer, requestLen) != (int)requestLen) { if (read(fd, replyBuffer, requestLen) != (int)requestLen) {
sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C " sif::error << "I2cComIF::requestReceiveMessage: Reading from I2C "
<< "device failed with error code " << errno <<". Description" << "device failed with error code " << errno <<". Description"
<< " of error: " << strerror(errno) << std::endl; << " of error: " << strerror(errno) << std::endl;
close(fd);
i2cDeviceMapIter->second.replyLen = 0;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
i2cDeviceMapIter->second.replyLen = requestLen; i2cDeviceMapIter->second.replyLen = requestLen;
close(fd);
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -146,8 +173,8 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie,
address_t i2cAddress = i2cCookie->getAddress(); address_t i2cAddress = i2cCookie->getAddress();
i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress); i2cDeviceMapIter = i2cDeviceMap.find(i2cAddress);
if (i2cDeviceMapIter == i2cDeviceMap.end()) { if (i2cDeviceMapIter == i2cDeviceMap.end()) {
sif::error << "I2cComIF::getReplyBuffer: i2cAddress of Cookie not " sif::error << "I2cComIF::readReceivedMessage: i2cAddress of Cookie not "
<< "registered in i2cDeviceMap" << std::endl; << "found in i2cDeviceMap" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
} }
*buffer = i2cDeviceMapIter->second.replyBuffer.data(); *buffer = i2cDeviceMapIter->second.replyBuffer.data();
@ -155,3 +182,22 @@ ReturnValue_t I2cComIF::readReceivedMessage(CookieIF *cookie,
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t I2cComIF::openDevice(std::string deviceFile,
address_t i2cAddress, int* fileDescriptor) {
*fileDescriptor = open(deviceFile.c_str(), O_RDWR);
if (*fileDescriptor < 0) {
sif::error << "I2cComIF: Opening i2c device failed with error code "
<< errno << ". Error description: " << strerror(errno)
<< std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
if (ioctl(*fileDescriptor, I2C_SLAVE, i2cAddress) < 0) {
sif::error << "I2cComIF: Specifying target device failed with error "
<< "code " << errno << ". Error description "
<< strerror(errno) << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -32,7 +32,6 @@ public:
private: private:
typedef struct I2cInstance { typedef struct I2cInstance {
int fileDescriptor;
std::vector<uint8_t> replyBuffer; std::vector<uint8_t> replyBuffer;
size_t replyLen; size_t replyLen;
} I2cInstance_t; } I2cInstance_t;
@ -44,6 +43,17 @@ private:
* the appropriate file descriptor will be stored */ * the appropriate file descriptor will be stored */
I2cDeviceMap i2cDeviceMap; I2cDeviceMap i2cDeviceMap;
I2cDeviceMapIter i2cDeviceMapIter; I2cDeviceMapIter i2cDeviceMapIter;
/**
* @brief This function opens an i2c device and binds the opened file
* to a specific i2c address.
* @param deviceFile The name of the device file. E.g. i2c-0
* @param i2cAddress The address of the i2c slave device.
* @param fileDescriptor Pointer to device descriptor.
* @return RETURN_OK if successful, otherwise RETURN_FAILED.
*/
ReturnValue_t openDevice(std::string deviceFile,
address_t i2cAddress, int* fileDescriptor);
}; };
#endif /* BSP_Q7S_COMIF_I2COMIF_H_ */ #endif /* BSP_Q7S_COMIF_I2COMIF_H_ */

View File

@ -229,62 +229,6 @@ RM := del
-include _obj/linux/devel/bsp_q7s/comIF/subdir.mk -include _obj/linux/devel/bsp_q7s/comIF/subdir.mk
-include _obj/linux/devel/bsp_q7s/boardconfig/subdir.mk -include _obj/linux/devel/bsp_q7s/boardconfig/subdir.mk
-include _obj/linux/devel/bsp_q7s/subdir.mk -include _obj/linux/devel/bsp_q7s/subdir.mk
-include Debug/libcsp/CMakeFiles/libcsp.dir/src/transport/subdir.mk
-include Debug/libcsp/CMakeFiles/libcsp.dir/src/rtable/subdir.mk
-include Debug/libcsp/CMakeFiles/libcsp.dir/src/interfaces/subdir.mk
-include Debug/libcsp/CMakeFiles/libcsp.dir/src/drivers/can/subdir.mk
-include Debug/libcsp/CMakeFiles/libcsp.dir/src/crypto/subdir.mk
-include Debug/libcsp/CMakeFiles/libcsp.dir/src/arch/posix/subdir.mk
-include Debug/libcsp/CMakeFiles/libcsp.dir/src/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/tmtcservices/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/tmtcpacket/pus/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/tmtcpacket/packetmatcher/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/tmtcpacket/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/tmstorage/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/timemanager/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/thermal/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/tcdistribution/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/tasks/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/subsystem/modes/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/subsystem/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/storagemanager/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/serviceinterface/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/serialize/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/rmap/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/pus/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/power/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/parameters/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/osal/linux/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/objectmanager/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/monitoring/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/modes/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/memory/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/ipc/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/internalError/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/housekeeping/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/health/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/globalfunctions/math/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/globalfunctions/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/fdir/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/events/eventmatching/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/events/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/devicehandlers/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/datapoollocal/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/datapool/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/datalinklayer/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/coordinates/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/controller/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/container/subdir.mk
-include Debug/fsfw/CMakeFiles/fsfw.dir/action/subdir.mk
-include Debug/CMakeFiles/eive_obsw.dir/mission/utility/subdir.mk
-include Debug/CMakeFiles/eive_obsw.dir/mission/devices/subdir.mk
-include Debug/CMakeFiles/eive_obsw.dir/mission/core/subdir.mk
-include Debug/CMakeFiles/eive_obsw.dir/fsfwconfig/pollingsequence/subdir.mk
-include Debug/CMakeFiles/eive_obsw.dir/fsfwconfig/ipc/subdir.mk
-include Debug/CMakeFiles/eive_obsw.dir/bsp_q7s/comIF/cookies/subdir.mk
-include Debug/CMakeFiles/eive_obsw.dir/bsp_q7s/comIF/subdir.mk
-include Debug/CMakeFiles/eive_obsw.dir/bsp_q7s/boardconfig/subdir.mk
-include Debug/CMakeFiles/eive_obsw.dir/bsp_q7s/subdir.mk
-include Debug/CMakeFiles/3.19.1/CompilerIdCXX/subdir.mk -include Debug/CMakeFiles/3.19.1/CompilerIdCXX/subdir.mk
-include Debug/CMakeFiles/3.19.1/CompilerIdC/subdir.mk -include Debug/CMakeFiles/3.19.1/CompilerIdC/subdir.mk
-include subdir.mk -include subdir.mk

View File

@ -25,62 +25,6 @@ CPP_DEPS :=
SUBDIRS := \ SUBDIRS := \
Debug/CMakeFiles/3.19.1/CompilerIdC \ Debug/CMakeFiles/3.19.1/CompilerIdC \
Debug/CMakeFiles/3.19.1/CompilerIdCXX \ Debug/CMakeFiles/3.19.1/CompilerIdCXX \
Debug/CMakeFiles/eive_obsw.dir/bsp_q7s \
Debug/CMakeFiles/eive_obsw.dir/bsp_q7s/boardconfig \
Debug/CMakeFiles/eive_obsw.dir/bsp_q7s/comIF \
Debug/CMakeFiles/eive_obsw.dir/bsp_q7s/comIF/cookies \
Debug/CMakeFiles/eive_obsw.dir/fsfwconfig/ipc \
Debug/CMakeFiles/eive_obsw.dir/fsfwconfig/pollingsequence \
Debug/CMakeFiles/eive_obsw.dir/mission/core \
Debug/CMakeFiles/eive_obsw.dir/mission/devices \
Debug/CMakeFiles/eive_obsw.dir/mission/utility \
Debug/fsfw/CMakeFiles/fsfw.dir/action \
Debug/fsfw/CMakeFiles/fsfw.dir/container \
Debug/fsfw/CMakeFiles/fsfw.dir/controller \
Debug/fsfw/CMakeFiles/fsfw.dir/coordinates \
Debug/fsfw/CMakeFiles/fsfw.dir/datalinklayer \
Debug/fsfw/CMakeFiles/fsfw.dir/datapool \
Debug/fsfw/CMakeFiles/fsfw.dir/datapoollocal \
Debug/fsfw/CMakeFiles/fsfw.dir/devicehandlers \
Debug/fsfw/CMakeFiles/fsfw.dir/events \
Debug/fsfw/CMakeFiles/fsfw.dir/events/eventmatching \
Debug/fsfw/CMakeFiles/fsfw.dir/fdir \
Debug/fsfw/CMakeFiles/fsfw.dir/globalfunctions \
Debug/fsfw/CMakeFiles/fsfw.dir/globalfunctions/math \
Debug/fsfw/CMakeFiles/fsfw.dir/health \
Debug/fsfw/CMakeFiles/fsfw.dir/housekeeping \
Debug/fsfw/CMakeFiles/fsfw.dir/internalError \
Debug/fsfw/CMakeFiles/fsfw.dir/ipc \
Debug/fsfw/CMakeFiles/fsfw.dir/memory \
Debug/fsfw/CMakeFiles/fsfw.dir/modes \
Debug/fsfw/CMakeFiles/fsfw.dir/monitoring \
Debug/fsfw/CMakeFiles/fsfw.dir/objectmanager \
Debug/fsfw/CMakeFiles/fsfw.dir/osal/linux \
Debug/fsfw/CMakeFiles/fsfw.dir/parameters \
Debug/fsfw/CMakeFiles/fsfw.dir/power \
Debug/fsfw/CMakeFiles/fsfw.dir/pus \
Debug/fsfw/CMakeFiles/fsfw.dir/rmap \
Debug/fsfw/CMakeFiles/fsfw.dir/serialize \
Debug/fsfw/CMakeFiles/fsfw.dir/serviceinterface \
Debug/fsfw/CMakeFiles/fsfw.dir/storagemanager \
Debug/fsfw/CMakeFiles/fsfw.dir/subsystem \
Debug/fsfw/CMakeFiles/fsfw.dir/subsystem/modes \
Debug/fsfw/CMakeFiles/fsfw.dir/tasks \
Debug/fsfw/CMakeFiles/fsfw.dir/tcdistribution \
Debug/fsfw/CMakeFiles/fsfw.dir/thermal \
Debug/fsfw/CMakeFiles/fsfw.dir/timemanager \
Debug/fsfw/CMakeFiles/fsfw.dir/tmstorage \
Debug/fsfw/CMakeFiles/fsfw.dir/tmtcpacket \
Debug/fsfw/CMakeFiles/fsfw.dir/tmtcpacket/packetmatcher \
Debug/fsfw/CMakeFiles/fsfw.dir/tmtcpacket/pus \
Debug/fsfw/CMakeFiles/fsfw.dir/tmtcservices \
Debug/libcsp/CMakeFiles/libcsp.dir/src/arch/posix \
Debug/libcsp/CMakeFiles/libcsp.dir/src/crypto \
Debug/libcsp/CMakeFiles/libcsp.dir/src \
Debug/libcsp/CMakeFiles/libcsp.dir/src/drivers/can \
Debug/libcsp/CMakeFiles/libcsp.dir/src/interfaces \
Debug/libcsp/CMakeFiles/libcsp.dir/src/rtable \
Debug/libcsp/CMakeFiles/libcsp.dir/src/transport \
_obj/linux/devel/bsp_q7s \ _obj/linux/devel/bsp_q7s \
_obj/linux/devel/bsp_q7s/boardconfig \ _obj/linux/devel/bsp_q7s/boardconfig \
_obj/linux/devel/bsp_q7s/comIF \ _obj/linux/devel/bsp_q7s/comIF \

View File

@ -15,14 +15,17 @@ 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,
DUMMY_GPS1 = 131, DUMMY_GPS1 = 131,
}; };
enum i2cAddresses: address_t {
TMP1075_TCS_1 = 72,
TMP1075_TCS_2 = 73,
};
/* Addresses of devices supporting the CSP protocol */ /* Addresses of devices supporting the CSP protocol */
enum cspAddresses: uint8_t { enum cspAddresses: uint8_t {
P60DOCK = 4, P60DOCK = 4,