Disk: Implement NeoMemoryDiskReadDriver

This commit is contained in:
Paul Hollinsky
2022-02-25 01:14:57 -05:00
parent fe4d5e0c15
commit f8bfb243fa
10 changed files with 127 additions and 10 deletions
+1
View File
@@ -8,6 +8,7 @@ namespace icsneo {
enum class Command : uint8_t {
EnableNetworkCommunication = 0x07,
EnableNetworkCommunicationEx = 0x08,
NeoReadMemory = 0x40,
RequestSerialNumber = 0xA1,
GetMainVersion = 0xA3, // Previously known as RED_CMD_APP_VERSION_REQ
SetSettings = 0xA4, // Previously known as RED_CMD_SET_BAUD_REQ, follow up with SaveSettings to write to EEPROM
@@ -0,0 +1,20 @@
#ifndef __READMEMORYMESSAGE_H_
#define __READMEMORYMESSAGE_H_
#ifdef __cplusplus
#include "icsneo/communication/message/message.h"
namespace icsneo {
class NeoReadMemorySDMessage : public RawMessage {
public:
NeoReadMemorySDMessage() : RawMessage(Message::Type::RawMessage, Network::NetID::NeoMemorySDRead) {}
uint32_t startAddress = 0;
};
}
#endif // __cplusplus
#endif
+4 -3
View File
@@ -41,7 +41,7 @@ public:
RED_EXT_MEMORYREAD = 20,
RED_INT_MEMORYREAD = 21,
RED_DFLASH_READ = 22,
RED_SDCARD_READ = 23,
NeoMemorySDRead = 23, // Response from NeoMemory (MemoryTypeSD)
CAN_ERRBITS = 24,
RED_DFLASH_WRITE_DONE = 25,
RED_WAVE_CAN1_LOGICAL = 26,
@@ -272,6 +272,7 @@ public:
case NetID::Main51:
case NetID::ReadSettings:
case NetID::EthPHYControl:
case NetID::NeoMemorySDRead:
return Type::Internal;
case NetID::Invalid:
case NetID::Any:
@@ -360,8 +361,8 @@ public:
return "RED_INT_MEMORYREAD";
case NetID::RED_DFLASH_READ:
return "RED_DFLASH_READ";
case NetID::RED_SDCARD_READ:
return "RED_SDCARD_READ";
case NetID::NeoMemorySDRead:
return "NeoMemorySDRead";
case NetID::CAN_ERRBITS:
return "CAN_ERRBITS";
case NetID::RED_DFLASH_WRITE_DONE:
@@ -0,0 +1,35 @@
#ifndef __NEOMEMORYDISKREADDRIVER_H__
#define __NEOMEMORYDISKREADDRIVER_H__
#ifdef __cplusplus
#include "icsneo/disk/diskreaddriver.h"
#include <limits>
namespace icsneo {
/**
* A disk read driver which uses the neoMemory command to read from the disk
*
* This can only request reads by sector, so it will be very slow, but is likely supported by any device with a disk
*/
class NeoMemoryDiskReadDriver : public DiskReadDriver {
public:
Access getAccess() const override { return Access::VSA; }
std::pair<uint32_t, uint32_t> getBlockSizeBounds() const override {
static_assert(SectorSize <= std::numeric_limits<uint32_t>::max(), "Incorrect sector size");
static_assert(SectorSize >= std::numeric_limits<uint32_t>::min(), "Incorrect sector size");
return { static_cast<uint32_t>(SectorSize), static_cast<uint32_t>(SectorSize) };
}
private:
static constexpr const uint8_t MemoryTypeSD = 0x01; // Logical Disk
optional<uint64_t> readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) override;
};
}
#endif // __cplusplus
#endif // __NEOMEMORYDISKREADDRIVER_H__
+6 -1
View File
@@ -4,6 +4,7 @@
#ifdef __cplusplus
#include "icsneo/disk/diskreaddriver.h"
#include <limits>
namespace icsneo {
@@ -17,7 +18,11 @@ public:
optional<uint64_t> readLogicalDisk(Communication& com, device_eventhandler_t report,
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout) override;
Access getAccess() const override { return Access::None; }
std::pair<uint32_t, uint32_t> getBlockSizeBounds() const override { return {SectorSize, SectorSize}; }
std::pair<uint32_t, uint32_t> getBlockSizeBounds() const override {
static_assert(SectorSize <= std::numeric_limits<uint32_t>::max(), "Incorrect sector size");
static_assert(SectorSize >= std::numeric_limits<uint32_t>::min(), "Incorrect sector size");
return { static_cast<uint32_t>(SectorSize), static_cast<uint32_t>(SectorSize) };
}
private:
optional<uint64_t> readLogicalDiskAligned(Communication& com, device_eventhandler_t report,