diff --git a/RosNet.Test/ApiTests.cs b/RosNet.Test/ApiTests.cs index fe967ab..5c76044 100644 --- a/RosNet.Test/ApiTests.cs +++ b/RosNet.Test/ApiTests.cs @@ -20,7 +20,7 @@ public static string GetTestPath(string relativePath) [Fact] public void TestGetConnectionFields() { - string path = GetTestPath("TestBag.bag"); + string path = GetTestPath("ApiTestBag.bag"); RosBag rosBag = new RosBag(path); rosBag.Read(); Dictionary> fields = rosBag.GetConnectionFields(); @@ -34,7 +34,7 @@ public void TestGetConnectionFields() [Fact] public void TestGetTimeSeries() { - string path = GetTestPath("TestBag.bag"); + string path = GetTestPath("ApiTestBag.bag"); RosBag rosBag = new RosBag(path); rosBag.Read(); List<(Time, FieldValue)> timeSeries = rosBag.GetTimeSeries("/amk/motor_moment", "FL_motor_moment"); diff --git a/RosNet.Test/DataModelTests.cs b/RosNet.Test/DataModelTests.cs index 5f6a1ef..e8a5f6c 100644 --- a/RosNet.Test/DataModelTests.cs +++ b/RosNet.Test/DataModelTests.cs @@ -16,4 +16,15 @@ public void TestToDateTime() // 1 tick is 100 nano seconds Assert.Equal(test.ToDateTime(), new DateTime(2022, 02, 15, 14, 35, 8).AddSeconds(epochNano * Math.Pow(10, -9))); } + + [Fact] + public void TestBagStartTime() + { + string path = ApiTests.GetTestPath("DataModelTestBag.bag"); + RosBag rosBag = new RosBag(path); + rosBag.Read(); + Assert.Equal(new Time(1622060004, 130476520), rosBag.BagStartTime); + + + } } diff --git a/RosNet.Test/TestBags/TestBag.bag b/RosNet.Test/TestBags/ApiTestBag.bag similarity index 100% rename from RosNet.Test/TestBags/TestBag.bag rename to RosNet.Test/TestBags/ApiTestBag.bag diff --git a/RosNet.Test/TestBags/DataModelTestBag.bag b/RosNet.Test/TestBags/DataModelTestBag.bag new file mode 100644 index 0000000..1bafe91 Binary files /dev/null and b/RosNet.Test/TestBags/DataModelTestBag.bag differ diff --git a/RosNet/DataModel/Message.cs b/RosNet/DataModel/Message.cs index 52ba665..3d71c4a 100644 --- a/RosNet/DataModel/Message.cs +++ b/RosNet/DataModel/Message.cs @@ -10,7 +10,7 @@ public class Message { //Header fields of message record: public int Conn { get; } - public Time TimeStamp { get; } + public Time TimeStamp { get; } //Data in message record: public ReadOnlyDictionary Data { get; internal set; } diff --git a/RosNet/DataModel/RosBag.cs b/RosNet/DataModel/RosBag.cs index 01b9f8d..eb9a93b 100644 --- a/RosNet/DataModel/RosBag.cs +++ b/RosNet/DataModel/RosBag.cs @@ -10,6 +10,7 @@ public class RosBag { public Dictionary Connections { get; private set; } //List of connection records in rosbag public string Path { get; private set; } + public Time BagStartTime { get; private set; } private RosBagReader _rosBagReader; /// @@ -20,6 +21,7 @@ public RosBag(string path) this.Connections = new Dictionary(); this.Path = path; this._rosBagReader = new RosBagReader(); + this.BagStartTime = new Time(uint.MaxValue, uint.MaxValue); } /// @@ -104,4 +106,17 @@ public Dictionary> GetConnectionFields() return timeSeries; } + + /// + /// Sets the bag start time to the variable "time", if this is lower + /// than the current bag start time + /// + /// The Time object that might be the new bag start time + internal void SetBagStartTime(Time time) + { + if (time.CompareTo(BagStartTime) < 0) + { + BagStartTime = time; + } + } } diff --git a/RosNet/RosReader/UnParsedMessageHandler.cs b/RosNet/RosReader/UnParsedMessageHandler.cs index 3fafe0d..b748e11 100644 --- a/RosNet/RosReader/UnParsedMessageHandler.cs +++ b/RosNet/RosReader/UnParsedMessageHandler.cs @@ -48,6 +48,7 @@ public void ParseMessages(RosBag rosBag) { message.Data = new ReadOnlyDictionary(messageDataParser.ParseMessageData(data, kvp.Value.MessageDefinition)); rosBag.Connections[message.Conn].Messages.Add(message); + rosBag.SetBagStartTime(message.TimeStamp); } UnParsedMessageByConn.Remove(kvp.Key); }