Skip to content

Commit 1a99d4f

Browse files
committed
Merge remote-tracking branch 'origin/dev'
2 parents e9e6c8e + 3627c82 commit 1a99d4f

15 files changed

Lines changed: 315 additions & 76 deletions

.nsis/installer-win32.nsi

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,18 @@
1818
!define SLUG "${NAME} v${VERSION}"
1919
!define UPDATEURL "https://github.com/sanny32/OpenModSim/releases"
2020

21+
!define MUI_FINISHPAGE_TEXT "${NAME} v${VERSION} (x86) has been installed on your computer."
22+
!define MUI_FINISHPAGE_RUN "$INSTDIR\${APPFILE}"
23+
!define MUI_FINISHPAGE_RUN_TEXT "Launch ${NAME}"
24+
!define MUI_FINISHPAGE_RUN_CHECKED
25+
2126
#--------------------------------
27+
# Variables
28+
29+
Var /GLOBAL DISPLAYNAME
30+
Var RebootRequired
2231

23-
VAR /GLOBAL DISPLAYNAME
32+
#--------------------------------
2433

2534
!macro SetDisplayName un
2635
Function ${un}SetDisplayName
@@ -58,6 +67,7 @@ FunctionEnd
5867
!insertmacro MUI_PAGE_LICENSE ${LICENSE_FILE}
5968
!insertmacro MUI_PAGE_DIRECTORY
6069
!insertmacro MUI_PAGE_INSTFILES
70+
!insertmacro MUI_PAGE_FINISH
6171

6272
# Uninstaller pages
6373
!insertmacro MUI_UNPAGE_CONFIRM
@@ -98,7 +108,12 @@ FunctionEnd
98108

99109
Section "Visual Studio Runtime"
100110
SetOutPath "$INSTDIR"
101-
ExecWait "$INSTDIR\vc_redist.x86.exe /install /quiet"
111+
ExecWait '"$INSTDIR\vc_redist.x86.exe" /install /quiet /norestart' $0
112+
113+
; 3010 = reboot required
114+
${If} $0 == 3010
115+
StrCpy $RebootRequired "1"
116+
${EndIf}
102117
SectionEnd
103118

104119
#--------------------------------
@@ -113,6 +128,26 @@ FunctionEnd
113128
CreateShortCut "$SMPROGRAMS\${NAME}\${NAME}.lnk" "$INSTDIR\${APPFILE}" "" "$INSTDIR\${ICOFILE}"
114129
SectionEnd
115130
#--------------------------------
131+
132+
#--------------------------------
133+
# Post-install section: ask about reboot only once
134+
Section -Post
135+
; Check if VC Redist indicated reboot is required
136+
${If} $RebootRequired == "1"
137+
MessageBox MB_ICONEXCLAMATION|MB_YESNO \
138+
"A system restart is required to complete the installation.$\r$\nRestart now?" \
139+
IDYES DoReboot
140+
141+
; If user clicked "No", continue silently
142+
Goto EndPost
143+
144+
DoReboot:
145+
Reboot
146+
${EndIf}
147+
148+
EndPost:
149+
SectionEnd
150+
116151
# Remove empty parent directories
117152

118153
Function un.RMDirUP
@@ -142,10 +177,20 @@ FunctionEnd
142177
# Section - Uninstaller
143178

144179
Section "Uninstall"
180+
# Attempt to delete the exe directly
181+
ClearErrors
182+
Delete "$INSTDIR\${APPFILE}"
183+
IfErrors ProcessStillRunning ProcessNotFound
184+
185+
ProcessStillRunning:
186+
MessageBox MB_ICONEXCLAMATION|MB_OK "The application is still running. Uninstallation cannot continue."
187+
Quit
188+
189+
ProcessNotFound:
145190
# Delete Shortcut
146191
Delete "$DESKTOP\${NAME}.lnk"
147192

148-
# Delete Start Menu Folder
193+
# Delete Start Menu Folder
149194
RMDir /r "$SMPROGRAMS\${NAME}"
150195

151196
# Delete Uninstall

.nsis/installer-win64.nsi

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
!define SLUG "${NAME} v${VERSION}"
1717
!define UPDATEURL "https://github.com/sanny32/OpenModSim/releases"
1818

19+
!define MUI_FINISHPAGE_TEXT "${NAME} v${VERSION} has been installed on your computer."
20+
!define MUI_FINISHPAGE_RUN "$INSTDIR\${APPFILE}"
21+
!define MUI_FINISHPAGE_RUN_TEXT "Launch ${NAME}"
22+
!define MUI_FINISHPAGE_RUN_CHECKED
23+
24+
#--------------------------------
25+
# Variables
26+
27+
Var RebootRequired
28+
1929
#--------------------------------
2030
# General
2131

@@ -31,6 +41,7 @@
3141
!insertmacro MUI_PAGE_LICENSE ${LICENSE_FILE}
3242
!insertmacro MUI_PAGE_DIRECTORY
3343
!insertmacro MUI_PAGE_INSTFILES
44+
!insertmacro MUI_PAGE_FINISH
3445

