Skip to content

Commit

Permalink
updated manifest and added parser.py
Browse files Browse the repository at this point in the history
  • Loading branch information
OcelotEmpire committed Jan 8, 2025
1 parent 474b751 commit 7e622fe
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "data/RoveComm"]
path = data/RoveComm
url = https://github.com/MissouriMRDT/RoveComm_Base.git
8 changes: 0 additions & 8 deletions RoveComm.Test/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,6 @@
_RoveCommService.On<float>(0, AddPacket);
_RoveCommService.On<double>(0, AddPacket);
_RoveCommService.On<char>(0, AddPacket);
_RoveCommService.On<float>(
"Core",
"DriveSpeeds",
async (packet) => {
Console.WriteLine(string.Join(", ", packet.Data));
await InvokeAsync(StateHasChanged);
}
);

ApplyManifestSettings();

Expand Down
2 changes: 1 addition & 1 deletion RoveComm.Test/RoveComm.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="RoveComm" Version="1.0.0" />
<PackageReference Include="RoveComm" Version="1.0.1" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion RoveComm/RoveComm.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>1.0.1</VersionPrefix>
<VersionPrefix>1.0.2</VersionPrefix>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
142 changes: 137 additions & 5 deletions RoveComm/RoveCommManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ public enum RoveCommDataType
CHAR = 8,
}

public class RoveCommDeviceDesc
{
public string Ip { get; init; }

public RoveCommDeviceDesc(string ip)
{
Ip = ip;
}
}

public class RoveCommBoardDesc
{
public string IP { get; init; }
Expand All @@ -42,7 +52,6 @@ public RoveCommBoardDesc(string ip,
}
}


public class RoveCommPacketDesc
{
public int DataID { get; init; }
Expand All @@ -69,6 +78,18 @@ public static class SystemPackets
public static readonly int NO_DATA = 6;
}

public static readonly IReadOnlyDictionary<string, RoveCommDeviceDesc> Devices = new Dictionary<string, RoveCommDeviceDesc>
{
["BasestationSwitch"] = new RoveCommDeviceDesc("192.168.254.2"),
["RoverSwitch"] = new RoveCommDeviceDesc("192.168.254.1"),
["Rover900MHzRocket"] = new RoveCommDeviceDesc("10.0.0.3"),
["Basestation900MHzRocket"] = new RoveCommDeviceDesc("10.0.0.4"),
["Rover5GHzRocket"] = new RoveCommDeviceDesc("10.0.0.19"),
["Basestation5GHzRocket"] = new RoveCommDeviceDesc("10.0.0.20"),
["Rover2_4GHzRocket"] = new RoveCommDeviceDesc("10.0.0.11"),
["Basestation2_4GHzRocket"] = new RoveCommDeviceDesc("10.0.0.12")
};

