2021-09-19 12:27:48 +02:00
|
|
|
#include <fcntl.h>
|
2022-11-02 10:26:45 +01:00
|
|
|
#include <linux/ipcore/Ptme.h>
|
2022-01-17 15:58:27 +01:00
|
|
|
#include <sys/mman.h>
|
2022-01-24 16:33:22 +01:00
|
|
|
#include <unistd.h>
|
2022-01-26 17:59:31 +01:00
|
|
|
|
2021-09-26 08:29:30 +02:00
|
|
|
#include "PtmeConfig.h"
|
2023-01-23 11:52:46 +01:00
|
|
|
#include "eive/definitions.h"
|
2022-01-17 15:58:27 +01:00
|
|
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
Ptme::Ptme(object_id_t objectId) : SystemObject(objectId) {}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
Ptme::~Ptme() {}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
|
|
|
ReturnValue_t Ptme::initialize() {
|
2022-01-17 15:58:27 +01:00
|
|
|
VcInterfaceMapIter iter;
|
|
|
|
for (iter = vcInterfaceMap.begin(); iter != vcInterfaceMap.end(); iter++) {
|
2022-01-24 16:33:22 +01:00
|
|
|
iter->second->initialize();
|
2022-01-17 15:58:27 +01:00
|
|
|
}
|
2022-08-24 17:27:47 +02:00
|
|
|
return returnvalue::OK;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
ReturnValue_t Ptme::writeToVc(uint8_t vcId, const uint8_t* data, size_t size) {
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-01-17 15:58:27 +01:00
|
|
|
VcInterfaceMapIter vcInterfaceMapIter = vcInterfaceMap.find(vcId);
|
|
|
|
if (vcInterfaceMapIter == vcInterfaceMap.end()) {
|
|
|
|
sif::warning << "Ptme::writeToVc: No virtual channel interface found for the virtual "
|
|
|
|
"channel with id "
|
|
|
|
<< static_cast<unsigned int>(vcId) << std::endl;
|
|
|
|
return UNKNOWN_VC_ID;
|
|
|
|
}
|
|
|
|
result = vcInterfaceMapIter->second->write(data, size);
|
|
|
|
return result;
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
|
|
|
|
2023-03-09 17:44:05 +01:00
|
|
|
void Ptme::addVcInterface(VcId_t vcId, VirtualChannelIF* vc) {
|
2023-01-23 11:52:46 +01:00
|
|
|
if (vcId > config::NUMBER_OF_VIRTUAL_CHANNELS) {
|
2022-01-17 15:58:27 +01:00
|
|
|
sif::warning << "Ptme::addVcInterface: Invalid virtual channel ID" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
if (vc == nullptr) {
|
|
|
|
sif::warning << "Ptme::addVcInterface: Invalid virtual channel interface" << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
auto status = vcInterfaceMap.emplace(vcId, vc);
|
|
|
|
if (status.second == false) {
|
|
|
|
sif::warning << "Ptme::addVcInterface: Failed to add virtual channel interface to "
|
|
|
|
"virtual channel map"
|
|
|
|
<< std::endl;
|
|
|
|
return;
|
|
|
|
}
|
2021-09-19 12:27:48 +02:00
|
|
|
}
|
2023-03-10 18:04:04 +01:00
|
|
|
|
|
|
|
bool Ptme::isBusy(uint8_t vcId) const {
|
|
|
|
const auto& vcInterfaceMapIter = vcInterfaceMap.find(vcId);
|
|
|
|
if (vcInterfaceMapIter == vcInterfaceMap.end()) {
|
|
|
|
sif::warning << "Ptme::writeToVc: No virtual channel interface found for the virtual "
|
|
|
|
"channel with id "
|
|
|
|
<< static_cast<unsigned int>(vcId) << std::endl;
|
|
|
|
return UNKNOWN_VC_ID;
|
|
|
|
}
|
|
|
|
return vcInterfaceMapIter->second->isBusy();
|
|
|
|
}
|