27 const char *
const name
29 FileDownlinkComponentBase(name),
39 lastCompletedType(
Fw::FilePacket::T_NONE),
52 FileDownlinkComponentBase::init(queueDepth, instance);
63 this->timeout = timeout;
64 this->cooldown = cooldown;
65 this->cycleTime = cycleTime;
66 this->configured =
true;
71 sizeof(
struct FileEntry)
98 switch(this->mode.get())
104 reinterpret_cast<U8*
>(&this->curEntry),
105 sizeof(this->curEntry),
116 this->curEntry.srcFilename,
117 this->curEntry.destFilename,
118 this->curEntry.offset,
119 this->curEntry.length
123 case Mode::COOLDOWN: {
124 if (this->curTimer >= this->cooldown) {
126 this->mode.set(Mode::IDLE);
128 this->curTimer += cycleTime;
134 if (this->curTimer >= this->timeout) {
136 this->log_WARNING_HI_DownlinkTimeout(this->file.sourceName, this->file.destName);
137 this->enterCooldown();
140 this->curTimer += cycleTime;
149 Svc::SendFileResponse FileDownlink ::
152 const sourceFileNameString& sourceFilename,
153 const destFileNameString& destFilename,
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 = cntxId++;
168 FW_ASSERT(sourceFilename.length() <
sizeof(entry.srcFilename));
169 FW_ASSERT(destFilename.length() <
sizeof(entry.destFilename));
176 return SendFileResponse(SendFileStatus::STATUS_ERROR, std::numeric_limits<U32>::max());
178 return SendFileResponse(SendFileStatus::STATUS_OK, entry.context);
187 this->pingOut_out(0,key);
191 bufferReturn_handler(
198 if (this->lastBufferId != fwBuffer.
getContext() + 1 ||
199 this->mode.get() == Mode::IDLE) {
203 FW_ASSERT(this->mode.get() == Mode::WAIT || this->mode.get() == Mode::CANCEL, this->mode.get());
211 else if (this->mode.get() == Mode::WAIT) {
212 this->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();
249 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
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();
282 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::EXECUTION_ERROR);
293 if (this->mode.get() == Mode::DOWNLINK || this->mode.get() == Mode::WAIT) {
294 this->mode.set(Mode::CANCEL);
296 this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
303 Fw::CmdResponse FileDownlink ::
304 statusToCmdResp(SendFileStatus status)
307 case SendFileStatus::STATUS_OK:
308 return Fw::CmdResponse::OK;
309 case SendFileStatus::STATUS_ERROR:
310 return Fw::CmdResponse::EXECUTION_ERROR;
311 case SendFileStatus::STATUS_INVALID:
312 return Fw::CmdResponse::VALIDATION_ERROR;
313 case SendFileStatus::STATUS_BUSY:
314 return Fw::CmdResponse::BUSY;
321 return Fw::CmdResponse::EXECUTION_ERROR;
325 sendResponse(SendFileStatus resp)
327 if(this->curEntry.source == FileDownlink::COMMAND) {
328 this->cmdResponse_out(this->curEntry.opCode, this->curEntry.cmdSeq, statusToCmdResp(resp));
330 for(
NATIVE_INT_TYPE i = 0; i < this->getNum_FileComplete_OutputPorts(); i++) {
331 if(this->isConnected_FileComplete_OutputPort(i)) {
332 this->FileComplete_out(i, Svc::SendFileResponse(resp, this->curEntry.context));
340 const char* sourceFilename,
341 const char* destFilename,
354 this->mode.set(Mode::IDLE);
355 this->warnings.fileOpenError();
361 if (startOffset >= this->file.size) {
362 this->enterCooldown();
363 this->log_WARNING_HI_DownlinkPartialFail(this->file.sourceName, this->file.destName, startOffset, this->file.size);
366 }
else if (startOffset + length > this->file.size) {
369 this->log_WARNING_LO_DownlinkPartialWarning(startOffset, length, this->file.size, this->file.sourceName, this->file.destName);
370 length = this->file.size - startOffset;
374 this->getBuffer(this->buffer, FILE_PACKET);
375 this->sendStartPacket();
376 this->mode.set(Mode::WAIT);
377 this->sequenceIndex = 1;
379 this->byteOffset = startOffset;
384 this->log_ACTIVITY_HI_SendStarted(length, this->file.sourceName, this->file.destName);
385 this->endOffset = startOffset + length;
388 this->log_ACTIVITY_HI_SendStarted(this->file.size - startOffset, this->file.sourceName, this->file.destName);
389 this->endOffset = this->file.size;
394 sendDataPacket(U32 &byteOffset)
398 const U32 dataSize = (byteOffset + maxDataSize > this->endOffset) ? (this->endOffset - byteOffset) : maxDataSize;
401 if (dataSize + byteOffset == this->endOffset) {
406 this->file.read(buffer, byteOffset, dataSize);
408 this->warnings.fileRead(status);
415 static_cast<U16
>(dataSize),
418 ++this->sequenceIndex;
421 this->sendFilePacket(filePacket);
423 byteOffset += dataSize;
439 this->getBuffer(buffer, CANCEL_PACKET);
443 this->bufferSendOut_out(0, buffer);
444 this->packetsSent.packetSent();
455 endPacket.
header = header;
458 this->file.getChecksum(checksum);
463 this->sendFilePacket(filePacket);
473 this->file.sourceName.toChar(),
474 this->file.destName.toChar()
478 this->sendFilePacket(filePacket);
484 const U32 bufferSize = filePacket.
bufferSize();
486 FW_ASSERT(this->buffer.
getSize() >= bufferSize, bufferSize, this->buffer.getSize());
490 this->buffer.
setSize(bufferSize);
491 this->bufferSendOut_out(0, this->buffer);
494 this->packetsSent.packetSent();
500 this->file.osFile.close();
501 this->mode.set(Mode::COOLDOWN);
510 FW_ASSERT(this->mode.get() == Mode::CANCEL || this->mode.get() == Mode::DOWNLINK, this->mode.get());
513 this->sendCancelPacket();
521 this->log_WARNING_HI_SendDataFail(this->file.sourceName, this->byteOffset);
522 this->enterCooldown();
530 this->sendEndPacket();
533 this->mode.set(Mode::WAIT);
538 finishHelper(
bool cancel)
542 this->filesSent.fileSent();
543 this->log_ACTIVITY_HI_FileSent(this->file.sourceName, this->file.destName);
545 this->log_ACTIVITY_HI_DownlinkCanceled(this->file.sourceName, this->file.destName);
547 this->enterCooldown();
548 sendResponse(SendFileStatus::STATUS_OK);
552 getBuffer(
Fw::Buffer& buffer, PacketType type)
555 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, type);
557 buffer.
setData(this->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)
const char * toChar() const
The type of a cancel packet.
The type of a data packet.
The type of an end packet.
Header header
The packet header.
void setChecksum(const CFDP::Checksum &checksum)
Set the checksum.
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.
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.
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