windows compiles, some unittests give exceptions

This commit is contained in:
2023-01-25 23:54:46 +01:00
parent 0e7c6b117f
commit dcc28622a5
28 changed files with 155 additions and 128 deletions

View File

@ -9,6 +9,11 @@
#include "fsfw/returnvalues/FwClassIds.h"
#include "fsfw/returnvalues/returnvalue.h"
// Thanks, windows
#ifdef NO_ERROR
#undef NO_ERROR
#endif
namespace cfdp {
static constexpr char CFDP_VERSION_2_NAME[] = "CCSDS 727.0-B-5";

View File

@ -1,5 +1,10 @@
#include "FinishedPduReader.h"
// Thanks, windows
#ifdef NO_ERROR
#undef NO_ERROR
#endif
FinishPduReader::FinishPduReader(const uint8_t* pduBuf, size_t maxSize, FinishedInfo& info)
: FileDirectiveReader(pduBuf, maxSize), finishedInfo(info) {}

View File

@ -1,6 +1,7 @@
#ifndef FSFW_MEMORY_HASFILESYSTEMIF_H_
#define FSFW_MEMORY_HASFILESYSTEMIF_H_
#include <filesystem>
#include <cstddef>
#include "FileSystemArgsIF.h"
@ -10,16 +11,17 @@
#include "fsfw/returnvalues/returnvalue.h"
struct FilesystemParams {
explicit FilesystemParams(const char* path) : path(path) {}
explicit FilesystemParams(const std::filesystem::path::value_type* path) : path(path) {}
const char* path;
const std::filesystem::path::value_type* path;
FileSystemArgsIF* args = nullptr;
};
struct FileOpParams {
FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {}
FileOpParams(const std::filesystem::path::value_type* path, size_t size)
: fsParams(path), size(size) {}
[[nodiscard]] const char* path() const { return fsParams.path; }
[[nodiscard]] const std::filesystem::path::value_type* path() const { return fsParams.path; }
[[nodiscard]] FileSystemArgsIF* args() const { return fsParams.args; }
@ -139,8 +141,11 @@ class HasFileSystemIF {
* @param args Any other arguments which an implementation might require
* @return
*/
virtual ReturnValue_t removeFile(const char* path, FileSystemArgsIF* args) = 0;
virtual ReturnValue_t removeFile(const char* path) { return removeFile(path, nullptr); }
virtual ReturnValue_t removeFile(const std::filesystem::path::value_type* path,
FileSystemArgsIF* args) = 0;
virtual ReturnValue_t removeFile(const std::filesystem::path::value_type* path) {
return removeFile(path, nullptr);
}
/**
* @brief Generic function to create a directory
@ -165,10 +170,12 @@ class HasFileSystemIF {
return removeDirectory(params, false);
}
virtual ReturnValue_t rename(const char* oldPath, const char* newPath) {
virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath,
const std::filesystem::path::value_type* newPath) {
return rename(oldPath, newPath, nullptr);
}
virtual ReturnValue_t rename(const char* oldPath, const char* newPath,
virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath,
const std::filesystem::path::value_type* newPath,
FileSystemArgsIF* args) = 0;
};

View File

@ -58,7 +58,7 @@ class Type : public SerializeIF {
template <typename T>
struct PodTypeConversion {
static_assert(not std::is_same<T, bool>::value,
static_assert(! std::is_same<T, bool>::value,
"Do not use boolean for the PoolEntry type, use uint8_t "
"instead! The ECSS standard defines a boolean as a one bit "
"field. Therefore it is preferred to store a boolean as an "

View File

@ -37,16 +37,16 @@ void arrayprinter::print(const uint8_t *data, size_t size, OutputType type, bool
}
}
void arrayprinter::printHex(const uint8_t *data, size_t size, size_t maxCharPerLine) {
void arrayprinter::printHex(const uint8_t *data, size_t datasize, size_t maxCharPerLine) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
if (sif::info.crAdditionEnabled()) {
std::cout << "\r" << std::endl;
}
std::cout << "hex [" << std::setfill('0') << std::hex;
for (size_t i = 0; i < size; i++) {
for (size_t i = 0; i < datasize; i++) {
std::cout << std::setw(2) << static_cast<int>(data[i]);
if (i < size - 1) {
if (i < datasize - 1) {
std::cout << ",";
if (i > 0 and (i + 1) % maxCharPerLine == 0) {
std::cout << std::endl;
@ -56,27 +56,11 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, size_t maxCharPerL
std::cout << std::dec << std::setfill(' ');
std::cout << "]" << std::endl;
#else
// General format: 0x01, 0x02, 0x03 so it is number of chars times 6
// plus line break plus small safety margin.
char printBuffer[(size + 1) * 7 + 1] = {};
size_t currentPos = 0;
for (size_t i = 0; i < size; i++) {
// To avoid buffer overflows.
if (sizeof(printBuffer) - currentPos <= 7) {
break;
}
currentPos += snprintf(printBuffer + currentPos, 6, "%02x", data[i]);
if (i < size - 1) {
currentPos += sprintf(printBuffer + currentPos, ",");
if ((i + 1) % maxCharPerLine == 0) {
currentPos += sprintf(printBuffer + currentPos, "\n");
}
}
printf("hex [");
for (size_t i = 0; i < datasize; i++) {
printf("0x%02x ", data[i]);
}
#if FSFW_DISABLE_PRINTOUT == 0
printf("hex [%s]\n", printBuffer);
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
printf("]\n");
#endif
}
@ -100,26 +84,10 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, size_t maxCharPerL
#else
// General format: 32,243,-12 so it is number of chars times 4
// plus line break plus small safety margin.
uint16_t expectedLines = ceil((double)size / maxCharPerLine);
char printBuffer[size * 4 + 1 + expectedLines] = {};
size_t currentPos = 0;
for (size_t i = 0; i < size; i++) {
// To avoid buffer overflows.
if (sizeof(printBuffer) - currentPos <= 4) {
break;
}
currentPos += snprintf(printBuffer + currentPos, 4, "%d", data[i]);
if (i < size - 1) {
currentPos += sprintf(printBuffer + currentPos, ",");
if ((i + 1) % maxCharPerLine == 0) {
currentPos += sprintf(printBuffer + currentPos, "\n");
}
}
//TODO
}
#if FSFW_DISABLE_PRINTOUT == 0
printf("dec [%s]\n", printBuffer);
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
#endif
}

View File

@ -24,8 +24,8 @@
#else
#ifdef WIN32
#include <windows.h>
#include <winsock2.h>
#include <windows.h>
#if REG_DWORD == REG_DWORD_LITTLE_ENDIAN
#define BYTE_ORDER_SYSTEM LITTLE_ENDIAN
#else

View File

@ -17,6 +17,7 @@
#ifdef PLATFORM_WIN
#include <winsock2.h>
#include <ws2tcpip.h>
typedef SSIZE_T ssize_t;
#elif defined(PLATFORM_UNIX)
#include <netdb.h>

View File

@ -8,6 +8,7 @@
#ifdef PLATFORM_WIN
#include <winsock2.h>
typedef SSIZE_T ssize_t;
#elif defined(PLATFORM_UNIX)
#include <sys/socket.h>
#include <sys/types.h>

View File

@ -7,6 +7,7 @@
#ifdef PLATFORM_WIN
#include <ws2tcpip.h>
typedef SSIZE_T ssize_t;
#elif defined(PLATFORM_UNIX)
#include <arpa/inet.h>
#include <netdb.h>

View File

@ -9,7 +9,7 @@
#include "fsfw/serviceinterface/ServiceInterface.h"
#if defined(PLATFORM_WIN)
#include <processthreadsapi.h>
#include "fsfw/osal/windows/winTaskHelpers.h"
#elif defined(PLATFORM_UNIX)

View File

@ -4,6 +4,7 @@
#include <fsfw/returnvalues/returnvalue.h>
#include <thread>
#include <string>
namespace tasks {

View File

@ -5,7 +5,8 @@
#ifdef _WIN32
#include <minwindef.h>
#include <windows.h>
#include <processthreadsapi.h>
namespace tasks {

View File

@ -33,7 +33,7 @@
* @author baetz
* @ingroup serialize
*/
template <typename T, typename count_t = uint8_t>
template <typename T, typename count_t = size_t>
class SerialLinkedListAdapter : public SinglyLinkedList<T>, public SerializeIF {
public:
SerialLinkedListAdapter(typename LinkedElement<T>::Iterator start, bool printCount = false)

View File

@ -8,6 +8,7 @@
#ifdef PLATFORM_WIN
// wtf? Required for timeval!
#include <winsock2.h>
#include <winsock.h>
#endif

View File

@ -1,7 +1,7 @@
#include <stdbool.h>
#include <stdio.h>
void __attribute__((weak)) printChar(const char* character, bool errStream) {
void printChar(const char* character, bool errStream) {
if (errStream) {
fprintf(stderr, "%c", *character);
} else {

View File

@ -69,7 +69,8 @@ ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t
return returnvalue::OK;
}
ReturnValue_t HostFilesystem::removeFile(const char *path_, FileSystemArgsIF *args) {
ReturnValue_t HostFilesystem::removeFile(const std::filesystem::path::value_type *path_,
FileSystemArgsIF *args) {
if (path_ == nullptr) {
return returnvalue::FAILED;
}
@ -132,7 +133,8 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele
return HasFileSystemIF::GENERIC_DIR_ERROR;
}
ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_,
ReturnValue_t HostFilesystem::rename(const std::filesystem::path::value_type *oldPath_,
const std::filesystem::path::value_type *newPath_,
FileSystemArgsIF *args) {
if (oldPath_ == nullptr or newPath_ == nullptr) {
return returnvalue::FAILED;

View File

@ -15,10 +15,12 @@ class HostFilesystem : public HasFileSystemIF {
ReturnValue_t readFromFile(FileOpParams fileOpInfo, uint8_t **buffer, size_t &readSize,
size_t maxSize) override;
ReturnValue_t createFile(FilesystemParams params, const uint8_t *data, size_t size) override;
ReturnValue_t removeFile(const char *path, FileSystemArgsIF *args) override;
ReturnValue_t removeFile(const std::filesystem::path::value_type *path, FileSystemArgsIF *args) override;
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
ReturnValue_t rename(const char *oldPath, const char *newPath, FileSystemArgsIF *args) override;
ReturnValue_t rename(const std::filesystem::path::value_type *oldPath,
const std::filesystem::path::value_type *newPath,
FileSystemArgsIF *args) override;
std::error_code errorCode;
using HasFileSystemIF::createDirectory;