A very strange problem
g3cwi
Posts: 262
I have a simple piece of code that acts on some variables. They are different and have different names. However, a few lines down they all become the same value - without any code changing them. I have stopped all the parallel processes and searched for the variable being reassigned somewhere but nothing.
At the top: heading_avg_str is 180
but by the bottom it (and speed_avg_str) = 1034.
Most of the code is commented out so there is nothing there that I can see to cause this...
Puzzled!
Richard
heading_avg_last := 180 'debug heading_avg_str := num.ToStr(heading_avg_last, num#DEC) waitcnt(clkfreq/20 + cnt) speed_avg_last := 123 'debug speed_avg_str := num.ToStr(speed_avg_last, num#DEC) waitcnt(clkfreq/20 + cnt) alt_avg_last := 1034 'debug alt_avg_str := num.ToStr(alt_avg_last, num#DEC) waitcnt(clkfreq/20 + cnt) {Debug.cls Debug.str(string("Packet filler ")) debug.str(gps.satellites) Debug.nl debug.dec(speed_avg_last) debug.nl debug.dec(alt_avg_last)} '****Your data payload goes here**** 'Max 255 characters addToPacket(string("APRS implemented by G3CWI."), 26) addToPacket(string(" Test data: "), 12) {'Add speed to packet if speed_dec > 1 addToPacket(string("Speed "), 6) addToPacket(speed_str,3) addToPacket(string(" MPH. "), 6) else addToPacket(String("Not moving. "), 12) 'debug.str (speed_dec) 'Add altitude to packet if gps_alt_dec > 1 addToPacket(string("Alt. ") ,5) addToPacket(gps_alt_str ,4) addToPacket(string(" m. ") ,4) else addToPacket(String("Alt. not available. ") ,20) 'debug.str (speed_dec) 'Add heading to packet if speed_dec > 1 'Unreliable if speed too low/stopped addToPacket(string("Heading ") ,8) addToPacket(gps_heading_str ,3) addToPacket(string(" degrees.") ,9) Else addToPacket(string("Heading not available. ") ,23) } 'repeat 70 'debug delay 'waitcnt(clkfreq + cnt) 'Add average heading to packet if speed_avg_last > 1 addToPacket(string(" Speed ") ,7) debug.cls debug.str (speed_avg_str) debug.nl addToPacket(speed_avg_str , strsize(speed_avg_str)) addToPacket(string(" mph.") ,5) else addToPacket(string(" Not moving.") ,12) if speed_avg_last > 1 addToPacket(string(" Hdg. ") ,6) debug.str (heading_avg_str) debug.nl addToPacket(heading_avg_str , strsize(heading_avg_str)) addToPacket(string(" deg.") ,5)
At the top: heading_avg_str is 180
but by the bottom it (and speed_avg_str) = 1034.
Most of the code is commented out so there is nothing there that I can see to cause this...
Puzzled!
Richard
Comments
num = Numbers
Basically all three variables take on the value of the last conversion...
Regards
Richard
I think the problem is the numToStr. As the propeller/SPIN does not have dynamic memory allocation the function numToStr will always return the address of the same buffer which is used for conversion. So, you should simply use numToStr just before doing the output of one value.
If you really need more than one string in parallel these have be stored somewhere from the calling program, you have to call a bytemove and copy the string into another buffer.
That did not work. StrBuf is the Numbers buffer array (50 bytes). I have not explored bytemove before and now seems like a good time to try!
Regards
Richard
You don't want the "@" symbol in front of "heading_avg_str" since holds the location you want to copy from (it isn't the location itself).
Can you describe what you're trying to do.
I had this same problem and it took a few forum members to school me. I still have this problem, but now I can usually fix it after I realize.
Here is the format you can use, hopefully I can save you some of the hard knocks I went through
Some rules to remember about bytemove, it always wants a variable address ( @variable), not a variable name (variable). You can use a variable name if you've previous assigned it to another variables address (variableName := @variable) because at that point, the variable (variableName) is just acting as a liaison/pointer to the other variable address (@variable).
In my code below
byte b_suffix[_byteLimit] is a byte array and RxStringAddr is a long containing the address pointer to a byte array
If you give me your whole code, something that I can compile, and what you expect to see, I can try and get it working to show you how it should work
On a macroscale this is it:
http://aprs.fi/?call=G3CWI-12&_s=ll
I will take the modified code out for a spin(!) in a few minutes.
Regards
Richard
http://forums.parallax.com/showthread.php?138214-Bytemove-question-help&highlight=strin+repeat