Use native Matlab functions to display log messages.#1409
Use native Matlab functions to display log messages.#1409bcoconni merged 4 commits intoJSBSim-Team:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1409 +/- ##
=======================================
Coverage 25.22% 25.22%
=======================================
Files 169 169
Lines 18633 18633
=======================================
Hits 4701 4701
Misses 13932 13932 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Well done @bcoconni |
|
Hmm, especially given the recent discussion in #1407 regarding exception handling I was wondering what the situation regarding exceptions is when Matlab/Simulink call JSBSim's s-functions and JSBSim potentially throws an exception. Does Matlab/Simulink handle C++ exceptions coming from s-function implementations? Do they start a separate process so that any unhandled C++ exceptions, or OS exceptions don't take down the main Matlab/Simulink process? I don't have a copy of Matlab/Simulink installed, so I can't really test. So taking a look at the Matlab/Simulink documentation: It looks like they support fairly fine-grained in terms of allowing the s-function developer to specify which s-functions are exception free and which ones aren't, and Matlab/Simulink then take the appropriate action, e.g. wrapping the call in the try/catch before calling if the function hasn't been marked as exception free.
|
|
Not sure about what Matlab is exactly doing regarding C++ exceptions. However it seems to me that this PR and the current code in I have checked in the code of our S-function and could not find any occurrence of |
|
Yep, so first off Matlab/Simulink support and handle exceptions, so it's an example as in the discussion with @AirshipSim of a host program handling exceptions that may propagate from a library that it loads and calls, in this case an s-function wrapper of JSBSim. Although Matlab/Simulink do also offer, for performance reasons they state, an option for the library to state it won't propagate exceptions back to Matlab/Simulink. I also took a look at the time and didn't see JSBSim specifying that it was exception free, which means we don't need to worry about exceptions not being caught in JSBSim's s-functions, they can simply propagate back to Matlab/Simulink. So all good.
There is a subtle difference. Since we don't have a Now I'm guessing it may not make a practical difference. But without an installation of Matlab/Simulink I can't currently test it. I noticed that all the s-functions ( void mdlUpdate()
{
if(!checkInputs()) {
ssSetEErrorStatus();
return;
}
if(!doUpdate()) {
ssSetEErrorStatus();
return;
}
}The other option is to throw an exception and let that propagate back to Matlab/Simulink's code that calls the s-functions. |
|
I entirely agree with your statements but I am not sure where I should go from there ? Granted that the exception management of the S-function could most certainly be improved. But that is not the point of this PR. If the concern is that the code returns and then it calls case LogLevel::FATAL:
break;If the point is that this PR should fix the exception management then I am afraid I will not be able to do that since I do not have access to a Matlab license either. In that case, I suggest to discard this PR and wait for someone with a Matlab license to volunteer and fix that. |
|
So I have given some further thoughts to your comments @seanmcleod70 and revisited my code. It occurred to me that when we are in Simulink's exception handler, it is preferable not to call a function that may throw. I don't know for But since we need to display the error messages, all the calls to JSBSim functions in Most of the The |
|
The latest commit looks like the safer option. |
|
@agodemar any comments about the update ? |
|
@bcoconni your last thoughts and commit look reasonable to me. Ok to merge |
|
PR merged. Thanks. |
In this PR, the logging feature is used to display log messages using
mexPrintfand similar native Matlab functions. This ensures that the messages are displayed in the Matlab command window rather than in the terminal (if there is one).I have used the function
ssSetErrorStatusfor fatal errors which, according to the docs, seems the most appropriate. Let me know if another function would be more appropriate.Turn off the display of spaces in the diff to review the code because there are quite a lot of trailing spaces that have been removed.