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;
164 entry.srcFilename[0] = 0;
165 entry.destFilename[0] = 0;
166 entry.offset = offset;
167 entry.length = length;
168 entry.source = FileDownlink::PORT;
171 entry.context = cntxId++;
173 FW_ASSERT(sourceFilename.length() <
sizeof(entry.srcFilename));
174 FW_ASSERT(destFilename.length() <
sizeof(entry.destFilename));
181 return SendFileResponse(SendFileStatus::STATUS_ERROR, __UINT32_MAX__);
183 return SendFileResponse(SendFileStatus::STATUS_OK, entry.context);
192 this->pingOut_out(0,key);
196 bufferReturn_handler(
203 if (this->lastBufferId != fwBuffer.
getContext() + 1 ||
204 this->mode.get() == Mode::IDLE) {
208 FW_ASSERT(this->mode.get() == Mode::WAIT || this->mode.get() == Mode::CANCEL, this->mode.get());
216 else if (this->mode.get() == Mode::WAIT) {
217 this->mode.set(Mode::DOWNLINK);
220 this->downlinkPacket();
235 struct FileEntry entry;
236 entry.srcFilename[0] = 0;
237 entry.destFilename[0] = 0;
240 entry.source = FileDownlink::COMMAND;
241 entry.opCode = opCode;
242 entry.cmdSeq = cmdSeq;
243 entry.context = __UINT32_MAX__;
253 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
258 SendPartial_cmdHandler(
267 struct FileEntry entry;
268 entry.srcFilename[0] = 0;
269 entry.destFilename[0] = 0;
270 entry.offset = startOffset;
271 entry.length = length;
272 entry.source = FileDownlink::COMMAND;
273 entry.opCode = opCode;
274 entry.cmdSeq = cmdSeq;
275 entry.context = __UINT32_MAX__;
285 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
296 if (this->mode.get() == Mode::DOWNLINK || this->mode.get() == Mode::WAIT) {
297 this->mode.set(Mode::CANCEL);
299 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
306 Fw::CommandResponse FileDownlink ::
307 statusToCmdResp(SendFileStatus status)
310 case SendFileStatus::STATUS_OK:
311 return Fw::COMMAND_OK;
312 case SendFileStatus::STATUS_ERROR:
313 return Fw::COMMAND_EXECUTION_ERROR;
314 case SendFileStatus::STATUS_INVALID:
315 return Fw::COMMAND_VALIDATION_ERROR;
316 case SendFileStatus::STATUS_BUSY:
317 return Fw::COMMAND_BUSY;
324 return Fw::COMMAND_EXECUTION_ERROR;
328 sendResponse(SendFileStatus resp)
330 if(this->curEntry.source == FileDownlink::COMMAND) {
331 this->cmdResponse_out(this->curEntry.opCode, this->curEntry.cmdSeq, statusToCmdResp(resp));
333 for(
NATIVE_INT_TYPE i = 0; i < this->getNum_FileComplete_OutputPorts(); i++) {
334 if(this->isConnected_FileComplete_OutputPort(i)) {
335 this->FileComplete_out(i, Svc::SendFileResponse(resp, this->curEntry.context));
343 const char* sourceFilename,
344 const char* destFilename,
357 this->mode.set(Mode::IDLE);
358 this->warnings.fileOpenError();
364 if (startOffset >= this->file.size) {
365 this->enterCooldown();
366 this->log_WARNING_HI_DownlinkPartialFail(this->file.sourceName, this->file.destName, startOffset, this->file.size);
369 }
else if (startOffset + length > this->file.size) {
372 this->log_WARNING_LO_DownlinkPartialWarning(startOffset, length, this->file.size, this->file.sourceName, this->file.destName);
373 length = this->file.size - startOffset;
377 this->getBuffer(this->buffer, FILE_PACKET);
378 this->sendStartPacket();
379 this->mode.set(Mode::WAIT);
380 this->sequenceIndex = 1;
382 this->byteOffset = startOffset;
387 this->log_ACTIVITY_HI_SendStarted(length, this->file.sourceName, this->file.destName);
388 this->endOffset = startOffset + length;
391 this->log_ACTIVITY_HI_SendStarted(this->file.size - startOffset, this->file.sourceName, this->file.destName);
392 this->endOffset = this->file.size;
397 sendDataPacket(U32 &byteOffset)
401 const U32 dataSize = (byteOffset + maxDataSize > this->endOffset) ? (this->endOffset - byteOffset) : maxDataSize;
404 if (dataSize + byteOffset == this->endOffset) {
409 this->file.read(buffer, byteOffset, dataSize);
411 this->warnings.fileRead(status);
421 ++this->sequenceIndex;
424 this->sendFilePacket(filePacket);
426 byteOffset += dataSize;
433 sendCancelPacket(
void)
442 this->getBuffer(buffer, CANCEL_PACKET);
446 this->bufferSendOut_out(0, buffer);
447 this->packetsSent.packetSent();
458 endPacket.
header = header;
461 this->file.getChecksum(checksum);
466 this->sendFilePacket(filePacket);
471 sendStartPacket(
void)
476 this->file.sourceName.toChar(),
477 this->file.destName.toChar()
481 this->sendFilePacket(filePacket);
487 const U32 bufferSize = filePacket.
bufferSize();
489 FW_ASSERT(this->buffer.
getSize() >= bufferSize, bufferSize, this->buffer.getSize());
493 this->buffer.
setSize(bufferSize);
494 this->bufferSendOut_out(0, this->buffer);
497 this->packetsSent.packetSent();
503 this->file.osFile.close();
504 this->mode.set(Mode::COOLDOWN);
513 FW_ASSERT(this->mode.get() == Mode::CANCEL || this->mode.get() == Mode::DOWNLINK, this->mode.get());
516 this->sendCancelPacket();
524 this->log_WARNING_HI_SendDataFail(this->file.sourceName, this->byteOffset);
525 this->enterCooldown();
533 this->sendEndPacket();
536 this->mode.set(Mode::WAIT);
541 finishHelper(
bool cancel)
545 this->filesSent.fileSent();
546 this->log_ACTIVITY_HI_FileSent(this->file.sourceName, this->file.destName);
548 this->log_ACTIVITY_HI_DownlinkCanceled(this->file.sourceName, this->file.destName);
550 this->enterCooldown();
551 sendResponse(SendFileStatus::STATUS_OK);
555 getBuffer(
Fw::Buffer& buffer, PacketType type)
558 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, type);
560 buffer.
setData(this->memoryStore[type]);