37 m_lastCompletedType(
Fw::FilePacket::T_NONE),
43 this->m_cooldown = cooldown;
44 this->m_cycleTime = cycleTime;
45 this->m_configured =
true;
49 static_cast<FwSizeType>(fileQueueDepth), static_cast<FwSizeType>(
sizeof(
struct FileEntry)));
54 this->m_file.configureSandbox(directory);
72 void FileDownlink ::Run_handler(
const FwIndexType portNum, U32 context) {
73 switch (this->m_mode.get()) {
78 static_cast<FwSizeType>(
sizeof(this->m_curEntry)),
79 Os::Queue::BlockingType::NONBLOCKING, real_size, prio);
85 sendFile(this->m_curEntry.srcFilename, this->m_curEntry.destFilename, this->m_curEntry.offset,
86 this->m_curEntry.length);
89 case Mode::COOLDOWN: {
90 if (this->m_curTimer >= this->m_cooldown) {
94 this->m_curTimer += m_cycleTime;
99 this->m_curTimer += m_cycleTime;
113 struct FileEntry entry;
114 entry.offset = offset;
115 entry.length = length;
116 entry.source = FileDownlink::PORT;
119 entry.context = m_cntxId++;
122 if (sourceFilename.
length() >= entry.srcFilename.getCapacity()) {
125 }
else if (destFilename.
length() >= entry.destFilename.getCapacity()) {
129 entry.srcFilename = sourceFilename;
130 entry.destFilename = destFilename;
133 m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)), 0,
134 Os::Queue::BlockingType::NONBLOCKING);
143 void FileDownlink ::pingIn_handler(
const FwIndexType portNum, U32 key) {
154 FW_ASSERT(this->m_mode.get() == Mode::WAIT || this->m_mode.get() == Mode::CANCEL,
162 else if (this->m_mode.get() == Mode::WAIT) {
163 this->m_mode.set(Mode::DOWNLINK);
166 this->downlinkPacket();
173 void FileDownlink ::SendFile_cmdHandler(
const FwOpcodeType opCode,
177 struct FileEntry entry;
180 entry.source = FileDownlink::COMMAND;
181 entry.opCode = opCode;
182 entry.cmdSeq = cmdSeq;
183 entry.context = std::numeric_limits<U32>::max();
186 if (sourceFilename.
length() >= entry.srcFilename.getCapacity()) {
189 }
else if (destFilename.
length() >= entry.destFilename.getCapacity()) {
193 entry.srcFilename = sourceFilename;
194 entry.destFilename = destFilename;
197 m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)), 0,
198 Os::Queue::BlockingType::NONBLOCKING);
206 void FileDownlink ::SendPartial_cmdHandler(
FwOpcodeType opCode,
212 struct FileEntry entry;
213 entry.offset = startOffset;
214 entry.length = length;
215 entry.source = FileDownlink::COMMAND;
216 entry.opCode = opCode;
217 entry.cmdSeq = cmdSeq;
218 entry.context = std::numeric_limits<U32>::max();
221 if (sourceFilename.
length() >= entry.srcFilename.getCapacity()) {
224 }
else if (destFilename.
length() >= entry.destFilename.getCapacity()) {
228 entry.srcFilename = sourceFilename;
229 entry.destFilename = destFilename;
232 m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)), 0,
233 Os::Queue::BlockingType::NONBLOCKING);
241 void FileDownlink ::Cancel_cmdHandler(
const FwOpcodeType opCode,
const U32 cmdSeq) {
243 if (this->m_mode.get() == Mode::DOWNLINK || this->m_mode.get() == Mode::WAIT) {
244 this->m_mode.set(Mode::CANCEL);
253 Fw::CmdResponse FileDownlink ::statusToCmdResp(SendFileStatus status) {
272 void FileDownlink ::sendResponse(SendFileStatus resp) {
273 FW_ASSERT(this->m_curEntry.source == FileDownlink::COMMAND || this->m_curEntry.source == FileDownlink::PORT,
274 static_cast<FwAssertArgType>(this->m_curEntry.source));
275 if (this->m_curEntry.source == FileDownlink::COMMAND) {
276 this->
cmdResponse_out(this->m_curEntry.opCode, this->m_curEntry.cmdSeq, statusToCmdResp(resp));
297 this->m_warnings.sourceOutOfSandbox();
299 this->m_warnings.fileOpenError();
304 const U32 fileSize = this->m_file.getSize();
308 this->m_warnings.zeroSize();
313 }
else if (startOffset >= fileSize) {
314 this->enterCooldown();
320 }
else if (startOffset + length > fileSize) {
324 this->m_file.getDestName());
325 length = fileSize - startOffset;
329 this->getBuffer(this->m_buffer, FILE_PACKET);
330 this->sendStartPacket();
331 this->m_mode.set(Mode::WAIT);
332 this->m_sequenceIndex = 1;
333 this->m_curTimer = 0;
334 this->m_byteOffset = startOffset;
340 this->m_endOffset = startOffset + length;
343 this->m_file.getDestName());
344 this->m_endOffset = fileSize;
349 FW_ASSERT(byteOffset < this->m_endOffset);
350 const U32 maxDataSize =
353 (byteOffset + maxDataSize > this->m_endOffset) ? (this->m_endOffset - byteOffset) : maxDataSize;
354 U8 buffer[maxDataSize];
356 if (dataSize + byteOffset == this->m_endOffset) {
360 const Os::File::Status status = this->m_file.read(buffer, byteOffset, dataSize);
362 this->m_warnings.fileRead(status);
367 dataPacket.
initialize(this->m_sequenceIndex, byteOffset, static_cast<U16>(dataSize), buffer);
368 ++this->m_sequenceIndex;
371 this->sendFilePacket(filePacket);
373 byteOffset += dataSize;
378 void FileDownlink ::sendCancelPacket() {
381 cancelPacket.
initialize(this->m_sequenceIndex);
385 this->getBuffer(buffer, CANCEL_PACKET);
387 static_cast<FwAssertArgType>(buffer.
getSize()),
397 status = filePacket.
toBuffer(offsetBuffer);
400 this->m_packetsSent.packetSent();
403 void FileDownlink ::sendEndPacket() {
405 this->m_file.getChecksum(checksum);
408 endPacket.
initialize(this->m_sequenceIndex, checksum);
412 this->sendFilePacket(filePacket);
415 void FileDownlink ::sendStartPacket() {
417 startPacket.
initialize(this->m_file.getSize(), this->m_file.getSourceName().toChar(),
418 this->m_file.getDestName().toChar());
421 this->sendFilePacket(filePacket);
424 void FileDownlink ::sendFilePacket(
const Fw::FilePacket& filePacket) {
428 static_cast<FwAssertArgType>(this->m_buffer.
getSize()));
431 static_cast<FwPacketDescriptorType>(Fw::ComPacketType::FW_PACKET_FILE));
437 status = filePacket.
toBuffer(offsetBuffer);
440 this->m_buffer.
setSize(bufferSize);
444 this->m_packetsSent.packetSent();
447 void FileDownlink ::enterCooldown() {
448 this->m_file.getOsFile().close();
449 this->m_mode.set(Mode::COOLDOWN);
451 this->m_curTimer = 0;
454 void FileDownlink ::downlinkPacket() {
456 static_cast<FwAssertArgType>(this->m_lastCompletedType));
457 FW_ASSERT(this->m_mode.get() == Mode::CANCEL || this->m_mode.get() == Mode::DOWNLINK,
461 this->sendCancelPacket();
470 this->enterCooldown();
479 this->sendEndPacket();
482 this->m_mode.set(Mode::WAIT);
483 this->m_curTimer = 0;
486 void FileDownlink ::finishHelper(
bool cancel) {
489 this->m_filesSent.fileSent();
494 this->enterCooldown();
498 void FileDownlink ::getBuffer(
Fw::Buffer& buffer, PacketType type) {
500 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, static_cast<FwAssertArgType>(type));
502 buffer.
setData(this->m_memoryStore[type]);
Serialization/Deserialization operation was successful.
Status create(FwEnumStoreType id, const Fw::ConstStringBase &name, FwSizeType depth, FwSizeType messageSize) override
create queue storage through delegate
U16 FwPacketDescriptorType
The width of packet descriptors when they are serialized by the framework.
void fromCancelPacket(const CancelPacket &cancelPacket)
FwIdType FwOpcodeType
The type of a command opcode.
Path falls outside the configured sandbox directory.
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
void fromDataPacket(const DataPacket &dataPacket)
PlatformSizeType FwSizeType
Status receive(U8 *destination, FwSizeType capacity, BlockingType blockType, FwSizeType &actualSize, FwQueuePriorityType &priority) override
receive a message from the queue through delegate
void setContext(U32 context)
void setSize(FwSizeType size)
static constexpr FwIndexType getNum_FileComplete_OutputPorts()
The type of a cancel packet.
Status
status returned from the queue send function
void fromEndPacket(const EndPacket &endPacket)
The type of a data packet.
FwEnumStoreType getInstance() const
void fromStartPacket(const StartPacket &startPacket)
Enum representing a command response.
void bufferSendOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer) const
Invoke output port bufferSendOut.
SerializeStatus toBuffer(Buffer &buffer) const
FileDownlink(const char *const compName)
void log_ACTIVITY_HI_DownlinkCanceled(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
SerializeStatus
forward declaration for string
void configure(U32 cooldown, U32 cycleTime, U32 fileQueueDepth)
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
Auto-generated base for FileDownlink component.
void log_WARNING_LO_DownlinkPartialWarning(U32 startOffset, U32 length, U32 filesize, const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
bool isConnected_FileComplete_OutputPort(FwIndexType portNum) const
void pingOut_out(FwIndexType portNum, U32 key) const
Invoke output port pingOut.
void deinit() override
Allows de-initialization on teardown.
The type of a start packet.
Status send(const U8 *buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType) override
send a message into the queue through delegate
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
void teardown() override
teardown the queue
void FileComplete_out(FwIndexType portNum, const Svc::SendFileResponse &resp) const
Invoke output port FileComplete.
Command successfully executed.
void initialize(const U32 fileSize, const char *const sourcePath, const char *const destinationPath)
Initialize a StartPacket with sequence number 0.
uint8_t U8
8-bit unsigned integer
void log_ACTIVITY_HI_FileSent(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
FwSizeType getSize() const
PlatformQueuePriorityType FwQueuePriorityType
The type of queue priorities used.
Command had execution error.
void log_WARNING_HI_SendDataFail(const Fw::StringBase &sourceFileName, U32 byteOffset) const
Operation was successful.
PlatformIndexType FwIndexType
FwSizeType SizeType
The size type for a buffer - for backwards compatibility.
Send file response struct.
Command failed validation.
RateGroupDivider component implementation.
virtual SizeType length() const
Get the length of the string.
message sent/received okay
void log_WARNING_HI_FilenameDestinationOverflow() const
static const U32 FILEDOWNLINK_INTERNAL_BUFFER_SIZE
void initialize(const U32 sequenceIndex, const U32 byteOffset, const U16 dataSize, const U8 *const data)
Initialize a data packet.
static const bool FILEDOWNLINK_COMMAND_FAILURES_DISABLED
Implementation of malloc based allocator.
void deinit()
Cleans up file queue before dispatching to underlying component.
void log_WARNING_HI_FilenameSourceOverflow() const
void log_ACTIVITY_HI_SendStarted(U32 fileSize, const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
void initialize(const U32 sequenceIndex, const CFDP::Checksum &checksum)
Initialize an end packet.
void log_WARNING_HI_DownlinkPartialFail(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName, U32 startOffset, U32 filesize) const
void initialize(const U32 sequenceIndex)
Initialize a cancel packet.
ExternalSerializeBufferWithMemberCopy getSerializer()
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
The type of an end packet.