Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protobuffer poc #115

Merged
merged 8 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion EDSEditorGUI/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
version.txt
version.txt
EDSEditorGUI.csproj.user
86 changes: 84 additions & 2 deletions EDSEditorGUI/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,13 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
Warnings.warning_list.Clear();

OpenFileDialog odf = new OpenFileDialog();
odf.Filter = "All supported files (*.xdd;*.xdc;*.xpd;*.eds;*.dcf)|*.xdd;*.xdc;*.xpd;*.eds;*.dcf|"
odf.Filter = "All supported files (*.xdd;*.xdc;*.xpd;*.eds;*.dcf;*.binpb;*.json)|*.xdd;*.xdc;*.xpd;*.eds;*.dcf;*.binpb;*.json|"
+ "CANopen XDD (*.xdd)|*.xdd|"
+ "CANopen XDC (*.xdc)|*.xdc|"
+ "CANopen XPD (*.xpd)|*.xpd|"
+ "Electronic Data Sheet (*.eds)|*.eds|"
+ "Device Configuration File (*.dcf)|*.dcf";
+ "Device Configuration File (*.dcf)|*.dcf|"
+ "CANopen Protobuffer (*.binpb;*.json)|*.binpb;*.json";

if (odf.ShowDialog() == DialogResult.OK)
{
Expand All @@ -304,6 +305,14 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
openEDSfile(odf.FileName, InfoSection.Filetype.File_DCF);
break;

case ".binpb":
OpenProtobufferfile(odf.FileName, false);
break;

case ".json":
OpenProtobufferfile(odf.FileName, true);
break;

default:
return;

Expand Down Expand Up @@ -369,6 +378,49 @@ private void openXDDfile(string path)

}

private void OpenProtobufferfile(string path, bool json)
{
Warnings.warning_list.Clear();

try
{
EDSsharp eds;

CanOpenXDD_1_1 coxml_1_1 = new CanOpenXDD_1_1();
eds = coxml_1_1.ReadProtobuf(path, json);

if (eds == null)
{
return;
}

eds.projectFilename = path;

DeviceView device = new DeviceView(eds, network);

device.UpdateODViewForEDS += Device_UpdateODViewForEDS;
eds.OnDataDirty += Eds_onDataDirty;

tabControl1.TabPages.Add(eds.di.ProductName);
tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(device);

device.Dock = DockStyle.Fill;
device.dispatch_updateOD();

network.Add(eds);
}
catch (Exception ex)
{
Warnings.warning_list.Add(ex.ToString());
}

if (Warnings.warning_list.Count != 0)
{
WarningsFrm frm = new WarningsFrm();
frm.Show();
}
}

private void Device_UpdateODViewForEDS(object sender, UpdateODViewEventArgs e)
{
foreach (TabPage page in tabControl1.TabPages)
Expand Down Expand Up @@ -484,6 +536,8 @@ private void exportDeviceFileToolStripMenuItem_Click(object sender, EventArgs e)
sfd.Filter = "CANopen XDD v1.1 stripped (*.xdd)|*.xdd|" //must be first or change condition below
+ "Electronic Data Sheet (*.eds)|*.eds|"
+ "Device Configuration File (*.dcf)|*.dcf|"
+ "Protobuffer binary, experimental (*.binpb)|*.binpb|"
+ "Protobuffer JSON, experimental (*.json)|*.json|"
+ "Documentation (*.md)|*.md|"
+ "CANopen XDD v1.0, old (*.xdd)|*.xdd";

Expand Down Expand Up @@ -605,6 +659,20 @@ void dosave(DeviceView dv, string FileName, bool xddfileVersion_1_1, bool stripp
dv.eds.xddfilename_1_0 = FileName;
}
break;

case ".binpb":
case ".json":
Warnings.warning_list.Clear();

CanOpenXDD_1_1 copb = new CanOpenXDD_1_1();
copb.WriteProtobuf(FileName, dv.eds, Path.GetExtension(FileName) == ".json");

if (Warnings.warning_list.Count != 0)
{
WarningsFrm frm = new WarningsFrm();
frm.Show();
}
break;
}

dv.dispatch_updateOD();
Expand Down Expand Up @@ -683,6 +751,12 @@ void OpenRecentFile(object sender, EventArgs e)

if (ext == ".xdd" || ext == ".xdc" || ext == ".xpd")
openXDDfile(filepath);

else if (ext == ".binpb")
OpenProtobufferfile(filepath, false);
else if (ext == ".json")
OpenProtobufferfile(filepath, true);

if ( ext == ".eds" )
openEDSfile(filepath, InfoSection.Filetype.File_EDS);
if (ext == ".dcf")
Expand Down Expand Up @@ -1203,6 +1277,14 @@ private void ODEditor_MainForm_DragDrop(object sender, DragEventArgs e)
openXDDNetworkfile(fileName);
break;

case ".binpb":
OpenProtobufferfile(fileName, false);
break;

case ".json":
OpenProtobufferfile(fileName, true);
break;

default:
break;

Expand Down
Loading
Loading