erase command
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good

This commit is contained in:
Jakob Meier 2021-12-24 07:31:21 +01:00
parent 14dec1d700
commit 2ea75d2a05
3 changed files with 109 additions and 9 deletions

View File

@ -59,7 +59,6 @@ enum PoolIds: lp_id_t {
TIME_TEMPERATURE_SET, TIME_TEMPERATURE_SET,
MCU_TEMPERATURE, MCU_TEMPERATURE,
CMOS_TEMPERATURE, CMOS_TEMPERATURE,
TICKS_SOLUTION_SET, TICKS_SOLUTION_SET,
TIME_SOLUTION_SET, TIME_SOLUTION_SET,
CALI_QW, CALI_QW,
@ -83,7 +82,6 @@ enum PoolIds: lp_id_t {
TRUST_WORTHY, TRUST_WORTHY,
STABLE_COUNT, STABLE_COUNT,
SOLUTION_STRATEGY, SOLUTION_STRATEGY,
TICKS_HISTOGRAM_SET, TICKS_HISTOGRAM_SET,
TIME_HISTOGRAM_SET, TIME_HISTOGRAM_SET,
HISTOGRAM_BINA0, HISTOGRAM_BINA0,
@ -122,7 +120,6 @@ enum PoolIds: lp_id_t {
HISTOGRAM_BIND6, HISTOGRAM_BIND6,
HISTOGRAM_BIND7, HISTOGRAM_BIND7,
HISTOGRAM_BIND8, HISTOGRAM_BIND8,
TICKS_CONTRAST_SET, TICKS_CONTRAST_SET,
TIME_CONTRAST_SET, TIME_CONTRAST_SET,
CONTRAST_BINA0, CONTRAST_BINA0,
@ -160,7 +157,8 @@ enum PoolIds: lp_id_t {
CONTRAST_BIND5, CONTRAST_BIND5,
CONTRAST_BIND6, CONTRAST_BIND6,
CONTRAST_BIND7, CONTRAST_BIND7,
CONTRAST_BIND8 CONTRAST_BIND8,
CHKSUM
}; };
static const DeviceCommandId_t PING_REQUEST = 0; static const DeviceCommandId_t PING_REQUEST = 0;
@ -213,6 +211,7 @@ static const uint32_t TIME_SET_ID = REQ_TIME;
static const uint32_t SOLUTION_SET_ID = REQ_SOLUTION; static const uint32_t SOLUTION_SET_ID = REQ_SOLUTION;
static const uint32_t HISTOGRAM_SET_ID = REQ_HISTOGRAM; static const uint32_t HISTOGRAM_SET_ID = REQ_HISTOGRAM;
static const uint32_t CONTRAST_SET_ID = REQ_CONTRAST; static const uint32_t CONTRAST_SET_ID = REQ_CONTRAST;
static const uint32_t CHECKSUM_SET_ID = CHECKSUM;
/** Max size of unencoded frame */ /** Max size of unencoded frame */
static const size_t MAX_FRAME_SIZE = 1200; static const size_t MAX_FRAME_SIZE = 1200;
@ -225,6 +224,7 @@ static const uint8_t TIME_SET_ENTRIES = 4;
static const uint8_t SOLUTION_SET_ENTRIES = 23; static const uint8_t SOLUTION_SET_ENTRIES = 23;
static const uint8_t HISTOGRAM_SET_ENTRIES = 38; static const uint8_t HISTOGRAM_SET_ENTRIES = 38;
static const uint8_t CONTRAST_SET_ENTRIES = 38; static const uint8_t CONTRAST_SET_ENTRIES = 38;
static const uint8_t CHECKSUM_SET_ENTRIES = 1;
// Action, parameter and telemetry IDs // Action, parameter and telemetry IDs
namespace ID { namespace ID {
@ -905,7 +905,7 @@ public:
} }
void printChecksum() { void printChecksum() {
sif::info << "ChecksumReply::printChecksum: 0x" << checksum << std::endl; sif::info << "ChecksumReply::printChecksum: 0x" << std::hex << checksum << std::endl;
} }
private: private:
@ -919,6 +919,38 @@ private:
uint32_t length = 0; uint32_t length = 0;
uint32_t checksum = 0; uint32_t checksum = 0;
}; };
class EraseReply {
public:
EraseReply(const uint8_t* datafield) {
region = *datafield;
}
uint8_t getRegion() {
return region;
}
private:
uint8_t region = 0;
};
class ChecksumSet:
public StaticLocalDataSet<CHECKSUM_SET_ENTRIES> {
public:
// Size of dataset
static const size_t SIZE = 156;
ChecksumSet(HasLocalDataPoolIF* owner):
StaticLocalDataSet(owner, CHECKSUM_SET_ID) {
}
ChecksumSet(object_id_t objectId):
StaticLocalDataSet(sid_t(objectId, CHECKSUM_SET_ID)) {
}
lp_var_t<uint32_t> checksum = lp_var_t<uint32_t>(sid.objectId, PoolIds::CHKSUM, this);
};
} }
#endif /* MISSION_STARTRACKER_DEFINITIONS_H_ */ #endif /* MISSION_STARTRACKER_DEFINITIONS_H_ */

