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
@@ -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__
|
||||
Reference in New Issue
Block a user