map/das-dn/third_party/AdsLib/AdsFile.h
2024-12-03 10:36:06 +08:00

71 lines
1.7 KiB
C++

// SPDX-License-Identifier: MIT
/**
Copyright (c) 2020 - 2022 Beckhoff Automation GmbH & Co. KG
*/
#pragma once
#pragma pack( push, 1)
#include "AdsDevice.h"
enum FOPEN : uint32_t {
READ = 1 << 0,
WRITE = 1 << 1,
APPEND = 1 << 2,
PLUS = 1 << 3,
BINARY = 1 << 4,
TEXT = 1 << 5,
ENSURE_DIR = 1 << 6,
ENABLE_DIR = 1 << 7,
OVERWRITE = 1 << 8,
OVERWRITE_RENAME = 1 << 9,
SHIFT_OPENPATH = 16,
};
namespace Beckhoff
{
namespace Ads
{
/**
* @brief This structure describes file information reveived via ADS
*
* Calling ReadWriteReqEx2 with IndexGroup == SYSTEMSERVICE_FFILEFIND
* will return ADS file information in the provided readData buffer.
* The data of that information is structured as TcFileFindData.
*/
struct TcFileFindData {
uint32_t hFile;
uint32_t dwFileAttributes;
uint64_t nReserved1[5];
char cFileName[260];
char unused[14];
uint16_t nReserved2;
bool isDirectory(void) const
{
return 0x10 & dwFileAttributes;
}
void letoh(void)
{
hFile = Beckhoff::letoh(hFile);
dwFileAttributes = Beckhoff::letoh(dwFileAttributes);
}
};
struct AdsFile {
AdsFile(const AdsDevice& route, const std::string& filename, uint32_t flags);
void Read(const size_t size, void* data, uint32_t& bytesRead) const;
void Write(const size_t size, const void* data) const;
static void Delete(const AdsDevice& route, const std::string& filename, uint32_t flags);
static int Find(const AdsDevice& route, const std::string& path, const size_t maxdepth, std::ostream& os);
private:
const AdsDevice& m_Route;
const AdsHandle m_Handle;
};
}
}
#pragma pack( pop )