chosing float or dec automatically (+other questions now)
Basil
Posts: 380
Hi All,
Not sure if this is dooable but thought i'd ask.
In my dataflash chip, I have a series of decimal and floats all stored in longs (well bytes really, but groups of 4 bytes)
I need to 'play them back' over serial to a com terminal.
Is there was way for the prop to tell wether its reading a decimal number or a float from the dataflash?...(This next part is easy)... and then either send it as decimal, or convert floattostring depening on its decision?
Thanks,
Alec
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec
My our page
Post Edited (Basil) : 9/11/2008 12:38:03 AM GMT
Not sure if this is dooable but thought i'd ask.
In my dataflash chip, I have a series of decimal and floats all stored in longs (well bytes really, but groups of 4 bytes)
I need to 'play them back' over serial to a com terminal.
Is there was way for the prop to tell wether its reading a decimal number or a float from the dataflash?...(This next part is easy)... and then either send it as decimal, or convert floattostring depening on its decision?
Thanks,
Alec
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec
My our page
Post Edited (Basil) : 9/11/2008 12:38:03 AM GMT
Comments
Here's the format information: en.wikipedia.org/wiki/IEEE_754
Hmmmm. Good ideas. I think the maximum length my integers will be is 12bits.
So if I do the following, should that work.
temp := value from memory
temp := temp & %1111000000000000
if temp <> 0
temp is a float
else
temp is an int
Thanks,
Alec
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec
My our page
You also have to decide whether zero is an integer or floating point value. It's a special
case of all zero bits.
That makes sense except for 1 part.
If I send all 0's over serial, does it matter if i send serial.str(FloattoString(0.0)) or serial.dec(0)?
Wouldn't the end result still be a whole lot of 0's?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec
My our page
floating point if they have a decimal point in them, you'll still end up with zero values since the
IEEE floating point zero value is the same as the integer zero.
Thanks mike [noparse]:)[/noparse]
Will try a few things and see how we go.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec
My our page
When saving my data to the dataflash i'm currently doing the following:
DF_Send(Circ_Buf_Start_byte, 32)
DF_Send(DF_next_flight, 32)
DF_Send(flighttime, 32)
...
DF_Send(Pyro_Test, 32)
DF_Send(Pyro_Test, 32)
DF_Send(Pyro_Test, 32)
All these variables are longs and are declared in the VAR section in the same order I write it to the DF.
Are the varaibles actually stored in the RAM in the same order I declare them, so I can loop through the data using the memory address of the variable and incrementing it by 4 each iteration of the loop (I assume id increment 4 bytes to go to the next long, rather than 32bits).
Also, I have a question about the EEPROM object (VarBackup/VarRestore)
In either of these methods, I need to specify a start and end address.
With the end address, is it the address of the first byte AFTER the data I want to save that I pass to the method, or the address of the first byte in the last long that I pass?
As an example, using the above data. Assuming I want to store all longs from 'DF_Next_flight' to 'Pyro_Test[noparse]/noparse][b]2[/b', do I call"
VarBackup(DF_Next_Flight, PyroTest[noparse]/noparse][b]2[/b) or VarBackup(DF_Next_Flight, PyroTest[noparse]/noparse][b]3[/b)
Thanks!
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec
My our page
I have no idea about your EEPROM object. There are several in the Object Exchange. Usually the documentation (comments in the source) will explain what parameters are used for what purpose.
I think I answered my own questions with the EEPROM.
This line out of the EEPROM object...
repeat addr from startAddr to endAddr - 1
endAddr-1 would suggest I specify the first byte AFTER the data [noparse]:)[/noparse]
Thanks for the help again,
Alec
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec
My our page
How would I pass the variable at address 'i' to a method which is expecting an actual variable not an address?
Currently doing lots of DF_Send(Variable, 32) calls where Variable is a long containing a result.
I want to do
Its the Variable at i part I cant get, Im missing something obvious I know it...
Alec
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
-Alec
My our page