WIP: SCEX Init #272

Closed
muellerr wants to merge 62 commits from irini into develop
2 changed files with 44 additions and 22 deletions
Showing only changes of commit 20328f89ae - Show all commits

View File

@ -46,6 +46,9 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic
if (commandDataLen == 1) {
tempCheck = commandData[0];
}
if (commandActive) {
return DeviceHandlerIF::BUSY;
}
switch (deviceCommand) {
case (PING): {
@ -87,12 +90,13 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
}
}
commandActive = true;
rawPacket = cmdBuf.data();
return RETURN_OK;
}
void ScexDeviceHandler::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(scex::Cmds::PING, 3);
insertInCommandAndReplyMap(scex::Cmds::PING, 5);
insertInCommandAndReplyMap(scex::Cmds::ION_CMD, 3);
insertInCommandAndReplyMap(scex::Cmds::TEMP_CMD, 3);
insertInCommandAndReplyMap(scex::Cmds::EXP_STATUS_CMD, 3);
@ -106,11 +110,8 @@ void ScexDeviceHandler::fillCommandAndReplyMap() {
ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remainingSize,
DeviceCommandId_t* foundId, size_t* foundLen) {
uint8_t* decodedPacket = nullptr;
size_t len = 0;
const uint8_t* helperPtr = decodedPacket;
ReturnValue_t result = helper.deSerialize(&helperPtr, &len);
size_t len = remainingSize;
ReturnValue_t result = helper.deSerialize(&start, &len);
if (result == ScexHelper::INVALID_CRC) {
sif::warning << "ScexDeviceHandler::scanForReply: CRC invalid" << std::endl;
@ -126,8 +127,12 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
// cmd auswertung (in file reinschreiben)
using namespace scex;
ReturnValue_t status = RETURN_OK;
auto oneFileHandler = [&](std::string cmdName) {
fileId = random_string(6);
finishCountdown.setTimeout(SHORT_CD);
// countdown starten
finishCountdown.resetTimer();
std::ostringstream oss("/tmp/scex-");
oss << cmdName << fileId << ".bin";
fileName = oss.str();
@ -144,6 +149,7 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
};
auto multiFileHandler = [&](std::string cmdName) {
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
finishCountdown.setTimeout(LONG_CD);
// countdown starten
finishCountdown.resetTimer();
@ -164,38 +170,38 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
if (debugMode) {
out << helper;
}
if (finishCountdown.hasTimedOut()) {
triggerEvent(scex::EXPERIMENT_TIMEDOUT, id, 0);
reader.finish();
sif::warning << "ScexDeviceHandler::interpretDiviceReply: Reader timeout" << std::endl;
fileNameSet = false;
}
}
return RETURN_OK;
};
switch (id) {
case (PING): {
return oneFileHandler("ping_");
status = oneFileHandler("ping_");
break;
}
case (ION_CMD): {
return oneFileHandler("ion_");
status = oneFileHandler("ion_");
break;
}
case (TEMP_CMD): {
return oneFileHandler("temp_");
status = oneFileHandler("temp_");
break;
}
case (EXP_STATUS_CMD): {
return oneFileHandler("exp_status_");
status = oneFileHandler("exp_status_");
break;
}
case (FRAM): {
return multiFileHandler("fram_");
status = multiFileHandler("fram_");
break;
}
case (ONE_CELL): {
return multiFileHandler("one_cell_");
status = multiFileHandler("one_cell_");
break;
}
case (ALL_CELLS_CMD): {
return multiFileHandler("all_cell_");
status = multiFileHandler("all_cell_");
break;
}
default:
// Unknown DeviceCommand
@ -203,13 +209,24 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
}
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {
reader.finish();
commandActive = false;
if (id != PING) {
sif::info << "Reader is finished" << std::endl;
fileNameSet = false;
}
}
return RETURN_OK;
return status;
}
void ScexDeviceHandler::performOperationHook() {
if (commandActive and finishCountdown.hasTimedOut()) {
triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0);
reader.finish();
sif::warning << "ScexDeviceHandler::interpretDiviceReply: Reader timeout" << std::endl;
fileNameSet = false;
commandActive = false;
}
}
uint32_t ScexDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {

View File

@ -14,16 +14,19 @@ class ScexDeviceHandler : public DeviceHandlerBase {
virtual ~ScexDeviceHandler();
private:
static constexpr uint32_t LONG_CD = 180 * 1000;
static constexpr uint32_t SHORT_CD = 7000;
std::array<uint8_t, 64> cmdBuf = {};
std::string fileId = "";
std::string fileName = "";
bool fileNameSet = false;
bool commandActive = false;
bool debugMode = true;
scex::Cmds currCmd = scex::Cmds::PING;
SdCardMountedIF *sdcMan = nullptr;
Countdown finishCountdown = Countdown(180 * 1000);
Countdown finishCountdown = Countdown(LONG_CD);
std::string random_string(std::string::size_type length);
@ -32,6 +35,8 @@ class ScexDeviceHandler : public DeviceHandlerBase {
void doShutDown() override;
ScexHelper helper;
ScexUartReader &reader;
void performOperationHook() override;
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,