0
\$\begingroup\$

I am using two function for lat and long DMS conversion. when I am using those two function ,either lat or lon is display correctly in my UART.when If i will print latitude first in UART,displaying correct DMS value.then when I will print longitude second its dosnt show the right value(0000000).

void lat_DMS(char *lat_data, char *lat_return)
{
                char temp[3],temp1[3];
                float res1=atof(lat_data);
                float flo=res1/100;
                int ilong=flo;
                latdeg[0]=ilong;
                sprintf(temp,"%03d",ilong);
                strncat(lat_return,temp,strlen(temp));
                float lati=flo-ilong;//subtract the values
                float res12=lati*60;//multiply the value differ value with 60
                int minutes=res12;
                latdeg[1]=minutes;
                sprintf(temp,"%02d",minutes);
                strncat(lat_return,temp,strlen(temp));  
                float isec=res12-minutes;
                int lasec=isec*60;
                latdeg[2]=lasec;
                sprintf(temp,"%02d",lasec);
                strncat(lat_return,temp,strlen(temp));

}

void lon_DMS(char *lon_data, char *lon_return)
{
                char temp1[3];
                float res2=atof(lon_data);
                float lonflo=res2/100;
                int inlong=lonflo;
                londeg[0]=inlong;
                sprintf(temp1,"%03d",inlong);
                strncat(lon_return,temp1,strlen(temp1));
                float longi=lonflo-inlong;//subtract the values
                float lonres=longi*60;//multiply the value differe value with 60
                int lonminutes=lonres;
                londeg[1]=lonminutes;
                sprintf(temp1,"%02d",lonminutes);
                strncat(lon_return,temp1,strlen(temp1));  
                float lonsec=lonres-lonminutes;
                int longisec=lonsec*60;
                londeg[2]=longisec;
                sprintf(temp1,"%02d",longisec);
                strncat(lon_return,temp1,strlen(temp1));


}

I am storing value in arrays for transmitting 4 bytes+4bytes of lat and long(Deg,Min,sec,dire each 1 byte)

in main function

     uartwrite("LAT:");          
    lat_DMS(latPtr,&Dlat);
    uartwrite(&Dlat);
    uartwrite("\r\n");
    memset(Dlat,'\0',strlen(Dlat));

 uartwrite("LON:");          
    lon_DMS(lonPtr,&Dlon);
    uartwrite(&Dlon);
    uartwrite("\r\n");
    memset(Dlon,'\0',strlen(Dlon));

whether stack is full? I am confused.i am loading my program on my controller ,its not loading correctly and when loading on second time on micro cont,the previously loaded program is running.I have written uartwrite on while loop more than 2 time its not showing the lat and lon value

\$\endgroup\$
1
\$\begingroup\$

You haven't explicitly stated anywhere in the question what the input and output formats are so I'm guessing a little.

And I'm not sure why you seem to have over complicated it so much. You certainly have far more variables and string copies than you need. Assuming you have NMEA format values coming in then all you need is:

// lon_data = NMEA format string DDDMM.mmmmm
// lon_return = DDMMSS.sss
void lon_DMS(const char *lon_data, char *lon_return)
{
  float workingValue = atof(lon_data);
  int degrees = workingValue/100;
  workingValue = workingValue - degrees *100; // minutes only
  int minutes = (int) workingValue;
  workingValue = 60*(workingValue - minutes); // seconds
  sprintf(lon_return ,"%03d%02d%06.3f", degrees, minutes, workingValue);
}
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.