libedssharp icon indicating copy to clipboard operation
libedssharp copied to clipboard

read-only/const VISIBLE_STRING max size/initializer

Open iurly opened this issue 8 years ago • 3 comments

I'm trying to export some read-only strings (i.e. identifier information which needs to be calculated at startup). I was thinking about defining it in RAM and initializing it at some point during startup. Ideally I would only need to set a pointer to some RAM or FLASH area where it is stored. The only way I found to achieve this though would be to declare it as a VISIBLE_STRING and provide an initializer which is long enough to contain the maximum allowed string length, and then have the startup code overwrite it. Is there a better way to do this? Thanks!

iurly avatar Jan 05 '18 19:01 iurly

Really this is a question for the CanOpenNode list as i only export the CO_OD file in the format that can open node expects...

That said i'll say what i know, using a direct string there is probably not much you can do as this is the way the OD works. However you may be able to achieve something much nicer by using the OD access override functions CO_OD_configure() this function registers a callback that triggers on every OD read/write and you can handle what happens and data storage yourself, so its possible to use a user buffer in ram/rom/whatever and handle it anyway you like.

robincornelius avatar Jan 06 '18 17:01 robincornelius

Thank you, I also though about the callback way though I was about to leave it as a last resort.

So I started with the constant initializer approach but I found a few issues:

  • I found no way in Object Dictionary Editor v0.5.2 to specify a dummy string of, let's say, 12 bytes, with 12 being a readable number. So I would have to use "\0" 12 times or "123456789012".
  • The constant string seems to generate the wrong number in the .length field of the CO_OD_entryRecord_t (apparently, it outputs the right size in decimal format, but it mistakenly prefixes it with a 0x). If confirmed, that's an issue with this project.
  • Even ignoring the two issues above, I found no easy way to change the "string" length (i.e. the above field) in software. That's because CO_OD_entryRecord_t is declared as const and therefore allocated in read-only flash. I would also have to use the full array name and the numerical subindex which I don't like.

So I guess I'll have to go with the callback approach then. Thanks!

iurly avatar Jan 06 '18 23:01 iurly

Issue 2 "The constant string seems to generate the wrong number" is fixed in git and on the dropbox preview builds.

1 Is a good addition for the editor, being able to set a dummy length for a string would be useful

robincornelius avatar Jan 21 '18 21:01 robincornelius