mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
LiveData: Initial implementation
Add support for live data subscription via Device::subscribeLiveData() and Device::unsubscribeLiveData(). The live data API can be used to subscribe to individual "signals", a full list of which can be found in LiveDataValueType.
This commit is contained in:
committed by
Kyle Schwarz
parent
018f1fac8e
commit
8d704b1bbb
@@ -94,6 +94,16 @@ public:
|
||||
CoreminiUploadVersionMismatch = 0x2040,
|
||||
DiskNotConnected = 0x2041,
|
||||
UnexpectedResponse = 0x2042,
|
||||
LiveDataInvalidHandle = 0x2043,
|
||||
LiveDataInvalidCommand = 0x2044,
|
||||
LiveDataInvalidArgument = 0x2045,
|
||||
LiveDataVersionMismatch = 0x2046,
|
||||
LiveDataNoDeviceResponse = 0x2047,
|
||||
LiveDataMaxSignalsReached = 0x2048,
|
||||
LiveDataCommandFailed = 0x2049,
|
||||
LiveDataEncoderError = 0x2050,
|
||||
LiveDataDecoderError = 0x2051,
|
||||
LiveDataNotSupported = 0x2052,
|
||||
|
||||
// Transport Events
|
||||
FailedToRead = 0x3000,
|
||||
|
||||
@@ -35,7 +35,7 @@ enum class Command : uint8_t {
|
||||
ExtendedData = 0xF2, // Previously known as RED_CMD_EXTENDED_DATA
|
||||
FlexRayControl = 0xF3,
|
||||
CoreMiniPreload = 0xF4, // Previously known as RED_CMD_COREMINI_PRELOAD
|
||||
PHYControlRegisters = 0xEF
|
||||
PHYControlRegisters = 0xEF,
|
||||
};
|
||||
|
||||
enum class ExtendedCommand : uint16_t {
|
||||
@@ -53,6 +53,7 @@ enum class ExtendedCommand : uint16_t {
|
||||
Reboot = 0x001C,
|
||||
SetUploadedFlag = 0x0027,
|
||||
GenericBinaryInfo = 0x0030,
|
||||
LiveData = 0x0035,
|
||||
};
|
||||
|
||||
enum class ExtendedResponse : int32_t {
|
||||
@@ -68,6 +69,16 @@ enum class ExtendedDataSubCommand : uint32_t {
|
||||
GenericBinaryRead = 13,
|
||||
};
|
||||
|
||||
#pragma pack(push,1)
|
||||
struct ExtendedCommandHeader {
|
||||
uint8_t netid; // should be Main51
|
||||
uint16_t fullLength;
|
||||
uint8_t command; // should be Command::Extended
|
||||
uint16_t extendedCommand;
|
||||
uint16_t payloadLength;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
#ifndef __LIVEDATA_H__
|
||||
#define __LIVEDATA_H__
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "icsneo/communication/command.h"
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
typedef uint32_t LiveDataHandle;
|
||||
static constexpr size_t MAX_LIVE_DATA_ENTRIES = 20;
|
||||
|
||||
enum class LiveDataCommand : uint32_t {
|
||||
STATUS = 0,
|
||||
SUBSCRIBE,
|
||||
UNSUBSCRIBE,
|
||||
RESPONSE,
|
||||
CLEAR_ALL,
|
||||
};
|
||||
|
||||
enum class LiveDataStatus : uint32_t {
|
||||
SUCCESS = 0,
|
||||
ERR_UNKNOWN_COMMAND,
|
||||
ERR_HANDLE,
|
||||
ERR_DUPLICATE,
|
||||
ERR_FULL
|
||||
};
|
||||
|
||||
enum LiveDataObjectType : uint16_t {
|
||||
MISC = 8,
|
||||
SNA = UINT16_MAX,
|
||||
};
|
||||
|
||||
enum class LiveDataValueType : uint32_t {
|
||||
GPS_LATITUDE = 2,
|
||||
GPS_LONGITUDE,
|
||||
GPS_ALTITUDE,
|
||||
GPS_SPEED,
|
||||
GPS_VALID,
|
||||
GPS_ENABLE = 62,
|
||||
GPS_ACCURACY = 120,
|
||||
GPS_BEARING = 121,
|
||||
GPS_TIME = 122,
|
||||
GPS_TIME_VALID = 123,
|
||||
};
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const LiveDataCommand cmd) {
|
||||
switch (cmd) {
|
||||
case LiveDataCommand::STATUS: return os << "Status";
|
||||
case LiveDataCommand::SUBSCRIBE: return os << "Subscribe";
|
||||
case LiveDataCommand::UNSUBSCRIBE: return os << "Unsubscribe";
|
||||
case LiveDataCommand::RESPONSE: return os << "Response";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const LiveDataStatus cmd) {
|
||||
switch (cmd) {
|
||||
case LiveDataStatus::SUCCESS: return os << "Success";
|
||||
case LiveDataStatus::ERR_UNKNOWN_COMMAND: return os << "Error: Unknown Command";
|
||||
case LiveDataStatus::ERR_HANDLE: return os << "Error: Handle";
|
||||
case LiveDataStatus::ERR_DUPLICATE: return os << "Error: Duplicate";
|
||||
case LiveDataStatus::ERR_FULL: return os << "Error: Argument limit reached";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, const LiveDataValueType cmd) {
|
||||
switch (cmd) {
|
||||
case LiveDataValueType::GPS_LATITUDE: return os << "GPS Latitude";
|
||||
case LiveDataValueType::GPS_LONGITUDE: return os << "GPS Longitude";
|
||||
case LiveDataValueType::GPS_ALTITUDE: return os << "GPS Altitude";
|
||||
case LiveDataValueType::GPS_SPEED: return os << "GPS Speed";
|
||||
case LiveDataValueType::GPS_VALID: return os << "GPS Valid";
|
||||
case LiveDataValueType::GPS_ENABLE: return os << "GPS Enabled";
|
||||
case LiveDataValueType::GPS_ACCURACY: return os << "GPS Accuracy";
|
||||
case LiveDataValueType::GPS_BEARING: return os << "GPS Bearing";
|
||||
case LiveDataValueType::GPS_TIME: return os << "GPS Time";
|
||||
case LiveDataValueType::GPS_TIME_VALID: return os << "GPS Time Valid";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
#pragma pack(push,2)
|
||||
struct LiveDataHeader {
|
||||
uint32_t version; // See LiveDataVersion
|
||||
uint32_t cmd;
|
||||
uint32_t handle;
|
||||
};
|
||||
|
||||
struct LiveDataArgument {
|
||||
LiveDataObjectType objectType;
|
||||
uint32_t objectIndex;
|
||||
uint32_t signalIndex;
|
||||
LiveDataValueType valueType;
|
||||
};
|
||||
|
||||
struct LiveDataValueHeader {
|
||||
uint16_t length; // Number of bytes to follow header
|
||||
uint8_t reserved[2];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LiveDataValueHeader header;
|
||||
int64_t value;
|
||||
} LiveDataValue;
|
||||
|
||||
struct LiveDataValueResponse : public LiveDataHeader {
|
||||
uint32_t numArgs;
|
||||
LiveDataValue values[1];
|
||||
};
|
||||
|
||||
struct LiveDataStatusResponse : public LiveDataHeader {
|
||||
LiveDataCommand requestedCommand;
|
||||
LiveDataStatus status;
|
||||
};
|
||||
|
||||
struct LiveDataSubscribe : public LiveDataHeader {
|
||||
uint32_t numArgs;
|
||||
uint32_t freqMs;
|
||||
uint32_t expireMs;
|
||||
LiveDataArgument args[1];
|
||||
};
|
||||
|
||||
struct ExtResponseHeader {
|
||||
ExtendedCommand command;
|
||||
uint16_t length;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
namespace LiveDataUtil
|
||||
{
|
||||
|
||||
LiveDataHandle getNewHandle();
|
||||
double liveDataValueToDouble(const LiveDataValue& val);
|
||||
static constexpr uint32_t LiveDataVersion = 1;
|
||||
|
||||
} // namespace LiveDataUtil
|
||||
} // namespace icsneo
|
||||
|
||||
#endif // _cplusplus
|
||||
#endif // __LIVEDATA_H__
|
||||
@@ -0,0 +1,44 @@
|
||||
#ifndef __EXTENDEDLIVEDATAMESSAGE_H_
|
||||
#define __EXTENDEDLIVEDATAMESSAGE_H_
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <chrono>
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/command.h"
|
||||
#include "icsneo/communication/livedata.h"
|
||||
|
||||
namespace icsneo {
|
||||
class LiveDataMessage : public RawMessage {
|
||||
public:
|
||||
LiveDataMessage() : RawMessage(Message::Type::LiveData, Network::NetID::ExtendedCommand) {}
|
||||
LiveDataHandle handle;
|
||||
LiveDataCommand cmd;
|
||||
};
|
||||
|
||||
class LiveDataCommandMessage : public LiveDataMessage {
|
||||
public:
|
||||
LiveDataCommandMessage() {}
|
||||
std::chrono::milliseconds updatePeriod;
|
||||
std::chrono::milliseconds expirationTime;
|
||||
std::vector<std::shared_ptr<LiveDataArgument>> args;
|
||||
void appendSignalArg(LiveDataValueType valueType);
|
||||
};
|
||||
|
||||
class LiveDataValueMessage : public LiveDataMessage {
|
||||
public:
|
||||
LiveDataValueMessage() {}
|
||||
uint32_t numArgs;
|
||||
std::vector<std::shared_ptr<LiveDataValue>> values;
|
||||
};
|
||||
|
||||
class LiveDataStatusMessage : public LiveDataMessage {
|
||||
public:
|
||||
LiveDataStatusMessage() {}
|
||||
LiveDataCommand requestedCommand;
|
||||
LiveDataStatus status;
|
||||
};
|
||||
|
||||
} // namespace icsneo
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // __EXTENDEDLIVEDATAMESSAGE_H_
|
||||
@@ -37,6 +37,7 @@ public:
|
||||
ComponentVersions = 0x800c,
|
||||
SupportedFeatures = 0x800d,
|
||||
GenericBinaryStatus = 0x800e,
|
||||
LiveData = 0x800f,
|
||||
};
|
||||
|
||||
Message(Type t) : type(t) {}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef __LIVEDATAPACKET_H__
|
||||
#define __LIVEDATAPACKET_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "icsneo/api/eventmanager.h"
|
||||
#include "icsneo/communication/message/message.h"
|
||||
#include "icsneo/communication/message/livedatamessage.h"
|
||||
#include "icsneo/communication/livedata.h"
|
||||
|
||||
namespace icsneo {
|
||||
|
||||
class LiveDataMessage;
|
||||
|
||||
struct HardwareLiveDataPacket {
|
||||
static std::shared_ptr<Message> DecodeToMessage(const std::vector<uint8_t>& bytes, const device_eventhandler_t& report);
|
||||
static bool EncodeFromMessage(LiveDataMessage& message, std::vector<uint8_t>& bytes, const device_eventhandler_t& report);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __LIVEDATAPACKET_H__
|
||||
@@ -35,7 +35,9 @@
|
||||
#include "icsneo/communication/message/supportedfeaturesmessage.h"
|
||||
#include "icsneo/communication/message/genericbinarystatusmessage.h"
|
||||
#include "icsneo/communication/message/extendeddatamessage.h"
|
||||
#include "icsneo/communication/message/livedatamessage.h"
|
||||
#include "icsneo/communication/packet/genericbinarystatuspacket.h"
|
||||
#include "icsneo/communication/packet/livedatapacket.h"
|
||||
#include "icsneo/device/extensions/flexray/controller.h"
|
||||
#include "icsneo/communication/message/flexray/control/flexraycontrolmessage.h"
|
||||
#include "icsneo/communication/message/ethphymessage.h"
|
||||
@@ -561,6 +563,9 @@ public:
|
||||
*/
|
||||
virtual bool supportsWiVI() const { return false; }
|
||||
|
||||
// Returns true if this device supports Live Data subscription
|
||||
virtual bool supportsLiveData() const { return false; }
|
||||
|
||||
std::optional<EthPhyMessage> sendEthPhyMsg(const EthPhyMessage& message, std::chrono::milliseconds timeout = std::chrono::milliseconds(50));
|
||||
|
||||
std::optional<bool> SetCollectionUploaded(uint32_t collectionEntryByteAddress);
|
||||
@@ -570,6 +575,9 @@ public:
|
||||
|
||||
std::optional<size_t> getGenericBinarySize(uint16_t binaryIndex);
|
||||
bool readBinaryFile(std::ostream& stream, uint16_t binaryIndex);
|
||||
bool subscribeLiveData(std::shared_ptr<LiveDataCommandMessage> message);
|
||||
bool unsubscribeLiveData(const LiveDataHandle& handle);
|
||||
bool clearAllLiveData();
|
||||
|
||||
protected:
|
||||
bool online = false;
|
||||
|
||||
@@ -75,6 +75,8 @@ protected:
|
||||
|
||||
bool supportsWiVI() const override { return true; }
|
||||
|
||||
bool supportsLiveData() const override { return true; }
|
||||
|
||||
std::optional<MemoryAddress> getCoreminiStartAddressFlash() const override {
|
||||
return 33*1024*1024;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ protected:
|
||||
|
||||
bool supportsWiVI() const override { return true; }
|
||||
|
||||
bool supportsLiveData() const override { return true; }
|
||||
|
||||
std::optional<MemoryAddress> getCoreminiStartAddressFlash() const override {
|
||||
return 33*1024*1024;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user