From f8b944a613a654767dc4407d9b0f5bf3413c476a Mon Sep 17 00:00:00 2001 From: Jabberrock Date: Mon, 11 Nov 2024 12:27:52 -0800 Subject: [PATCH] Adds `log_messages` field to device data so that SlimeVR GUI can display log messages from the device --- .../generated/all_generated.h | 23 +++++++++-- .../data_feed/device_data/DeviceData.java | 20 +++++++++- .../data_feed/device_data/DeviceDataT.java | 6 +++ .../data_feed/device_data/DeviceData.kt | 26 ++++++++++++- .../device_data/device_data_generated.rs | 17 ++++++++ .../data-feed/device-data/device-data.ts | 39 +++++++++++++++++-- schema/data_feed/device_data.fbs | 3 ++ 7 files changed, 125 insertions(+), 9 deletions(-) diff --git a/protocol/cpp/include/solarxr_protocol/generated/all_generated.h b/protocol/cpp/include/solarxr_protocol/generated/all_generated.h index 113a1500..b0fc0136 100644 --- a/protocol/cpp/include/solarxr_protocol/generated/all_generated.h +++ b/protocol/cpp/include/solarxr_protocol/generated/all_generated.h @@ -3777,7 +3777,8 @@ struct DeviceData FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VT_CUSTOM_NAME = 6, VT_HARDWARE_INFO = 8, VT_HARDWARE_STATUS = 10, - VT_TRACKERS = 12 + VT_TRACKERS = 12, + VT_LOG_MESSAGES = 14 }; const solarxr_protocol::datatypes::DeviceId *id() const { return GetStruct(VT_ID); @@ -3799,6 +3800,9 @@ struct DeviceData FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { const flatbuffers::Vector> *trackers() const { return GetPointer> *>(VT_TRACKERS); } + const flatbuffers::Vector> *log_messages() const { + return GetPointer> *>(VT_LOG_MESSAGES); + } bool Verify(flatbuffers::Verifier &verifier) const { return VerifyTableStart(verifier) && VerifyField(verifier, VT_ID, 1) && @@ -3811,6 +3815,9 @@ struct DeviceData FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { VerifyOffset(verifier, VT_TRACKERS) && verifier.VerifyVector(trackers()) && verifier.VerifyVectorOfTables(trackers()) && + VerifyOffset(verifier, VT_LOG_MESSAGES) && + verifier.VerifyVector(log_messages()) && + verifier.VerifyVectorOfStrings(log_messages()) && verifier.EndTable(); } }; @@ -3834,6 +3841,9 @@ struct DeviceDataBuilder { void add_trackers(flatbuffers::Offset>> trackers) { fbb_.AddOffset(DeviceData::VT_TRACKERS, trackers); } + void add_log_messages(flatbuffers::Offset>> log_messages) { + fbb_.AddOffset(DeviceData::VT_LOG_MESSAGES, log_messages); + } explicit DeviceDataBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); @@ -3851,8 +3861,10 @@ inline flatbuffers::Offset CreateDeviceData( flatbuffers::Offset custom_name = 0, flatbuffers::Offset hardware_info = 0, flatbuffers::Offset hardware_status = 0, - flatbuffers::Offset>> trackers = 0) { + flatbuffers::Offset>> trackers = 0, + flatbuffers::Offset>> log_messages = 0) { DeviceDataBuilder builder_(_fbb); + builder_.add_log_messages(log_messages); builder_.add_trackers(trackers); builder_.add_hardware_status(hardware_status); builder_.add_hardware_info(hardware_info); @@ -3867,16 +3879,19 @@ inline flatbuffers::Offset CreateDeviceDataDirect( const char *custom_name = nullptr, flatbuffers::Offset hardware_info = 0, flatbuffers::Offset hardware_status = 0, - const std::vector> *trackers = nullptr) { + const std::vector> *trackers = nullptr, + const std::vector> *log_messages = nullptr) { auto custom_name__ = custom_name ? _fbb.CreateString(custom_name) : 0; auto trackers__ = trackers ? _fbb.CreateVector>(*trackers) : 0; + auto log_messages__ = log_messages ? _fbb.CreateVector>(*log_messages) : 0; return solarxr_protocol::data_feed::device_data::CreateDeviceData( _fbb, id, custom_name__, hardware_info, hardware_status, - trackers__); + trackers__, + log_messages__); } } // namespace device_data diff --git a/protocol/java/src/solarxr_protocol/data_feed/device_data/DeviceData.java b/protocol/java/src/solarxr_protocol/data_feed/device_data/DeviceData.java index bcdd6cef..d79313ce 100644 --- a/protocol/java/src/solarxr_protocol/data_feed/device_data/DeviceData.java +++ b/protocol/java/src/solarxr_protocol/data_feed/device_data/DeviceData.java @@ -47,8 +47,12 @@ public final class DeviceData extends Table { public int trackersLength() { int o = __offset(12); return o != 0 ? __vector_len(o) : 0; } public solarxr_protocol.data_feed.tracker.TrackerData.Vector trackersVector() { return trackersVector(new solarxr_protocol.data_feed.tracker.TrackerData.Vector()); } public solarxr_protocol.data_feed.tracker.TrackerData.Vector trackersVector(solarxr_protocol.data_feed.tracker.TrackerData.Vector obj) { int o = __offset(12); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } + public String logMessages(int j) { int o = __offset(14); return o != 0 ? __string(__vector(o) + j * 4) : null; } + public int logMessagesLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; } + public StringVector logMessagesVector() { return logMessagesVector(new StringVector()); } + public StringVector logMessagesVector(StringVector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; } - public static void startDeviceData(FlatBufferBuilder builder) { builder.startTable(5); } + public static void startDeviceData(FlatBufferBuilder builder) { builder.startTable(6); } public static void addId(FlatBufferBuilder builder, int idOffset) { builder.addStruct(0, idOffset, 0); } public static void addCustomName(FlatBufferBuilder builder, int customNameOffset) { builder.addOffset(1, customNameOffset, 0); } public static void addHardwareInfo(FlatBufferBuilder builder, int hardwareInfoOffset) { builder.addOffset(2, hardwareInfoOffset, 0); } @@ -56,6 +60,9 @@ public final class DeviceData extends Table { public static void addTrackers(FlatBufferBuilder builder, int trackersOffset) { builder.addOffset(4, trackersOffset, 0); } public static int createTrackersVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } public static void startTrackersVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } + public static void addLogMessages(FlatBufferBuilder builder, int logMessagesOffset) { builder.addOffset(5, logMessagesOffset, 0); } + public static int createLogMessagesVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); } + public static void startLogMessagesVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); } public static int endDeviceData(FlatBufferBuilder builder) { int o = builder.endTable(); return o; @@ -84,6 +91,9 @@ public void unpackTo(DeviceDataT _o) { solarxr_protocol.data_feed.tracker.TrackerDataT[] _oTrackers = new solarxr_protocol.data_feed.tracker.TrackerDataT[trackersLength()]; for (int _j = 0; _j < trackersLength(); ++_j) {_oTrackers[_j] = (trackers(_j) != null ? trackers(_j).unpack() : null);} _o.setTrackers(_oTrackers); + String[] _oLogMessages = new String[logMessagesLength()]; + for (int _j = 0; _j < logMessagesLength(); ++_j) {_oLogMessages[_j] = logMessages(_j);} + _o.setLogMessages(_oLogMessages); } public static int pack(FlatBufferBuilder builder, DeviceDataT _o) { if (_o == null) return 0; @@ -97,12 +107,20 @@ public static int pack(FlatBufferBuilder builder, DeviceDataT _o) { for (solarxr_protocol.data_feed.tracker.TrackerDataT _e : _o.getTrackers()) { __trackers[_j] = solarxr_protocol.data_feed.tracker.TrackerData.pack(builder, _e); _j++;} _trackers = createTrackersVector(builder, __trackers); } + int _logMessages = 0; + if (_o.getLogMessages() != null) { + int[] __logMessages = new int[_o.getLogMessages().length]; + int _j = 0; + for (String _e : _o.getLogMessages()) { __logMessages[_j] = builder.createString(_e); _j++;} + _logMessages = createLogMessagesVector(builder, __logMessages); + } startDeviceData(builder); addId(builder, solarxr_protocol.datatypes.DeviceId.pack(builder, _o.getId())); addCustomName(builder, _customName); addHardwareInfo(builder, _hardwareInfo); addHardwareStatus(builder, _hardwareStatus); addTrackers(builder, _trackers); + addLogMessages(builder, _logMessages); return endDeviceData(builder); } } diff --git a/protocol/java/src/solarxr_protocol/data_feed/device_data/DeviceDataT.java b/protocol/java/src/solarxr_protocol/data_feed/device_data/DeviceDataT.java index 071bc66a..5d8554e1 100644 --- a/protocol/java/src/solarxr_protocol/data_feed/device_data/DeviceDataT.java +++ b/protocol/java/src/solarxr_protocol/data_feed/device_data/DeviceDataT.java @@ -13,6 +13,7 @@ public class DeviceDataT { private solarxr_protocol.datatypes.hardware_info.HardwareInfoT hardwareInfo; private solarxr_protocol.datatypes.hardware_info.HardwareStatusT hardwareStatus; private solarxr_protocol.data_feed.tracker.TrackerDataT[] trackers; + private String[] logMessages; public solarxr_protocol.datatypes.DeviceIdT getId() { return id; } @@ -34,6 +35,10 @@ public class DeviceDataT { public void setTrackers(solarxr_protocol.data_feed.tracker.TrackerDataT[] trackers) { this.trackers = trackers; } + public String[] getLogMessages() { return logMessages; } + + public void setLogMessages(String[] logMessages) { this.logMessages = logMessages; } + public DeviceDataT() { this.id = new solarxr_protocol.datatypes.DeviceIdT(); @@ -41,6 +46,7 @@ public DeviceDataT() { this.hardwareInfo = null; this.hardwareStatus = null; this.trackers = null; + this.logMessages = null; } } diff --git a/protocol/kotlin/src/solarxr_protocol/data_feed/device_data/DeviceData.kt b/protocol/kotlin/src/solarxr_protocol/data_feed/device_data/DeviceData.kt index 7ea843d8..d5f50fa7 100644 --- a/protocol/kotlin/src/solarxr_protocol/data_feed/device_data/DeviceData.kt +++ b/protocol/kotlin/src/solarxr_protocol/data_feed/device_data/DeviceData.kt @@ -81,6 +81,18 @@ class DeviceData : Table() { get() { val o = __offset(12); return if (o != 0) __vector_len(o) else 0 } + fun logMessages(j: Int) : String? { + val o = __offset(14) + return if (o != 0) { + __string(__vector(o) + j * 4) + } else { + null + } + } + val logMessagesLength : Int + get() { + val o = __offset(14); return if (o != 0) __vector_len(o) else 0 + } companion object { @JvmStatic fun validateVersion() = Constants.FLATBUFFERS_22_10_26() @@ -92,7 +104,7 @@ class DeviceData : Table() { return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)) } @JvmStatic - fun startDeviceData(builder: FlatBufferBuilder) = builder.startTable(5) + fun startDeviceData(builder: FlatBufferBuilder) = builder.startTable(6) @JvmStatic fun addId(builder: FlatBufferBuilder, id: Int) = builder.addStruct(0, id, 0) @JvmStatic @@ -114,6 +126,18 @@ class DeviceData : Table() { @JvmStatic fun startTrackersVector(builder: FlatBufferBuilder, numElems: Int) = builder.startVector(4, numElems, 4) @JvmStatic + fun addLogMessages(builder: FlatBufferBuilder, logMessages: Int) = builder.addOffset(5, logMessages, 0) + @JvmStatic + fun createLogMessagesVector(builder: FlatBufferBuilder, data: IntArray) : Int { + builder.startVector(4, data.size, 4) + for (i in data.size - 1 downTo 0) { + builder.addOffset(data[i]) + } + return builder.endVector() + } + @JvmStatic + fun startLogMessagesVector(builder: FlatBufferBuilder, numElems: Int) = builder.startVector(4, numElems, 4) + @JvmStatic fun endDeviceData(builder: FlatBufferBuilder) : Int { val o = builder.endTable() return o diff --git a/protocol/rust/src/generated/solarxr_protocol/data_feed/device_data/device_data_generated.rs b/protocol/rust/src/generated/solarxr_protocol/data_feed/device_data/device_data_generated.rs index af9a830a..2eee7615 100644 --- a/protocol/rust/src/generated/solarxr_protocol/data_feed/device_data/device_data_generated.rs +++ b/protocol/rust/src/generated/solarxr_protocol/data_feed/device_data/device_data_generated.rs @@ -33,6 +33,7 @@ impl<'a> DeviceData<'a> { pub const VT_HARDWARE_INFO: flatbuffers::VOffsetT = 8; pub const VT_HARDWARE_STATUS: flatbuffers::VOffsetT = 10; pub const VT_TRACKERS: flatbuffers::VOffsetT = 12; + pub const VT_LOG_MESSAGES: flatbuffers::VOffsetT = 14; #[inline] pub unsafe fn init_from_table(table: flatbuffers::Table<'a>) -> Self { @@ -44,6 +45,7 @@ impl<'a> DeviceData<'a> { args: &'args DeviceDataArgs<'args> ) -> flatbuffers::WIPOffset> { let mut builder = DeviceDataBuilder::new(_fbb); + if let Some(x) = args.log_messages { builder.add_log_messages(x); } if let Some(x) = args.trackers { builder.add_trackers(x); } if let Some(x) = args.hardware_status { builder.add_hardware_status(x); } if let Some(x) = args.hardware_info { builder.add_hardware_info(x); } @@ -93,6 +95,13 @@ impl<'a> DeviceData<'a> { // which contains a valid value in this slot unsafe { self._tab.get::>>>(DeviceData::VT_TRACKERS, None)} } + #[inline] + pub fn log_messages(&self) -> Option>> { + // Safety: + // Created from valid Table for this object + // which contains a valid value in this slot + unsafe { self._tab.get::>>>(DeviceData::VT_LOG_MESSAGES, None)} + } } impl flatbuffers::Verifiable for DeviceData<'_> { @@ -107,6 +116,7 @@ impl flatbuffers::Verifiable for DeviceData<'_> { .visit_field::>("hardware_info", Self::VT_HARDWARE_INFO, false)? .visit_field::>("hardware_status", Self::VT_HARDWARE_STATUS, false)? .visit_field::>>>("trackers", Self::VT_TRACKERS, false)? + .visit_field::>>>("log_messages", Self::VT_LOG_MESSAGES, false)? .finish(); Ok(()) } @@ -117,6 +127,7 @@ pub struct DeviceDataArgs<'a> { pub hardware_info: Option>>, pub hardware_status: Option>>, pub trackers: Option>>>>, + pub log_messages: Option>>>, } impl<'a> Default for DeviceDataArgs<'a> { #[inline] @@ -127,6 +138,7 @@ impl<'a> Default for DeviceDataArgs<'a> { hardware_info: None, hardware_status: None, trackers: None, + log_messages: None, } } } @@ -157,6 +169,10 @@ impl<'a: 'b, 'b> DeviceDataBuilder<'a, 'b> { self.fbb_.push_slot_always::>(DeviceData::VT_TRACKERS, trackers); } #[inline] + pub fn add_log_messages(&mut self, log_messages: flatbuffers::WIPOffset>>) { + self.fbb_.push_slot_always::>(DeviceData::VT_LOG_MESSAGES, log_messages); + } + #[inline] pub fn new(_fbb: &'b mut flatbuffers::FlatBufferBuilder<'a>) -> DeviceDataBuilder<'a, 'b> { let start = _fbb.start_table(); DeviceDataBuilder { @@ -179,6 +195,7 @@ impl core::fmt::Debug for DeviceData<'_> { ds.field("hardware_info", &self.hardware_info()); ds.field("hardware_status", &self.hardware_status()); ds.field("trackers", &self.trackers()); + ds.field("log_messages", &self.log_messages()); ds.finish() } } diff --git a/protocol/typescript/src/solarxr-protocol/data-feed/device-data/device-data.ts b/protocol/typescript/src/solarxr-protocol/data-feed/device-data/device-data.ts index cf35b8de..ed63d3a9 100644 --- a/protocol/typescript/src/solarxr-protocol/data-feed/device-data/device-data.ts +++ b/protocol/typescript/src/solarxr-protocol/data-feed/device-data/device-data.ts @@ -76,8 +76,20 @@ trackersLength():number { return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; } +logMessages(index: number):string +logMessages(index: number,optionalEncoding:flatbuffers.Encoding):string|Uint8Array +logMessages(index: number,optionalEncoding?:any):string|Uint8Array|null { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.__string(this.bb!.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null; +} + +logMessagesLength():number { + const offset = this.bb!.__offset(this.bb_pos, 14); + return offset ? this.bb!.__vector_len(this.bb_pos + offset) : 0; +} + static startDeviceData(builder:flatbuffers.Builder) { - builder.startObject(5); + builder.startObject(6); } static addId(builder:flatbuffers.Builder, idOffset:flatbuffers.Offset) { @@ -112,6 +124,22 @@ static startTrackersVector(builder:flatbuffers.Builder, numElems:number) { builder.startVector(4, numElems, 4); } +static addLogMessages(builder:flatbuffers.Builder, logMessagesOffset:flatbuffers.Offset) { + builder.addFieldOffset(5, logMessagesOffset, 0); +} + +static createLogMessagesVector(builder:flatbuffers.Builder, data:flatbuffers.Offset[]):flatbuffers.Offset { + builder.startVector(4, data.length, 4); + for (let i = data.length - 1; i >= 0; i--) { + builder.addOffset(data[i]!); + } + return builder.endVector(); +} + +static startLogMessagesVector(builder:flatbuffers.Builder, numElems:number) { + builder.startVector(4, numElems, 4); +} + static endDeviceData(builder:flatbuffers.Builder):flatbuffers.Offset { const offset = builder.endObject(); return offset; @@ -124,7 +152,8 @@ unpack(): DeviceDataT { this.customName(), (this.hardwareInfo() !== null ? this.hardwareInfo()!.unpack() : null), (this.hardwareStatus() !== null ? this.hardwareStatus()!.unpack() : null), - this.bb!.createObjList(this.trackers.bind(this), this.trackersLength()) + this.bb!.createObjList(this.trackers.bind(this), this.trackersLength()), + this.bb!.createScalarList(this.logMessages.bind(this), this.logMessagesLength()) ); } @@ -135,6 +164,7 @@ unpackTo(_o: DeviceDataT): void { _o.hardwareInfo = (this.hardwareInfo() !== null ? this.hardwareInfo()!.unpack() : null); _o.hardwareStatus = (this.hardwareStatus() !== null ? this.hardwareStatus()!.unpack() : null); _o.trackers = this.bb!.createObjList(this.trackers.bind(this), this.trackersLength()); + _o.logMessages = this.bb!.createScalarList(this.logMessages.bind(this), this.logMessagesLength()); } } @@ -144,7 +174,8 @@ constructor( public customName: string|Uint8Array|null = null, public hardwareInfo: HardwareInfoT|null = null, public hardwareStatus: HardwareStatusT|null = null, - public trackers: (TrackerDataT)[] = [] + public trackers: (TrackerDataT)[] = [], + public logMessages: (string)[] = [] ){} @@ -153,6 +184,7 @@ pack(builder:flatbuffers.Builder): flatbuffers.Offset { const hardwareInfo = (this.hardwareInfo !== null ? this.hardwareInfo!.pack(builder) : 0); const hardwareStatus = (this.hardwareStatus !== null ? this.hardwareStatus!.pack(builder) : 0); const trackers = DeviceData.createTrackersVector(builder, builder.createObjectOffsetList(this.trackers)); + const logMessages = DeviceData.createLogMessagesVector(builder, builder.createObjectOffsetList(this.logMessages)); DeviceData.startDeviceData(builder); DeviceData.addId(builder, (this.id !== null ? this.id!.pack(builder) : 0)); @@ -160,6 +192,7 @@ pack(builder:flatbuffers.Builder): flatbuffers.Offset { DeviceData.addHardwareInfo(builder, hardwareInfo); DeviceData.addHardwareStatus(builder, hardwareStatus); DeviceData.addTrackers(builder, trackers); + DeviceData.addLogMessages(builder, logMessages); return DeviceData.endDeviceData(builder); } diff --git a/schema/data_feed/device_data.fbs b/schema/data_feed/device_data.fbs index 7949272e..c1c6efcc 100644 --- a/schema/data_feed/device_data.fbs +++ b/schema/data_feed/device_data.fbs @@ -38,4 +38,7 @@ table DeviceData { /// Info about all trackers attached to this device trackers: [solarxr_protocol.data_feed.tracker.TrackerData]; + + /// Log messages sent from the device + log_messages: [string]; }