String Parsing/Converting
g3cwi
Posts: 262
Dear all
I am using the GPS_IO_MINI to extract data from the NMEA information from my GPS. I need to use the velocity and GPS fix quality as numbers. A first attempt failed after which it occured to me that they were probably extracted as strings. First question - is that right?
If they are strings, I need to convert them into decimals. One is an integer (quality), the other is not (velocity). In practice I only need the integer part of the velocity though. Looking around I have found lots of objects that can turn strings into decimals but (newbie alert) they all "return a pointer" and I don't know how to use them. So the second question is where can I find a gentle walkthrough description of using methods that "return a pointer"? If you assume that I have no more programming knowledge than the average Cocker Spaniel you will have the level just right!
Oh and I also need some advice on just getting the integer part of the velocity out of the string!
Time for breakfast.
Regards from rainy England
Richard
I am using the GPS_IO_MINI to extract data from the NMEA information from my GPS. I need to use the velocity and GPS fix quality as numbers. A first attempt failed after which it occured to me that they were probably extracted as strings. First question - is that right?
If they are strings, I need to convert them into decimals. One is an integer (quality), the other is not (velocity). In practice I only need the integer part of the velocity though. Looking around I have found lots of objects that can turn strings into decimals but (newbie alert) they all "return a pointer" and I don't know how to use them. So the second question is where can I find a gentle walkthrough description of using methods that "return a pointer"? If you assume that I have no more programming knowledge than the average Cocker Spaniel you will have the level just right!
Oh and I also need some advice on just getting the integer part of the velocity out of the string!
Time for breakfast.
Regards from rainy England
Richard
Comments
value := numbers.FromStr(gps.speed, numbers#DEC)
This returns nothing at all so I am still puzzled.
Regards
Richard
As I mentioned, I'm new to this...
Regards
Richard
Next would be to check serial.hex(gps.speed, 8), if that value is NULL then it's not available, otherwise (not equal NULL) what does serial.str(gps.speed) report?
!5315.80N/00208.80W-0.00 Knots A
I used the numbers object and then added 120 to the "speed" and "333" to the valid, this gave:
<0x06>5<0xfa><0x80>F Knots 0N/
where <0x06>5<0xfa><0x80>F is the speed and;
0N/ is the valid.
I am debugging over an APRS network and clearly it can't interpret these values as decimal numbers so something's wrong!
Regards
Richard
Regards
Richard
This fails to work as hoped. I am really finding this whole address and content thing most confusing.
Any ideas?
Regards
Richard
I want to change a floating point number into a string.
FloatString has the perfect subroutine:
FloatToFormat(single, width, dp) : stringptr
However, I have been unable to figure out how to use it - the problem being that I don't understand
a) how to get back the string pointer and then
b) how to use it to get the string back.
Assuming my number is stored so that:
test := 123.456
I then tried combinations of:
test := fs.Floattoformat (test, 6, 2)
Debug.str (test)
I tried sprinkling @ signs around but still no joy. I am clearly mis-understanding the whole "address", Pointer, string thing.
Help appreciated.
Regards
Richard
Strings are encoded (we're dealing with ASCII encoding) byte arrays where each byte represents a character. Strings end with a zero. Called zero or null terminated.
This is incorrect syntax
This is correct syntax
Hopefully this example helps a bit. This is the first time I used Float32. Someone will correct me if I did not use the object correctly.
Thanks for your interest. The number I have is of the form 123.456 and is a floating point decimal. Basically I need to round it to 0 decimal places (i.e. 123) and then use it as a string. That was the reason for looking at theFloattoFormat method from the FloatString Object. However as I don't really understand the terminology I don't know how to recover the pointer and how to use it to recover the string itself.
Regards
Richard
I'm not much further along the trail than you are but I think I just walked your path last week. I've attached my sloppy code that is a work in progress. If I understand your issue correctly, essentially what you need to do is apply the Numbers object. I give an example in the code below. If I'm not mistaken, if you bring in a decimal number into the Prop, say 123.45, you will by default get 123 . I hope I'm not being captain obvious and this helps you out.
Point of order to the experts out there: I noticed that the object GPS_IO_mini does NOT have a STOP method. Should it by convention have a Stop method and that Stop method be part of the Start method?
Regards,
Steve Woodrough
'Till the next problem
regards
Richard