I want to send various data from different sensors (data types) through serial port. But I am having a problem that after some time my function call never returns.
I made sequence diagram to depict you better what I am trying to implement:
Message sent through serial stream has the following format: |STX|Data Type|Data Length|Data|ETX, and is represented by Message class.
Message.h
http://textuploader.com/dkcvh
Message.cpp
http://textuploader.com/dkcvg
MessageEncoder.h
http://textuploader.com/dkcv7
MessageEncoder.cpp
http://textuploader.com/dkcv2
MessageSerialization.h
http://textuploader.com/dkcvu
MessageSerialization.cpp
http://textuploader.com/dkcn4
MessageProcessor.h
http://textuploader.com/dkcvn
MessageProcessor.cpp
http://textuploader.com/dkcvy
main.cpp
http://textuploader.com/dkcnr
I have checked MessageEncoder and MessageSerialzation methods and they work fine, problem is in MessageProcessor class. After MessageProcessor::processTransmitData method call in main, method returns normally, but after some time everything stops. I have figured out that the problem resides in last 3 lines of MessageProcessor::processTransmitData method
delete encodedMessage;
delete serializedBuffer;
Somehow program gets stuck after calling these delete functions. And I am almost sure it has something to do with memory allocation for encodedMessage and serializedBuffer pointers. serializedBuffer is allocated in MessageProcessor::processTransmitData method, and encodedMessage is allocated in MessageEncoder::encode method. I think that at some point, stackoverflow happens
you can see at the end of COM port at this picture that output gets stuck.