Skip to content

Commit

Permalink
add named pdu
Browse files Browse the repository at this point in the history
  • Loading branch information
tmori committed Dec 7, 2024
1 parent 20d0391 commit d0337f6
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 9 deletions.
43 changes: 43 additions & 0 deletions Runtime/pdu/core/NamedPdu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using hakoniwa.pdu.interfaces;

public class NamedPdu: INamedPdu
{
private string robotName;
private IPdu pdu;
public NamedPdu(string robot_name, IPdu _pdu)
{
this.robotName = robot_name;
this.pdu = _pdu;
}
public string RobtName => robotName;
public IPdu Pdu => pdu;
public string Name => pdu.Name;
public string TypeName => pdu.TypeName;
public string PackageName => pdu.PackageName;

public T GetData<T>(string field_name)
{
return pdu.GetData<T>(field_name);
}

public T[] GetDataArray<T>(string field_name)
{
return pdu.GetDataArray<T>(field_name);
}

public void SetData<T>(string field_name, T value)
{
pdu.SetData<T>(field_name, value);
}

public void SetData<T>(string field_name, T[] value)
{
pdu.SetData<T>(field_name, value);
}

public void SetData<T>(string field_name, int off, T value)
{
pdu.SetData<T>(field_name, value);
}
}
11 changes: 11 additions & 0 deletions Runtime/pdu/core/NamedPdu.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions Runtime/pdu/core/PduManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,21 @@ private void GetPackageTypeName(string robotName, string pduName, out string pac
packageName = parts[0];
typeName = parts[1];
}

public INamedPdu CreateNamedPdu(string robotName, string pduName)
{
var pdu = CreatePdu(robotName, pduName);
return new NamedPdu(robotName, pdu);
}

public string WriteNamedPdu(INamedPdu npdu)
{
return WritePdu(npdu.RobtName, npdu.Pdu);
}

public Task<bool> FlushNamedPdu(INamedPdu npdu)
{
return FlushPdu(npdu.RobtName, npdu.Pdu.Name);
}
}
}
8 changes: 8 additions & 0 deletions Runtime/pdu/interfaces/INamedpdu.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace hakoniwa.pdu.interfaces
{
public interface INamedPdu: IPdu
{
string RobtName { get; }
IPdu Pdu { get; }
}
}
11 changes: 11 additions & 0 deletions Runtime/pdu/interfaces/INamedpdu.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Runtime/pdu/interfaces/IPduManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ public interface IPduManager
string WritePdu(string robotName, IPdu pdu);
Task<bool> FlushPdu(string key);
Task<bool> FlushPdu(string robotName, string pduName);

IPdu ReadPdu(string robotName, string pduName);
int GetChannelId(string robotName, string pduName);
int GetPduSize(string robotName, string pduName);

INamedPdu CreateNamedPdu(string robotName, string pduName);
string WriteNamedPdu(INamedPdu npdu);
Task<bool> FlushNamedPdu(INamedPdu npdu);

}
}
8 changes: 4 additions & 4 deletions Tests/tests/hakoniwa.pdu.test/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ public void Ev3PduSensor_Test()
/*
* Create Test.
*/
IPdu pdu = mgr.CreatePdu(robotName, pduName);
Assert.NotNull(pdu);
INamedPdu npdu = mgr.CreateNamedPdu(robotName, pduName);
Assert.NotNull(npdu);

Ev3PduSensor sensor = new Ev3PduSensor(pdu);
Ev3PduSensor sensor = new Ev3PduSensor(npdu.Pdu);

Assert.Equal(2, sensor.color_sensors.Length);
Assert.Equal(2, sensor.touch_sensors.Length);
Expand All @@ -220,7 +220,7 @@ public void Ev3PduSensor_Test()
Assert.Equal(2u, sensor.motor_angle[1]);
Assert.Equal(3u, sensor.motor_angle[2]);

mgr.WritePdu(robotName, pdu);
mgr.WriteNamedPdu(npdu);

/*
* Read Test.
Expand Down
11 changes: 6 additions & 5 deletions Tests/tests/hakoniwa.uc.test/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public async Task Test_Twist()
/*
* Create Test.
*/
IPdu pdu = mgr.CreatePdu(robotName, pduName);
Assert.NotNull(pdu);
INamedPdu npdu = mgr.CreateNamedPdu(robotName, pduName);
Assert.NotNull(npdu);

Twist twist = new Twist(pdu);
Twist twist = new Twist(npdu.Pdu);
//double x_val = pdu.GetData<IPdu>("linear").GetData<double>("x");
double x_val = twist.linear.x;
Assert.Equal(0, x_val);
Expand All @@ -118,10 +118,11 @@ public async Task Test_Twist()
//pdu.GetData<IPdu>("angular").SetData<double>("z", -1.0);
twist.linear.x = 1.0;
twist.angular.z = -1.0;
var key = mgr.WritePdu(robotName, pdu);
var key = mgr.WriteNamedPdu(npdu);

//await mgr.FlushPdu(robotName, pduName);
await mgr.FlushPdu(key);
//await mgr.FlushPdu(key);
await mgr.FlushNamedPdu(npdu);

IPdu tmp = mgr.ReadPdu(robotName, pduName);
Assert.Null(tmp);
Expand Down

0 comments on commit d0337f6

Please sign in to comment.