mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
Device: Implement version handling
This commit is contained in:
@@ -9,11 +9,13 @@ enum class Command : uint8_t {
|
||||
EnableNetworkCommunication = 0x07,
|
||||
EnableNetworkCommunicationEx = 0x08,
|
||||
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
|
||||
//GetSettings = 0xA5, // Previously known as RED_CMD_READ_BAUD_REQ, now unused
|
||||
SaveSettings = 0xA6,
|
||||
UpdateLEDState = 0xA7,
|
||||
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
|
||||
RequestStatusUpdate = 0xBC,
|
||||
ReadSettings = 0xC7, // Previously known as 3G_READ_SETTINGS_EX
|
||||
MiscControl = 0xE7,
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "icsneo/communication/packet.h"
|
||||
#include "icsneo/communication/message/callback/messagecallback.h"
|
||||
#include "icsneo/communication/message/serialnumbermessage.h"
|
||||
#include "icsneo/device/deviceversion.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/communication/packetizer.h"
|
||||
#include "icsneo/communication/encoder.h"
|
||||
@@ -53,6 +54,7 @@ public:
|
||||
virtual bool sendCommand(Command cmd, std::vector<uint8_t> arguments = {});
|
||||
bool getSettingsSync(std::vector<uint8_t>& data, std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
|
||||
std::shared_ptr<SerialNumberMessage> getSerialNumberSync(std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
|
||||
optional< std::vector< optional<DeviceAppVersion> > > getVersionsSync(std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
|
||||
|
||||
int addMessageCallback(const MessageCallback& cb);
|
||||
bool removeMessageCallback(int id);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef __VERSIONMESSAGE_H_
|
||||
#define __VERSIONMESSAGE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/device/deviceversion.h"
|
||||
#include "icsneo/platform/optional.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class VersionMessage : public Message {
|
||||
public:
|
||||
VersionMessage(bool main) : MainChip(main) { network = Network::NetID::Main51; }
|
||||
|
||||
// If true, the included version is for the main chip
|
||||
const bool MainChip;
|
||||
|
||||
// nullopt here indicates invalid
|
||||
std::vector< optional<DeviceAppVersion> > Versions;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef __VERSIONPACKET_H__
|
||||
#define __VERSIONPACKET_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/communication/message/versionmessage.h"
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
struct HardwareVersionPacket {
|
||||
static std::shared_ptr<VersionMessage> DecodeMainToMessage(const std::vector<uint8_t>& bytestream);
|
||||
static std::shared_ptr<VersionMessage> DecodeSecondaryToMessage(const std::vector<uint8_t>& bytestream);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "icsneo/device/idevicesettings.h"
|
||||
#include "icsneo/device/nullsettings.h"
|
||||
#include "icsneo/device/devicetype.h"
|
||||
#include "icsneo/device/deviceversion.h"
|
||||
#include "icsneo/communication/communication.h"
|
||||
#include "icsneo/communication/packetizer.h"
|
||||
#include "icsneo/communication/encoder.h"
|
||||
@@ -210,6 +211,11 @@ public:
|
||||
NODISCARD("If the Lifetime is not held, disconnects will be immediately unsuppressed")
|
||||
Lifetime suppressDisconnects();
|
||||
|
||||
/**
|
||||
* For use by extensions only. A more stable API will be provided in the future.
|
||||
*/
|
||||
const std::vector<optional<DeviceAppVersion>>& getVersions() const { return versions; }
|
||||
|
||||
/**
|
||||
* Some alternate communication protocols do not support DFU
|
||||
*/
|
||||
@@ -328,6 +334,7 @@ protected:
|
||||
private:
|
||||
neodevice_t data;
|
||||
std::shared_ptr<ResetStatusMessage> latestResetStatus;
|
||||
std::vector<optional<DeviceAppVersion>> versions;
|
||||
|
||||
mutable std::mutex extensionsLock;
|
||||
std::vector<std::shared_ptr<DeviceExtension>> extensions;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef __DEVICEVERSION_H_
|
||||
#define __DEVICEVERSION_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "icsneo/platform/optional.h"
|
||||
#include <cstdint>
|
||||
#include <array>
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
struct DeviceAppVersion {
|
||||
uint8_t major = 0;
|
||||
uint8_t minor = 0;
|
||||
|
||||
bool operator!=(const DeviceAppVersion& rhs) const { return major != rhs.major || minor != rhs.minor; }
|
||||
};
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user