Device: Add device hardware info retrieval support
parent
3782e12ef6
commit
9a1cd1124d
|
|
@ -259,6 +259,7 @@ set(SRC_FILES
|
||||||
communication/packet/componentversionpacket.cpp
|
communication/packet/componentversionpacket.cpp
|
||||||
communication/packet/supportedfeaturespacket.cpp
|
communication/packet/supportedfeaturespacket.cpp
|
||||||
communication/packet/genericbinarystatuspacket.cpp
|
communication/packet/genericbinarystatuspacket.cpp
|
||||||
|
communication/packet/hardwareinfopacket.cpp
|
||||||
communication/decoder.cpp
|
communication/decoder.cpp
|
||||||
communication/encoder.cpp
|
communication/encoder.cpp
|
||||||
communication/ethernetpacketizer.cpp
|
communication/ethernetpacketizer.cpp
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
#include "icsneo/communication/message/extendeddatamessage.h"
|
#include "icsneo/communication/message/extendeddatamessage.h"
|
||||||
#include "icsneo/communication/message/livedatamessage.h"
|
#include "icsneo/communication/message/livedatamessage.h"
|
||||||
#include "icsneo/communication/message/diskdatamessage.h"
|
#include "icsneo/communication/message/diskdatamessage.h"
|
||||||
|
#include "icsneo/communication/message/hardwareinfo.h"
|
||||||
#include "icsneo/communication/command.h"
|
#include "icsneo/communication/command.h"
|
||||||
#include "icsneo/device/device.h"
|
#include "icsneo/device/device.h"
|
||||||
#include "icsneo/communication/packet/canpacket.h"
|
#include "icsneo/communication/packet/canpacket.h"
|
||||||
|
|
@ -35,6 +36,8 @@
|
||||||
#include "icsneo/communication/packet/mdiopacket.h"
|
#include "icsneo/communication/packet/mdiopacket.h"
|
||||||
#include "icsneo/communication/packet/genericbinarystatuspacket.h"
|
#include "icsneo/communication/packet/genericbinarystatuspacket.h"
|
||||||
#include "icsneo/communication/packet/livedatapacket.h"
|
#include "icsneo/communication/packet/livedatapacket.h"
|
||||||
|
#include "icsneo/communication/packet/hardwareinfopacket.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace icsneo;
|
using namespace icsneo;
|
||||||
|
|
@ -358,6 +361,16 @@ bool Decoder::decode(std::shared_ptr<Message>& result, const std::shared_ptr<Pac
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
case Command::GetHardwareInfo: {
|
||||||
|
result = HardwareInfoPacket::DecodeToMessage(packet->data);
|
||||||
|
|
||||||
|
if(!result) {
|
||||||
|
report(APIEvent::Type::PacketDecodingError, APIEvent::Severity::Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
auto msg = std::make_shared<Main51Message>();
|
auto msg = std::make_shared<Main51Message>();
|
||||||
msg->command = Command(packet->data[0]);
|
msg->command = Command(packet->data[0]);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
#include "icsneo/communication/packet/hardwareinfopacket.h"
|
||||||
|
#include "icsneo/communication/message/hardwareinfo.h"
|
||||||
|
#include <iostream>
|
||||||
|
using namespace icsneo;
|
||||||
|
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint8_t valid;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t day;
|
||||||
|
uint8_t month;
|
||||||
|
uint16_t year;
|
||||||
|
} manufactureDate;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t major;
|
||||||
|
uint8_t minor;
|
||||||
|
} hwRev;
|
||||||
|
uint8_t deviceId;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t major;
|
||||||
|
uint8_t minor;
|
||||||
|
} blVersion;
|
||||||
|
} HardwareInfoFrame;
|
||||||
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
std::shared_ptr<HardwareInfo> HardwareInfoPacket::DecodeToMessage(const std::vector<uint8_t>& bytes) {
|
||||||
|
if(bytes.size() < (sizeof(HardwareInfoFrame) + 1)) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto* frame = reinterpret_cast<const HardwareInfoFrame*>(&bytes[1]);
|
||||||
|
|
||||||
|
auto msg = std::make_shared<HardwareInfo>();
|
||||||
|
|
||||||
|
msg->manufactureDate.day = frame->manufactureDate.day;
|
||||||
|
msg->manufactureDate.year = frame->manufactureDate.year;
|
||||||
|
msg->manufactureDate.month = frame->manufactureDate.month;
|
||||||
|
|
||||||
|
msg->hardwareRevision.major = frame->hwRev.major;
|
||||||
|
msg->hardwareRevision.minor = frame->hwRev.minor;
|
||||||
|
|
||||||
|
msg->bootloaderVersion.major = frame->blVersion.major;
|
||||||
|
msg->bootloaderVersion.minor = frame->blVersion.minor;
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
@ -722,6 +722,37 @@ Network Device::getNetworkByNumber(Network::Type type, size_t index) const {
|
||||||
return Network::NetID::Invalid;
|
return Network::NetID::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<HardwareInfo> Device::getHardwareInfo(std::chrono::milliseconds timeout) {
|
||||||
|
if(!isOpen()) {
|
||||||
|
report(APIEvent::Type::DeviceCurrentlyClosed, APIEvent::Severity::Error);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isOnline()) {
|
||||||
|
report(APIEvent::Type::DeviceCurrentlyOffline, APIEvent::Severity::Error);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto filter = std::make_shared<MessageFilter>(Message::Type::HardwareInfo);
|
||||||
|
|
||||||
|
auto response = com->waitForMessageSync([this]() {
|
||||||
|
return com->sendCommand(Command::GetHardwareInfo);
|
||||||
|
}, filter, timeout);
|
||||||
|
|
||||||
|
if(!response) {
|
||||||
|
report(APIEvent::Type::Timeout, APIEvent::Severity::Error);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto hardwareInfo = std::dynamic_pointer_cast<HardwareInfo>(response);
|
||||||
|
if(!hardwareInfo) {
|
||||||
|
report(APIEvent::Type::UnexpectedResponse, APIEvent::Severity::Error);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hardwareInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::optional<uint64_t> Device::readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout, Disk::MemoryType memType) {
|
std::optional<uint64_t> Device::readLogicalDisk(uint64_t pos, uint8_t* into, uint64_t amount, std::chrono::milliseconds timeout, Disk::MemoryType memType) {
|
||||||
if(!into || timeout <= std::chrono::milliseconds(0)) {
|
if(!into || timeout <= std::chrono::milliseconds(0)) {
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ enum class Command : uint8_t {
|
||||||
UpdateLEDState = 0xA7,
|
UpdateLEDState = 0xA7,
|
||||||
SetDefaultSettings = 0xA8, // Follow up with SaveSettings to write to EEPROM
|
SetDefaultSettings = 0xA8, // Follow up with SaveSettings to write to EEPROM
|
||||||
GetSecondaryVersions = 0xA9, // Previously known as RED_CMD_PERIPHERALS_APP_VERSION_REQ, versions other than the main chip
|
GetSecondaryVersions = 0xA9, // Previously known as RED_CMD_PERIPHERALS_APP_VERSION_REQ, versions other than the main chip
|
||||||
|
GetHardwareInfo = 0xB7, // Previously known as RED_CMD_HARDWARE_VERSION_REQ
|
||||||
GetLogicalDiskInfo = 0xBB, // Previously known as RED_CMD_GET_SDCARD_INFO
|
GetLogicalDiskInfo = 0xBB, // Previously known as RED_CMD_GET_SDCARD_INFO
|
||||||
RequestStatusUpdate = 0xBC,
|
RequestStatusUpdate = 0xBC,
|
||||||
ReadSettings = 0xC7, // Previously known as 3G_READ_SETTINGS_EX
|
ReadSettings = 0xC7, // Previously known as 3G_READ_SETTINGS_EX
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,20 @@ class ComponentVersion {
|
||||||
public:
|
public:
|
||||||
ComponentVersion(uint8_t valid, uint8_t componentInfo, uint32_t identifier, uint32_t dotVersion, uint32_t commitHash) :
|
ComponentVersion(uint8_t valid, uint8_t componentInfo, uint32_t identifier, uint32_t dotVersion, uint32_t commitHash) :
|
||||||
valid(valid), componentInfo(componentInfo), identifier(identifier), dotVersion(dotVersion), commitHash(commitHash) {}
|
valid(valid), componentInfo(componentInfo), identifier(identifier), dotVersion(dotVersion), commitHash(commitHash) {}
|
||||||
|
|
||||||
|
static ComponentVersion FromAppVersion(uint32_t identifier, uint8_t appMajor, uint8_t appMinor) {
|
||||||
|
uint32_t dotVersion = (appMajor << 24) | (appMinor << 16);
|
||||||
|
|
||||||
|
|
||||||
|
return ComponentVersion(
|
||||||
|
static_cast<uint8_t>(1u),
|
||||||
|
static_cast<uint8_t>(0u),
|
||||||
|
identifier,
|
||||||
|
dotVersion,
|
||||||
|
static_cast<uint8_t>(0u)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const bool valid;
|
const bool valid;
|
||||||
const uint8_t componentInfo;
|
const uint8_t componentInfo;
|
||||||
const uint32_t identifier;
|
const uint32_t identifier;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
#ifndef _HARDWARE_INFO_MESSAGE_H_
|
||||||
|
#define _HARDWARE_INFO_MESSAGE_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include "icsneo/communication/message/message.h"
|
||||||
|
|
||||||
|
namespace icsneo {
|
||||||
|
|
||||||
|
class HardwareInfo : public Message {
|
||||||
|
public:
|
||||||
|
HardwareInfo() : Message(Message::Type::HardwareInfo) {}
|
||||||
|
struct Version {
|
||||||
|
uint8_t major;
|
||||||
|
uint8_t minor;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Date {
|
||||||
|
uint8_t day;
|
||||||
|
uint8_t month;
|
||||||
|
uint16_t year;
|
||||||
|
};
|
||||||
|
|
||||||
|
Date manufactureDate;
|
||||||
|
Version hardwareRevision;
|
||||||
|
Version bootloaderVersion;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -38,6 +38,7 @@ public:
|
||||||
SupportedFeatures = 0x800d,
|
SupportedFeatures = 0x800d,
|
||||||
GenericBinaryStatus = 0x800e,
|
GenericBinaryStatus = 0x800e,
|
||||||
LiveData = 0x800f,
|
LiveData = 0x800f,
|
||||||
|
HardwareInfo = 0x8010
|
||||||
};
|
};
|
||||||
|
|
||||||
Message(Type t) : type(t) {}
|
Message(Type t) : type(t) {}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef __HARDWAREINFOPACKET_H__
|
||||||
|
#define __HARDWAREINFOPACKET_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace icsneo {
|
||||||
|
|
||||||
|
class HardwareInfo;
|
||||||
|
|
||||||
|
struct HardwareInfoPacket {
|
||||||
|
static std::shared_ptr<HardwareInfo> DecodeToMessage(const std::vector<uint8_t>& bytes);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
#endif // __DEVICECOMPONENTVERSIONPACKET_H__
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#include "icsneo/communication/message/scriptstatusmessage.h"
|
#include "icsneo/communication/message/scriptstatusmessage.h"
|
||||||
#include "icsneo/communication/message/supportedfeaturesmessage.h"
|
#include "icsneo/communication/message/supportedfeaturesmessage.h"
|
||||||
#include "icsneo/communication/message/genericbinarystatusmessage.h"
|
#include "icsneo/communication/message/genericbinarystatusmessage.h"
|
||||||
|
#include "icsneo/communication/message/hardwareinfo.h"
|
||||||
#include "icsneo/communication/message/extendeddatamessage.h"
|
#include "icsneo/communication/message/extendeddatamessage.h"
|
||||||
#include "icsneo/communication/message/livedatamessage.h"
|
#include "icsneo/communication/message/livedatamessage.h"
|
||||||
#include "icsneo/communication/packet/genericbinarystatuspacket.h"
|
#include "icsneo/communication/packet/genericbinarystatuspacket.h"
|
||||||
|
|
@ -45,6 +46,8 @@
|
||||||
#include "icsneo/platform/nodiscard.h"
|
#include "icsneo/platform/nodiscard.h"
|
||||||
#include "icsneo/disk/vsa/vsa.h"
|
#include "icsneo/disk/vsa/vsa.h"
|
||||||
#include "icsneo/disk/vsa/vsaparser.h"
|
#include "icsneo/disk/vsa/vsaparser.h"
|
||||||
|
#include "icsneo/communication/message/versionmessage.h"
|
||||||
|
|
||||||
|
|
||||||
#define ICSNEO_FINDABLE_DEVICE_BASE(className, type) \
|
#define ICSNEO_FINDABLE_DEVICE_BASE(className, type) \
|
||||||
static constexpr DeviceType::Enum DEVICE_TYPE = type; \
|
static constexpr DeviceType::Enum DEVICE_TYPE = type; \
|
||||||
|
|
@ -222,6 +225,7 @@ public:
|
||||||
virtual size_t getNetworkCountByType(Network::Type) const;
|
virtual size_t getNetworkCountByType(Network::Type) const;
|
||||||
virtual Network getNetworkByNumber(Network::Type, size_t) const;
|
virtual Network getNetworkByNumber(Network::Type, size_t) const;
|
||||||
|
|
||||||
|
std::shared_ptr<HardwareInfo> getHardwareInfo(std::chrono::milliseconds timeout = std::chrono::milliseconds(2));
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -565,6 +569,7 @@ public:
|
||||||
*/
|
*/
|
||||||
const std::vector<std::optional<DeviceAppVersion>>& getVersions() const { return versions; }
|
const std::vector<std::optional<DeviceAppVersion>>& getVersions() const { return versions; }
|
||||||
const std::vector<ComponentVersion>& getComponentVersions() const { return componentVersions; }
|
const std::vector<ComponentVersion>& getComponentVersions() const { return componentVersions; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some alternate communication protocols do not support DFU
|
* Some alternate communication protocols do not support DFU
|
||||||
*/
|
*/
|
||||||
|
|
@ -822,8 +827,6 @@ protected:
|
||||||
|
|
||||||
neodevice_t& getWritableNeoDevice() { return data; }
|
neodevice_t& getWritableNeoDevice() { return data; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
neodevice_t data;
|
neodevice_t data;
|
||||||
std::shared_ptr<ResetStatusMessage> latestResetStatus;
|
std::shared_ptr<ResetStatusMessage> latestResetStatus;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue