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)
97 switch(this->mode.get())
103 (
U8 *) &this->curEntry,
104 sizeof(this->curEntry),
115 this->curEntry.srcFilename,
116 this->curEntry.destFilename,
117 this->curEntry.offset,
118 this->curEntry.length
122 case Mode::COOLDOWN: {
123 if (this->curTimer >= this->cooldown) {
125 this->mode.set(Mode::IDLE);
127 this->curTimer += cycleTime;
133 if (this->curTimer >= this->timeout) {
135 this->log_WARNING_HI_DownlinkTimeout(this->file.sourceName, this->file.destName);
136 this->enterCooldown();
139 this->curTimer += cycleTime;
148 Svc::SendFileResponse FileDownlink ::
151 sourceFileNameString sourceFilename,
152 destFileNameString destFilename,
157 struct FileEntry entry;
158 entry.srcFilename[0] = 0;
159 entry.destFilename[0] = 0;
160 entry.offset = offset;
161 entry.length = length;
162 entry.source = FileDownlink::PORT;
165 entry.context = cntxId++;
167 FW_ASSERT(sourceFilename.length() <
sizeof(entry.srcFilename));
168 FW_ASSERT(destFilename.length() <
sizeof(entry.destFilename));
175 return SendFileResponse(SendFileStatus::STATUS_ERROR, U32_MAX);
177 return SendFileResponse(SendFileStatus::STATUS_OK, entry.context);
186 this->pingOut_out(0,key);
190 bufferReturn_handler(
197 if (this->lastBufferId != fwBuffer.
getContext() + 1 ||
198 this->mode.get() == Mode::IDLE) {
202 FW_ASSERT(this->mode.get() == Mode::WAIT || this->mode.get() == Mode::CANCEL, this->mode.get());
210 else if (this->mode.get() == Mode::WAIT) {
211 this->mode.set(Mode::DOWNLINK);
214 this->downlinkPacket();
229 struct FileEntry entry;
230 entry.srcFilename[0] = 0;
231 entry.destFilename[0] = 0;
234 entry.source = FileDownlink::COMMAND;
235 entry.opCode = opCode;
236 entry.cmdSeq = cmdSeq;
237 entry.context = U32_MAX;
248 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
253 SendPartial_cmdHandler(
262 struct FileEntry entry;
263 entry.srcFilename[0] = 0;
264 entry.destFilename[0] = 0;
265 entry.offset = startOffset;
266 entry.length = length;
267 entry.source = FileDownlink::COMMAND;
268 entry.opCode = opCode;
269 entry.cmdSeq = cmdSeq;
270 entry.context = U32_MAX;
281 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_EXECUTION_ERROR);
292 if (this->mode.get() == Mode::DOWNLINK || this->mode.get() == Mode::WAIT) {
293 this->mode.set(Mode::CANCEL);
295 this->cmdResponse_out(opCode, cmdSeq, Fw::COMMAND_OK);
302 Fw::CommandResponse FileDownlink ::
303 statusToCmdResp(SendFileStatus status)
306 case SendFileStatus::STATUS_OK:
307 return Fw::COMMAND_OK;
308 case SendFileStatus::STATUS_ERROR:
309 return Fw::COMMAND_EXECUTION_ERROR;
310 case SendFileStatus::STATUS_INVALID:
311 return Fw::COMMAND_VALIDATION_ERROR;
312 case SendFileStatus::STATUS_BUSY:
313 return Fw::COMMAND_BUSY;
320 return Fw::COMMAND_EXECUTION_ERROR;
324 sendResponse(SendFileStatus resp)
326 if(this->curEntry.source == FileDownlink::COMMAND) {
327 this->cmdResponse_out(this->curEntry.opCode, this->curEntry.cmdSeq, statusToCmdResp(resp));
329 for(
NATIVE_INT_TYPE i = 0; i < this->getNum_FileComplete_OutputPorts(); i++) {
330 if(this->isConnected_FileComplete_OutputPort(i)) {
331 this->FileComplete_out(i, Svc::SendFileResponse(resp, this->curEntry.context));
339 const char* sourceFilename,
340 const char* destFilename,
353 this->mode.set(Mode::IDLE);
354 this->warnings.fileOpenError();
360 if (startOffset >= this->file.size) {
361 this->enterCooldown();
362 this->log_WARNING_HI_DownlinkPartialFail(this->file.sourceName, this->file.destName, startOffset, this->file.size);
365 }
else if (startOffset + length > this->file.size) {
368 this->log_WARNING_LO_DownlinkPartialWarning(startOffset, length, this->file.size, this->file.sourceName, this->file.destName);
369 length = this->file.size - startOffset;
373 this->getBuffer(this->buffer, FILE_PACKET);
374 this->sendStartPacket();
375 this->mode.set(Mode::WAIT);
376 this->sequenceIndex = 1;
378 this->byteOffset = startOffset;
383 this->log_ACTIVITY_HI_SendStarted(length, this->file.sourceName, this->file.destName);
384 this->endOffset = startOffset + length;
387 this->log_ACTIVITY_HI_SendStarted(this->file.size - startOffset, this->file.sourceName, this->file.destName);
388 this->endOffset = this->file.size;
393 sendDataPacket(U32 &byteOffset)
397 const U32 dataSize = (byteOffset + maxDataSize > this->endOffset) ? (this->endOffset - byteOffset) : maxDataSize;
400 if (dataSize + byteOffset == this->endOffset) {
405 this->file.read(buffer, byteOffset, dataSize);
407 this->warnings.fileRead(status);
417 ++this->sequenceIndex;
420 this->sendFilePacket(filePacket);
422 byteOffset += dataSize;
429 sendCancelPacket(
void)
438 this->getBuffer(buffer, CANCEL_PACKET);
442 this->bufferSendOut_out(0, buffer);
443 this->packetsSent.packetSent();
454 endPacket.
header = header;
457 this->file.getChecksum(checksum);
462 this->sendFilePacket(filePacket);
467 sendStartPacket(
void)
472 this->file.sourceName.toChar(),
473 this->file.destName.toChar()
477 this->sendFilePacket(filePacket);
483 const U32 bufferSize = filePacket.
bufferSize();
485 FW_ASSERT(this->buffer.
getSize() >= bufferSize, bufferSize, this->buffer.getSize());
489 this->buffer.
setSize(bufferSize);
490 this->bufferSendOut_out(0, this->buffer);
493 this->packetsSent.packetSent();
499 this->file.osFile.close();
500 this->mode.set(Mode::COOLDOWN);
509 FW_ASSERT(this->mode.get() == Mode::CANCEL || this->mode.get() == Mode::DOWNLINK, this->mode.get());
512 this->sendCancelPacket();
520 this->log_WARNING_HI_SendDataFail(this->file.sourceName, this->byteOffset);
521 this->enterCooldown();
529 this->sendEndPacket();
532 this->mode.set(Mode::WAIT);
537 finishHelper(
bool cancel)
541 this->filesSent.fileSent();
542 this->log_ACTIVITY_HI_FileSent(this->file.sourceName, this->file.destName);
544 this->log_ACTIVITY_HI_DownlinkCanceled(this->file.sourceName, this->file.destName);
546 this->enterCooldown();
547 sendResponse(SendFileStatus::STATUS_OK);
551 getBuffer(
Fw::Buffer& buffer, PacketType type)
554 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, type);
556 buffer.
setData(this->memoryStore[type]);