3546
# Uninstaller pages
3647
!insertmacro MUI_UNPAGE_CONFIRM
@@ -71,7 +82,12 @@
7182

7283
Section "Visual Studio Runtime"
7384
SetOutPath "$INSTDIR"
74-
ExecWait "$INSTDIR\vc_redist.x64.exe /install /quiet"
85+
ExecWait '"$INSTDIR\vc_redist.x64.exe" /install /quiet /norestart' $0
86+
87+
; 3010 = reboot required
88+
${If} $0 == 3010
89+
StrCpy $RebootRequired "1"
90+
${EndIf}
7591
SectionEnd
7692

7793
#--------------------------------
@@ -86,6 +102,26 @@
86102
CreateShortCut "$SMPROGRAMS\${NAME}\${NAME}.lnk" "$INSTDIR\${APPFILE}" "" "$INSTDIR\${ICOFILE}"
87103
SectionEnd
88104
#--------------------------------
105+
106+
#--------------------------------
107+
# Post-install section: ask about reboot only once
108+
Section -Post
109+
; Check if VC Redist indicated reboot is required
110+
${If} $RebootRequired == "1"
111+
MessageBox MB_ICONEXCLAMATION|MB_YESNO \
112+
"A system restart is required to complete the installation.$\r$\nRestart now?" \
113+
IDYES DoReboot
114+
115+
; If user clicked "No", continue silently
116+
Goto EndPost
117+
118+
DoReboot:
119+
Reboot
120+
${EndIf}
121+
122+
EndPost:
123+
SectionEnd
124+
89125
# Remove empty parent directories
90126

91127
Function un.RMDirUP
@@ -115,10 +151,20 @@
115151
# Section - Uninstaller
116152

117153
Section "Uninstall"
154+
# Attempt to delete the exe directly
155+
ClearErrors
156+
Delete "$INSTDIR\${APPFILE}"
157+
IfErrors ProcessStillRunning ProcessNotFound
158+
159+
ProcessStillRunning:
160+
MessageBox MB_ICONEXCLAMATION|MB_OK "The application is still running. Uninstallation cannot continue."
161+
Quit
162+
163+
ProcessNotFound:
118164
# Delete Shortcut
119165
Delete "$DESKTOP\${NAME}.lnk"
120166

121-
# Delete Start Menu Folder
167+
# Delete Start Menu Folder
122168
RMDir /r "$SMPROGRAMS\${NAME}"
123169

124170
# Delete Uninstall

.pkg/deb/rules.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ override_dh_shlibdeps:
1616

1717
sed -i 's/, libgcc-s1 (>= [^)]*)//g' debian/@PACKAGE_NAME@.substvars
1818
sed -i 's/libgcc-s1 (>= [^)]*), //g' debian/@PACKAGE_NAME@.substvars
19+
sed -i 's/, libgdk-pixbuf2.0-0 (>= [^)]*)//g' debian/@PACKAGE_NAME@.substvars
20+
sed -i 's/libgdk-pixbuf2.0-0 (>= [^)]*), //g' debian/@PACKAGE_NAME@.substvars
1921

2022
cat debian/@PACKAGE_NAME@.substvars || true
2123

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,13 @@ The following minimum operating system versions are supported for OpenModSim:
141141
- Ubuntu Linux 22.04
142142
- Mint Linux 22
143143
- Fedora Linux 41
144+
- Rocky Linux 9.7
144145
- OpenSuse Linux 15.6
145146
- Alt Linux 11
146147
- Astra Linux 1.7
147148
- RedOS 8
148149

149-
# Install from binary distributions
150+
# Install from [binary distributions](https://github.com/sanny32/OpenModSim/releases/latest)
150151

151152
Below are the methods for installing the OpenModSim for different OS
152153

@@ -177,7 +178,7 @@ or for Qt5 package:
177178
sudo apt remove qt5-omodsim
178179
```
179180

180-
## RedHat/Fedora/RedOS Linux
181+
## RedHat/Fedora/Rocky/RedOS Linux
181182
### Install
182183
Install the RPM package from the command line:
183184
```bash

omodsim/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.16)
22

33
project(omodsim
4-
VERSION 1.11.1
4+
VERSION 1.11.2
55
DESCRIPTION "An Open Source Modbus Slave (Server) Utility"
66
LANGUAGES CXX)
77

omodsim/datasimulator.cpp

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <QDateTime>
12
#include <QRandomGenerator>
23
#include "datasimulator.h"
34

@@ -7,9 +8,11 @@
78
///
89
DataSimulator::DataSimulator(QObject* parent)
910
: QObject{parent}
10-
,_elapsed(0)
1111
{
12+
_timer.setSingleShot(true);
13+
_timer.setTimerType(Qt::PreciseTimer);
1214
connect(&_timer, &QTimer::timeout, this, &DataSimulator::on_timeout);
15+
_masterTimer.start();
1316
}
1417

1518
///
@@ -48,8 +51,8 @@ void DataSimulator::startSimulation(DataDisplayMode mode, quint8 deviceId, QModb
4851
}
4952

5053
_simulationMap[{ deviceId, type, addr}] = { mode, params, value };
51-
resumeSimulations();
5254

