Skip to content

Commit

Permalink
Added bag start time, and a way to update it (#84)
Browse files Browse the repository at this point in the history
* Added bag start time, and a way to update it

* Added StartTime-test

Co-authored-by: Juni <junitrigger@gmail.com>
  • Loading branch information
Kytzis and Juni-hub authored Mar 18, 2022
1 parent 71178a2 commit be4b433
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions RosNet.Test/ApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, List<string>> fields = rosBag.GetConnectionFields();
Expand All @@ -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");
Expand Down
11 changes: 11 additions & 0 deletions RosNet.Test/DataModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);


}
}
File renamed without changes.
Binary file added RosNet.Test/TestBags/DataModelTestBag.bag
Binary file not shown.
2 changes: 1 addition & 1 deletion RosNet/DataModel/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,FieldValue> Data { get; internal set; }
Expand Down
15 changes: 15 additions & 0 deletions RosNet/DataModel/RosBag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class RosBag
{
public Dictionary<int, Connection> 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;

/// <summary>
Expand All @@ -20,6 +21,7 @@ public RosBag(string path)
this.Connections = new Dictionary<int, Connection>();
this.Path = path;
this._rosBagReader = new RosBagReader();
this.BagStartTime = new Time(uint.MaxValue, uint.MaxValue);
}

/// <summary>
Expand Down Expand Up @@ -104,4 +106,17 @@ public Dictionary<string, List<string>> GetConnectionFields()

return timeSeries;
}

/// <summary>
/// Sets the bag start time to the variable "time", if this is lower
/// than the current bag start time
/// </summary>
/// <param name="time">The Time object that might be the new bag start time</param>
internal void SetBagStartTime(Time time)
{
if (time.CompareTo(BagStartTime) < 0)
{
BagStartTime = time;
}
}
}
1 change: 1 addition & 0 deletions RosNet/RosReader/UnParsedMessageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void ParseMessages(RosBag rosBag)
{
message.Data = new ReadOnlyDictionary<string, FieldValue>(messageDataParser.ParseMessageData(data, kvp.Value.MessageDefinition));
rosBag.Connections[message.Conn].Messages.Add(message);
rosBag.SetBagStartTime(message.TimeStamp);
}
UnParsedMessageByConn.Remove(kvp.Key);
}
Expand Down

0 comments on commit be4b433

Please sign in to comment.