Skip to content

Commit 7abdbda

Browse files
committed
Multiple tags concealment now supported for offset/value parameters, ongoing work into path
1 parent 0229b4f commit 7abdbda

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

dhalsim/python2/generic_scada.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def __init__(self, intermediate_yaml_path):
9393
self.update_cache_flag = False
9494
self.plcs_ready = False
9595

96+
self.previous_cache = {}
97+
for ip in self.plc_data:
98+
self.previous_cache[ip] = [0] * len(self.plc_data[ip])
99+
96100
self.cache = {}
97101
for ip in self.plc_data:
98102
self.cache[ip] = [0] * len(self.plc_data[ip])
@@ -286,6 +290,7 @@ def update_cache(self, lock, cache_update_time):
286290

287291
while self.update_cache_flag:
288292
for plc_ip in self.cache:
293+
# Maintain old values if there could not be uploaded
289294
try:
290295
values = self.receive_multiple(self.plc_data[plc_ip], plc_ip)
291296
with lock:
@@ -295,8 +300,8 @@ def update_cache(self, lock, cache_update_time):
295300
"PLC receive_multiple with tags {tags} from {ip} failed with exception '{e}'".format(
296301
tags=self.plc_data[plc_ip],
297302
ip=plc_ip, e=str(e)))
298-
time.sleep(cache_update_time)
299303
continue
304+
300305
#self.logger.debug(
301306
# "SCADA cache updated for {tags}, with value {values}, from {ip}".format(tags=self.plc_data[plc_ip],
302307
# values=values,
@@ -322,7 +327,6 @@ def main_loop(self, sleep=0.5, test_break=False):
322327
while not self.get_sync(2):
323328
pass
324329

325-
# Wait until we acquire the first sync before polling the PLCs
326330
if not self.plcs_ready:
327331
self.plcs_ready = True
328332
self.update_cache_flag = True
@@ -334,7 +338,13 @@ def main_loop(self, sleep=0.5, test_break=False):
334338
results = [master_time, datetime.now()]
335339
with lock:
336340
for plc_ip in self.plc_data:
337-
results.extend(self.cache[plc_ip])
341+
if self.cache[plc_ip]:
342+
results.extend(self.cache[plc_ip])
343+
else:
344+
results.extend(self.previous_cache[plc_ip])
345+
346+
self.previous_cache[plc_ip] = self.cache[plc_ip]
347+
338348
self.saved_values.append(results)
339349

340350
# Save scada_values.csv when needed

0 commit comments

Comments
 (0)