prep imtq startup handling
This commit is contained in:
@ -27,7 +27,7 @@ ReturnValue_t ImtqPollingTask::performOperation(uint8_t operationCode) {
|
||||
|
||||
comStatus = returnvalue::OK;
|
||||
// Stopwatch watch;
|
||||
switch (currentRequest) {
|
||||
switch (currentRequest.requestType) {
|
||||
case imtq::RequestType::MEASURE_NO_ACTUATION: {
|
||||
// Measured to take 24 ms for debug and release builds.
|
||||
// Stopwatch watch;
|
||||
@ -51,6 +51,9 @@ void ImtqPollingTask::handleMeasureStep() {
|
||||
uint8_t* replyPtr;
|
||||
ImtqRepliesDefault replies(replyBuf.data());
|
||||
// If some startup handling is added later, set configured after it was done once.
|
||||
if (performStartup) {
|
||||
performStartup = false;
|
||||
}
|
||||
replies.setConfigured();
|
||||
|
||||
// Can be used later to verify correct timing (e.g. all data has been read)
|
||||
@ -73,7 +76,7 @@ void ImtqPollingTask::handleMeasureStep() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (specialRequest != imtq::SpecialRequest::NONE) {
|
||||
if (currentRequest.specialRequest != imtq::SpecialRequest::NONE) {
|
||||
auto executeSelfTest = [&](imtq::selfTest::Axis axis) {
|
||||
cmdBuf[0] = imtq::CC::SELF_TEST_CMD;
|
||||
cmdBuf[1] = axis;
|
||||
@ -81,7 +84,7 @@ void ImtqPollingTask::handleMeasureStep() {
|
||||
};
|
||||
// If a self-test is already ongoing, ignore the request.
|
||||
if (replies.getSystemState()[2] != static_cast<uint8_t>(imtq::mode::SELF_TEST)) {
|
||||
switch (specialRequest) {
|
||||
switch (currentRequest.specialRequest) {
|
||||
case (imtq::SpecialRequest::DO_SELF_TEST_POS_X): {
|
||||
executeSelfTest(imtq::selfTest::Axis::X_POSITIVE);
|
||||
break;
|
||||
@ -234,18 +237,21 @@ ReturnValue_t ImtqPollingTask::initializeInterface(CookieIF* cookie) {
|
||||
ReturnValue_t ImtqPollingTask::sendMessage(CookieIF* cookie, const uint8_t* sendData,
|
||||
size_t sendLen) {
|
||||
const auto* imtqReq = reinterpret_cast<const imtq::Request*>(sendData);
|
||||
if (sendLen != sizeof(imtq::Request)) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
{
|
||||
MutexGuard mg(ipcLock);
|
||||
if (imtqReq->request == imtq::RequestType::ACTUATE) {
|
||||
std::memcpy(dipoles, imtqReq->dipoles, sizeof(dipoles));
|
||||
torqueDuration = imtqReq->torqueDuration;
|
||||
}
|
||||
currentRequest = imtqReq->request;
|
||||
specialRequest = imtqReq->specialRequest;
|
||||
if (state != InternalState::IDLE) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
state = InternalState::IS_BUSY;
|
||||
if (currentRequest.mode != imtqReq->mode) {
|
||||
if (imtqReq->mode == acs::SimpleSensorMode::NORMAL) {
|
||||
performStartup = true;
|
||||
}
|
||||
}
|
||||
std::memcpy(¤tRequest, imtqReq, sendLen);
|
||||
}
|
||||
semaphore->release();
|
||||
|
||||
@ -345,10 +351,10 @@ void ImtqPollingTask::buildDipoleCommand() {
|
||||
uint8_t* serPtr = cmdBuf.data() + 1;
|
||||
size_t serLen = 0;
|
||||
for (uint8_t idx = 0; idx < 3; idx++) {
|
||||
SerializeAdapter::serialize(&dipoles[idx], &serPtr, &serLen, cmdBuf.size(),
|
||||
SerializeAdapter::serialize(¤tRequest.dipoles[idx], &serPtr, &serLen, cmdBuf.size(),
|
||||
SerializeIF::Endianness::LITTLE);
|
||||
}
|
||||
SerializeAdapter::serialize(&torqueDuration, &serPtr, &serLen, cmdBuf.size(),
|
||||
SerializeAdapter::serialize(¤tRequest.torqueDuration, &serPtr, &serLen, cmdBuf.size(),
|
||||
SerializeIF::Endianness::LITTLE);
|
||||
// sif::debug << "Dipole X: " << dipoles[0] << std::endl;
|
||||
// sif::debug << "Torqeu Dur: " << torqueDuration << std::endl;
|
||||
@ -357,22 +363,28 @@ void ImtqPollingTask::buildDipoleCommand() {
|
||||
|
||||
ReturnValue_t ImtqPollingTask::readReceivedMessage(CookieIF* cookie, uint8_t** buffer,
|
||||
size_t* size) {
|
||||
imtq::RequestType currentRequest;
|
||||
imtq::Request currentRequest;
|
||||
{
|
||||
MutexGuard mg(ipcLock);
|
||||
currentRequest = this->currentRequest;
|
||||
std::memcpy(¤tRequest, &this->currentRequest, sizeof(currentRequest));
|
||||
}
|
||||
|
||||
size_t replyLen = 0;
|
||||
MutexGuard mg(bufLock);
|
||||
if (currentRequest == imtq::RequestType::MEASURE_NO_ACTUATION) {
|
||||
replyLen = getExchangeBufLen(specialRequest);
|
||||
memcpy(exchangeBuf.data(), replyBuf.data(), replyLen);
|
||||
} else if (currentRequest == imtq::RequestType::ACTUATE) {
|
||||
replyLen = ImtqRepliesWithTorque::BASE_LEN;
|
||||
memcpy(exchangeBuf.data(), replyBufActuation.data(), replyLen);
|
||||
} else {
|
||||
*size = 0;
|
||||
{
|
||||
MutexGuard mg(bufLock);
|
||||
if (currentRequest.requestType == imtq::RequestType::MEASURE_NO_ACTUATION) {
|
||||
replyLen = getExchangeBufLen(currentRequest.specialRequest);
|
||||
memcpy(exchangeBuf.data(), replyBuf.data(), replyLen);
|
||||
} else if (currentRequest.requestType == imtq::RequestType::ACTUATE) {
|
||||
replyLen = ImtqRepliesWithTorque::BASE_LEN;
|
||||
memcpy(exchangeBuf.data(), replyBufActuation.data(), replyLen);
|
||||
} else {
|
||||
*size = 0;
|
||||
}
|
||||
}
|
||||
{
|
||||
MutexGuard mg(ipcLock);
|
||||
this->currentRequest.requestType = imtq::RequestType::DO_NOTHING;
|
||||
}
|
||||
*buffer = exchangeBuf.data();
|
||||
*size = replyLen;
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <fsfw/tasks/SemaphoreIF.h>
|
||||
#include <fsfw_hal/linux/i2c/I2cCookie.h>
|
||||
#include <mission/acs/acsBoardPolling.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
@ -24,7 +25,6 @@ class ImtqPollingTask : public SystemObject,
|
||||
static constexpr ReturnValue_t NO_REPLY_AVAILABLE = returnvalue::makeCode(2, 0);
|
||||
|
||||
enum class InternalState { IDLE, IS_BUSY } state = InternalState::IDLE;
|
||||
imtq::RequestType currentRequest = imtq::RequestType::MEASURE_NO_ACTUATION;
|
||||
|
||||
SemaphoreIF* semaphore;
|
||||
ReturnValue_t comStatus = returnvalue::OK;
|
||||
@ -38,10 +38,14 @@ class ImtqPollingTask : public SystemObject,
|
||||
// Required in addition to integration time, otherwise old data might be read.
|
||||
static constexpr uint32_t MGM_READ_BUFFER_TIME_MS = 6;
|
||||
bool ignoreNextActuateRequest = false;
|
||||
bool performStartup = false;
|
||||
|
||||
imtq::SpecialRequest specialRequest = imtq::SpecialRequest::NONE;
|
||||
int16_t dipoles[3] = {};
|
||||
uint16_t torqueDuration = 0;
|
||||
imtq::Request currentRequest{};
|
||||
// int16_t dipoles[3] = {};
|
||||
// uint16_t torqueDuration = 0;
|
||||
// imtq::RequestType currentRequest = imtq::RequestType::MEASURE_NO_ACTUATION;
|
||||
// imtq::SpecialRequest specialRequest = imtq::SpecialRequest::NONE;
|
||||
// acs::SimpleSensorMode mode = acs::SimpleSensorMode::OFF;
|
||||
|
||||
std::array<uint8_t, 32> cmdBuf;
|
||||
std::array<uint8_t, 524> replyBuf;
|
||||
|
Reference in New Issue
Block a user