mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
Device: Add reconnect()
This commit is contained in:
committed by
Kyle Schwarz
parent
5d672d48d4
commit
b48160286b
@@ -229,6 +229,7 @@ public:
|
||||
virtual bool goOffline();
|
||||
virtual bool enableLogData();
|
||||
virtual bool disableLogData();
|
||||
virtual bool reconnect(std::chrono::milliseconds timeout, std::chrono::milliseconds interval = std::chrono::milliseconds(100));
|
||||
|
||||
enum class PreloadReturn : uint8_t
|
||||
{
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#ifndef __FOUNDDEVICE_H_
|
||||
#define __FOUNDDEVICE_H_
|
||||
|
||||
#include "icsneo/communication/driver.h"
|
||||
#include "icsneo/device/neodevice.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class Driver;
|
||||
typedef std::function< std::unique_ptr<Driver>(device_eventhandler_t err, neodevice_t& forDevice) > driver_factory_t;
|
||||
|
||||
class FoundDevice {
|
||||
|
||||
@@ -25,10 +25,6 @@ public:
|
||||
return supportedNetworks;
|
||||
}
|
||||
|
||||
bool supportsComponentVersions() const override { return true; }
|
||||
|
||||
bool getEthPhyRegControlSupported() const override { return true; }
|
||||
|
||||
ProductID getProductID() const override {
|
||||
return ProductID::RADEpsilon;
|
||||
}
|
||||
@@ -46,7 +42,9 @@ public:
|
||||
.add<FlashPhase>(ChipID::RADEpsilon_MCHIP, BootloaderCommunication::RED)
|
||||
.add<ReconnectPhase>();
|
||||
}
|
||||
bool supportsComponentVersions() const override { return true; }
|
||||
|
||||
bool getEthPhyRegControlSupported() const override { return true; }
|
||||
protected:
|
||||
RADEpsilon(neodevice_t neodevice, const driver_factory_t& makeDriver) : Device(neodevice) {
|
||||
initialize<RADEpsilonSettings, Disk::NeoMemoryDiskDriver, Disk::NeoMemoryDiskDriver>(makeDriver);
|
||||
|
||||
@@ -28,6 +28,7 @@ public:
|
||||
bool supportsComponentVersions() const override { return true; }
|
||||
|
||||
bool getEthPhyRegControlSupported() const override { return true; }
|
||||
|
||||
ProductID getProductID() const override {
|
||||
return ProductID::RADEpsilon;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
|
||||
const std::vector<ChipInfo>& getChipInfo() const override {
|
||||
static std::vector<ChipInfo> chips = {
|
||||
{ChipID::RADGigastar_ZYNQ, true, "ZCHIP", "RADGigastar2_T1S_LIN_SW_bin", 1, FirmwareType::Zip},
|
||||
{ChipID::RADGigastar_ZYNQ, true, "ZCHIP", "RADGigastar_SW_bin", 1, FirmwareType::Zip},
|
||||
{ChipID::RADGigastar_FFG_ZYNQ, false, "ZCHIP", "RADGigastar_FFG_SW_bin", 1, FirmwareType::Zip},
|
||||
{ChipID::RADGigastar_USBZ_ZYNQ, true, "USB ZCHIP", "RADGigastar_USBz_SW_bin", 2, FirmwareType::Zip},
|
||||
{ChipID::RADGigastar_USBZ_Z7010_ZYNQ, false, "USB ZCHIP", "RADGigastar_USBz_Z7010_SW_bin", 2, FirmwareType::Zip},
|
||||
@@ -41,24 +41,39 @@ public:
|
||||
|
||||
BootloaderPipeline getBootloader() override {
|
||||
if(supportsComponentVersions()) {
|
||||
// main: 16.1, usb: 14.0
|
||||
auto chipVersions = getChipVersions();
|
||||
auto mainVersion = std::find_if(chipVersions.begin(), chipVersions.end(), [](const auto& ver) { return ver.name == "ZCHIP"; });
|
||||
auto usbVersion = std::find_if(chipVersions.begin(), chipVersions.end(), [](const auto& ver) { return ver.name == "USB ZCHIP"; });
|
||||
|
||||
bool useNewBootloader = false;
|
||||
if(mainVersion != chipVersions.end()) {
|
||||
static constexpr uint8_t NewBootloaderMajor = 0;
|
||||
static constexpr uint8_t NewBootloaderMinor = 0;
|
||||
|
||||
static constexpr uint8_t NewBootloaderMajor = 16;
|
||||
static constexpr uint8_t NewBootloaderMinor = 1;
|
||||
if(
|
||||
mainVersion->major > NewBootloaderMajor ||
|
||||
(mainVersion->major == NewBootloaderMajor && mainVersion->minor > NewBootloaderMinor)
|
||||
(mainVersion->major == NewBootloaderMajor && mainVersion->minor >= NewBootloaderMinor)
|
||||
) {
|
||||
BootloaderPipeline pipeline;
|
||||
for(const auto& version : chipVersions) {
|
||||
pipeline.add<FlashPhase>(version.id, BootloaderCommunication::RADMultiChip);
|
||||
}
|
||||
pipeline.add<ReconnectPhase>();
|
||||
pipeline.add<WaitPhase>(std::chrono::milliseconds(3000));
|
||||
return pipeline;
|
||||
useNewBootloader = true;
|
||||
}
|
||||
} else if(usbVersion != chipVersions.end()) {
|
||||
static constexpr uint8_t NewBootloaderMajorUSB = 14;
|
||||
static constexpr uint8_t NewBootloaderMinorUSB= 0;
|
||||
if(
|
||||
usbVersion->major > NewBootloaderMajorUSB ||
|
||||
(usbVersion->major == NewBootloaderMajorUSB && usbVersion->minor >= NewBootloaderMinorUSB)
|
||||
) {
|
||||
useNewBootloader = true;
|
||||
}
|
||||
}
|
||||
if(useNewBootloader) {
|
||||
BootloaderPipeline pipeline;
|
||||
for(const auto& version : chipVersions) {
|
||||
pipeline.add<FlashPhase>(version.id, BootloaderCommunication::RADMultiChip);
|
||||
}
|
||||
pipeline.add<ReconnectPhase>();
|
||||
pipeline.add<WaitPhase>(std::chrono::milliseconds(3000));
|
||||
return pipeline;
|
||||
}
|
||||
}
|
||||
// If we've reached this point, then we use the legacy flashing
|
||||
|
||||
@@ -15,9 +15,9 @@ namespace icsneo
|
||||
class RADGigastar2 : public Device {
|
||||
public:
|
||||
enum class FirmwareVariant {
|
||||
T1Sx6_CANx1_LINx16,
|
||||
T1Sx8_CANx4_LINx6,
|
||||
Invalid
|
||||
T1Sx6_CANx1_LINx16 = 0,
|
||||
T1Sx8_CANx4_LINx6 = 1,
|
||||
Invalid = 2
|
||||
};
|
||||
|
||||
// Serial numbers start with GT
|
||||
@@ -100,6 +100,8 @@ public:
|
||||
|
||||
FirmwareVariant getCurrentVariant() {
|
||||
if(supportsComponentVersions()) {
|
||||
refreshComponentVersions();
|
||||
|
||||
const auto& components = getComponentVersions();
|
||||
for(const auto& component : components) {
|
||||
if(!component.valid) {
|
||||
@@ -107,7 +109,10 @@ public:
|
||||
}
|
||||
|
||||
if(component.identifier == static_cast<uint32_t>(ChipID::RADGigastar2_ZYNQ)) {
|
||||
auto res = static_cast<FirmwareVariant>(std::clamp<uint8_t>(component.componentInfo, 0, 2));
|
||||
if(component.componentInfo > 2) {
|
||||
return FirmwareVariant::Invalid;
|
||||
}
|
||||
auto res = static_cast<FirmwareVariant>(component.componentInfo);
|
||||
if(variantToFlash == FirmwareVariant::Invalid) {
|
||||
variantToFlash = res; // Set the variantToFlash if it hasn't been set yet, we always flash the same firmware variant as the current if it is unspecified
|
||||
}
|
||||
@@ -140,41 +145,21 @@ public:
|
||||
}
|
||||
|
||||
BootloaderPipeline getBootloader() override {
|
||||
if(supportsComponentVersions()) {
|
||||
auto chipVersions = getChipVersions();
|
||||
auto mainVersion = std::find_if(chipVersions.begin(), chipVersions.end(), [](const auto& ver) { return ver.name == "ZCHIP"; });
|
||||
if(mainVersion != chipVersions.end()) {
|
||||
static constexpr uint8_t NewBootloaderMajor = 0;
|
||||
static constexpr uint8_t NewBootloaderMinor = 0;
|
||||
|
||||
if(
|
||||
mainVersion->major > NewBootloaderMajor ||
|
||||
(mainVersion->major == NewBootloaderMajor && mainVersion->minor > NewBootloaderMinor)
|
||||
) {
|
||||
BootloaderPipeline pipeline;
|
||||
for(const auto& version : chipVersions) {
|
||||
pipeline.add<FlashPhase>(version.id, BootloaderCommunication::RADMultiChip);
|
||||
}
|
||||
pipeline.add<ReconnectPhase>();
|
||||
pipeline.add<WaitPhase>(std::chrono::milliseconds(3000));
|
||||
return pipeline;
|
||||
}
|
||||
}
|
||||
auto chipVersions = getChipVersions();
|
||||
BootloaderPipeline pipeline;
|
||||
for(const auto& version : chipVersions) {
|
||||
pipeline.add<FlashPhase>(version.id, BootloaderCommunication::RADMultiChip);
|
||||
}
|
||||
// If we've reached this point, then we use the legacy flashing
|
||||
if(com->driver->isEthernet()) {
|
||||
return BootloaderPipeline()
|
||||
.add<FlashPhase>(ChipID::RADGigastar2_ZYNQ, BootloaderCommunication::RAD)
|
||||
.add<ReconnectPhase>()
|
||||
.add<WaitPhase>(std::chrono::milliseconds(3000));
|
||||
}
|
||||
return BootloaderPipeline()
|
||||
.add<FlashPhase>(ChipID::RADGigastar_USBZ_ZYNQ, BootloaderCommunication::RAD)
|
||||
.add<ReconnectPhase>()
|
||||
.add<WaitPhase>(std::chrono::milliseconds(3000));
|
||||
pipeline.add<ReconnectPhase>();
|
||||
pipeline.add<WaitPhase>(std::chrono::milliseconds(3000));
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
std::vector<VersionReport> getChipVersions(bool refreshComponents = true) override {
|
||||
if(variantToFlash == FirmwareVariant::Invalid) {
|
||||
getCurrentVariant();
|
||||
}
|
||||
|
||||
if(refreshComponents) {
|
||||
refreshComponentVersions();
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/device/chipid.h"
|
||||
#include "icsneo/device/deviceversion.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@@ -17,6 +18,10 @@ struct VersionReport {
|
||||
uint8_t minor;
|
||||
uint8_t maintenance;
|
||||
uint8_t build;
|
||||
|
||||
icsneo::DeviceAppVersion makeAppVersion() const {
|
||||
return {major, minor};
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user