WIP: SCEX Init #272
@ -46,6 +46,9 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic
|
|||||||
if (commandDataLen == 1) {
|
if (commandDataLen == 1) {
|
||||||
tempCheck = commandData[0];
|
tempCheck = commandData[0];
|
||||||
}
|
}
|
||||||
|
if (commandActive) {
|
||||||
|
return DeviceHandlerIF::BUSY;
|
||||||
|
}
|
||||||
|
|
||||||
switch (deviceCommand) {
|
switch (deviceCommand) {
|
||||||
case (PING): {
|
case (PING): {
|
||||||
@ -87,12 +90,13 @@ ReturnValue_t ScexDeviceHandler::buildCommandFromCommand(DeviceCommandId_t devic
|
|||||||
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
return DeviceHandlerIF::COMMAND_NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
commandActive = true;
|
||||||
rawPacket = cmdBuf.data();
|
rawPacket = cmdBuf.data();
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScexDeviceHandler::fillCommandAndReplyMap() {
|
void ScexDeviceHandler::fillCommandAndReplyMap() {
|
||||||
insertInCommandAndReplyMap(scex::Cmds::PING, 3);
|
insertInCommandAndReplyMap(scex::Cmds::PING, 5);
|
||||||
insertInCommandAndReplyMap(scex::Cmds::ION_CMD, 3);
|
insertInCommandAndReplyMap(scex::Cmds::ION_CMD, 3);
|
||||||
insertInCommandAndReplyMap(scex::Cmds::TEMP_CMD, 3);
|
insertInCommandAndReplyMap(scex::Cmds::TEMP_CMD, 3);
|
||||||
insertInCommandAndReplyMap(scex::Cmds::EXP_STATUS_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,
|
ReturnValue_t ScexDeviceHandler::scanForReply(const uint8_t* start, size_t remainingSize,
|
||||||
DeviceCommandId_t* foundId, size_t* foundLen) {
|
DeviceCommandId_t* foundId, size_t* foundLen) {
|
||||||
uint8_t* decodedPacket = nullptr;
|
size_t len = remainingSize;
|
||||||
size_t len = 0;
|
ReturnValue_t result = helper.deSerialize(&start, &len);
|
||||||
|
|
||||||
const uint8_t* helperPtr = decodedPacket;
|
|
||||||
ReturnValue_t result = helper.deSerialize(&helperPtr, &len);
|
|
||||||
|
|
||||||
if (result == ScexHelper::INVALID_CRC) {
|
if (result == ScexHelper::INVALID_CRC) {
|
||||||
sif::warning << "ScexDeviceHandler::scanForReply: CRC invalid" << std::endl;
|
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)
|
// cmd auswertung (in file reinschreiben)
|
||||||
using namespace scex;
|
using namespace scex;
|
||||||
|
|
||||||
|
ReturnValue_t status = RETURN_OK;
|
||||||
auto oneFileHandler = [&](std::string cmdName) {
|
auto oneFileHandler = [&](std::string cmdName) {
|
||||||
fileId = random_string(6);
|
fileId = random_string(6);
|
||||||
|
finishCountdown.setTimeout(SHORT_CD);
|
||||||
|
// countdown starten
|
||||||
|
finishCountdown.resetTimer();
|
||||||
std::ostringstream oss("/tmp/scex-");
|
std::ostringstream oss("/tmp/scex-");
|
||||||
oss << cmdName << fileId << ".bin";
|
oss << cmdName << fileId << ".bin";
|
||||||
fileName = oss.str();
|
fileName = oss.str();
|
||||||
@ -144,6 +149,7 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
|
|||||||
};
|
};
|
||||||
auto multiFileHandler = [&](std::string cmdName) {
|
auto multiFileHandler = [&](std::string cmdName) {
|
||||||
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
|
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
|
||||||
|
finishCountdown.setTimeout(LONG_CD);
|
||||||
// countdown starten
|
// countdown starten
|
||||||
finishCountdown.resetTimer();
|
finishCountdown.resetTimer();
|
||||||
|
|
||||||
@ -164,38 +170,38 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
};
|
};
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case (PING): {
|
case (PING): {
|
||||||
return oneFileHandler("ping_");
|
status = oneFileHandler("ping_");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case (ION_CMD): {
|
case (ION_CMD): {
|
||||||
return oneFileHandler("ion_");
|
status = oneFileHandler("ion_");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case (TEMP_CMD): {
|
case (TEMP_CMD): {
|
||||||
return oneFileHandler("temp_");
|
status = oneFileHandler("temp_");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case (EXP_STATUS_CMD): {
|
case (EXP_STATUS_CMD): {
|
||||||
return oneFileHandler("exp_status_");
|
status = oneFileHandler("exp_status_");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case (FRAM): {
|
case (FRAM): {
|
||||||
return multiFileHandler("fram_");
|
status = multiFileHandler("fram_");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case (ONE_CELL): {
|
case (ONE_CELL): {
|
||||||
return multiFileHandler("one_cell_");
|
status = multiFileHandler("one_cell_");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case (ALL_CELLS_CMD): {
|
case (ALL_CELLS_CMD): {
|
||||||
return multiFileHandler("all_cell_");
|
status = multiFileHandler("all_cell_");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// Unknown DeviceCommand
|
// Unknown DeviceCommand
|
||||||
@ -203,13 +209,24 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
|
|||||||
}
|
}
|
||||||
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {
|
if (helper.getPacketCounter() == helper.getTotalPacketCounter()) {
|
||||||
reader.finish();
|
reader.finish();
|
||||||
|
commandActive = false;
|
||||||
if (id != PING) {
|
if (id != PING) {
|
||||||
sif::info << "Reader is finished" << std::endl;
|
sif::info << "Reader is finished" << std::endl;
|
||||||
fileNameSet = false;
|
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) {
|
uint32_t ScexDeviceHandler::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) {
|
||||||
|
@ -14,16 +14,19 @@ class ScexDeviceHandler : public DeviceHandlerBase {
|
|||||||
virtual ~ScexDeviceHandler();
|
virtual ~ScexDeviceHandler();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr uint32_t LONG_CD = 180 * 1000;
|
||||||
|
static constexpr uint32_t SHORT_CD = 7000;
|
||||||
std::array<uint8_t, 64> cmdBuf = {};
|
std::array<uint8_t, 64> cmdBuf = {};
|
||||||
|
|
||||||
std::string fileId = "";
|
std::string fileId = "";
|
||||||
std::string fileName = "";
|
std::string fileName = "";
|
||||||
bool fileNameSet = false;
|
bool fileNameSet = false;
|
||||||
|
bool commandActive = false;
|
||||||
bool debugMode = true;
|
bool debugMode = true;
|
||||||
|
|
||||||
scex::Cmds currCmd = scex::Cmds::PING;
|
scex::Cmds currCmd = scex::Cmds::PING;
|
||||||
SdCardMountedIF *sdcMan = nullptr;
|
SdCardMountedIF *sdcMan = nullptr;
|
||||||
Countdown finishCountdown = Countdown(180 * 1000);
|
Countdown finishCountdown = Countdown(LONG_CD);
|
||||||
|
|
||||||
std::string random_string(std::string::size_type length);
|
std::string random_string(std::string::size_type length);
|
||||||
|
|
||||||
@ -32,6 +35,8 @@ class ScexDeviceHandler : public DeviceHandlerBase {
|
|||||||
void doShutDown() override;
|
void doShutDown() override;
|
||||||
ScexHelper helper;
|
ScexHelper helper;
|
||||||
ScexUartReader &reader;
|
ScexUartReader &reader;
|
||||||
|
|
||||||
|
void performOperationHook() override;
|
||||||
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;
|
||||||
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override;
|
||||||
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t *commandData,
|
||||||
|
Loading…
Reference in New Issue
Block a user