fprime/Svc/FileUplink/File.cpp
Thomas Boyer-Chammard c69ff72110
Format Svc and add to CI (#3978)
* Format Svc and add to CI

* Fix comlogger include

* fix assert UTs

* Fix static analysis warning

* formatting
2025-08-04 16:21:47 -07:00

52 lines
1.7 KiB
C++

// ======================================================================
// \title File.cpp
// \author bocchino
// \brief cpp file for FileUplink::File
//
// \copyright
// Copyright 2009-2016, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include <Fw/Types/Assert.hpp>
#include <Fw/Types/StringUtils.hpp>
#include <Svc/FileUplink/FileUplink.hpp>
namespace Svc {
Os::File::Status FileUplink::File ::open(const Fw::FilePacket::StartPacket& startPacket) {
const U32 length = startPacket.getDestinationPath().getLength();
char path[Fw::FilePacket::PathName::MAX_LENGTH + 1];
memcpy(path, startPacket.getDestinationPath().getValue(), length);
path[length] = 0;
Fw::LogStringArg logStringArg(path);
this->name = logStringArg;
this->size = startPacket.getFileSize();
CFDP::Checksum checksum;
this->m_checksum = checksum;
return this->osFile.open(path, Os::File::OPEN_WRITE);
}
Os::File::Status FileUplink::File ::write(const U8* const data, const U32 byteOffset, const U32 length) {
Os::File::Status status;
status = this->osFile.seek(byteOffset, Os::File::SeekType::ABSOLUTE);
if (status != Os::File::OP_OK) {
return status;
}
FwSizeType intLength = length;
// Note: not waiting for the file write to finish
status = this->osFile.write(data, intLength, Os::File::WaitType::NO_WAIT);
if (status != Os::File::OP_OK) {
return status;
}
FW_ASSERT(static_cast<U32>(intLength) == length, static_cast<FwAssertArgType>(intLength));
this->m_checksum.update(data, byteOffset, length);
return Os::File::OP_OK;
}
} // namespace Svc