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 FileDownlink::File
5 //
6 // \copyright
7 // Copyright 2009-2015, 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 <FpConfig.hpp>
16 #include <Os/FileSystem.hpp>
17 
18 namespace Svc {
19 
20  Os::File::Status FileDownlink::File ::
21  open(
22  const char *const sourceFileName,
23  const char *const destFileName
24  )
25  {
26 
27  // Set source name
28  Fw::LogStringArg sourceLogStringArg(sourceFileName);
29  this->m_sourceName = sourceLogStringArg;
30 
31  // Set dest name
32  Fw::LogStringArg destLogStringArg(destFileName);
33  this->m_destName = destLogStringArg;
34 
35  // Set size
36  FwSizeType file_size;
37  const Os::FileSystem::Status status =
38  Os::FileSystem::getFileSize(sourceFileName, file_size);
39  if (status != Os::FileSystem::OP_OK)
40  return Os::File::BAD_SIZE;
41  // If the size does not cast cleanly to the desired U32 type, return size error
42  if (static_cast<FwSizeType>(static_cast<U32>(file_size)) != file_size) {
43  return Os::File::BAD_SIZE;
44  }
45  this->m_size = static_cast<U32>(file_size);
46 
47  // Initialize checksum
48  CFDP::Checksum checksum;
49  this->m_checksum = checksum;
50 
51  // Open osFile for reading
52  return this->m_osFile.open(sourceFileName, Os::File::OPEN_READ);
53 
54  }
55 
56  Os::File::Status FileDownlink::File ::
57  read(
58  U8 *const data,
59  const U32 byteOffset,
60  const U32 size
61  )
62  {
63 
64  Os::File::Status status;
65  status = this->m_osFile.seek(byteOffset);
66  if (status != Os::File::OP_OK)
67  return status;
68 
69  NATIVE_INT_TYPE intSize = size;
70  status = this->m_osFile.read(data, intSize);
71  if (status != Os::File::OP_OK)
72  return status;
73  // Force a bad size error when the U32 carrying size is bad
74  if (static_cast<U32>(intSize) != size) {
75  return Os::File::BAD_SIZE;
76  }
77  this->m_checksum.update(data, byteOffset, size);
78 
79  return Os::File::OP_OK;
80 
81  }
82 }
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:26
PlatformSizeType FwSizeType
Definition: FpConfig.h:18
C++-compatible configuration header for fprime configuration.
Class representing a CFDP checksum.
Definition: Checksum.hpp:23
Status
Definition: File.hpp:23
@ BAD_SIZE
Invalid size parameter.
Definition: File.hpp:28
@ OP_OK
Operation was successful.
Definition: File.hpp:24
@ OPEN_READ
Open file for reading.
Definition: File.hpp:15
Status getFileSize(const char *path, FwSizeType &size)
append file origin to destination file. If boolean true, creates a brand new file if the destination ...
Definition: FileSystem.cpp:38
@ OP_OK
Operation was successful.
Definition: FileSystem.hpp:15