public static readonly IReadOnlyDictionary<string, RoveCommBoardDesc> Boards = new Dictionary<string, RoveCommBoardDesc>
{
["Core"] = new RoveCommBoardDesc
Expand Down Expand Up @@ -762,18 +783,25 @@ public static class SystemPackets
2,
RoveCommDataType.DOUBLE
),
// [Lat, Lon]
// [Lat, Lon, MarkerID, MarkerRadius (meters)]
["AddMarkerLeg"] = new RoveCommPacketDesc
(
11003,
2,
4,
RoveCommDataType.DOUBLE
),
// [Lat, Lon]
// [Lat, Lon, ObjectRadius (meters)]
["AddObjectLeg"] = new RoveCommPacketDesc
(
11004,
2,
3,
RoveCommDataType.DOUBLE
),
// [Lat, Lon, ObstacleRadius (meters)]
["AddObstacle"] = new RoveCommPacketDesc
(
11008,
3,
RoveCommDataType.DOUBLE
),
//
Expand Down Expand Up @@ -924,6 +952,110 @@ public static class SystemPackets

}
),
["CameraServer"] = new RoveCommBoardDesc
(
ip: "192.168.4.102",
commands: new Dictionary<string, RoveCommPacketDesc>
{
// Take a picture with the current camera. [0] is the camera to take a picture with.
["TakePhoto"] = new RoveCommPacketDesc
(
14000,
1,
RoveCommDataType.UINT8_T
),
// Stop the current camera stream. [0] is the camera to stop streaming. [1] is the action (0 = Shutdown, 1 = Startup, 2 = Restart).
["ToggleStream"] = new RoveCommPacketDesc
(
14001,
2,
RoveCommDataType.UINT8_T
),
// Adjust brightness level (0-255). [0] is the camera ID, [1] is the brightness level.
["AdjustBrightness"] = new RoveCommPacketDesc
(
14002,
2,
RoveCommDataType.UINT8_T
),
// Adjust contrast level (0-255). [0] is the camera ID, [1] is the contrast level.
["AdjustContrast"] = new RoveCommPacketDesc
(
14003,
2,
RoveCommDataType.UINT8_T
),
// Adjust saturation level (0-255). [0] is the camera ID, [1] is the saturation level.
["AdjustSaturation"] = new RoveCommPacketDesc
(
14004,
2,
RoveCommDataType.UINT8_T
),
// Adjust hue level (0-255). [0] is the camera ID, [1] is the hue level.
["AdjustHue"] = new RoveCommPacketDesc
(
14005,
2,
RoveCommDataType.UINT8_T
),
// Set white balance temperature. [0] is the camera ID, [1] is the white balance level.
["SetWhiteBalance"] = new RoveCommPacketDesc
(
14008,
2,
RoveCommDataType.UINT8_T
),
// Adjust backlight contrast level (0-255). [0] is the camera ID, [1] is the backlight contrast level.
["AdjustBacklightContrast"] = new RoveCommPacketDesc
(
14009,
2,
RoveCommDataType.UINT8_T
),
// Set exposure level. [0] is the camera ID, [1] is the exposure level.
["SetExposure"] = new RoveCommPacketDesc
(
14010,
2,
RoveCommDataType.INT32_T
)
},
telemetry: new Dictionary<string, RoveCommPacketDesc>
{
// Bitmask values for which cameras are able to stream. LSB is Camera 0, MSB is Camera 7.
["AvailableCameras"] = new RoveCommPacketDesc
(
14100,
1,
RoveCommDataType.UINT8_T
),
// Which cameras the system is currently streaming on each port
["StreamingCameras"] = new RoveCommPacketDesc
(
14101,
4,
RoveCommDataType.UINT8_T
),
// Picture has been taken.
["PictureTaken1"] = new RoveCommPacketDesc
(
14102,
1,
RoveCommDataType.UINT8_T
)
},
errors: new Dictionary<string, RoveCommPacketDesc>
{
// Camera has errored and stopped streaming. [0] is ID of camera as an integer (not bitmask).
["CameraUnavailable"] = new RoveCommPacketDesc
(
14200,
1,
RoveCommDataType.UINT8_T
)
}
),
["IRSpectrometer"] = new RoveCommBoardDesc
(
ip: "192.168.3.104",
Expand Down
1 change: 1 addition & 0 deletions data/RoveComm
Submodule RoveComm added at cc53e1
154 changes: 154 additions & 0 deletions tools/parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import json

rovecomm_version = 3
file_path = "../RoveComm/RoveCommManifest.cs"
json_path = "../data/RoveComm/manifest.json"

data_type_lookup = {
"INT8_T" : "RoveCommDataType.INT8_T",
"UINT8_T" : "RoveCommDataType.UINT8_T",
"INT16_T" : "RoveCommDataType.INT16_T",
"UINT16_T" : "RoveCommDataType.UINT16_T",
"INT32_T" : "RoveCommDataType.INT32_T",
"UINT32_T" : "RoveCommDataType.UINT32_T",
"FLOAT_T" : "RoveCommDataType.FLOAT",
"DOUBLE_T" : "RoveCommDataType.DOUBLE",
"CHAR" : "RoveCommDataType.CHAR",
}

packet_type_lookup = {
"Commands" : "commands",
"Telemetry" : "telemetry",
"Error" : "errors",
}

def main() -> None:
with open(json_path, "r") as file:
manifest = json.load(file)

with open(file_path, "w") as file:
file.write("""\
namespace RoveComm;
""")
file.write("""
public static class RoveCommConsts
{
public static readonly int RoveCommVersion = 3;
public static readonly int UDPPort = 11000;
public static readonly int TCPPort = 12000;
public static readonly int HeaderSize = 6;
public static readonly int MaxDataSize = 65535 / 3;
public static readonly int UpdateRate = 100; // milliseconds
}
""")

file.write("""
public enum RoveCommDataType
{
INT8_T = 0,
UINT8_T = 1,
INT16_T = 2,
UINT16_T = 3,
INT32_T = 4,
UINT32_T = 5,
FLOAT = 6,
DOUBLE = 7,
CHAR = 8,
}
""")
file.write("""
public class RoveCommDeviceDesc
{
public string Ip { get; init; }
public RoveCommDeviceDesc(string ip)
{
Ip = ip;
}
}
""")
file.write("""
public class RoveCommBoardDesc
{
public string IP { get; init; }
public IReadOnlyDictionary<string, RoveCommPacketDesc> Commands { get; init; }
public IReadOnlyDictionary<string, RoveCommPacketDesc> Telemetry { get; init; }
public IReadOnlyDictionary<string, RoveCommPacketDesc> Errors { get; init; }
public RoveCommBoardDesc(string ip,
IReadOnlyDictionary<string, RoveCommPacketDesc>? commands = null,
IReadOnlyDictionary<string, RoveCommPacketDesc>? telemetry = null,
IReadOnlyDictionary<string, RoveCommPacketDesc>? errors = null)
{
IP = ip;
Commands = commands ?? new Dictionary<string, RoveCommPacketDesc>();
Telemetry = telemetry ?? new Dictionary<string, RoveCommPacketDesc>();
Errors = errors ?? new Dictionary<string, RoveCommPacketDesc>();
}
}
""")
file.write("""
public class RoveCommPacketDesc
{
public int DataID { get; init; }
public int DataCount { get; init; }
public RoveCommDataType DataType { get; init; }
public RoveCommPacketDesc(int dataId, int dataCount, RoveCommDataType dataType)
{
DataID = dataId;
DataCount = dataCount;
DataType = dataType;
}
}
""")
# :-D
file.write(f"""
public static class RoveCommManifest
{{
public static class SystemPackets
{{
public static readonly int PING = 1;
public static readonly int PING_REPLY = 2;
public static readonly int SUBSCRIBE = 3;
public static readonly int UNSUBSCRIBE = 4;
public static readonly int INVALID_VERSION = 5;
public static readonly int NO_DATA = 6;
}}
public static readonly IReadOnlyDictionary<string, RoveCommDeviceDesc> Devices = new Dictionary<string, RoveCommDeviceDesc>
{{
{",\n".join((f"""\
["{device}"] = new RoveCommDeviceDesc("{device_desc["Ip"]}")"""
for device, device_desc in manifest["NetworkDevices"].items()))}
}};
public static readonly IReadOnlyDictionary<string, RoveCommBoardDesc> Boards = new Dictionary<string, RoveCommBoardDesc>
{{
{",\n".join((f"""\
["{board}"] = new RoveCommBoardDesc
(
ip: "{board_desc["Ip"]}"\
{"".join((f""",
{packet_type}: new Dictionary<string, RoveCommPacketDesc>
{{
{",\n".join((f"""\
// {packet_desc["comments"]}
["{command}"] = new RoveCommPacketDesc
(
{packet_desc["dataId"]},
{packet_desc["dataCount"]},
{data_type_lookup[packet_desc["dataType"]]}
)"""
for command, packet_desc in board_desc[json_type].items()))}
}}"""
for json_type, packet_type in packet_type_lookup.items()
if json_type in board_desc ))}
)"""
for board, board_desc in manifest["RovecommManifest"].items()))}
}};
}}
""")

if __name__ == "__main__":
main()

0 comments on commit 7e622fe

Please sign in to comment.