windows building again
This commit is contained in:
@ -2,7 +2,6 @@
|
||||
#define FSFW_MEMORY_HASFILESYSTEMIF_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
|
||||
#include "FileSystemArgsIF.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
@ -11,17 +10,16 @@
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
|
||||
struct FilesystemParams {
|
||||
explicit FilesystemParams(const std::filesystem::path::value_type* path) : path(path) {}
|
||||
explicit FilesystemParams(const char* path) : path(path) {}
|
||||
|
||||
const std::filesystem::path::value_type* path;
|
||||
const char* path;
|
||||
FileSystemArgsIF* args = nullptr;
|
||||
};
|
||||
|
||||
struct FileOpParams {
|
||||
FileOpParams(const std::filesystem::path::value_type* path, size_t size)
|
||||
: fsParams(path), size(size) {}
|
||||
FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {}
|
||||
|
||||
[[nodiscard]] const std::filesystem::path::value_type* path() const { return fsParams.path; }
|
||||
[[nodiscard]] const char* path() const { return fsParams.path; }
|
||||
|
||||
[[nodiscard]] FileSystemArgsIF* args() const { return fsParams.args; }
|
||||
|
||||
@ -141,11 +139,8 @@ class HasFileSystemIF {
|
||||
* @param args Any other arguments which an implementation might require
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
}
|
||||
virtual ReturnValue_t removeFile(const char* path, FileSystemArgsIF* args) = 0;
|
||||
virtual ReturnValue_t removeFile(const char* path) { return removeFile(path, nullptr); }
|
||||
|
||||
/**
|
||||
* @brief Generic function to create a directory
|
||||
@ -170,12 +165,10 @@ class HasFileSystemIF {
|
||||
return removeDirectory(params, false);
|
||||
}
|
||||
|
||||
virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath,
|
||||
const std::filesystem::path::value_type* newPath) {
|
||||
virtual ReturnValue_t rename(const char* oldPath, const char* newPath) {
|
||||
return rename(oldPath, newPath, nullptr);
|
||||
}
|
||||
virtual ReturnValue_t rename(const std::filesystem::path::value_type* oldPath,
|
||||
const std::filesystem::path::value_type* newPath,
|
||||
virtual ReturnValue_t rename(const char* oldPath, const char* newPath,
|
||||
FileSystemArgsIF* args) = 0;
|
||||
};
|
||||
|
||||
|
@ -24,8 +24,11 @@
|
||||
#else
|
||||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
// Thanks, windows
|
||||
// clang-format off
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
// clang-format on
|
||||
#if REG_DWORD == REG_DWORD_LITTLE_ENDIAN
|
||||
#define BYTE_ORDER_SYSTEM LITTLE_ENDIAN
|
||||
#else
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#elif defined(PLATFORM_UNIX)
|
||||
#include <netdb.h>
|
||||
|
@ -5,8 +5,11 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <processthreadsapi.h>
|
||||
// Thanks, windows
|
||||
// clang-format off
|
||||
#include <windows.h>
|
||||
#include <processthreadsapi.h>
|
||||
// clang-format on
|
||||
|
||||
namespace tasks {
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
target_sources(
|
||||
${LIB_FSFW_NAME}
|
||||
PRIVATE CCSDSTime.cpp Countdown.cpp Stopwatch.cpp TimeMessage.cpp
|
||||
CdsShortTimeStamper.cpp ClockCommon.cpp)
|
||||
CdsShortTimeStamper.cpp ClockCommon.cpp boost_timegm.cpp)
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
#include "boost_timegm.h"
|
||||
|
||||
#include "fsfw/ipc/MutexGuard.h"
|
||||
#include "fsfw/timemanager/Clock.h"
|
||||
|
||||
@ -56,8 +58,9 @@ ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) {
|
||||
ReturnValue_t Clock::convertTimevalToTimeOfDay(const timeval* from, TimeOfDay_t* to) {
|
||||
struct tm time_tm;
|
||||
// WINDOWS does not provide gmtime_r, but gmtime_s
|
||||
#ifdef PLATFORM_WIN
|
||||
errno_t result = gmtime_s(&time_tm, &from->tv_sec);
|
||||
#ifdef _MSC_VER
|
||||
time_t seconds = from->tv_sec;
|
||||
errno_t result = gmtime_s(&time_tm, &seconds);
|
||||
if (result != 0) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
@ -92,28 +95,11 @@ ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval*
|
||||
|
||||
time_tm.tm_isdst = 0;
|
||||
|
||||
// Windows:
|
||||
// time_t seconds = _mkgmtime(&time_tm);
|
||||
// Glibc:
|
||||
// time_t seconds = timegm(&time_tm);
|
||||
// Portable (?)
|
||||
char* tz;
|
||||
tz = getenv("TZ");
|
||||
setenv("TZ", "", 1);
|
||||
tzset();
|
||||
time_t seconds = mktime(&time_tm);
|
||||
if (tz)
|
||||
setenv("TZ", tz, 1);
|
||||
else
|
||||
unsetenv("TZ");
|
||||
tzset();
|
||||
time_t seconds = internal_timegm(&time_tm);
|
||||
|
||||
to->tv_sec = seconds;
|
||||
to->tv_usec = from->usecond;
|
||||
|
||||
if (seconds == (time_t)-1) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef FSFW_TIMEMANAGER_TIMEREADERIF_H
|
||||
#define FSFW_TIMEMANAGER_TIMEREADERIF_H
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <ctime>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@ -10,8 +10,8 @@
|
||||
|
||||
#ifdef PLATFORM_WIN
|
||||
// wtf? Required for timeval!
|
||||
#include <winsock.h>
|
||||
#include <winsock2.h>
|
||||
#include <winsock.h>
|
||||
#endif
|
||||
|
||||
#include "TimeStampIF.h"
|
||||
|
69
src/fsfw/timemanager/boost_timegm.cpp
Normal file
69
src/fsfw/timemanager/boost_timegm.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
// (C) Copyright Howard Hinnant
|
||||
// (C) Copyright 2010-2011 Vicente J. Botet Escriba
|
||||
// Use, modification and distribution are subject to the Boost Software License,
|
||||
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt).
|
||||
|
||||
//===-------------------------- locale ------------------------------------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is dual licensed under the MIT and the University of Illinois Open
|
||||
// Source Licenses. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// This code was adapted by Vicente from Howard Hinnant's experimental work
|
||||
// on chrono i/o to Boost and some functions from libc++/locale to emulate the missing
|
||||
// time_get::get()
|
||||
|
||||
|
||||
#include "boost_timegm.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
int32_t is_leap(int32_t year) {
|
||||
if (year % 400 == 0) return 1;
|
||||
if (year % 100 == 0) return 0;
|
||||
if (year % 4 == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
int32_t days_from_0(int32_t year) {
|
||||
year--;
|
||||
return 365 * year + (year / 400) - (year / 100) + (year / 4);
|
||||
}
|
||||
int32_t days_from_1970(int32_t year) {
|
||||
static const int32_t days_from_0_to_1970 = days_from_0(1970);
|
||||
return days_from_0(year) - days_from_0_to_1970;
|
||||
}
|
||||
int32_t days_from_1jan(int32_t year, int32_t month, int32_t day) {
|
||||
static const int32_t days[2][12] = {{0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334},
|
||||
{0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}};
|
||||
|
||||
return days[is_leap(year)][month - 1] + day - 1;
|
||||
}
|
||||
|
||||
|
||||
time_t internal_timegm(std::tm const *t) {
|
||||
int year = t->tm_year + 1900;
|
||||
int month = t->tm_mon;
|
||||
if (month > 11) {
|
||||
year += month / 12;
|
||||
month %= 12;
|
||||
} else if (month < 0) {
|
||||
int years_diff = (-month + 11) / 12;
|
||||
year -= years_diff;
|
||||
month += 12 * years_diff;
|
||||
}
|
||||
month++;
|
||||
int day = t->tm_mday;
|
||||
int day_of_year = days_from_1jan(year, month, day);
|
||||
int days_since_epoch = days_from_1970(year) + day_of_year;
|
||||
|
||||
time_t seconds_in_day = 3600 * 24;
|
||||
time_t result =
|
||||
seconds_in_day * days_since_epoch + 3600 * t->tm_hour + 60 * t->tm_min + t->tm_sec;
|
||||
|
||||
return result;
|
||||
}
|
5
src/fsfw/timemanager/boost_timegm.h
Normal file
5
src/fsfw/timemanager/boost_timegm.h
Normal file
@ -0,0 +1,5 @@
|
||||
#include <ctime>
|
||||
|
||||
|
||||
|
||||
time_t internal_timegm(std::tm const *t);
|
@ -69,7 +69,7 @@ ReturnValue_t HostFilesystem::createFile(FilesystemParams params, const uint8_t
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
ReturnValue_t HostFilesystem::removeFile(const std::filesystem::path::value_type *path_,
|
||||
ReturnValue_t HostFilesystem::removeFile(const char *path_,
|
||||
FileSystemArgsIF *args) {
|
||||
if (path_ == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
@ -133,8 +133,7 @@ ReturnValue_t HostFilesystem::removeDirectory(FilesystemParams params, bool dele
|
||||
return HasFileSystemIF::GENERIC_DIR_ERROR;
|
||||
}
|
||||
|
||||
ReturnValue_t HostFilesystem::rename(const std::filesystem::path::value_type *oldPath_,
|
||||
const std::filesystem::path::value_type *newPath_,
|
||||
ReturnValue_t HostFilesystem::rename(const char *oldPath_, const char *newPath_,
|
||||
FileSystemArgsIF *args) {
|
||||
if (oldPath_ == nullptr or newPath_ == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
|
@ -15,12 +15,11 @@ 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 std::filesystem::path::value_type *path,
|
||||
ReturnValue_t removeFile(const char *path,
|
||||
FileSystemArgsIF *args) override;
|
||||
ReturnValue_t createDirectory(FilesystemParams params, bool createParentDirs) override;
|
||||
ReturnValue_t removeDirectory(FilesystemParams params, bool deleteRecurively) override;
|
||||
ReturnValue_t rename(const std::filesystem::path::value_type *oldPath,
|
||||
const std::filesystem::path::value_type *newPath,
|
||||
ReturnValue_t rename(const char *oldPath, const char *newPath,
|
||||
FileSystemArgsIF *args) override;
|
||||
|
||||
std::error_code errorCode;
|
||||
|
Reference in New Issue
Block a user