27 const char *
const name
39 m_lastCompletedType(
Fw::FilePacket::T_NONE),
46 void FileDownlink :: {
…}
63 this->m_timeout = timeout;
64 this->m_cooldown = cooldown;
65 this->m_cycleTime = cycleTime;
66 this->m_configured =
true;
71 sizeof(
struct FileEntry)
55 void FileDownlink :: {
…}
76 void FileDownlink :: {
…}
98 switch(this->m_mode.get())
104 reinterpret_cast<U8*
>(&this->m_curEntry),
105 sizeof(this->m_curEntry),
116 this->m_curEntry.srcFilename,
117 this->m_curEntry.destFilename,
118 this->m_curEntry.offset,
119 this->m_curEntry.length
123 case Mode::COOLDOWN: {
124 if (this->m_curTimer >= this->m_cooldown) {
125 this->m_curTimer = 0;
126 this->m_mode.set(Mode::IDLE);
128 this->m_curTimer += m_cycleTime;
134 if (this->m_curTimer >= this->m_timeout) {
135 this->m_curTimer = 0;
136 this->log_WARNING_HI_DownlinkTimeout(this->m_file.getSourceName(), this->m_file.getDestName());
137 this->enterCooldown();
140 this->m_curTimer += m_cycleTime;
158 struct FileEntry entry;
159 entry.srcFilename[0] = 0;
160 entry.destFilename[0] = 0;
161 entry.offset = offset;
162 entry.length = length;
163 entry.source = FileDownlink::PORT;
166 entry.context = m_cntxId++;
168 FW_ASSERT(sourceFilename.length() <
sizeof(entry.srcFilename));
169 FW_ASSERT(destFilename.length() <
sizeof(entry.destFilename));
187 this->pingOut_out(0,key);
191 bufferReturn_handler(
198 if (this->m_lastBufferId != fwBuffer.
getContext() + 1 ||
199 this->m_mode.get() == Mode::IDLE) {
203 FW_ASSERT(this->m_mode.get() == Mode::WAIT || this->m_mode.get() == Mode::CANCEL, this->m_mode.get());
211 else if (this->m_mode.get() == Mode::WAIT) {
212 this->m_mode.set(Mode::DOWNLINK);
215 this->downlinkPacket();
230 struct FileEntry entry;
231 entry.srcFilename[0] = 0;
232 entry.destFilename[0] = 0;
235 entry.source = FileDownlink::COMMAND;
236 entry.opCode = opCode;
237 entry.cmdSeq = cmdSeq;
238 entry.context = std::numeric_limits<U32>::max();
254 SendPartial_cmdHandler(
263 struct FileEntry entry;
264 entry.srcFilename[0] = 0;
265 entry.destFilename[0] = 0;
266 entry.offset = startOffset;
267 entry.length = length;
268 entry.source = FileDownlink::COMMAND;
269 entry.opCode = opCode;
270 entry.cmdSeq = cmdSeq;
271 entry.context = std::numeric_limits<U32>::max();
293 if (this->m_mode.get() == Mode::DOWNLINK || this->m_mode.get() == Mode::WAIT) {
294 this->m_mode.set(Mode::CANCEL);
304 statusToCmdResp(SendFileStatus status)
325 sendResponse(SendFileStatus resp)
327 if(this->m_curEntry.source == FileDownlink::COMMAND) {
328 this->cmdResponse_out(this->m_curEntry.opCode, this->m_curEntry.cmdSeq, statusToCmdResp(resp));
330 for(
NATIVE_INT_TYPE i = 0; i < this->getNum_FileComplete_OutputPorts(); i++) {
331 if(this->isConnected_FileComplete_OutputPort(i)) {
340 const char* sourceFilename,
341 const char* destFilename,
354 this->m_mode.set(Mode::IDLE);
355 this->m_warnings.fileOpenError();
361 if (startOffset >= this->m_file.getSize()) {
362 this->enterCooldown();
363 this->log_WARNING_HI_DownlinkPartialFail(this->m_file.getSourceName(), this->m_file.getDestName(), startOffset, this->m_file.getSize());
366 }
else if (startOffset + length > this->m_file.getSize()) {
369 this->log_WARNING_LO_DownlinkPartialWarning(startOffset, length, this->m_file.getSize(), this->m_file.getSourceName(), this->m_file.getDestName());
370 length = this->m_file.getSize() - startOffset;
374 this->getBuffer(this->m_buffer, FILE_PACKET);
375 this->sendStartPacket();
376 this->m_mode.set(Mode::WAIT);
377 this->m_sequenceIndex = 1;
378 this->m_curTimer = 0;
379 this->m_byteOffset = startOffset;
384 this->log_ACTIVITY_HI_SendStarted(length, this->m_file.getSourceName(), this->m_file.getDestName());
385 this->m_endOffset = startOffset + length;
388 this->log_ACTIVITY_HI_SendStarted(this->m_file.getSize() - startOffset, this->m_file.getSourceName(), this->m_file.getDestName());
389 this->m_endOffset = this->m_file.getSize();
394 sendDataPacket(U32 &byteOffset)
396 FW_ASSERT(byteOffset < this->m_endOffset);
398 const U32 dataSize = (byteOffset + maxDataSize > this->m_endOffset) ? (this->m_endOffset - byteOffset) : maxDataSize;
401 if (dataSize + byteOffset == this->m_endOffset) {
406 this->m_file.read(buffer, byteOffset, dataSize);
408 this->m_warnings.fileRead(status);
414 this->m_sequenceIndex,
416 static_cast<U16
>(dataSize),
418 ++this->m_sequenceIndex;
421 this->sendFilePacket(filePacket);
423 byteOffset += dataSize;
434 cancelPacket.
initialize(this->m_sequenceIndex);
438 this->getBuffer(buffer, CANCEL_PACKET);
442 this->bufferSendOut_out(0, buffer);
443 this->m_packetsSent.packetSent();
450 this->m_file.getChecksum(checksum);
453 endPacket.
initialize(this->m_sequenceIndex, checksum);
457 this->sendFilePacket(filePacket);
466 this->m_file.getSize(),
467 this->m_file.getSourceName().toChar(),
468 this->m_file.getDestName().toChar()
472 this->sendFilePacket(filePacket);
478 const U32 bufferSize = filePacket.
bufferSize();
479 FW_ASSERT(this->m_buffer.getData() !=
nullptr);
480 FW_ASSERT(this->m_buffer.getSize() >= bufferSize, bufferSize, this->m_buffer.getSize());
484 this->m_buffer.setSize(bufferSize);
485 this->bufferSendOut_out(0, this->m_buffer);
488 this->m_packetsSent.packetSent();
494 this->m_file.getOsFile().close();
495 this->m_mode.set(Mode::COOLDOWN);
497 this->m_curTimer = 0;
504 FW_ASSERT(this->m_mode.get() == Mode::CANCEL || this->m_mode.get() == Mode::DOWNLINK, this->m_mode.get());
507 this->sendCancelPacket();
515 this->log_WARNING_HI_SendDataFail(this->m_file.getSourceName(), this->m_byteOffset);
516 this->enterCooldown();
524 this->sendEndPacket();
527 this->m_mode.set(Mode::WAIT);
528 this->m_curTimer = 0;
532 finishHelper(
bool cancel)
536 this->m_filesSent.fileSent();
537 this->log_ACTIVITY_HI_FileSent(this->m_file.getSourceName(), this->m_file.getDestName());
539 this->log_ACTIVITY_HI_DownlinkCanceled(this->m_file.getSourceName(), this->m_file.getDestName());
541 this->enterCooldown();
546 getBuffer(
Fw::Buffer& buffer, PacketType type)
549 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, type);
551 buffer.
setData(this->m_memoryStore[type]);
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
PlatformUIntType NATIVE_UINT_TYPE
C++-compatible configuration header for fprime configuration.
Class representing a CFDP checksum.
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.
void init()
Object initializer.
NATIVE_UINT_TYPE length() const
Get length of string.
@ OP_OK
Operation was successful.
@ QUEUE_OK
message sent/received okay
@ QUEUE_NONBLOCKING
Queue receive always returns even if there is no message.
Auto-generated base for FileDownlink component.
Send file response struct.
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed
SerializeStatus
forward declaration for string
@ FW_SERIALIZE_OK
Serialization/Deserialization operation was successful.
SendFileRequestPortStrings::StringSize100 sourceFileNameString
SendFileRequestPortStrings::StringSize100 destFileNameString
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