writing file works now
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit

This commit is contained in:
Irini Kosmidou
2022-08-30 18:36:00 +02:00
parent 4ce48d01c6
commit a6582313f7
6 changed files with 52 additions and 49 deletions

View File

@ -126,7 +126,6 @@ void ScexDeviceHandler::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(scex::Cmds::TEMP_CMD, 3);
insertInCommandAndReplyMap(scex::Cmds::EXP_STATUS_CMD, 3);
// TODO: Pr<50>fen: richtige Variablen?
insertInCommandAndReplyMap(scex::Cmds::ALL_CELLS_CMD, 0, nullptr, 0, false, false,
scex::Cmds::ALL_CELLS_CMD, &finishCountdown);
insertInCommandAndReplyMap(scex::Cmds::ONE_CELL, 0, nullptr, 0, false, false,
@ -141,28 +140,29 @@ ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remai
DeviceCommandId_t* foundId, size_t* foundLen) {
size_t len = remainingSize;
ReturnValue_t result = helper.deSerialize(&start, &len);
bool commandFound = false;
if (result == ScexHelper::INVALID_CRC) {
sif::warning << "ScexDeviceHandler::scanForReply: CRC invalid" << std::endl;
} else {
*foundId = helper.getCmd();
commandFound = true;
*foundLen = remainingSize;
} else {
result = handleValidReply(remainingSize, foundId, foundLen);
}
if (commandFound) {
uint32_t remainingMillis = finishCountdown.getRemainingMillis();
if (commandActive and finishCountdown.hasTimedOut()) {
triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0);
reader.finish();
sif::warning << "ScexDeviceHandler::performOperationHook: Reader timeout; RemMillis: "
<< remainingMillis << std::endl;
fileNameSet = false;
commandActive = false;
}
uint32_t remainingMillis = finishCountdown.getRemainingMillis();
if (commandActive and finishCountdown.hasTimedOut()) {
triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0);
reader.finish();
sif::warning << "ScexDeviceHandler::performOperationHook: Reader timeout; RemMillis: "
<< remainingMillis << std::endl;
fileNameSet = false;
commandActive = false;
}
return result;
}
ReturnValue_t ScexDeviceHandler::handleValidReply(size_t remSize, DeviceCommandId_t* foundId,
size_t* foundLen) {
using namespace scex;
ReturnValue_t result = OK;
auto multiFileHandler = [&](std::string cmdName) {
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
fileId = random_string(6);
@ -171,27 +171,28 @@ ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remai
fileName = oss.str();
fileNameSet = true;
ofstream out(fileName, ofstream::binary);
if (debugMode) {
uint32_t remainingMillis = finishCountdown.getRemainingMillis();
sif::info << "ScexDeviceHandler::interpretDeviceReply:MultifileHandler: RemMillis: "
<< remainingMillis << std::endl;
}
if (out.bad()) {
sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName
<< std::endl;
return FAILED;
}
out << helper;
} else {
ofstream out(fileName,
ofstream::binary | ofstream::app); // append
if (debugMode) {
out << helper;
if (out.bad()) {
sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName
<< std::endl;
return FAILED;
}
out << helper;
}
return OK;
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {
*foundId = helper.getCmd();
return OK;
}
return IGNORE_FULL_PACKET;
};
ReturnValue_t status = OK;
switch (helper.getCmd()) {
case (FRAM): {
if (debugMode) {
@ -200,18 +201,23 @@ ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remai
sif::info << "ScexDeviceHandler::interpretDeviceReply: RemMillis: " << remainingMillis
<< std::endl;
}
status = multiFileHandler("fram_");
result = multiFileHandler("fram_");
break;
}
case (ONE_CELL): {
status = multiFileHandler("one_cell_");
result = multiFileHandler("one_cell_");
break;
}
case (ALL_CELLS_CMD): {
status = multiFileHandler("all_cell_");
result = multiFileHandler("all_cell_");
break;
}
default: {
*foundId = helper.getCmd();
break;
}
}
*foundLen = remSize;
return result;
}
@ -225,16 +231,13 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
std::ostringstream oss("/tmp/scex-", std::ostringstream::ate);
oss << cmdName << fileId << ".bin";
fileName = oss.str();
std::cout << fileName << std::endl;
ofstream out(fileName, ofstream::binary);
if (out.bad()) {
sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName
<< std::endl;
return FAILED;
}
if (debugMode) {
out << helper;
}
out << helper;
return OK;
};
@ -258,6 +261,9 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
default:
// Unknown DeviceCommand
if(id == FRAM or id == ONE_CELL or id == ALL_CELLS_CMD) {
break;
}
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {

View File

@ -22,7 +22,7 @@ class ScexDeviceHandler : public DeviceHandlerBase {
std::string fileName = "";
bool fileNameSet = false;
bool commandActive = false;
bool debugMode = true;
bool debugMode = false;
scex::Cmds currCmd = scex::Cmds::PING;
SdCardMountedIF *sdcMan = nullptr;
@ -45,6 +45,7 @@ class ScexDeviceHandler : public DeviceHandlerBase {
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;
ReturnValue_t handleValidReply(size_t remSize, DeviceCommandId_t *foundId, size_t *foundLen);
uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) override;
ReturnValue_t getSwitches(const uint8_t **switches, uint8_t *numberOfSwitches) override;