26 const char *
const name
28 FileDownlinkComponentBase(name),
38 lastCompletedType(
Fw::FilePacket::T_NONE),
51 FileDownlinkComponentBase::init(queueDepth, instance);
62 this->timeout = timeout;
63 this->cooldown = cooldown;
64 this->cycleTime = cycleTime;
65 this->configured =
true;
70 sizeof(
struct FileEntry)
84 FileDownlinkComponentBase::start(identifier, priority, stackSize, cpuAffinity);
103 switch(this->mode.get())
109 (
U8 *) &this->curEntry,
110 sizeof(this->curEntry),
121 this->curEntry.srcFilename,
122 this->curEntry.destFilename,
123 this->curEntry.offset,
124 this->curEntry.length
128 case Mode::COOLDOWN: {
129 if (this->curTimer >= this->cooldown) {
131 this->mode.set(Mode::IDLE);
133 this->curTimer += cycleTime;
139 if (this->curTimer >= this->timeout) {
141 this->log_WARNING_HI_DownlinkTimeout(this->file.sourceName, this->file.destName);
142 this->enterCooldown();
145 this->curTimer += cycleTime;
154 Svc::SendFileResponse FileDownlink ::
157 sourceFileNameString sourceFilename,
158 destFileNameString destFilename,
163 struct FileEntry entry = {
168 .source = FileDownlink::PORT,
174 FW_ASSERT(sourceFilename.length() <
sizeof(entry.srcFilename));
175 FW_ASSERT(destFilename.length() <
sizeof(entry.destFilename));
182 return SendFileResponse(SendFileStatus::ERROR, __UINT32_MAX__);
184 return SendFileResponse(SendFileStatus::OK, entry.context);
193 this->pingOut_out(0,key);
197 bufferReturn_handler(
204 if (this->lastBufferId != fwBuffer.
getContext() + 1 ||
205 this->mode.get() == Mode::IDLE) {
209 FW_ASSERT(this->mode.get() == Mode::WAIT || this->mode.get() == Mode::CANCEL, this->mode.get());
217 else if (this->mode.get() == Mode::WAIT) {
218 this->mode.set(Mode::DOWNLINK);
221 this->downlinkPacket();
236 struct FileEntry entry = {
241 .source = FileDownlink::COMMAND,
244 .context =__UINT32_MAX__
255 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
260 SendPartial_cmdHandler(
269 struct FileEntry entry = {
272 .offset = startOffset,
274 .source = FileDownlink::COMMAND,
277 .context = __UINT32_MAX__
288 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
299 if (this->mode.get() == Mode::DOWNLINK || this->mode.get() == Mode::WAIT) {
300 this->mode.set(Mode::CANCEL);
302 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
309 Fw::CommandResponse FileDownlink ::
310 statusToCmdResp(SendFileStatus status)
313 case SendFileStatus::OK:
314 return Fw::COMMAND_OK;
315 case SendFileStatus::ERROR:
316 return Fw::COMMAND_EXECUTION_ERROR;
317 case SendFileStatus::INVALID:
318 return Fw::COMMAND_VALIDATION_ERROR;
320 return Fw::COMMAND_BUSY;
327 return Fw::COMMAND_EXECUTION_ERROR;
331 sendResponse(SendFileStatus resp)
333 if(this->curEntry.source == FileDownlink::COMMAND) {
334 this->cmdResponse_out(this->curEntry.opCode, this->curEntry.cmdSeq, statusToCmdResp(resp));
336 for(
NATIVE_INT_TYPE i = 0; i < this->getNum_FileComplete_OutputPorts(); i++) {
337 if(this->isConnected_FileComplete_OutputPort(i)) {
338 this->FileComplete_out(i, Svc::SendFileResponse(resp, this->curEntry.context));
346 const char* sourceFilename,
347 const char* destFilename,
360 this->mode.set(Mode::IDLE);
361 this->warnings.fileOpenError();
367 if (startOffset >= this->file.size) {
368 this->enterCooldown();
369 this->log_WARNING_HI_DownlinkPartialFail(this->file.sourceName, this->file.destName, startOffset, this->file.size);
372 }
else if (startOffset + length > this->file.size) {
375 this->log_WARNING_LO_DownlinkPartialWarning(startOffset, length, this->file.size, this->file.sourceName, this->file.destName);
376 length = this->file.size - startOffset;
380 this->getBuffer(this->buffer, FILE_PACKET);
381 this->sendStartPacket();
382 this->mode.set(Mode::WAIT);
383 this->sequenceIndex = 1;
385 this->byteOffset = startOffset;
390 this->log_ACTIVITY_HI_SendStarted(length, this->file.sourceName, this->file.destName);
391 this->endOffset = startOffset + length;
394 this->log_ACTIVITY_HI_SendStarted(this->file.size - startOffset, this->file.sourceName, this->file.destName);
395 this->endOffset = this->file.size;
400 sendDataPacket(U32 &byteOffset)
404 const U32 dataSize = (byteOffset + maxDataSize > this->endOffset) ? (this->endOffset - byteOffset) : maxDataSize;
407 if (dataSize + byteOffset == this->endOffset) {
412 this->file.read(buffer, byteOffset, dataSize);
414 this->warnings.fileRead(status);
424 ++this->sequenceIndex;
427 this->sendFilePacket(filePacket);
429 byteOffset += dataSize;
436 sendCancelPacket(
void)
445 this->getBuffer(buffer, CANCEL_PACKET);
449 this->bufferSendOut_out(0, buffer);
450 this->packetsSent.packetSent();
461 endPacket.
header = header;
464 this->file.getChecksum(checksum);
469 this->sendFilePacket(filePacket);
474 sendStartPacket(
void)
479 this->file.sourceName.toChar(),
480 this->file.destName.toChar()
484 this->sendFilePacket(filePacket);
490 const U32 bufferSize = filePacket.
bufferSize();
492 FW_ASSERT(this->buffer.
getSize() >= bufferSize, bufferSize, this->buffer.getSize());
496 this->buffer.
setSize(bufferSize);
497 this->bufferSendOut_out(0, this->buffer);
500 this->packetsSent.packetSent();
506 this->file.osFile.close();
507 this->mode.set(Mode::COOLDOWN);
516 FW_ASSERT(this->mode.get() == Mode::CANCEL || this->mode.get() == Mode::DOWNLINK, this->mode.get());
519 this->sendCancelPacket();
527 this->log_WARNING_HI_SendDataFail(this->file.sourceName, this->byteOffset);
528 this->enterCooldown();
536 this->sendEndPacket();
539 this->mode.set(Mode::WAIT);
544 finishHelper(
bool cancel)
548 this->filesSent.fileSent();
549 this->log_ACTIVITY_HI_FileSent(this->file.sourceName, this->file.destName);
551 this->log_ACTIVITY_HI_DownlinkCanceled(this->file.sourceName, this->file.destName);
553 this->enterCooldown();
554 sendResponse(SendFileStatus::OK);
558 getBuffer(
Fw::Buffer& buffer, PacketType type)
561 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, type);
563 buffer.
setData(this->memoryStore[type]);