Disk: Implement NeoMemoryDiskReadDriver
parent
fe4d5e0c15
commit
f8bfb243fa
|
|
@ -150,6 +150,7 @@ set(SRC_FILES
|
||||||
device/device.cpp
|
device/device.cpp
|
||||||
disk/diskreaddriver.cpp
|
disk/diskreaddriver.cpp
|
||||||
disk/nulldiskreaddriver.cpp
|
disk/nulldiskreaddriver.cpp
|
||||||
|
disk/neomemorydiskreaddriver.cpp
|
||||||
${PLATFORM_SRC}
|
${PLATFORM_SRC}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "icsneo/communication/message/resetstatusmessage.h"
|
#include "icsneo/communication/message/resetstatusmessage.h"
|
||||||
#include "icsneo/communication/message/readsettingsmessage.h"
|
#include "icsneo/communication/message/readsettingsmessage.h"
|
||||||
#include "icsneo/communication/message/canerrorcountmessage.h"
|
#include "icsneo/communication/message/canerrorcountmessage.h"
|
||||||
|
#include "icsneo/communication/message/neoreadmemorysdmessage.h"
|
||||||
#include "icsneo/communication/message/flexray/control/flexraycontrolmessage.h"
|
#include "icsneo/communication/message/flexray/control/flexraycontrolmessage.h"
|
||||||
#include "icsneo/communication/command.h"
|
#include "icsneo/communication/command.h"
|
||||||
#include "icsneo/device/device.h"
|
#include "icsneo/device/device.h"
|
||||||
|
|
@ -179,6 +180,18 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||||
result = std::make_shared<RawMessage>(packet->network, packet->data);
|
result = std::make_shared<RawMessage>(packet->network, packet->data);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case Network::NetID::NeoMemorySDRead: {
|
||||||
|
if(packet->data.size() != 512 + sizeof(uint32_t)) {
|
||||||
|
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
|
||||||
|
return false; // Should get enough data for a start address and sector
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto msg = std::make_shared<NeoReadMemorySDMessage>();
|
||||||
|
result = msg;
|
||||||
|
msg->startAddress = *reinterpret_cast<uint32_t*>(packet->data.data());
|
||||||
|
msg->data.insert(msg->data.end(), packet->data.begin() + 4, packet->data.end());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
case Network::NetID::FlexRayControl: {
|
case Network::NetID::FlexRayControl: {
|
||||||
auto frResult = std::make_shared<FlexRayControlMessage>(*packet);
|
auto frResult = std::make_shared<FlexRayControlMessage>(*packet);
|
||||||
if(!frResult->decoded) {
|
if(!frResult->decoded) {
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,7 @@ bool Encoder::encode(const Packetizer& packetizer, std::vector<uint8_t>& result,
|
||||||
case Command::EnableNetworkCommunicationEx:
|
case Command::EnableNetworkCommunicationEx:
|
||||||
case Command::GetMainVersion:
|
case Command::GetMainVersion:
|
||||||
case Command::GetSecondaryVersions:
|
case Command::GetSecondaryVersions:
|
||||||
|
case Command::NeoReadMemory:
|
||||||
// There is a firmware handling idiosyncrasy with these commands
|
// There is a firmware handling idiosyncrasy with these commands
|
||||||
// They must be encoded in the short format
|
// They must be encoded in the short format
|
||||||
m51msg->forceShortFormat = true;
|
m51msg->forceShortFormat = true;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
#include "icsneo/disk/neomemorydiskreaddriver.h"
|
||||||
|
#include "icsneo/communication/message/neoreadmemorysdmessage.h"
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
using namespace icsneo;
|
||||||
|
|
||||||
|
optional<uint64_t> NeoMemoryDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||||
|
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) {
|
||||||
|
static std::shared_ptr<MessageFilter> NeoMemorySDRead = std::make_shared<MessageFilter>(Network::NetID::NeoMemorySDRead);
|
||||||
|
|
||||||
|
if(amount != SectorSize)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
const uint64_t currentSector = pos / SectorSize;
|
||||||
|
auto msg = com.waitForMessageSync([¤tSector, &com] {
|
||||||
|
return com.sendCommand(Command::NeoReadMemory, {
|
||||||
|
MemoryTypeSD,
|
||||||
|
uint8_t(currentSector & 0xFF),
|
||||||
|
uint8_t((currentSector >> 8) & 0xFF),
|
||||||
|
uint8_t((currentSector >> 16) & 0xFF),
|
||||||
|
uint8_t((currentSector >> 24) & 0xFF),
|
||||||
|
uint8_t(SectorSize & 0xFF),
|
||||||
|
uint8_t((SectorSize >> 8) & 0xFF),
|
||||||
|
uint8_t((SectorSize >> 16) & 0xFF),
|
||||||
|
uint8_t((SectorSize >> 24) & 0xFF)
|
||||||
|
});
|
||||||
|
}, NeoMemorySDRead, timeout);
|
||||||
|
|
||||||
|
if(!msg)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
const auto sdmsg = std::dynamic_pointer_cast<NeoReadMemorySDMessage>(msg);
|
||||||
|
if(!sdmsg || sdmsg->data.size() != SectorSize) {
|
||||||
|
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
|
||||||
|
return nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(into, sdmsg->data.data(), SectorSize);
|
||||||
|
return SectorSize;
|
||||||
|
}
|
||||||
|
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
using namespace icsneo;
|
using namespace icsneo;
|
||||||
|
|
||||||
optional<uint64_t> NullDiskReadDriver::readLogicalDisk(Communication& com, device_eventhandler_t report,
|
optional<uint64_t> NullDiskReadDriver::readLogicalDisk(Communication&, device_eventhandler_t report,
|
||||||
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) {
|
uint64_t, uint8_t*, uint64_t, std::chrono::milliseconds) {
|
||||||
report(APIEvent::Type::DiskNotSupported, APIEvent::Severity::Error);
|
report(APIEvent::Type::DiskNotSupported, APIEvent::Severity::Error);
|
||||||
return std::nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<uint64_t> NullDiskReadDriver::readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
optional<uint64_t> NullDiskReadDriver::readLogicalDiskAligned(Communication&, device_eventhandler_t report,
|
||||||
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout) {
|
uint64_t, uint8_t*, uint64_t, std::chrono::milliseconds) {
|
||||||
report(APIEvent::Type::DiskNotSupported, APIEvent::Severity::Error);
|
report(APIEvent::Type::DiskNotSupported, APIEvent::Severity::Error);
|
||||||
return std::nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ namespace icsneo {
|
||||||
enum class Command : uint8_t {
|
enum class Command : uint8_t {
|
||||||
EnableNetworkCommunication = 0x07,
|
EnableNetworkCommunication = 0x07,
|
||||||
EnableNetworkCommunicationEx = 0x08,
|
EnableNetworkCommunicationEx = 0x08,
|
||||||
|
NeoReadMemory = 0x40,
|
||||||
RequestSerialNumber = 0xA1,
|
RequestSerialNumber = 0xA1,
|
||||||
GetMainVersion = 0xA3, // Previously known as RED_CMD_APP_VERSION_REQ
|
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
|
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
|
||||||
|
|
@ -41,7 +41,7 @@ public:
|
||||||
RED_EXT_MEMORYREAD = 20,
|
RED_EXT_MEMORYREAD = 20,
|
||||||
RED_INT_MEMORYREAD = 21,
|
RED_INT_MEMORYREAD = 21,
|
||||||
RED_DFLASH_READ = 22,
|
RED_DFLASH_READ = 22,
|
||||||
RED_SDCARD_READ = 23,
|
NeoMemorySDRead = 23, // Response from NeoMemory (MemoryTypeSD)
|
||||||
CAN_ERRBITS = 24,
|
CAN_ERRBITS = 24,
|
||||||
RED_DFLASH_WRITE_DONE = 25,
|
RED_DFLASH_WRITE_DONE = 25,
|
||||||
RED_WAVE_CAN1_LOGICAL = 26,
|
RED_WAVE_CAN1_LOGICAL = 26,
|
||||||
|
|
@ -272,6 +272,7 @@ public:
|
||||||
case NetID::Main51:
|
case NetID::Main51:
|
||||||
case NetID::ReadSettings:
|
case NetID::ReadSettings:
|
||||||
case NetID::EthPHYControl:
|
case NetID::EthPHYControl:
|
||||||
|
case NetID::NeoMemorySDRead:
|
||||||
return Type::Internal;
|
return Type::Internal;
|
||||||
case NetID::Invalid:
|
case NetID::Invalid:
|
||||||
case NetID::Any:
|
case NetID::Any:
|
||||||
|
|
@ -360,8 +361,8 @@ public:
|
||||||
return "RED_INT_MEMORYREAD";
|
return "RED_INT_MEMORYREAD";
|
||||||
case NetID::RED_DFLASH_READ:
|
case NetID::RED_DFLASH_READ:
|
||||||
return "RED_DFLASH_READ";
|
return "RED_DFLASH_READ";
|
||||||
case NetID::RED_SDCARD_READ:
|
case NetID::NeoMemorySDRead:
|
||||||
return "RED_SDCARD_READ";
|
return "NeoMemorySDRead";
|
||||||
case NetID::CAN_ERRBITS:
|
case NetID::CAN_ERRBITS:
|
||||||
return "CAN_ERRBITS";
|
return "CAN_ERRBITS";
|
||||||
case NetID::RED_DFLASH_WRITE_DONE:
|
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__
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
#include "icsneo/disk/diskreaddriver.h"
|
#include "icsneo/disk/diskreaddriver.h"
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
namespace icsneo {
|
namespace icsneo {
|
||||||
|
|
||||||
|
|
@ -17,7 +18,11 @@ public:
|
||||||
optional<uint64_t> readLogicalDisk(Communication& com, device_eventhandler_t report,
|
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;
|
uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout = DefaultTimeout) override;
|
||||||
Access getAccess() const override { return Access::None; }
|
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:
|
private:
|
||||||
optional<uint64_t> readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
optional<uint64_t> readLogicalDiskAligned(Communication& com, device_eventhandler_t report,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue