v1.14.0 #304

Merged
muellerr merged 366 commits from develop into main 2022-10-10 17:46:38 +02:00
Showing only changes of commit 2f4d44433d - Show all commits

View File

@ -32,9 +32,9 @@ ReturnValue_t ScexDeviceHandler::buildTransitionDeviceCommand(DeviceCommandId_t*
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t ScexDeviceHandler::buildCommandFromCommand( ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
DeviceCommandId_t deviceCommand, // DeviceCommandId_t const uint8_t* commandData,
const uint8_t* commandData, size_t commandDataLen) { size_t commandDataLen) {
using namespace scex; using namespace scex;
auto cmdTyped = static_cast<scex::Cmds>(deviceCommand); auto cmdTyped = static_cast<scex::Cmds>(deviceCommand);
@ -52,7 +52,7 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(
{nullptr, 0}); {nullptr, 0});
return RETURN_OK; return RETURN_OK;
} }
case (FRAM): { case (EXP_STATUS_CMD): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0}); {nullptr, 0});
return RETURN_OK; return RETURN_OK;
@ -67,6 +67,11 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(
{nullptr, 0}); {nullptr, 0});
return RETURN_OK; return RETURN_OK;
} }
case (FRAM): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandDataLen - 1});
return RETURN_OK;
}
case (ONE_CELL): { case (ONE_CELL): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen, prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{commandData + 1, commandDataLen - 1}); {commandData + 1, commandDataLen - 1});
@ -77,11 +82,6 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(
{commandData + 1, commandDataLen - 1}); {commandData + 1, commandDataLen - 1});
return RETURN_OK; return RETURN_OK;
} }
case (EXP_STATUS_CMD): {
prepareScexCmd(cmdTyped, commandData[0], {cmdBuf.data(), cmdBuf.size()}, rawPacketLen,
{nullptr, 0});
return RETURN_OK;
}
} }
return RETURN_OK; return RETURN_OK;
} }
@ -106,13 +106,9 @@ ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remai
const uint8_t* helperPtr = decodedPacket; const uint8_t* helperPtr = decodedPacket;
ReturnValue_t result = helper.deSerialize(&helperPtr, &len); ReturnValue_t result = helper.deSerialize(&helperPtr, &len);
if (result == ScexHelper::INVALID_CRC) {
sif::warning << "CRC invalid" << std::endl;
}
// crc check
if (result == ScexHelper::INVALID_CRC) { if (result == ScexHelper::INVALID_CRC) {
sif::warning << "CRC invalid" << std::endl; sif::warning << "ScexDeviceHandler::scanForReply: CRC invalid" << std::endl;
return result; return result;
} }
*foundId = helper.getCmd(); *foundId = helper.getCmd();
@ -142,29 +138,36 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
return RETURN_OK; return RETURN_OK;
}; };
auto multiFileHandler = [&](std::string cmdName) { auto multiFileHandler = [&](std::string cmdName) {
if (helper.getPacketCounter() == 1) { if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
// countdown starten // countdown starten
finishCountdown.resetTimer(); finishCountdown.resetTimer();
fileId = random_string(6); fileId = random_string(6);
std::ostringstream oss("/tmp/scex-"); std::ostringstream oss("/tmp/scex-");
oss << cmdName << fileId << ".bin"; oss << cmdName << fileId << ".bin";
fileName = oss.str(); fileName = oss.str();
ofstream out(fileName, fileNameSet = true;
ofstream::binary); // neues file anlegen ofstream out(fileName, ofstream::binary);
if (out.bad()) {
sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName
<< std::endl;
return RETURN_FAILED;
}
} else { } else {
ofstream out(fileName, ofstream out(fileName,
ofstream::binary | ofstream::app); // an bestehendes file appenden ofstream::binary | ofstream::app); // append
if (debugMode) { if (debugMode) {
out << helper; out << helper;
} }
if (finishCountdown.hasTimedOut()) {
triggerEvent(scex::EXPERIMENT_TIMEDOUT, id, 0);
reader.finish();
sif::warning << "ScexDeviceHandler::interpretDiviceReply: Reader timeout" << std::endl;
fileNameSet = false;
}
} }
if (finishCountdown.hasTimedOut()) {
triggerEvent(scex::EXPERIMENT_TIMEDOUT, id, 0);
reader.finish();
sif::warning << "ScexDeviceHandler: Reader timeout" << std::endl;
// cmdDone = true;
fileNameSet = false;
}
return RETURN_OK; return RETURN_OK;
}; };
switch (id) { switch (id) {
@ -193,17 +196,14 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
// Unknown DeviceCommand // Unknown DeviceCommand
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED; return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
} }
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) { if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {
reader.finish(); reader.finish();
sif::info << "Reader is finished" << std::endl; if (id != PING) {
// cmdDone = true; sif::info << "Reader is finished" << std::endl;
fileNameSet = false; fileNameSet = false;
if (helper.getCmd() == scex::Cmds::PING) {
// cmdSent = false;
fileNameSet = true; // to not generate everytime new file
} }
} }
return RETURN_OK; return RETURN_OK;
} }