What is the common way to split a sentence of data in data blocks?
For use in a GPS project I have to split a data stream into several parts.
The data sentence is separated with commas ',' and each block represents a certain part of the data I need.
So for instance $GPGGA,11111.11,222.22,3,444,5555555555,66,,7
Must become:
- variable1= $GPGGA
- variable2= 11111.11
- variable3= 222.22
- variable4= 3
- variable5= 444
- variable6= 5555555555
- variable7= 66
- variable8=
- variable9= 7
Is there a standard way to accomplish this?
I have tried my own method, but maybe this was to difficult.
I'm not sure that the length of each sentence is the same, so if there is a method to easily split these sentences, I'm willing to learn..
Any help is welcome.
Best tactic: how to split data sentences?
Moderator: Benj
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Best tactic: how to split data sentences?
Hi MJU,
I'm assuming you require help with flowcode V6?
If so take a look at the flowchart.
I did not have a lot of time but thought of one way.
There maybe a better way?
Martin
I'm assuming you require help with flowcode V6?
If so take a look at the flowchart.
I did not have a lot of time but thought of one way.
There maybe a better way?
Martin
- Attachments
-
- Split Variables1.fcfx
- (10.59 KiB) Downloaded 339 times
Martin
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Best tactic: how to split data sentences?
Hello Martin, my hero!medelec35 wrote:Hi MJU,
I'm assuming you require help with flowcode V6?
If so take a look at the flowchart.
I did not have a lot of time but thought of one way.
There maybe a better way?
Martin
Thank you for your help!
Would you believe this is almost the same way I did this?
I used a few more variables to get there, but your solution looks very good!
I always think that professional programmers know 'tactics' to get solutions much better then people like me.
I want to learn!
Thanks!!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Best tactic: how to split data sentences?
Hello,
So you know the GPS component will also do this for you automatically behind the scenes and do the conversions for you from hours and minutes to longitude or latitude.
So you know the GPS component will also do this for you automatically behind the scenes and do the conversions for you from hours and minutes to longitude or latitude.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Best tactic: how to split data sentences?
Thank you BenJ, but the GPS component is assigned to the standard UART pins.Benj wrote:Hello,
So you know the GPS component will also do this for you automatically behind the scenes and do the conversions for you from hours and minutes to longitude or latitude.
I can not tell the component to use other pins for the GPS but the standard pins.
With other components we can choose "software", but with this one this doesn't work.
If like now I use an Arduino Uno with the normal UART in use to communicate with my PC and the GPS module connected to D3/4 I need to solve this.
No worries, in this case I learn a lot about the NMEA sentences.
But if you could, you may always look into the GPS component and why I can't choose other pins..
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: Best tactic: how to split data sentences?
Hi MJU,
No problem, Just glad I could help.
Sounds like you was very near to your own solution.
I have moved topic to V6 section since I posted a V6 flowchart.
Martin
No problem, Just glad I could help.
Sounds like you was very near to your own solution.
I have moved topic to V6 section since I posted a V6 flowchart.
Martin
Martin
-
- Posts: 502
- Joined: Wed Nov 07, 2007 6:51 pm
- Location: Antwerp Belgium
- Has thanked: 121 times
- Been thanked: 108 times
- Contact:
Re: Best tactic: how to split data sentences?
I looked at it in greater detail and for me this is of great beauty.medelec35 wrote:Hi MJU,
I'm assuming you require help with flowcode V6?
If so take a look at the flowchart.
I did not have a lot of time but thought of one way.
There maybe a better way?
Martin
My solution was opposite from your solution and your way is much better.
I started to count the "MainStringVariable" from 0 until I found a ",".
So this way I had a start and an end point.
Between these two there was the string I was looking for.
So I "mid$"-ed this into a variable. (which I needed to count).
So by switching the endpoint and use it as a startpoint for the next part it worked.
But this was much more complicated then your method.
You keep adding figures onto a string until you find the ","..
Such a beautiful solution