37 m_lastCompletedType(
Fw::FilePacket::T_NONE),
43 this->m_cooldown = cooldown;
44 this->m_cycleTime = cycleTime;
45 this->m_configured =
true;
49 static_cast<FwSizeType>(fileQueueDepth), static_cast<FwSizeType>(
sizeof(
struct FileEntry)));
68 void FileDownlink ::Run_handler(
const FwIndexType portNum, U32 context) {
69 switch (this->m_mode.get()) {
74 static_cast<FwSizeType>(
sizeof(this->m_curEntry)),
75 Os::Queue::BlockingType::NONBLOCKING, real_size, prio);
81 sendFile(this->m_curEntry.srcFilename, this->m_curEntry.destFilename, this->m_curEntry.offset,
82 this->m_curEntry.length);
85 case Mode::COOLDOWN: {
86 if (this->m_curTimer >= this->m_cooldown) {
90 this->m_curTimer += m_cycleTime;
95 this->m_curTimer += m_cycleTime;
109 struct FileEntry entry;
110 entry.offset = offset;
111 entry.length = length;
112 entry.source = FileDownlink::PORT;
115 entry.context = m_cntxId++;
119 entry.srcFilename = sourceFilename;
120 entry.destFilename = destFilename;
122 Os::Queue::Status status = m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)),
123 0, Os::Queue::BlockingType::NONBLOCKING);
131 void FileDownlink ::pingIn_handler(
const FwIndexType portNum, U32 key) {
142 FW_ASSERT(this->m_mode.get() == Mode::WAIT || this->m_mode.get() == Mode::CANCEL,
150 else if (this->m_mode.get() == Mode::WAIT) {
151 this->m_mode.set(Mode::DOWNLINK);
154 this->downlinkPacket();
161 void FileDownlink ::SendFile_cmdHandler(
const FwOpcodeType opCode,
165 struct FileEntry entry;
168 entry.source = FileDownlink::COMMAND;
169 entry.opCode = opCode;
170 entry.cmdSeq = cmdSeq;
171 entry.context = std::numeric_limits<U32>::max();
175 entry.srcFilename = sourceFilename;
176 entry.destFilename = destFilename;
178 Os::Queue::Status status = m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)),
179 0, Os::Queue::BlockingType::NONBLOCKING);
186 void FileDownlink ::SendPartial_cmdHandler(
FwOpcodeType opCode,
192 struct FileEntry entry;
193 entry.offset = startOffset;
194 entry.length = length;
195 entry.source = FileDownlink::COMMAND;
196 entry.opCode = opCode;
197 entry.cmdSeq = cmdSeq;
198 entry.context = std::numeric_limits<U32>::max();
202 entry.srcFilename = sourceFilename;
203 entry.destFilename = destFilename;
205 Os::Queue::Status status = m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)),
206 0, Os::Queue::BlockingType::NONBLOCKING);
213 void FileDownlink ::Cancel_cmdHandler(
const FwOpcodeType opCode,
const U32 cmdSeq) {
215 if (this->m_mode.get() == Mode::DOWNLINK || this->m_mode.get() == Mode::WAIT) {
216 this->m_mode.set(Mode::CANCEL);
225 Fw::CmdResponse FileDownlink ::statusToCmdResp(SendFileStatus status) {
244 void FileDownlink ::sendResponse(SendFileStatus resp) {
245 if (this->m_curEntry.source == FileDownlink::COMMAND) {
246 this->
cmdResponse_out(this->m_curEntry.opCode, this->m_curEntry.cmdSeq, statusToCmdResp(resp));
266 this->m_warnings.fileOpenError();
270 const U32 fileSize = this->m_file.getSize();
274 this->m_warnings.zeroSize();
279 }
else if (startOffset >= fileSize) {
280 this->enterCooldown();
286 }
else if (startOffset + length > fileSize) {
290 this->m_file.getDestName());
291 length = fileSize - startOffset;
295 this->getBuffer(this->m_buffer, FILE_PACKET);
296 this->sendStartPacket();
297 this->m_mode.set(Mode::WAIT);
298 this->m_sequenceIndex = 1;
299 this->m_curTimer = 0;
300 this->m_byteOffset = startOffset;
306 this->m_endOffset = startOffset + length;
309 this->m_file.getDestName());
310 this->m_endOffset = fileSize;
315 FW_ASSERT(byteOffset < this->m_endOffset);
316 const U32 maxDataSize =
319 (byteOffset + maxDataSize > this->m_endOffset) ? (this->m_endOffset - byteOffset) : maxDataSize;
320 U8 buffer[maxDataSize];
322 if (dataSize + byteOffset == this->m_endOffset) {
326 const Os::File::Status status = this->m_file.read(buffer, byteOffset, dataSize);
328 this->m_warnings.fileRead(status);
333 dataPacket.
initialize(this->m_sequenceIndex, byteOffset, static_cast<U16>(dataSize), buffer);
334 ++this->m_sequenceIndex;
337 this->sendFilePacket(filePacket);
339 byteOffset += dataSize;
344 void FileDownlink ::sendCancelPacket() {
347 cancelPacket.
initialize(this->m_sequenceIndex);
351 this->getBuffer(buffer, CANCEL_PACKET);
353 static_cast<FwAssertArgType>(buffer.
getSize()),
363 status = filePacket.
toBuffer(offsetBuffer);
366 this->m_packetsSent.packetSent();
369 void FileDownlink ::sendEndPacket() {
371 this->m_file.getChecksum(checksum);
374 endPacket.
initialize(this->m_sequenceIndex, checksum);
378 this->sendFilePacket(filePacket);
381 void FileDownlink ::sendStartPacket() {
383 startPacket.
initialize(this->m_file.getSize(), this->m_file.getSourceName().toChar(),
384 this->m_file.getDestName().toChar());
387 this->sendFilePacket(filePacket);
390 void FileDownlink ::sendFilePacket(
const Fw::FilePacket& filePacket) {
394 static_cast<FwAssertArgType>(this->m_buffer.
getSize()));
397 static_cast<FwPacketDescriptorType>(Fw::ComPacketType::FW_PACKET_FILE));
403 status = filePacket.
toBuffer(offsetBuffer);
406 this->m_buffer.
setSize(bufferSize);
410 this->m_packetsSent.packetSent();
413 void FileDownlink ::enterCooldown() {
414 this->m_file.getOsFile().close();
415 this->m_mode.set(Mode::COOLDOWN);
417 this->m_curTimer = 0;
420 void FileDownlink ::downlinkPacket() {
422 static_cast<FwAssertArgType>(this->m_lastCompletedType));
423 FW_ASSERT(this->m_mode.get() == Mode::CANCEL || this->m_mode.get() == Mode::DOWNLINK,
427 this->sendCancelPacket();
436 this->enterCooldown();
445 this->sendEndPacket();
448 this->m_mode.set(Mode::WAIT);
449 this->m_curTimer = 0;
452 void FileDownlink ::finishHelper(
bool cancel) {
455 this->m_filesSent.fileSent();
460 this->enterCooldown();
464 void FileDownlink ::getBuffer(
Fw::Buffer& buffer, PacketType type) {
466 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, static_cast<FwAssertArgType>(type));
468 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
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
SerializeStatus
forward declaration for string
void configure(U32 cooldown, U32 cycleTime, U32 fileQueueDepth)
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
void deinit() override
Allows de-initialization on teardown.
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 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
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
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.