Inter cog communication, passing variables
Dizzy
Posts: 9
Hello I've been feverishly trying to get variables to pass between objects in SPIN. What I have is an XBee object I've modified constantly polling for input packets on one cog and a dashboard cog that should be passed those packets. From the examples I've seen it seems like parent objects can modify variables in child objects instead of the other way around? Either way this is what I'm attempting in a nutshell:
Inside Dashboard Object
---Inside Xbee object
For some reason in the text above the forum is deleting the brackets off of some of my stuff. packet is byte array of 3. the second line where inByte2 := packet is missing brackets. Please disregard syntax.
What is the correct syntax to get the Xbee object to be able to change the variables passed in from teh dashboard object?
Thanks,
Diz
Post Edited (Dizzy) : 3/8/2008 5:58:39 PM GMT
Inside Dashboard Object
net.start(6,5,0,9600,@byte1,@byte2) <-This starts the Xbee module on pins 5&&6 @baud of 9600 passing the two packets I want the Xbee to update byte1 and byte2
---Inside Xbee object
byte packet Pub Start (RXpin, TXPin, Mode, Baud, inByte1, inByte2) repeat RxStrTime(5,@packet) inByte1 := packet[noparse][[/noparse]0] inByte2 := packet I've also tried BYTE[noparse][[/noparse]@inByte1] := packet[noparse][[/noparse]0] and BYTE[noparse][[/noparse]inByte1] := packet[noparse][[/noparse]0]
For some reason in the text above the forum is deleting the brackets off of some of my stuff. packet is byte array of 3. the second line where inByte2 := packet is missing brackets. Please disregard syntax.
What is the correct syntax to get the Xbee object to be able to change the variables passed in from teh dashboard object?
Thanks,
Diz
Post Edited (Dizzy) : 3/8/2008 5:58:39 PM GMT
Comments
Look:
As C SPIN uses call-by-value (-> look-up what that means)
So the "value" of your "dummy" parameters is a pointer to byte1 and to byte2.
Assigning to "dummy" parameters just changes them locally; this is done by many programmers, for different reasons;
generally to save a local variable or an assignment... This has no effect outside the routine
@dummyParameter is just a pointer to that dummy parameter - not of much use in your case
BYTE[noparse][[/noparse]inByte1] is the method of choice! It is called "de-referentiation" and the most important way to access to vectors from sub-routines
or over object borders. Referencing and Derefenecing are most important techniques in all machine language like applications.
There is no ambitious piece of code working without it, and understanding ALL OF ITS ASPECTS is needed to make the step
from the VERY BEGINNER to the ADVANCED BEGINNER
Have you defined byte1 as BYTE ? You may need to use WORD[noparse][[/noparse] ] or LONG[noparse][[/noparse] ] otherwise ?
You haven't actually explained what isn't working with your code. Are you sure that RxStrTime() is even returning ? Have you tried trimming your code back to find what does work and doesn't ? You can try removing the call to RxStrTime(), force known values intp packet[noparse]/noparse and check they get passed back. For a simple observer who doesn't know what you code is it's only possible to make stabs in the dark. Your mechanism for passing addresses looks okay so the problem is likely somewhere else.
===== Main Object =====
===== Scanner Object =====
The important thing is that the pointer that gets passed in is really an
address, so I reserve a long variable called map that I use in the
scanner object to reference the byte using
byte [noparse][[/noparse] map ][noparse][[/noparse] row ] := distance
In my case I am using an array of bytes, so I have the second reference of [noparse][[/noparse] row ]. -Chuck
If so, that would be a very efficient way to pass multiple word or byte "packets" back to the calling method. I am propably wrong in my thinking, but that's how it looks to me anyway.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
E3 = Thought
http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.
This
copies EIGHT BITS to the byte at address "map+row" - and nothing else!
no, if you wanted to pass back two bytes you would need to use
And define map in the main as a Word Array. I guess it is confusing that I used map in both objects. The scanner object should have defined that map variable as mapPointer. This pointer could have been a word I think, but a long is ok. I only pass back 20 bytes since my sonar only returns a number from 6 to 200. So 20 readings fit into 20 bytes. -Chuck-
.