Calling data from "external" source

I am building a simulator for a project for which I would like to call GPS data from an external source. I haven't decided where this source is going to be held, Sd card etc, but for now that part is irrelevament as I can refer to a .h file I presume.

The data currently is in csv format and comprises of 3 collumns, such as....

long, lat, altitude 
-0.717625,54.435313,200
-0.717445,54.435280,201
-0.717131,54.435217,201
-0.716908,54.435156,202
-0.716506,54.435117,202
-0.716105,54.435051,201
-0.715928,54.435019,201
-0.715752,54.434960,202
-0.715531,54.434900,202
-0.715357,54.434815,203
-0.715183,54.434731,201
-0.715009,54.434673,202

The piece of code which is of interest is...

void loop()
{
    for (int i = 0; i < count; ++i)
    {
        int result = 0;

        track_sim_reg track_reg = {0};

        track_reg.longitude = (int32_t) (DEG_TO_RAD(-0.717625f) * 10000000.0f);
        track_reg.latitude = (int32_t) (DEG_TO_RAD(54.435313f) * 10000000.0f);
        track_reg.altitude = 200;

        delay(10);
    }
    delay(100);
}

Where the actual figures are currently represented for lat, long and altitude in the loop function, how would I call the next consecutive line from the .csv to populate these fields please.

I can visualise what I need, just not sure what format is best to store the data in (csv, json etc) for it to be called from the loop.

Many thanks and hope that all makes sense !

Array initialization statements work fine for testing code, e.g.

float test_data[3] = {-0.717625,54.435313,200.0};
...
        track_reg.longitude = (int32_t) (DEG_TO_RAD(test_data[0]) * 10000000.0f);

If the GPS data will be in NMEA format, you will need to translate the ASCII DDDMM.SSSSS format to float or double, and that is trickier than it may seem.

Thank you @jremington. Thankfully the GPS data will be in the correct format, so no conversion is required.

With an array, does this just contain the 3 elements in the one line as there are another 10 lines of data in the example that would need to be called 1 line at a time on each pass of the loop.

You can use a 2D array for as much data as memory will hold, and loop over the leftmost index. Don't forget that array indices start with "0".

float test_data[][3] = {
{-0.717625,54.435313,200.0},
{-0.717445,54.435280,201.0},
{-0.717131,54.435217,201.0}
};

...
        track_reg.longitude = (int32_t) (DEG_TO_RAD(test_data[i][0]) * 10000000.0f);

Thank you again @jremington, your help was very valuable and set me on the right path. Thank you for taking the time to explain :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.