Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle incomplete messages at serial port #128

Merged
merged 1 commit into from Oct 26, 2016

Conversation

bernhard-thiele
Copy link
Collaborator

Related to #117, #119, #127

@bernhard-thiele
Copy link
Collaborator Author

I think that should solve the issue for the Linux part. Any comments?

@tbeu
Copy link
Collaborator

tbeu commented Oct 25, 2016

serial->nReceivedBytes should not be accessed outside the mutex.

@bernhard-thiele
Copy link
Collaborator Author

Hm, serial->nReceivedBytes is only used in its own thread, except for function MDD_serialPortGetReceivedBytes(..) which reads it.

One could protect everything by a mutex, but using MDD_serialPortGetReceivedBytes(..), e.g., to check whether enough bytes have been received before doing something is not very robust anyway. There is no guarantee that the number of read bytes doesn't change immediately in the reading thread after the function has been called. This potentially invalidates any condition under which some action would be triggered in the Modelica code part. Maybe its best to just flag it as an unsafe function which might have some use for debugging, but shouldn't be used for anything else.

@tbeu
Copy link
Collaborator

tbeu commented Oct 25, 2016

If serial->nReceivedBytes is only used in its own thread, then there is no need to have it in the serial struct. See also #127 (comment)

@tbeu
Copy link
Collaborator

tbeu commented Oct 25, 2016

Hm, MDD_serialPortGetReceivedBytes is called in the test module (test_MDDSerialPort.c). And this is not only the case for serial port I/O but basically for all other communication drivers. Thus deprecating one, which is fine for me, is not enough. I propose to deprecate all of them and to adapt the tests.

@bernhard-thiele
Copy link
Collaborator Author

Okay, I came up with another solution which should be more useful. serial->nReceivedBytes will now contain the sum of all received bytes and its access is protected by a mutex (see commit).

Related to #117, #119, #127, #129

- Deprecating serial port function "getReceivedBytes" #129
- Mutex is used to protect access to "serial->nReceivedBytes"
- Fixed buffer types void* -> unsigned char*
- The Modelica interface functions will only see new values
  if a complete message is available
- Incomplete messages are written in an internal buffer which
  grows until it contains a complete message which is then
  copied into the buffer that the Modelica interface functions
  access.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants