27 const char *
const name
39 m_lastCompletedType(
Fw::FilePacket::T_NONE),
54 this->m_timeout = timeout;
55 this->m_cooldown = cooldown;
56 this->m_cycleTime = cycleTime;
57 this->m_configured =
true;
62 static_cast<FwSizeType>(
sizeof(
struct FileEntry))
89 switch(this->m_mode.get())
95 reinterpret_cast<U8*
>(&this->m_curEntry),
96 static_cast<FwSizeType>(
sizeof(this->m_curEntry)),
97 Os::Queue::BlockingType::NONBLOCKING,
107 this->m_curEntry.srcFilename,
108 this->m_curEntry.destFilename,
109 this->m_curEntry.offset,
110 this->m_curEntry.length
114 case Mode::COOLDOWN: {
115 if (this->m_curTimer >= this->m_cooldown) {
116 this->m_curTimer = 0;
119 this->m_curTimer += m_cycleTime;
125 if (this->m_curTimer >= this->m_timeout) {
126 this->m_curTimer = 0;
128 this->enterCooldown();
131 this->m_curTimer += m_cycleTime;
149 struct FileEntry entry;
150 entry.srcFilename[0] = 0;
151 entry.destFilename[0] = 0;
152 entry.offset = offset;
153 entry.length = length;
154 entry.source = FileDownlink::PORT;
157 entry.context = m_cntxId++;
182 bufferReturn_handler(
189 if (this->m_lastBufferId != fwBuffer.
getContext() + 1 ||
194 FW_ASSERT(this->m_mode.get() == Mode::WAIT || this->m_mode.get() == Mode::CANCEL, this->m_mode.get());
202 else if (this->m_mode.get() == Mode::WAIT) {
203 this->m_mode.set(Mode::DOWNLINK);
206 this->downlinkPacket();
221 struct FileEntry entry;
222 entry.srcFilename[0] = 0;
223 entry.destFilename[0] = 0;
226 entry.source = FileDownlink::COMMAND;
227 entry.opCode = opCode;
228 entry.cmdSeq = cmdSeq;
229 entry.context = std::numeric_limits<U32>::max();
245 SendPartial_cmdHandler(
254 struct FileEntry entry;
255 entry.srcFilename[0] = 0;
256 entry.destFilename[0] = 0;
257 entry.offset = startOffset;
258 entry.length = length;
259 entry.source = FileDownlink::COMMAND;
260 entry.opCode = opCode;
261 entry.cmdSeq = cmdSeq;
262 entry.context = std::numeric_limits<U32>::max();
284 if (this->m_mode.get() == Mode::DOWNLINK || this->m_mode.get() == Mode::WAIT) {
285 this->m_mode.set(Mode::CANCEL);
295 statusToCmdResp(SendFileStatus status)
316 sendResponse(SendFileStatus resp)
318 if(this->m_curEntry.source == FileDownlink::COMMAND) {
319 this->
cmdResponse_out(this->m_curEntry.opCode, this->m_curEntry.cmdSeq, statusToCmdResp(resp));
331 const char* sourceFilename,
332 const char* destFilename,
346 this->m_warnings.fileOpenError();
352 if (startOffset >= this->m_file.getSize()) {
353 this->enterCooldown();
357 }
else if (startOffset + length > this->m_file.getSize()) {
361 length = this->m_file.getSize() - startOffset;
365 this->getBuffer(this->m_buffer, FILE_PACKET);
366 this->sendStartPacket();
367 this->m_mode.set(Mode::WAIT);
368 this->m_sequenceIndex = 1;
369 this->m_curTimer = 0;
370 this->m_byteOffset = startOffset;
376 this->m_endOffset = startOffset + length;
380 this->m_endOffset = this->m_file.getSize();
385 sendDataPacket(U32 &byteOffset)
387 FW_ASSERT(byteOffset < this->m_endOffset);
389 const U32 dataSize = (byteOffset + maxDataSize > this->m_endOffset) ? (this->m_endOffset - byteOffset) : maxDataSize;
392 if (dataSize + byteOffset == this->m_endOffset) {
397 this->m_file.read(buffer, byteOffset, dataSize);
399 this->m_warnings.fileRead(status);
405 this->m_sequenceIndex,
407 static_cast<U16
>(dataSize),
409 ++this->m_sequenceIndex;
412 this->sendFilePacket(filePacket);
414 byteOffset += dataSize;
425 cancelPacket.
initialize(this->m_sequenceIndex);
429 this->getBuffer(buffer, CANCEL_PACKET);
434 this->m_packetsSent.packetSent();
441 this->m_file.getChecksum(checksum);
444 endPacket.
initialize(this->m_sequenceIndex, checksum);
448 this->sendFilePacket(filePacket);
457 this->m_file.getSize(),
458 this->m_file.getSourceName().toChar(),
459 this->m_file.getDestName().toChar()
463 this->sendFilePacket(filePacket);
469 const U32 bufferSize = filePacket.
bufferSize();
472 this->m_buffer.
getSize() >= bufferSize,
478 this->m_buffer.
setSize(bufferSize);
482 this->m_packetsSent.packetSent();
488 this->m_file.getOsFile().close();
489 this->m_mode.set(Mode::COOLDOWN);
491 this->m_curTimer = 0;
498 FW_ASSERT(this->m_mode.get() == Mode::CANCEL || this->m_mode.get() == Mode::DOWNLINK, this->m_mode.get());
501 this->sendCancelPacket();
510 this->enterCooldown();
518 this->sendEndPacket();
521 this->m_mode.set(Mode::WAIT);
522 this->m_curTimer = 0;
526 finishHelper(
bool cancel)
530 this->m_filesSent.fileSent();
535 this->enterCooldown();
540 getBuffer(
Fw::Buffer& buffer, PacketType type)
543 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, type);
545 buffer.
setData(this->m_memoryStore[type]);
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
PlatformAssertArgType FwAssertArgType
PlatformSizeType FwSizeType
PlatformQueuePriorityType FwQueuePriorityType
C++-compatible configuration header for fprime configuration.
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
void setContext(U32 context)
Enum representing a command response.
@ EXECUTION_ERROR
Command had execution error.
@ VALIDATION_ERROR
Command failed validation.
@ OK
Command successfully executed.
const char * toChar() const
The type of a cancel packet.
void initialize(const U32 sequenceIndex)
Initialize a cancel packet.
The type of a data packet.
void initialize(const U32 sequenceIndex, const U32 byteOffset, const U16 dataSize, const U8 *const data)
Initialize a data packet.
The type of an end packet.
void initialize(const U32 sequenceIndex, const CFDP::Checksum &checksum)
Initialize an end packet.
virtual const CHAR * toChar() const =0
SizeType length() const
Get length of string.
@ OP_OK
Operation was successful.
Status send(const U8 *buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType) override
send a message into the queue through delegate
Status receive(U8 *destination, FwSizeType capacity, BlockingType blockType, FwSizeType &actualSize, FwQueuePriorityType &priority) override
receive a message from the queue through delegate
Status create(const Fw::StringBase &name, FwSizeType depth, FwSizeType messageSize) override
create queue storage through delegate
Status
status returned from the queue send function
@ OP_OK
message sent/received okay
Auto-generated base for FileDownlink component.
void bufferSendOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferSendOut.
FwIndexType getNum_FileComplete_OutputPorts() const
void FileComplete_out(FwIndexType portNum, const Svc::SendFileResponse &resp)
Invoke output port FileComplete.
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
bool isConnected_FileComplete_OutputPort(FwIndexType portNum)
void log_WARNING_HI_DownlinkPartialFail(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName, U32 startOffset, U32 filesize)
void log_WARNING_HI_DownlinkTimeout(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName)
void log_ACTIVITY_HI_SendStarted(U32 fileSize, const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName)
void log_ACTIVITY_HI_DownlinkCanceled(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName)
void log_WARNING_LO_DownlinkPartialWarning(U32 startOffset, U32 length, U32 filesize, const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName)
void log_ACTIVITY_HI_FileSent(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName)
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
void log_WARNING_HI_SendDataFail(const Fw::StringBase &sourceFileName, U32 byteOffset)
FileDownlink(const char *const compName)
void configure(U32 timeout, U32 cooldown, U32 cycleTime, U32 fileQueueDepth)
Send file response struct.
char * string_copy(char *destination, const char *source, FwSizeType num)
copy string with null-termination guaranteed
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
@ OP_OK
Operation succeeded.
static const bool FILEDOWNLINK_COMMAND_FAILURES_DISABLED
static const U32 FILEDOWNLINK_INTERNAL_BUFFER_SIZE
The type of a start packet.
void initialize(const U32 fileSize, const char *const sourcePath, const char *const destinationPath)
Initialize a StartPacket with sequence number 0.
void fromCancelPacket(const CancelPacket &cancelPacket)
void fromEndPacket(const EndPacket &endPacket)
void fromDataPacket(const DataPacket &dataPacket)
void fromStartPacket(const StartPacket &startPacket)
SerializeStatus toBuffer(Buffer &buffer) const