check busy state
Some checks failed
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
Robin Müller 2023-03-10 18:04:04 +01:00
parent 3c0b8f9e8b
commit 976235a79f
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
10 changed files with 43 additions and 12 deletions

View File

@ -41,7 +41,7 @@ void PapbVcInterface::startPacketTransfer() { *vcBaseReg = CONFIG_START; }
void PapbVcInterface::endPacketTransfer() { *vcBaseReg = CONFIG_END; }
ReturnValue_t PapbVcInterface::pollPapbBusySignal() {
ReturnValue_t PapbVcInterface::pollPapbBusySignal() const {
gpio::Levels papbBusyState = gpio::Levels::LOW;
ReturnValue_t result = returnvalue::OK;
@ -53,7 +53,6 @@ ReturnValue_t PapbVcInterface::pollPapbBusySignal() {
return returnvalue::FAILED;
}
if (papbBusyState == gpio::Levels::LOW) {
sif::warning << "PapbVcInterface::pollPapbBusySignal: PAPB busy" << std::endl;
return PAPB_BUSY;
}
@ -80,6 +79,8 @@ void PapbVcInterface::isVcInterfaceBufferEmpty() {
return;
}
bool PapbVcInterface::isBusy() const { return pollPapbBusySignal() == PAPB_BUSY; }
ReturnValue_t PapbVcInterface::sendTestFrame() {
/** Size of one complete transfer frame data field amounts to 1105 bytes */
uint8_t testPacket[1105];

View File

@ -32,6 +32,13 @@ class PapbVcInterface : public VirtualChannelIF {
std::string uioFile, int mapNum);
virtual ~PapbVcInterface();
bool isBusy() const override;
/**
*
* @param data
* @param size
* @return returnvalue::OK on successfull write, PAPB_BUSY if PAPB is busy.
*/
ReturnValue_t write(const uint8_t* data, size_t size) override;
ReturnValue_t initialize() override;
@ -95,7 +102,7 @@ class PapbVcInterface : public VirtualChannelIF {
*
* @return returnvalue::OK when ready to receive data else PAPB_BUSY.
*/
ReturnValue_t pollPapbBusySignal();
ReturnValue_t pollPapbBusySignal() const;
/**
* @brief This function can be used for debugging to check whether there are packets in

View File

@ -51,3 +51,14 @@ void Ptme::addVcInterface(VcId_t vcId, VirtualChannelIF* vc) {
return;
}
}
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();
}

View File

@ -35,6 +35,7 @@ class Ptme : public PtmeIF, public SystemObject {
ReturnValue_t initialize() override;
ReturnValue_t writeToVc(uint8_t vcId, const uint8_t* data, size_t size) override;
bool isBusy(uint8_t vcId) const override;
/**
* @brief This function adds the reference to a virtual channel interface to the vcInterface

View File

@ -22,6 +22,7 @@ class PtmeIF {
* @param size Number of bytes to write
*/
virtual ReturnValue_t writeToVc(uint8_t vcId, const uint8_t* data, size_t size) = 0;
virtual bool isBusy(uint8_t vcId) const = 0;
};
#endif /* LINUX_OBC_PTMEIF_H_ */

View File

@ -16,6 +16,8 @@ class DirectTmSinkIF {
* @param size Number of bytes to write
*/
virtual ReturnValue_t write(const uint8_t* data, size_t size) = 0;
virtual bool isBusy() const = 0;
};
#endif /* MISSION_TMTC_DIRECTTMSINKIF_H_ */

View File

@ -191,12 +191,15 @@ ReturnValue_t PersistentTmStore::startDumpFromUpTo(uint32_t fromUnixSeconds,
ReturnValue_t PersistentTmStore::loadNextDumpFile() {
using namespace std::filesystem;
dumpParams.currentSize = 0;
std::error_code e;
for (; dumpParams.dirIter != directory_iterator(); dumpParams.dirIter++) {
dumpParams.dirEntry = *dumpParams.dirIter;
if (dumpParams.dirEntry.is_directory(e)) {
continue;
}
sif::debug << "handling file " << dumpParams.dirEntry << std::endl;
dumpParams.fileSize = std::filesystem::file_size(dumpParams.dirEntry.path(), e);
if (e) {
sif::error << "PersistentTmStore: Could not retrieve file size: " << e.message() << std::endl;
@ -221,10 +224,9 @@ ReturnValue_t PersistentTmStore::loadNextDumpFile() {
auto fileEpoch = static_cast<uint32_t>(timegm(&fileTime));
if ((fileEpoch > dumpParams.fromUnixTime) and
(fileEpoch + rolloverDiffSeconds <= dumpParams.untilUnixTime)) {
dumpParams.currentSize = 0;
dumpParams.currentFileUnixStamp = fileEpoch;
std::ifstream ifile(file, std::ios::binary);
if(ifile.bad()) {
if (ifile.bad()) {
sif::error << "PersistentTmStore: File is bad" << std::endl;
continue;
}
@ -245,6 +247,7 @@ ReturnValue_t PersistentTmStore::dumpNextPacket(DirectTmSinkIF& tmSink, size_t&
if (state == State::IDLE) {
return returnvalue::FAILED;
}
sif::debug << "Current file idx: " << dumpParams.currentSize << std::endl;
PusTmReader reader(&timeReader, fileBuf.data() + dumpParams.currentSize,
fileBuf.size() - dumpParams.currentSize);
// CRC check to fully ensure this is a valid TM
@ -262,7 +265,7 @@ ReturnValue_t PersistentTmStore::dumpNextPacket(DirectTmSinkIF& tmSink, size_t&
return loadNextDumpFile();
}
} else {
sif::error << "Parsing of PUS TM failed with code " << result << std::endl;
sif::error << "PersistentTmStore: Parsing of PUS TM failed with code " << result << std::endl;
triggerEvent(POSSIBLE_FILE_CORRUPTION, result, dumpParams.currentFileUnixStamp);
// Delete the file and load next. Could use better algorithm to partially
// restore the file dump, but for now do not trust the file.

View File

@ -21,12 +21,14 @@ bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store, Countd
if (store.getState() == PersistentTmStore::State::DUMPING) {
size_t dumpedLen;
bool fileHasSwapped;
// TODO: Maybe do a bit of a delay every 100-200 packets?
// TODO: We could continously dump until a file swap during active downlink..
// TODO: handle returnvalue?
result = store.dumpNextPacket(channel, dumpedLen, fileHasSwapped);
if (result == returnvalue::OK) {
dumpsPerformed = true;
if (not channel.isBusy()) {
// TODO: Maybe do a bit of a delay every 100-200 packets?
// TODO: We could continously dump until a file swap during active downlink..
// TODO: handle returnvalue?
result = store.dumpNextPacket(channel, dumpedLen, fileHasSwapped);
if (result == returnvalue::OK) {
dumpsPerformed = true;
}
}
} else {
// Handle TC requests, for example deletion or retrieval requests.

View File

@ -24,3 +24,5 @@ ReturnValue_t VirtualChannel::write(const uint8_t* data, size_t size) {
uint8_t VirtualChannel::getVcid() const { return vcId; }
const char* VirtualChannel::getName() const { return vcName.c_str(); }
bool VirtualChannel::isBusy() const { return ptme.isBusy(vcId); }

View File

@ -26,6 +26,7 @@ class VirtualChannel : public SystemObject, public VirtualChannelIF {
ReturnValue_t initialize() override;
ReturnValue_t sendNextTm(const uint8_t* data, size_t size);
bool isBusy() const override;
ReturnValue_t write(const uint8_t* data, size_t size) override;
uint8_t getVcid() const;