F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
File.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title File.cpp
3 // \author bocchino
4 // \brief cpp file for FileUplink::File
5 //
6 // \copyright
7 // Copyright 2009-2016, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
14 #include <Fw/Types/Assert.hpp>
15 #include <Fw/Types/StringUtils.hpp>
16 
17 namespace Svc {
18 
19  Os::File::Status FileUplink::File ::
20  open(const Fw::FilePacket::StartPacket& startPacket)
21  {
22  const U32 length = startPacket.getDestinationPath().getLength();
24  memcpy(path, startPacket.getDestinationPath().getValue(), length);
25  path[length] = 0;
26  Fw::LogStringArg logStringArg(path);
27  this->name = logStringArg;
28  this->size = startPacket.getFileSize();
29  CFDP::Checksum checksum;
30  this->m_checksum = checksum;
31  return this->osFile.open(path, Os::File::OPEN_WRITE);
32  }
33 
34  Os::File::Status FileUplink::File ::
35  write(
36  const U8 *const data,
37  const U32 byteOffset,
38  const U32 length
39  )
40  {
41 
42  Os::File::Status status;
43  status = this->osFile.seek(byteOffset);
44  if (status != Os::File::OP_OK) {
45  return status;
46  }
47 
48  NATIVE_INT_TYPE intLength = length;
49  //Note: not waiting for the file write to finish
50  status = this->osFile.write(data, intLength, false);
51  if (status != Os::File::OP_OK) {
52  return status;
53  }
54 
55  FW_ASSERT(static_cast<U32>(intLength) == length, intLength);
56  this->m_checksum.update(data, byteOffset, length);
57  return Os::File::OP_OK;
58 
59  }
60 
61 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
Class representing a CFDP checksum.
Definition: Checksum.hpp:23
const char * getValue(void) const
Get the path name value.
Definition: FilePacket.hpp:78
U32 getLength(void) const
Get the length of the path name value.
Definition: FilePacket.hpp:73
Status
Definition: File.hpp:23
@ OP_OK
Operation was successful.
Definition: File.hpp:24
@ OPEN_WRITE
Open file for writing.
Definition: File.hpp:16
The type of a start packet.
Definition: FilePacket.hpp:139
const PathName & getDestinationPath() const
Get the destination path.
Definition: FilePacket.hpp:173
U32 getFileSize() const
Get the file size.
Definition: FilePacket.hpp:183