Commit 4f2f2a5c authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Check constraints and detect uninitialized variables

parent 644c52f4
......@@ -347,7 +347,10 @@ def gui():
# Create a dock to handle the display of SDL diagrams
try:
sdl = sdlHandler(myWidget)
sdl.dll = dll
try:
sdl.dll = dll
except ValueError as err:
raise IOError(str(err))
sdl.msc.connect(msc.addToMsc)
sdl.msc_undo.connect(msc.undo)
sdl.msc_redo.connect(msc.redo)
......@@ -355,7 +358,7 @@ def gui():
sdl.msc_macro_stop.connect(msc.stop_undo_macro)
sdl.allowed_messages.connect(myWidget.allowed_editors)
except IOError as err:
log.info('SDL viewer not available - ' + str(err))
log.info('SDL Simulator Error - ' + str(err))
#log.info(traceback.format_exc())
sdl = None
else:
......@@ -383,7 +386,7 @@ def gui():
# Set the callback in the backend to send messages via the dll
# (handled in the SDL backend, also managing MSC traces)
if dll:
if dll and sdl:
DLLHandler = type('DLLHandler', (QObject,),
{'dll': Signal(unicode, type, type)})
encoder_backend.send_via_dll = DLLHandler()
......@@ -466,7 +469,7 @@ def gui():
#button.clicked.connect(editor.loadTC)
elif button.objectName() == 'sendButton':
button.clicked.connect(editor.sendTC)
if dll:
if dll and sdl:
sdl.param_tc_editors.append({'name':
editor.objectName(),
'editor': editor,
......@@ -515,13 +518,16 @@ def gui():
else:
log.info('Ignoring and deleting previously stored windows layout')
# Display the main window (including TM/TC editors)
myWidget.show()
ret = app.exec_()
sys.stdout = sys.__stdout__
if msgQ and hasTM:
pollingThread._bDie = True
pollingThread.wait()
if 'opengeode-simulator' in sys.argv[0] and not sdl:
ret = 1
else:
# Display the main window (including TM/TC editors)
myWidget.show()
ret = app.exec_()
sys.stdout = sys.__stdout__
if msgQ and hasTM:
pollingThread._bDie = True
pollingThread.wait()
return ret
if __name__ == '__main__':
......
......@@ -49,13 +49,13 @@ except ImportError:
try:
# Not correct, this assumes that the dataview is always named
# "dataview-uniq.asn" ! the actual name shall be parsed in the SDL model
import dataview_uniq_asn as ASN1
import datamodel # Generated by the Pyside B mapper
except ImportError:
#print 'No Python A mapper generated dataview, SDL handler cannot be used'
ASN1 = None
# Unicode separator used by Opengeode in the Ada backend
# to build unambiguous names, in particular when using nested states
UNICODE_SEP = u'\u00dc'
......@@ -262,7 +262,7 @@ class sdlHandler(QObject):
for var, (sort, _) in self.proc.variables.viewitems():
sortName = sort.ReferencedTypeName
item = asn1sccToasn1ValueEditorTypes(self.proc.dataview,
sortName, sort)
var, sort)
self.tree_items[var] = self.asn1_editor.setAsn1Model(item, row)
row += 1
# In the simulation panel, set the buttons to send paramless TC/timers
......@@ -281,7 +281,15 @@ class sdlHandler(QObject):
# Call the start transition of the SDL model
getattr(value, '{}_startup'.format(self.proc.processName))()
self.check_state()
self.init_state = self.current_hash = self.on_event()
try:
self.init_state = self.current_hash = self.on_event()
except ValueError as err:
# Exception raised when some SDL variables are not initialized
# (in that case impossible to read a proper state)
box = QMessageBox(QMessageBox.Critical,
'SDL Variable not initialized', str(err))
box.exec_()
raise
def load_properties(self, prop_file=None):
''' Try loading a shared object with properties to verify
......@@ -411,6 +419,38 @@ class sdlHandler(QObject):
if target is self.dll:
self.check_state()
def check_asn1_constraints(self, instance, typename_c):
''' ASN1SCC provides functions to check ASN.1 constraints '''
is_valid, err_code = instance.IsConstraintValid()
if not is_valid:
msg = ("Type {}: constraint error - {}"
.format(datamodel.errCodes[err_code]['name'],
datamodel.errCodes[err_code]['constraint']))
raise ValueError(msg)
def encode_uper(self, instance, typename_c):
''' Encode an ASN.1 value to unaligned PER using ASN1SCC '''
assert '-' not in typename_c
size = getattr(ASN1.DV, "{}_REQUIRED_BYTES_FOR_ENCODING"
.format(typename_c))
buf = ASN1.DataStream(size)
instance.Encode(buf)
print 'Encoded type {} - size {}'.format(typename_c, len(buf.GetPyString()))
return buf.GetPyString()
def decode_from_uper(self, uper_buf, typename_c, to_inst=None):
''' Decode an ASN.1 uPER-encoded value to a ctype instance
to_inst is an optional instance to put the value in '''
assert '-' not in typename_c
to_inst = to_inst or getattr(ASN1, typename_c)()
size = getattr(ASN1.DV, "{}_REQUIRED_BYTES_FOR_ENCODING"
.format(typename))
buf = ASN1.DataStream(size)
buf.SetFromPyString(uper_buf)
to_inst.Decode(buf)
print 'Decoded type {} - size {}'.format(typename_c, len(buf.GetPyString()))
return to_inst
def change_internal_state(self):
''' When user press the "Apply" button to change the model's internal
state (variables of the SDL model, or state of the automaton)
......@@ -460,6 +500,14 @@ class sdlHandler(QObject):
asn1_instance.SetData(value)
self.asn1_editor.updateVariable(root=self.tree_items[var],
asn1Var=asn1_instance)
try:
self.check_asn1_constraints(asn1_instance, typename)
except ValueError as err:
err_msg = (u"Variable {} has a value out of range - {}"
.format(var, str(err)))
raise ValueError(err_msg)
else:
uper_encoded = self.encode_uper(asn1_instance, typename)
complete_state.append(asn1_instance)
# Add the SDL state to the new global state
complete_state.append(self.current_sdl_state)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment