mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
* Created new SerialBufferBase as a parent of SerializeBufferBase. Renaming interface functions to be less confusing. * Deprecating copyRawOffset. No direct use-cases in F' core. * Make SerialBufferBase a true pure virtual interface. * Changing Serializable to work with SerialBufferBase parent interface. * Changing copyRaw and copyRawOffset to work with SerialBufferBase * Updating documentation for SerialBufferBase usage * Adding some documentation. Adding missing ASSERT in copyRaw. Fixing some bugs that new ASSERT uncovered. * Renaming SerializeBufferBase to LinearBufferBase. Add a using declaration to maintain backwards compatability. Properly mark LinearBufferBase functions as override. * Filling in the rest of the docstrings for the classes in Serializable * Removing redundant virtual keyword on override function * Applying clang formatting * Incorporating PR comments * Fix compile issues * Bump version to alpha * Format * v --------- Co-authored-by: M Starch <LeStarch@googlemail.com>
97 lines
2.5 KiB
C++
97 lines
2.5 KiB
C++
// ======================================================================
|
|
// \title CRCs.hpp
|
|
// \author Rob Bocchino
|
|
// \brief AMPCS CRC files
|
|
//
|
|
// \copyright
|
|
// Copyright (C) 2009-2018 California Institute of Technology.
|
|
// ALL RIGHTS RESERVED. United States Government Sponsorship
|
|
// acknowledged.
|
|
//
|
|
// ======================================================================
|
|
|
|
#include "Svc/CmdSequencer/test/ut/SequenceFiles/AMPCS/CRCs.hpp"
|
|
#include "Fw/Types/SerialBuffer.hpp"
|
|
#include "Fw/Types/String.hpp"
|
|
#include "Os/File.hpp"
|
|
#include "Os/FileSystem.hpp"
|
|
#include "gtest/gtest.h"
|
|
|
|
#define BUFFER_SIZE 256
|
|
|
|
namespace Svc {
|
|
|
|
namespace SequenceFiles {
|
|
|
|
namespace AMPCS {
|
|
|
|
namespace CRCs {
|
|
|
|
namespace {
|
|
|
|
//! Open a file
|
|
void openFile(Os::File& file, //!< The file
|
|
const char* const fileName, //!< The file name
|
|
const Os::File::Mode mode //!< The mode
|
|
) {
|
|
const Os::File::Status fileStatus = file.open(fileName, mode);
|
|
ASSERT_EQ(Os::File::OP_OK, fileStatus);
|
|
}
|
|
|
|
//! Write a file
|
|
void writeFile(Os::File& file, //!< The file
|
|
const U8* buffer, //!< The buffer
|
|
const U32 size //!< The number of bytes to write
|
|
) {
|
|
FwSizeType sizeThenActualSize = size;
|
|
const Os::File::Status status = file.write(buffer, sizeThenActualSize, Os::File::WaitType::WAIT);
|
|
ASSERT_EQ(Os::File::OP_OK, status);
|
|
const U32 actualSize = sizeThenActualSize;
|
|
ASSERT_EQ(size, actualSize);
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void createFile(Fw::SerializeBufferBase& buffer, const char* const fileName) {
|
|
CRC crc;
|
|
computeCRC(buffer, crc);
|
|
writeCRC(crc.m_computed, fileName);
|
|
}
|
|
|
|
void computeCRC(Fw::SerializeBufferBase& buffer, CRC& crc) {
|
|
crc.init();
|
|
const U8* const addr = buffer.getBuffAddr();
|
|
const U32 size = buffer.getSize();
|
|
crc.update(addr, size);
|
|
crc.finalize();
|
|
}
|
|
|
|
void removeFile(const char* const fileName) {
|
|
Fw::String s("rm -f ");
|
|
s += fileName;
|
|
s += ".CRC32";
|
|
int status = system(s.toChar());
|
|
ASSERT_EQ(0, status);
|
|
}
|
|
|
|
void writeCRC(const U32 crc, const char* const fileName) {
|
|
Os::File file;
|
|
U8 buffer[sizeof crc];
|
|
Fw::SerialBuffer serialBuffer(buffer, sizeof(buffer));
|
|
serialBuffer.serializeFrom(crc);
|
|
const U8* const addr = serialBuffer.getBuffAddr();
|
|
Fw::String hashFileName(fileName);
|
|
hashFileName += ".CRC32";
|
|
openFile(file, hashFileName.toChar(), Os::File::OPEN_WRITE);
|
|
writeFile(file, addr, sizeof(crc));
|
|
file.close();
|
|
}
|
|
|
|
} // namespace CRCs
|
|
|
|
} // namespace AMPCS
|
|
|
|
} // namespace SequenceFiles
|
|
|
|
} // namespace Svc
|