Indirectly accessing spin OBJ
Is there any way to have an indirect reference to a spin OBJ?
Basically, I have a function that can talk to a number of different possible communication interfaces (as long as the interface presents a consistent API, anyways).
Is there any way I can pass the function a pointer to an arbitrary OBJ instance?
Right now, the only way I can think of to do this is with a great big IF THEN statement, which would have to be updated every time I add a new communication interface, and would have to be parsed every time I want to call the OBJ.
I'd much rather just pass the whole function a pointer to the OBJ, and let it just assume that the OBJ has a read() and write() function.
Thanks.
(Hmmm. Does this basically boil down to me wanting to do object-oriented programming in spin?)
Basically, I have a function that can talk to a number of different possible communication interfaces (as long as the interface presents a consistent API, anyways).
Is there any way I can pass the function a pointer to an arbitrary OBJ instance?
Right now, the only way I can think of to do this is with a great big IF THEN statement, which would have to be updated every time I add a new communication interface, and would have to be parsed every time I want to call the OBJ.
I'd much rather just pass the whole function a pointer to the OBJ, and let it just assume that the OBJ has a read() and write() function.
Thanks.
(Hmmm. Does this basically boil down to me wanting to do object-oriented programming in spin?)
Comments
One of the ways is to use a predefined hub buffer location and pass the base location when the object is started. That way, the object knows where its read and write buffers are located.
I guess we need a bit more info. There are probably many ways although some are not elegant.
also look at : http://obex.parallax.com/objects/268/ for an simple example.
James
Say I have:
Now, assume that both OBJs have tx() and rx() functions:
I want to be able to do something like:
Note that the tx() and rx() functions should be executed in the calling function's COG. Using another COG to liaise between two already running cogs seems a bit silly, particularly as I can guarantee there will not be any collisions (there is only one function caller COG).
@kuroneko - That looks interesting, but it seems to be poking around in the raw spin bytecodes? I'm really not sure how it actually works.
Is the spin bytecode documented anywhere? Preferably in small words that I can understand?