55+
scheduleNextRun();
5356
emit simulationStarted(deviceId, type, addr);
5457
}
5558

@@ -63,6 +66,8 @@ void DataSimulator::stopSimulation(quint8 deviceId, QModbusDataUnit::RegisterTyp
6366
{
6467
_simulationMap.remove({ deviceId, type, addr});
6568
emit simulationStopped(deviceId, type, addr);
69+
70+
scheduleNextRun();
6671
}
6772

6873
///
@@ -87,8 +92,7 @@ void DataSimulator::pauseSimulations()
8792
///
8893
void DataSimulator::resumeSimulations()
8994
{
90-
if(!_timer.isActive())
91-
_timer.start(_interval);
95+
scheduleNextRun();
9296
}
9397

9498
///
@@ -130,42 +134,78 @@ ModbusSimulationMap2 DataSimulator::simulationMap() const
130134
return map;
131135
}
132136

137+
///
138+
/// \brief DataSimulator::scheduleNextRun
139+
///
140+
void DataSimulator::scheduleNextRun()
141+
{
142+
if (_simulationMap.isEmpty()) {
143+
_timer.stop();
144+
return;
145+
}
146+
147+
const qint64 currentTime = _masterTimer.elapsed();
148+
qint64 minNextTime = -1;
149+
150+
for (auto it = _simulationMap.constBegin(); it != _simulationMap.constEnd(); ++it) {
151+
const qint64 nextTime = it.value().NextRunTime;
152+
153+
if (minNextTime == -1 || nextTime < minNextTime) {
154+
minNextTime = nextTime;
155+
}
156+
}
157+
158+
const qint64 delay = qMax<qint64>(0, minNextTime - currentTime);
159+
160+
_timer.start(delay);
161+
}
162+
133163
///
134164
/// \brief DataSimulator::on_timeout
135165
///
136166
void DataSimulator::on_timeout()
137167
{
138-
_elapsed++;
139-
for(auto&& key : _simulationMap.keys())
168+
const qint64 currentTime = _masterTimer.elapsed();
169+
170+
QMutableMapIterator it(_simulationMap);
171+
while(it.hasNext())
140172
{
141-
const auto mode = _simulationMap[key].Mode;
142-
const auto params = _simulationMap[key].Params;
173+
it.next();
174+
175+
auto& sim = it.value();
176+
const auto& key = it.key();
177+
const auto mode = sim.Mode;
178+
const auto params = sim.Params;
143179
const auto interval = params.Interval;
144180

145-
if((_elapsed * _interval) % interval) continue;
181+
if (interval <= 0 || sim.NextRunTime > currentTime) continue;
146182

147183
switch(params.Mode)
148184
{
149185
case SimulationMode::Random:
150186
randomSimulation(mode, key.DeviceId, key.Type, key.Address, params.RandomParams);
151-
break;
187+
break;
152188

153189
case SimulationMode::Increment:
154190
incrementSimulation(mode, key.DeviceId, key.Type, key.Address, params.IncrementParams);
155-
break;
191+
break;
156192

157193
case SimulationMode::Decrement:
158194
decrementSimailation(mode, key.DeviceId, key.Type, key.Address, params.DecrementParams);
159-
break;
195+
break;
160196

161197
case SimulationMode::Toggle:
162198
toggleSimulation(key.DeviceId, key.Type, key.Address);
163-
break;
199+
break;
164200

165201
default:
166-
break;
202+
break;
167203
}
204+
205+
sim.NextRunTime = currentTime + interval;
168206
}
207+
208+
scheduleNextRun();
169209
}
170210

171211

omodsim/datasimulator.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define DATASIMULATOR_H
33

44
#include <QTimer>
5+
#include <QElapsedTimer>
56
#include <QModbusDataUnit>
67
#include <QXmlStreamWriter>
78
#include "modbussimulationparams.h"
@@ -53,20 +54,21 @@ private slots:
5354
void on_timeout();
5455

5556
private:
57+
void scheduleNextRun();
5658
void randomSimulation(DataDisplayMode mode, quint8 deviceId, QModbusDataUnit::RegisterType type, quint16 addr, const RandomSimulationParams& params);
5759
void incrementSimulation(DataDisplayMode mode, quint8 deviceId, QModbusDataUnit::RegisterType type, quint16 addr, const IncrementSimulationParams& params);
5860
void decrementSimailation(DataDisplayMode mode, quint8 deviceId, QModbusDataUnit::RegisterType type, quint16 addr, const DecrementSimulationParams& params);
5961
void toggleSimulation(quint8 deviceId, QModbusDataUnit::RegisterType type, quint16 addr);
6062

6163
private:
6264
QTimer _timer;
63-
quint32 _elapsed;
64-
const int _interval = 1;
65+
QElapsedTimer _masterTimer;
6566

6667
struct SimulationParams {
6768
DataDisplayMode Mode;
6869
ModbusSimulationParams Params;
6970
QVariant CurrentValue;
71+
qint64 NextRunTime = 0;
7072
};
7173

7274
QMap<ModbusSimulationMapKey, SimulationParams> _simulationMap;

0 commit comments

Comments
 (0)