Device: Add disk formatting

This commit is contained in:
Yasser Yassine
2025-07-22 20:02:06 +00:00
committed by Kyle Schwarz
parent d70defbf8a
commit 1e5e714f5b
20 changed files with 351 additions and 7 deletions
+2
View File
@@ -113,6 +113,8 @@ public:
AppErrorParsingFailed = 0x2055,
GPTPNotSupported = 0x2056,
SettingNotAvaiableDevice = 0x2057,
DiskFormatNotSupported = 0x2058,
DiskFormatInvalidCount = 0x2059,
// Transport Events
FailedToRead = 0x3000,
@@ -10,11 +10,12 @@ namespace icsneo {
class ExtendedResponseMessage : public Message {
public:
ExtendedResponseMessage(ExtendedCommand cmd, ExtendedResponse resp)
ExtendedResponseMessage(ExtendedCommand cmd, ExtendedResponse resp = ExtendedResponse::OK)
: Message(Message::Type::ExtendedResponse), command(cmd), response(resp) {}
const ExtendedCommand command;
const ExtendedResponse response;
std::vector<uint8_t> data;
#pragma pack(push, 2)
struct ResponseHeader {
@@ -15,20 +15,36 @@ namespace icsneo {
class ExtendedResponseFilter : public MessageFilter {
public:
ExtendedResponseFilter(icsneo::ExtendedResponse resp) : MessageFilter(Message::Type::ExtendedResponse), response(resp) {}
ExtendedResponseFilter(icsneo::ExtendedCommand cmd) : MessageFilter(Message::Type::ExtendedResponse), command(cmd), response(std::nullopt) {}
ExtendedResponseFilter(icsneo::ExtendedResponse resp) : MessageFilter(Message::Type::ExtendedResponse), command(std::nullopt), response(resp) {}
ExtendedResponseFilter(icsneo::ExtendedCommand cmd, icsneo::ExtendedResponse resp)
: MessageFilter(Message::Type::ExtendedResponse), command(cmd), response(resp) {}
bool match(const std::shared_ptr<Message>& message) const override {
if(!MessageFilter::match(message)) {
return false;
}
const auto respMsg = std::static_pointer_cast<ExtendedResponseMessage>(message);
return respMsg && matchResponse(respMsg->response);
return respMsg && matchResponse(respMsg->command, respMsg->response);
}
private:
icsneo::ExtendedResponse response;
bool matchResponse(icsneo::ExtendedResponse resp) const {
return response == resp;
std::optional<icsneo::ExtendedCommand> command = std::nullopt;
std::optional<icsneo::ExtendedResponse> response = std::nullopt;
bool matchResponse(icsneo::ExtendedCommand cmd, icsneo::ExtendedResponse resp) const {
if(command) {
if(*command != cmd) {
return false;
}
}
if(response) {
if(*response != resp) {
return false;
}
}
return true;
}
};
+17
View File
@@ -26,6 +26,7 @@
#include "icsneo/disk/diskreaddriver.h"
#include "icsneo/disk/diskwritedriver.h"
#include "icsneo/disk/nulldiskdriver.h"
#include "icsneo/disk/diskdetails.h"
#include "icsneo/communication/communication.h"
#include "icsneo/communication/packetizer.h"
#include "icsneo/communication/encoder.h"
@@ -637,6 +638,22 @@ public:
bool unsubscribeLiveData(const LiveDataHandle& handle);
bool clearAllLiveData();
bool setValueLiveData(std::shared_ptr<LiveDataSetValueMessage> message);
enum class DiskFormatDirective : uint8_t {
Continue,
Stop
};
using DiskFormatProgress = std::function<DiskFormatDirective(uint64_t sectorsFormatted, uint64_t sectorsTotal)>;
bool formatDisk(
const DiskDetails& config,
const DiskFormatProgress& handler = {},
std::chrono::milliseconds interval = std::chrono::milliseconds(500) /** Send updates at an interval of 500ms */
);
bool forceDiskConfigUpdate(const DiskDetails& config); // Forces a disk layout and enables change without formatting
std::shared_ptr<DiskDetails> getDiskDetails(std::chrono::milliseconds timeout = std::chrono::milliseconds(100));
virtual size_t getDiskCount() const { return 0; }
bool supportsDiskFormatting() const { return getDiskCount() != 0; }
// VSA Read functions
+2 -1
View File
@@ -924,7 +924,8 @@ public:
template<typename T> T getStructure() const { return *getStructurePointer<T>(); }
template<typename T> bool applyStructure(const T& newStructure);
const size_t& getSize() const { return structSize; }
size_t getSize() const { return structSize; }
size_t getSerialSize() const { return settings.size(); }
// if settings are disabled for this device. always false unless constructed null
bool disabled = false;
@@ -70,6 +70,10 @@ protected:
}
bool supportsGPTP() const override { return true; }
size_t getDiskCount() const override {
return 2;
}
};
@@ -141,6 +141,10 @@ protected:
bool supportsEraseMemory() const override {
return true;
}
size_t getDiskCount() const override {
return 1;
}
};
}
@@ -91,6 +91,10 @@ protected:
return true;
}
size_t getDiskCount() const override {
return 2;
}
};
}
@@ -75,6 +75,10 @@ protected:
bool supportsEraseMemory() const override {
return true;
}
size_t getDiskCount() const override {
return 2;
}
};
}
@@ -54,6 +54,10 @@ protected:
bool supportsEraseMemory() const override {
return true;
}
size_t getDiskCount() const override {
return 1;
}
};
}
@@ -107,6 +107,10 @@ protected:
std::optional<MemoryAddress> getCoreminiStartAddressSD() const override {
return 0;
}
size_t getDiskCount() const override {
return 1;
}
};
}
@@ -120,6 +120,10 @@ protected:
std::optional<MemoryAddress> getCoreminiStartAddressSD() const override {
return 0;
}
size_t getDiskCount() const override {
return 1;
}
};
}
@@ -137,6 +137,11 @@ namespace icsneo
{
return 0;
}
size_t getDiskCount() const override
{
return 1;
}
};
}
+44
View File
@@ -0,0 +1,44 @@
#ifndef __DISKDETAILS_H__
#define __DISKDETAILS_H__
#ifdef __cplusplus
#include <cstdint>
#include <vector>
#include <icsneo/api/eventmanager.h>
namespace icsneo {
enum class DiskLayout : uint8_t {
Spanned = 0,
RAID0 = 1
};
struct DiskInfo {
bool present; // Disk is connected
bool initialized; // Disk is initialized
bool formatted; // Disk is formatted
uint64_t sectors;
uint32_t bytesPerSector;
uint64_t size() const {
return sectors * bytesPerSector;
}
};
struct DiskDetails {
DiskLayout layout;
bool fullFormat;
std::vector<DiskInfo> disks;
static std::vector<uint8_t> Encode(const DiskDetails& config);
static std::shared_ptr<DiskDetails> Decode(const std::vector<uint8_t>& bytes, size_t diskCount, device_eventhandler_t report);
};
} // namespace icsneo
#endif // __cplusplus
#endif