View File

@ -17,7 +17,7 @@ StarTrackerHandler::StarTrackerHandler(object_id_t objectId, object_id_t comIF,
CookieIF * comCookie, StrHelper* strHelper) : CookieIF * comCookie, StrHelper* strHelper) :
DeviceHandlerBase(objectId, comIF, comCookie), temperatureSet(this), versionSet(this), powerSet( DeviceHandlerBase(objectId, comIF, comCookie), temperatureSet(this), versionSet(this), powerSet(
this), interfaceSet(this), timeSet(this), solutionSet(this), histogramSet(this), this), interfaceSet(this), timeSet(this), solutionSet(this), histogramSet(this),
contrastSet(this), strHelper(strHelper) { contrastSet(this), checksumSet(this), strHelper(strHelper) {
if (comCookie == nullptr) { if (comCookie == nullptr) {
sif::error << "StarTrackerHandler: Invalid com cookie" << std::endl; sif::error << "StarTrackerHandler: Invalid com cookie" << std::endl;
} }
@ -416,6 +416,10 @@ ReturnValue_t StarTrackerHandler::buildCommandFromCommand(DeviceCommandId_t devi
result = prepareParamCommand(commandData, commandDataLen, tracking); result = prepareParamCommand(commandData, commandDataLen, tracking);
return result; return result;
} }
case (StarTracker::ERASE): {
result = prepareEraseCommand(commandData, commandDataLen);
return result;
}
case (StarTracker::UNLOCK): { case (StarTracker::UNLOCK): {
result = prepareUnlockCommand(commandData, commandDataLen); result = prepareUnlockCommand(commandData, commandDataLen);
return result; return result;
@ -482,6 +486,8 @@ void StarTrackerHandler::fillCommandAndReplyMap() {
StarTracker::MAX_FRAME_SIZE * 2 + 2); StarTracker::MAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(StarTracker::RESET_ERROR, 3, nullptr, this->insertInCommandAndReplyMap(StarTracker::RESET_ERROR, 3, nullptr,
StarTracker::MAX_FRAME_SIZE * 2 + 2); StarTracker::MAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(StarTracker::ERASE, 3, nullptr,
StarTracker::MAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(StarTracker::UNLOCK, 3, nullptr, this->insertInCommandAndReplyMap(StarTracker::UNLOCK, 3, nullptr,
StarTracker::MAX_FRAME_SIZE * 2 + 2); StarTracker::MAX_FRAME_SIZE * 2 + 2);
this->insertInCommandAndReplyMap(StarTracker::CHECKSUM, 3, nullptr, this->insertInCommandAndReplyMap(StarTracker::CHECKSUM, 3, nullptr,
@ -561,6 +567,10 @@ ReturnValue_t StarTrackerHandler::interpretDeviceReply(DeviceCommandId_t id, con
result = handleActionReply(); result = handleActionReply();
break; break;
} }
case (StarTracker::ERASE): {
result = handleEraseReply();
break;
}
case (StarTracker::CHECKSUM): { case (StarTracker::CHECKSUM): {
result = handleChecksumReply(); result = handleChecksumReply();
break; break;
@ -785,7 +795,7 @@ ReturnValue_t StarTrackerHandler::initializeLocalDataPool(localpool::DataPool& l
localDataPoolMap.emplace(StarTracker::CONTRAST_BIND6, new PoolEntry<uint32_t>( { 0 })); localDataPoolMap.emplace(StarTracker::CONTRAST_BIND6, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(StarTracker::CONTRAST_BIND7, new PoolEntry<uint32_t>( { 0 })); localDataPoolMap.emplace(StarTracker::CONTRAST_BIND7, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(StarTracker::CONTRAST_BIND8, new PoolEntry<uint32_t>( { 0 })); localDataPoolMap.emplace(StarTracker::CONTRAST_BIND8, new PoolEntry<uint32_t>( { 0 }));
localDataPoolMap.emplace(StarTracker::CHKSUM, new PoolEntry<uint32_t>( { 0 }));
return RETURN_OK; return RETURN_OK;
} }
@ -840,6 +850,10 @@ ReturnValue_t StarTrackerHandler::scanForActionReply(DeviceCommandId_t *foundId)
*foundId = StarTracker::RESET_ERROR; *foundId = StarTracker::RESET_ERROR;
break; break;
} }
case (StarTracker::ID::ERASE): {
*foundId = StarTracker::ERASE;
break;
}
case (StarTracker::ID::UNLOCK): { case (StarTracker::ID::UNLOCK): {
*foundId = StarTracker::UNLOCK; *foundId = StarTracker::UNLOCK;
break; break;
@ -1057,7 +1071,25 @@ void StarTrackerHandler::prepareBootCommand() {
rawPacketLen = dataLinkLayer.getEncodedLength(); rawPacketLen = dataLinkLayer.getEncodedLength();
} }
ReturnValue_t StarTrackerHandler::prepareUnlockCommand(const uint8_t* commandData, size_t commandDataLen) { ReturnValue_t StarTrackerHandler::prepareEraseCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK;
if (commandDataLen != EraseCmd::LENGTH) {
return INVALID_LENGTH;
}
uint32_t length = 0;
struct EraseActionRequest req;
req.region = *commandData;
arc_pack_erase_action_req(&req, commandBuffer, &length);
dataLinkLayer.encodeFrame(commandBuffer, length);
rawPacket = dataLinkLayer.getEncodedFrame();
rawPacketLen = dataLinkLayer.getEncodedLength();
eraseCmd.rememberRegion = req.region;
return result;
}
ReturnValue_t StarTrackerHandler::prepareUnlockCommand(const uint8_t* commandData,
size_t commandDataLen) {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
uint32_t length = 0; uint32_t length = 0;
struct UnlockActionRequest req; struct UnlockActionRequest req;
@ -1292,6 +1324,21 @@ ReturnValue_t StarTrackerHandler::handleActionReply() {
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t StarTrackerHandler::handleEraseReply() {
ReturnValue_t result = RETURN_OK;
result = handleActionReply();
if (result != RETURN_OK) {
return result;
}
const uint8_t* replyData = dataLinkLayer.getReply() + ACTION_DATA_OFFSET;
StarTracker::EraseReply eraseReply(replyData);
if (eraseReply.getRegion() != eraseCmd.rememberRegion) {
sif::warning << "StarTrackerHandler::handleEraseReply: Region mismatch" << std::endl;
return REGION_MISMATCH;
}
return result;
}
ReturnValue_t StarTrackerHandler::handleChecksumReply() { ReturnValue_t StarTrackerHandler::handleChecksumReply() {
ReturnValue_t result = RETURN_OK; ReturnValue_t result = RETURN_OK;
result = handleActionReply(); result = handleActionReply();
@ -1312,6 +1359,9 @@ ReturnValue_t StarTrackerHandler::handleChecksumReply() {
sif::warning << "StarTrackerHandler::handleChecksumReply: Length mismatch" << std::endl; sif::warning << "StarTrackerHandler::handleChecksumReply: Length mismatch" << std::endl;
return LENGTH_MISSMATCH; return LENGTH_MISSMATCH;
} }
PoolReadGuard rg(&checksumSet);
checksumSet.checksum = checksumReply.getChecksum();
handleDeviceTM(&checksumSet, StarTracker::CHECKSUM);
#if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1 #if OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1
checksumReply.printChecksum(); checksumReply.printChecksum();
#endif /* OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1 */ #endif /* OBSW_VERBOSE_LEVEL >= 1 && OBSW_DEBUG_STARTRACKER == 1 */

View File

@ -164,6 +164,14 @@ private:
static const size_t MIN_LENGTH = 11; static const size_t MIN_LENGTH = 11;
}; };
class EraseCmd {
public:
static const uint8_t LENGTH = 1;
uint8_t rememberRegion = 0;
};
EraseCmd eraseCmd;
class UnlockCmd { class UnlockCmd {
public: public:
static const uint8_t CODE_OFFSET = 1; static const uint8_t CODE_OFFSET = 1;
@ -175,7 +183,6 @@ private:
static const uint8_t LENGTH_OFFSET = 5; static const uint8_t LENGTH_OFFSET = 5;
// Length of checksum command // Length of checksum command
static const size_t LENGTH = 9; static const size_t LENGTH = 9;
uint8_t rememberRegion = 0; uint8_t rememberRegion = 0;
uint32_t rememberAddress = 0; uint32_t rememberAddress = 0;
uint32_t rememberLength = 0; uint32_t rememberLength = 0;
@ -195,6 +202,7 @@ private:
StarTracker::SolutionSet solutionSet; StarTracker::SolutionSet solutionSet;
StarTracker::HistogramSet histogramSet; StarTracker::HistogramSet histogramSet;
StarTracker::ContrastSet contrastSet; StarTracker::ContrastSet contrastSet;
StarTracker::ChecksumSet checksumSet;
// Pointer to object responsible for uploading and downloading images to/from the star tracker // Pointer to object responsible for uploading and downloading images to/from the star tracker
StrHelper* strHelper = nullptr; StrHelper* strHelper = nullptr;
@ -298,6 +306,11 @@ private:
*/ */
void prepareBootCommand(); void prepareBootCommand();
/**
* @brief Fills command buffer with command to erase a flash region
*/
ReturnValue_t prepareEraseCommand(const uint8_t* commandData, size_t commandDataLen);
/** /**
* @brief Fills command buffer with command to unlock flash region * @brief Fills command buffer with command to unlock flash region
*/ */
@ -381,6 +394,11 @@ private:
*/ */
ReturnValue_t handleActionReply(); ReturnValue_t handleActionReply();
/**
* @brief Handles reply to erase command
*/
ReturnValue_t handleEraseReply();
/** /**
* @brief Handles reply to checksum command * @brief Handles reply to checksum command
*/ */