37 m_lastCompletedType(
Fw::FilePacket::T_NONE),
43 this->m_timeout = timeout;
44 this->m_cooldown = cooldown;
45 this->m_cycleTime = cycleTime;
46 this->m_configured =
true;
50 static_cast<FwSizeType>(fileQueueDepth), static_cast<FwSizeType>(
sizeof(
struct FileEntry)));
69 void FileDownlink ::Run_handler(
const FwIndexType portNum, U32 context) {
70 switch (this->m_mode.get()) {
75 static_cast<FwSizeType>(
sizeof(this->m_curEntry)),
76 Os::Queue::BlockingType::NONBLOCKING, real_size, prio);
82 sendFile(this->m_curEntry.srcFilename, this->m_curEntry.destFilename, this->m_curEntry.offset,
83 this->m_curEntry.length);
86 case Mode::COOLDOWN: {
87 if (this->m_curTimer >= this->m_cooldown) {
91 this->m_curTimer += m_cycleTime;
97 if (this->m_curTimer >= this->m_timeout) {
100 this->enterCooldown();
104 this->m_curTimer += m_cycleTime;
119 struct FileEntry entry;
120 entry.srcFilename[0] = 0;
121 entry.destFilename[0] = 0;
122 entry.offset = offset;
123 entry.length = length;
124 entry.source = FileDownlink::PORT;
127 entry.context = m_cntxId++;
132 static_cast<FwSizeType>(
sizeof(entry.srcFilename)));
134 static_cast<FwSizeType>(
sizeof(entry.destFilename)));
136 Os::Queue::Status status = m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)),
137 0, Os::Queue::BlockingType::NONBLOCKING);
145 void FileDownlink ::pingIn_handler(
const FwIndexType portNum, U32 key) {
156 FW_ASSERT(this->m_mode.get() == Mode::WAIT || this->m_mode.get() == Mode::CANCEL,
164 else if (this->m_mode.get() == Mode::WAIT) {
165 this->m_mode.set(Mode::DOWNLINK);
168 this->downlinkPacket();
175 void FileDownlink ::SendFile_cmdHandler(
const FwOpcodeType opCode,
179 struct FileEntry entry;
180 entry.srcFilename[0] = 0;
181 entry.destFilename[0] = 0;
184 entry.source = FileDownlink::COMMAND;
185 entry.opCode = opCode;
186 entry.cmdSeq = cmdSeq;
187 entry.context = std::numeric_limits<U32>::max();
192 static_cast<FwSizeType>(
sizeof(entry.srcFilename)));
194 static_cast<FwSizeType>(
sizeof(entry.destFilename)));
196 Os::Queue::Status status = m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)),
197 0, Os::Queue::BlockingType::NONBLOCKING);
204 void FileDownlink ::SendPartial_cmdHandler(
FwOpcodeType opCode,
210 struct FileEntry entry;
211 entry.srcFilename[0] = 0;
212 entry.destFilename[0] = 0;
213 entry.offset = startOffset;
214 entry.length = length;
215 entry.source = FileDownlink::COMMAND;
216 entry.opCode = opCode;
217 entry.cmdSeq = cmdSeq;
218 entry.context = std::numeric_limits<U32>::max();
223 static_cast<FwSizeType>(
sizeof(entry.srcFilename)));
225 static_cast<FwSizeType>(
sizeof(entry.destFilename)));
227 Os::Queue::Status status = m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)),
228 0, Os::Queue::BlockingType::NONBLOCKING);
235 void FileDownlink ::Cancel_cmdHandler(
const FwOpcodeType opCode,
const U32 cmdSeq) {
237 if (this->m_mode.get() == Mode::DOWNLINK || this->m_mode.get() == Mode::WAIT) {
238 this->m_mode.set(Mode::CANCEL);
247 Fw::CmdResponse FileDownlink ::statusToCmdResp(SendFileStatus status) {
266 void FileDownlink ::sendResponse(SendFileStatus resp) {
267 if (this->m_curEntry.source == FileDownlink::COMMAND) {
268 this->
cmdResponse_out(this->m_curEntry.opCode, this->m_curEntry.cmdSeq, statusToCmdResp(resp));
278 void FileDownlink ::sendFile(
const char* sourceFilename,
const char* destFilename, U32 startOffset, U32 length) {
285 this->m_warnings.fileOpenError();
290 if (startOffset >= this->m_file.getSize()) {
291 this->enterCooldown();
293 this->m_file.getSize());
297 }
else if (startOffset + length > this->m_file.getSize()) {
301 this->m_file.getSourceName(), this->m_file.getDestName());
302 length = this->m_file.getSize() - startOffset;
306 this->getBuffer(this->m_buffer, FILE_PACKET);
307 this->sendStartPacket();
308 this->m_mode.set(Mode::WAIT);
309 this->m_sequenceIndex = 1;
310 this->m_curTimer = 0;
311 this->m_byteOffset = startOffset;
317 this->m_endOffset = startOffset + length;
320 this->m_file.getDestName());
321 this->m_endOffset = this->m_file.getSize();
326 FW_ASSERT(byteOffset < this->m_endOffset);
327 const U32 maxDataSize =
330 (byteOffset + maxDataSize > this->m_endOffset) ? (this->m_endOffset - byteOffset) : maxDataSize;
331 U8 buffer[maxDataSize];
333 if (dataSize + byteOffset == this->m_endOffset) {
337 const Os::File::Status status = this->m_file.read(buffer, byteOffset, dataSize);
339 this->m_warnings.fileRead(status);
344 dataPacket.
initialize(this->m_sequenceIndex, byteOffset, static_cast<U16>(dataSize), buffer);
345 ++this->m_sequenceIndex;
348 this->sendFilePacket(filePacket);
350 byteOffset += dataSize;
355 void FileDownlink ::sendCancelPacket() {
358 cancelPacket.
initialize(this->m_sequenceIndex);
362 this->getBuffer(buffer, CANCEL_PACKET);
364 static_cast<FwAssertArgType>(buffer.
getSize()),
374 status = filePacket.
toBuffer(offsetBuffer);
377 this->m_packetsSent.packetSent();
380 void FileDownlink ::sendEndPacket() {
382 this->m_file.getChecksum(checksum);
385 endPacket.
initialize(this->m_sequenceIndex, checksum);
389 this->sendFilePacket(filePacket);
392 void FileDownlink ::sendStartPacket() {
394 startPacket.
initialize(this->m_file.getSize(), this->m_file.getSourceName().toChar(),
395 this->m_file.getDestName().toChar());
398 this->sendFilePacket(filePacket);
401 void FileDownlink ::sendFilePacket(
const Fw::FilePacket& filePacket) {
405 static_cast<FwAssertArgType>(this->m_buffer.
getSize()));
408 static_cast<FwPacketDescriptorType>(Fw::ComPacketType::FW_PACKET_FILE));
414 status = filePacket.
toBuffer(offsetBuffer);
417 this->m_buffer.
setSize(bufferSize);
421 this->m_packetsSent.packetSent();
424 void FileDownlink ::enterCooldown() {
425 this->m_file.getOsFile().close();
426 this->m_mode.set(Mode::COOLDOWN);
428 this->m_curTimer = 0;
431 void FileDownlink ::downlinkPacket() {
433 static_cast<FwAssertArgType>(this->m_lastCompletedType));
434 FW_ASSERT(this->m_mode.get() == Mode::CANCEL || this->m_mode.get() == Mode::DOWNLINK,
438 this->sendCancelPacket();
447 this->enterCooldown();
456 this->sendEndPacket();
459 this->m_mode.set(Mode::WAIT);
460 this->m_curTimer = 0;
463 void FileDownlink ::finishHelper(
bool cancel) {
466 this->m_filesSent.fileSent();
471 this->enterCooldown();
475 void FileDownlink ::getBuffer(
Fw::Buffer& buffer, PacketType type) {
477 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, static_cast<FwAssertArgType>(type));
479 buffer.
setData(this->m_memoryStore[type]);
Serialization/Deserialization operation was successful.
Status create(FwEnumStoreType id, const Fw::ConstStringBase &name, FwSizeType depth, FwSizeType messageSize) override
create queue storage through delegate
U16 FwPacketDescriptorType
The width of packet descriptors when they are serialized by the framework.
void fromCancelPacket(const CancelPacket &cancelPacket)
FwIdType FwOpcodeType
The type of a command opcode.
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
void fromDataPacket(const DataPacket &dataPacket)
PlatformSizeType FwSizeType
Status receive(U8 *destination, FwSizeType capacity, BlockingType blockType, FwSizeType &actualSize, FwQueuePriorityType &priority) override
receive a message from the queue through delegate
void setContext(U32 context)
void setSize(FwSizeType size)
static constexpr FwIndexType getNum_FileComplete_OutputPorts()
The type of a cancel packet.
Status
status returned from the queue send function
void fromEndPacket(const EndPacket &endPacket)
The type of a data packet.
FwEnumStoreType getInstance() const
virtual const CHAR * toChar() const =0
Convert to a C-style char*.
void fromStartPacket(const StartPacket &startPacket)
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
Enum representing a command response.
SerializeStatus toBuffer(Buffer &buffer) const
FileDownlink(const char *const compName)
void log_ACTIVITY_HI_DownlinkCanceled(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
void log_WARNING_HI_DownlinkTimeout(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
SerializeStatus
forward declaration for string
Class representing a 32-bit checksum as mandated by the CCSDS File Delivery Protocol.
Auto-generated base for FileDownlink component.
void log_WARNING_LO_DownlinkPartialWarning(U32 startOffset, U32 length, U32 filesize, const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
char * string_copy(char *destination, const char *source, FwSizeType num)
copy string with null-termination guaranteed
The type of a start packet.
Status send(const U8 *buffer, FwSizeType size, FwQueuePriorityType priority, BlockingType blockType) override
send a message into the queue through delegate
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
void deinit()
Allows de-initialization on teardown.
void bufferSendOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferSendOut.
void teardown() override
teardown the queue
Command successfully executed.
void initialize(const U32 fileSize, const char *const sourcePath, const char *const destinationPath)
Initialize a StartPacket with sequence number 0.
uint8_t U8
8-bit unsigned integer
void log_ACTIVITY_HI_FileSent(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
void configure(U32 timeout, U32 cooldown, U32 cycleTime, U32 fileQueueDepth)
FwSizeType getSize() const
PlatformQueuePriorityType FwQueuePriorityType
The type of queue priorities used.
Command had execution error.
void log_WARNING_HI_SendDataFail(const Fw::StringBase &sourceFileName, U32 byteOffset) const
const char * toChar() const
Convert to a C-style char*.
Operation was successful.
PlatformIndexType FwIndexType
FwSizeType SizeType
The size type for a buffer - for backwards compatibility.
Send file response struct.
Command failed validation.
RateGroupDivider component implementation.
virtual SizeType length() const
Get the length of the string.
message sent/received okay
static const U32 FILEDOWNLINK_INTERNAL_BUFFER_SIZE
void initialize(const U32 sequenceIndex, const U32 byteOffset, const U16 dataSize, const U8 *const data)
Initialize a data packet.
static const bool FILEDOWNLINK_COMMAND_FAILURES_DISABLED
bool isConnected_FileComplete_OutputPort(FwIndexType portNum)
Implementation of malloc based allocator.
void deinit()
Cleans up file queue before dispatching to underlying component.
void log_ACTIVITY_HI_SendStarted(U32 fileSize, const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName) const
void initialize(const U32 sequenceIndex, const CFDP::Checksum &checksum)
Initialize an end packet.
void log_WARNING_HI_DownlinkPartialFail(const Fw::StringBase &sourceFileName, const Fw::StringBase &destFileName, U32 startOffset, U32 filesize) const
void FileComplete_out(FwIndexType portNum, const Svc::SendFileResponse &resp)
Invoke output port FileComplete.
void initialize(const U32 sequenceIndex)
Initialize a cancel packet.
ExternalSerializeBufferWithMemberCopy getSerializer()
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
The type of an end packet.