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>(
sizeof(
struct FileEntry)));
64 void FileDownlink ::Run_handler(
const FwIndexType portNum, U32 context) {
65 switch (this->m_mode.get()) {
70 static_cast<FwSizeType>(
sizeof(this->m_curEntry)),
71 Os::Queue::BlockingType::NONBLOCKING, real_size, prio);
77 sendFile(this->m_curEntry.srcFilename, this->m_curEntry.destFilename, this->m_curEntry.offset,
78 this->m_curEntry.length);
81 case Mode::COOLDOWN: {
82 if (this->m_curTimer >= this->m_cooldown) {
86 this->m_curTimer += m_cycleTime;
92 if (this->m_curTimer >= this->m_timeout) {
95 this->enterCooldown();
99 this->m_curTimer += m_cycleTime;
114 struct FileEntry entry;
115 entry.srcFilename[0] = 0;
116 entry.destFilename[0] = 0;
117 entry.offset = offset;
118 entry.length = length;
119 entry.source = FileDownlink::PORT;
122 entry.context = m_cntxId++;
127 static_cast<FwSizeType>(
sizeof(entry.srcFilename)));
129 static_cast<FwSizeType>(
sizeof(entry.destFilename)));
131 Os::Queue::Status status = m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)),
132 0, Os::Queue::BlockingType::NONBLOCKING);
140 void FileDownlink ::pingIn_handler(
const FwIndexType portNum, U32 key) {
151 FW_ASSERT(this->m_mode.get() == Mode::WAIT || this->m_mode.get() == Mode::CANCEL,
159 else if (this->m_mode.get() == Mode::WAIT) {
160 this->m_mode.set(Mode::DOWNLINK);
163 this->downlinkPacket();
170 void FileDownlink ::SendFile_cmdHandler(
const FwOpcodeType opCode,
174 struct FileEntry entry;
175 entry.srcFilename[0] = 0;
176 entry.destFilename[0] = 0;
179 entry.source = FileDownlink::COMMAND;
180 entry.opCode = opCode;
181 entry.cmdSeq = cmdSeq;
182 entry.context = std::numeric_limits<U32>::max();
187 static_cast<FwSizeType>(
sizeof(entry.srcFilename)));
189 static_cast<FwSizeType>(
sizeof(entry.destFilename)));
191 Os::Queue::Status status = m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)),
192 0, Os::Queue::BlockingType::NONBLOCKING);
199 void FileDownlink ::SendPartial_cmdHandler(
FwOpcodeType opCode,
205 struct FileEntry entry;
206 entry.srcFilename[0] = 0;
207 entry.destFilename[0] = 0;
208 entry.offset = startOffset;
209 entry.length = length;
210 entry.source = FileDownlink::COMMAND;
211 entry.opCode = opCode;
212 entry.cmdSeq = cmdSeq;
213 entry.context = std::numeric_limits<U32>::max();
218 static_cast<FwSizeType>(
sizeof(entry.srcFilename)));
220 static_cast<FwSizeType>(
sizeof(entry.destFilename)));
222 Os::Queue::Status status = m_fileQueue.
send(reinterpret_cast<U8*>(&entry), static_cast<FwSizeType>(
sizeof(entry)),
223 0, Os::Queue::BlockingType::NONBLOCKING);
230 void FileDownlink ::Cancel_cmdHandler(
const FwOpcodeType opCode,
const U32 cmdSeq) {
232 if (this->m_mode.get() == Mode::DOWNLINK || this->m_mode.get() == Mode::WAIT) {
233 this->m_mode.set(Mode::CANCEL);
242 Fw::CmdResponse FileDownlink ::statusToCmdResp(SendFileStatus status) {
261 void FileDownlink ::sendResponse(SendFileStatus resp) {
262 if (this->m_curEntry.source == FileDownlink::COMMAND) {
263 this->
cmdResponse_out(this->m_curEntry.opCode, this->m_curEntry.cmdSeq, statusToCmdResp(resp));
273 void FileDownlink ::sendFile(
const char* sourceFilename,
const char* destFilename, U32 startOffset, U32 length) {
280 this->m_warnings.fileOpenError();
285 if (startOffset >= this->m_file.getSize()) {
286 this->enterCooldown();
288 this->m_file.getSize());
292 }
else if (startOffset + length > this->m_file.getSize()) {
296 this->m_file.getSourceName(), this->m_file.getDestName());
297 length = this->m_file.getSize() - startOffset;
301 this->getBuffer(this->m_buffer, FILE_PACKET);
302 this->sendStartPacket();
303 this->m_mode.set(Mode::WAIT);
304 this->m_sequenceIndex = 1;
305 this->m_curTimer = 0;
306 this->m_byteOffset = startOffset;
312 this->m_endOffset = startOffset + length;
315 this->m_file.getDestName());
316 this->m_endOffset = this->m_file.getSize();
321 FW_ASSERT(byteOffset < this->m_endOffset);
322 const U32 maxDataSize =
325 (byteOffset + maxDataSize > this->m_endOffset) ? (this->m_endOffset - byteOffset) : maxDataSize;
326 U8 buffer[maxDataSize];
328 if (dataSize + byteOffset == this->m_endOffset) {
332 const Os::File::Status status = this->m_file.read(buffer, byteOffset, dataSize);
334 this->m_warnings.fileRead(status);
339 dataPacket.
initialize(this->m_sequenceIndex, byteOffset, static_cast<U16>(dataSize), buffer);
340 ++this->m_sequenceIndex;
343 this->sendFilePacket(filePacket);
345 byteOffset += dataSize;
350 void FileDownlink ::sendCancelPacket() {
353 cancelPacket.
initialize(this->m_sequenceIndex);
357 this->getBuffer(buffer, CANCEL_PACKET);
359 static_cast<FwAssertArgType>(buffer.
getSize()),
368 status = filePacket.
toBuffer(offsetBuffer);
371 this->m_packetsSent.packetSent();
374 void FileDownlink ::sendEndPacket() {
376 this->m_file.getChecksum(checksum);
379 endPacket.
initialize(this->m_sequenceIndex, checksum);
383 this->sendFilePacket(filePacket);
386 void FileDownlink ::sendStartPacket() {
388 startPacket.
initialize(this->m_file.getSize(), this->m_file.getSourceName().toChar(),
389 this->m_file.getDestName().toChar());
392 this->sendFilePacket(filePacket);
395 void FileDownlink ::sendFilePacket(
const Fw::FilePacket& filePacket) {
399 static_cast<FwAssertArgType>(this->m_buffer.
getSize()));
407 status = filePacket.
toBuffer(offsetBuffer);
410 this->m_buffer.
setSize(bufferSize);
414 this->m_packetsSent.packetSent();
417 void FileDownlink ::enterCooldown() {
418 this->m_file.getOsFile().close();
419 this->m_mode.set(Mode::COOLDOWN);
421 this->m_curTimer = 0;
424 void FileDownlink ::downlinkPacket() {
426 static_cast<FwAssertArgType>(this->m_lastCompletedType));
427 FW_ASSERT(this->m_mode.get() == Mode::CANCEL || this->m_mode.get() == Mode::DOWNLINK,
431 this->sendCancelPacket();
440 this->enterCooldown();
449 this->sendEndPacket();
452 this->m_mode.set(Mode::WAIT);
453 this->m_curTimer = 0;
456 void FileDownlink ::finishHelper(
bool cancel) {
459 this->m_filesSent.fileSent();
464 this->enterCooldown();
468 void FileDownlink ::getBuffer(
Fw::Buffer& buffer, PacketType type) {
470 FW_ASSERT(type < COUNT_PACKET_TYPE && type >= 0, static_cast<FwAssertArgType>(type));
472 buffer.
setData(this->m_memoryStore[type]);
Serialization/Deserialization operation was successful.
void fromCancelPacket(const CancelPacket &cancelPacket)
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
The type of a cancel packet.
Status
status returned from the queue send function
SerializeStatus serialize(U8 val)
serialize 8-bit unsigned int
void setContext(SizeType context)
void setSize(SizeType size)
void fromEndPacket(const EndPacket &endPacket)
The type of a data packet.
void fromStartPacket(const StartPacket &startPacket)
void pingOut_out(FwIndexType portNum, U32 key)
Invoke output port pingOut.
Enum representing a command response.
FwIndexType getNum_FileComplete_OutputPorts() const
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.
U32 FwOpcodeType
The type of a command opcode.
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.
SizeType length() const
Get length of string.
void bufferSendOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferSendOut.
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)
Status create(const Fw::StringBase &name, FwSizeType depth, FwSizeType messageSize) override
create queue storage through delegate
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
Operation was successful.
U32 FwPacketDescriptorType
The type of a com packet descriptor.
PlatformIndexType FwIndexType
Send file response struct.
Command failed validation.
RateGroupDivider component implementation.
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)
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.
U32 SizeType
The size type for a buffer.
void initialize(const U32 sequenceIndex)
Initialize a cancel packet.
ExternalSerializeBufferWithMemberCopy getSerializer()
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
virtual const CHAR * toChar() const =0
The type of an end packet.