View previous topic :: View next topic |
Author |
Message |
jeroenpost
Joined: 19 Aug 2014 Posts: 3
|
Posted: Wed Sep 03, 2014 10:03 pm Post subject: 'Split' seems to breakup a string wrong |
|
|
I am new in the Bascom and Arduino world.
The project i am working on is an attempt to read GPS data, battery voltage, altitude and motor current from a model airplane and send this data to a laptop.
I came this far:
reading the GPS data from a SW-comport.
making 6,7,8 or 9 strings containing this data.
Adding the measurements current, voltage, altitude / airspeed.
and sending it to a SW-comport to a data sender.
Now something’s simple....add the relevant GPS data.
I want to break up the string with are containing data separated with a ",".
so..split should do the trick.
to show what the problem is…
T_int = Split(r_str(1) , S_str(1) , "," )
Ard(1) = ""
For S_int = 1 To T_int
Ard(1) = Ard(1) + S_str(s_int) + " "
Next
It should break up the string r_str(1) and place the parts separated with "," into an array S_Str().
then put is back together in Ard(1) but the "," should be replaced with spaces.
r_str(1) contains : $GPRMC,202313.00,A,5230.00005,N,00447.12334,E,0.041,,030914,,,A*7A
Ard(1) contains : $GPRMC 202524.00 A 5229.99807 N 00447.1217 4 E 0.054 030914 A*78
(don’t mind the difference in data)
Has anyone any idée why ‘split’ breaks up ,00447.12334,E, into 00447.1233 4 E
(GPS data is dynamic, splitting it up using a separator is the best way... if its works correct..)
See the attachment for the program
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Sep 03, 2014 11:04 pm Post subject: |
|
|
Hi Jeroen,
Welcome.
it seems that split() is working correct.
just tried it in the sim:
Code: | T_int = 1
r_str(1)="$GPRMC,202313.00,A,5230.00005,N,00447.12334,E,0.041,,030914,,,A*7A"
goto test
...
test:
T_int = Split(r_str(1) , S_str(1) , "," )
'prepaire data for HOST (more to come here)
Ard(1) = ""
For S_int = 1 To T_int
Ard(1) = Ard(1) + S_str(s_int) + ","
Next
print ard(1) ' '$GPRMC,202313.00,A,5230.00005,N,00447.1233,4,E,0.041,,030914,,,A*7A,
|
as you can see the results are the same.
if the only goal is to replace a char for another one have a look at REPLACECHARS in the help.
if you need split, debug by printing the data you have before and after the conversion.
I suspect the data you think you have is not what you have. Or the target array is too small so the strings are broken up. _________________ Mark |
|
Back to top |
|
|
jeroenpost
Joined: 19 Aug 2014 Posts: 3
|
Posted: Thu Sep 04, 2014 10:33 pm Post subject: |
|
|
Hi Mark,
In your SIM the Longitude is also broken up in two.
This is caused by the size of the target array string.
Read the manual, but don't believe everything they say…
The format of the Longitude should be dddmm.mmmm (10 char) (example:12158.3416)
The GPS send 00447.12334 and that’s 11 char’s
The format of the Latitude should be ddmm.mmmm (9 char) but also contains 1 more.
So…
Dim S_str(20) As String * 10
Should be
Dim S_str(20) As String * 12
Thanks….
Jeroen. |
|
Back to top |
|
|
Arera
Joined: 23 Sep 2007 Posts: 386 Location: Wuppertal, Germany
|
Posted: Sat Sep 06, 2014 11:16 am Post subject: |
|
|
It is always a good idea to dim strings a bit longer than you would expect them to be.
Strings can be (invisibly) terminated by one or two characters, or grow for any other reason. The only disadvantage of dimming them longer is the extra use of ram. If that is no point, dim them long. |
|
Back to top |
|
|
jeroenpost
Joined: 19 Aug 2014 Posts: 3
|
Posted: Wed Sep 10, 2014 8:22 pm Post subject: |
|
|
Arera,
I expected split to break of the string to make it fit the target array.
It does but Split puts the remains in the next element of the array.
But you right. I also encountered NULL chars in the source string, so extra space is useful.
I am not happy with a software-UART. It makes the program time critical.
Let’s see if I can use the hardware-UART…
Thanks for the response.
Jeroen. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|