Skip to content

Commit 257e1ad

Browse files
Jasper De Keukelaere (imec)Jasper De Keukelaere (imec)
authored andcommitted
feat: quick add option for auto start with desired network interface and mode
1 parent 0ccd944 commit 257e1ad

3 files changed

Lines changed: 59 additions & 3 deletions

File tree

PLCsimAdvanced_Manager/Components/Instance/Settings.razor

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
<MudCheckBox @bind-Checked="PowerOnStartup"></MudCheckBox>
2727
</MudStack>
2828
</MudItem>
29+
<MudItem xs="4">
30+
<MudStack>
31+
<MudText Typo="Typo.subtitle2">Communication Interface</MudText>
32+
<MudSelect T="string" @bind-Value="CommunicationInterface" OnKeyDown="updateSettings">
33+
<MudSelectItem Value="@("PLCSIM")">PLCSIM</MudSelectItem>
34+
<MudSelectItem Value="@("TCPIP-single")">TCP/IP Single Adapter</MudSelectItem>
35+
<MudSelectItem Value="@("TCPIP-multiple")">TCP/IP Multiple Adapter</MudSelectItem>
36+
</MudSelect>
37+
</MudStack>
38+
</MudItem>
2939
</MudGrid>
3040
</MudCard>
3141

@@ -41,6 +51,7 @@
4151
private bool _registerOnStartup;
4252
private bool _powerOnStartup;
4353
private bool _runOnStartup;
54+
private string _communicationInterface = "PLCSIM";
4455

4556
private IInstance SelectedInstance;
4657

@@ -52,6 +63,7 @@
5263
{
5364
_registerOnStartup = settings.RegisterOnStartup;
5465
_powerOnStartup = settings.PowerOnOnStartup;
66+
_communicationInterface = settings.CommunicationInterface;
5567
}
5668

5769
return base.OnInitializedAsync();
@@ -71,7 +83,7 @@
7183
}
7284
}
7385

74-
persistenceHandler.UpdateSettings(SelectedInstance.StoragePath, RegisterOnStartup, PowerOnStartup);
86+
updateSettings();
7587
}
7688
}
7789

@@ -89,8 +101,27 @@
89101
}
90102
}
91103

92-
persistenceHandler.UpdateSettings(SelectedInstance.StoragePath, RegisterOnStartup, PowerOnStartup);
104+
updateSettings();
105+
}
106+
}
107+
108+
109+
public string CommunicationInterface
110+
{
111+
get => _communicationInterface;
112+
set
113+
{
114+
if (_communicationInterface != value)
115+
{
116+
_communicationInterface = value;
117+
updateSettings();
118+
}
93119
}
94120
}
95121

122+
private void updateSettings()
123+
{
124+
persistenceHandler.UpdateSettings(SelectedInstance.StoragePath, RegisterOnStartup, PowerOnStartup, _communicationInterface.ToString());
125+
}
126+
96127
}

PLCsimAdvanced_Manager/Services/Persistence/PersistenceHandler.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ private void setStuffRight(string directory)
4646
}
4747
}
4848

49-
public void UpdateSettings(string directory, bool registerOnStartup , bool powerOnOnStartup)
49+
public void UpdateSettings(string directory, bool registerOnStartup , bool powerOnOnStartup, string communicationInterface)
5050
{
5151
setStuffRight(directory);
5252
_settings.RegisterOnStartup = registerOnStartup;
5353
_settings.PowerOnOnStartup = powerOnOnStartup;
54+
_settings.CommunicationInterface = communicationInterface;
5455
SaveSettings();
5556
}
5657

@@ -106,6 +107,9 @@ public class PersistenceSettings
106107
public bool RegisterOnStartup { get; set; } = false;
107108

108109
[JsonPropertyName("PowerOnOnStartup")] public bool PowerOnOnStartup { get; set; } = false;
110+
111+
[JsonPropertyName("CommunicationInterface")]
112+
public string CommunicationInterface { get; set; } = "PLCSIM";
109113
}
110114

111115
public class NodegraphJson

PLCsimAdvanced_Manager/Shared/StartupTasks.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ public static async Task GetPersistantSettings()
3131

3232
if (settings.PowerOnOnStartup)
3333
{
34+
switch (settings.CommunicationInterface)
35+
{
36+
case "PLCSIM":
37+
instance.CommunicationInterface = ECommunicationInterface.Softbus;
38+
break;
39+
case "TCPIP-single":
40+
instance.CommunicationInterface = ECommunicationInterface.TCPIP;
41+
SimulationRuntimeManager.NetworkMode = ECommunicationMode.Promiscuous;
42+
break;
43+
case "TCPIP-multiple":
44+
instance.CommunicationInterface = ECommunicationInterface.TCPIP;
45+
SimulationRuntimeManager.NetworkMode = ECommunicationMode.Non_Promiscuous;
46+
break;
47+
default:
48+
instance.CommunicationInterface = ECommunicationInterface.Softbus;
49+
break;
50+
}
51+
52+
3453
instance.PowerOn();
3554

3655
}
@@ -54,6 +73,8 @@ public class PersistenceSettings
5473
{
5574
[JsonPropertyName("RegisterOnStartup")] public bool RegisterOnStartup { get; set; } = false;
5675
[JsonPropertyName("PowerOnOnStartup")] public bool PowerOnOnStartup { get; set; } = false;
76+
[JsonPropertyName("CommunicationInterface")] public string CommunicationInterface { get; set; } = "PLCSIM";
77+
5778
}
5879

5980
public class Persistence

0 commit comments

Comments
 (0)