libads icon indicating copy to clipboard operation
libads copied to clipboard

Library expects ads packets to be maximum 1 ethernet frame

Open haakonnessjoen opened this issue 12 years ago • 5 comments

The library expects a packet to never exceed one ethernet frame. This is not a limitation in ADS it self.

All packets are read to this variable: dc->msgIn

Which is a stack variable of 1524 bytes. This variable should instead be dynamically allocated heap according to the length specified in the ads read/write command.

haakonnessjoen avatar Dec 19 '13 23:12 haakonnessjoen

in the libads branch the maxdatalen will be 8192 bytes https://github.com/gass/libads/blob/AdsRouter/src/ads.h#L43

Or we could just have a dynamically allocated datapointer (pointer to msgin). What is the best option?

gass avatar Dec 20 '13 18:12 gass

The best option would be to dynamically allocate the msgin pointer. If you read or write a big array of structs from ADS, the packet can get quite big.. Unless written specifically in the beckhoff manual, you should not limit it to a low number. I tried to read a struct of 69888 bytes when I found your 1524 byte limit. Which is far more than the 8192 limit you suggested.

haakonnessjoen avatar Dec 20 '13 20:12 haakonnessjoen

The data pointer present in the struct is not used. Can you propose a change to the code?

gass avatar Dec 20 '13 20:12 gass

I do not have the time to go through the code right now I am afraid. But I would suppose that it should be as easy as defining msgin as a char pointer instead of a char array of 1524 bytes. And then be sure to malloc/free it between each use. As far as I know, you always know how large the packets will be, before you attempt to read them. So just allocate it before reading from the socket.

I could look at it after christmas at some point, if you do not want to look at it.

On 20 December 2013 21:57, Luis Matos [email protected] wrote:

The data pointer present in the struct is not used. Can you propose a change to the code?

— Reply to this email directly or view it on GitHubhttps://github.com/gass/libads/issues/9#issuecomment-31041093 .

Håkon

haakonnessjoen avatar Dec 20 '13 21:12 haakonnessjoen

I need to merge the ads router code from Gerhard. If i finish it before, i'll do it. Cheers and merry Christmas.

gass avatar Dec 22 '13 16:12 gass