The second example regards the interpretation and formatting of the location data provided by SIM908.
The problem with GPS data is that, although the location data is unique, there are several formats to describe it.
It can thus arise the problem of finding ourselves using different formats with the risk to be confused. For this reason it is critical to analyze the format used by SIM908 and how you can convert it to other formats, which are also widely used (such as the one used by Google).
SIM908 uses a format that is described by the initials ddmm.mmmm, while other devices and services (such as Google Maps) use the decimal dd.dddddd.
The decimal format is widely used, it’s easir to manage, in the calculation of distances and speeds.
It is therefore necessary to know the relationship between the two formats in order to to use the one you prefer, based on your need.
The relationship between these two formats is expressed by the following formula:
dd.dddddd = dd + mm.mmmm / 60
Remember that the library provides the coordinates as a string, you need to use a method to convert these coordinates in numerical format if you want to use it within a formula.
One of these functions is contained within the stdlib.h library, can be included with the following command:
# include < stdlib.h>
Within the library you can see the function
atof (const char * str)
that returns a float containing the value expressed by the string.
To better understand what is expressed in this section let’s analyze the example.
The example proposed shows how to convert the format of the SIM908 ddmm.mmmm into the widely used dd.dddd format.
Firstly, to differentiate it from the previous example, we have chosen to perform the geolocation only after the user’s request it through a specific command via the serial communication.
Specifically, when the user wants to know his position, expressed in dd.dddd coordinates, he will send the string “GPS” through serial communication.
The shield will respond with two values , latitude and longitude, in the Google compatible format (simply insert these data into the search bar of Google Maps to display the location on the map.)
For the interpretation of the messages sent via the serial port, at each iteration of the loop we save all the characters on that port within a char array.
Then using the command
strcmp(inSerial, “GPS”)
you will go checking if the array actually contains the predetermined “GPS” command.
In case yes, you can enter the portion of the code that executes on that command.
After the commands to request the longitude and latitude in the native SIM908 -which we already analyzed in the previous example – we find the convert function, used to convert the coordinates.
This function has been developed on purpose and is available at the end of the code.
This function divides the string into the two parts: dd and mm.mmm.
The first problem you encounter concerns the part relative to degrees (the first part), described by the dd: this is not always composed of two characters! If the number is between 0 and 9, this part will be represented with a single character, and the output will be dmm.mmmm instead ddmm.mmmm.
To discriminate these two situations we check for the dot within the string, checking if this is present in position 3 or 4 (remember that in the array positions starts at 0).
This can be done with the function – again, developed on purpose and available at the end of the code –
int strpos (char *str, char *target )
that returns an integer representing the position in which the *target character is found in the string *str.
Once obtained this information we can extract the one or two characters for the first part of the string.
Similarly we extract the second part related to mm.mmm information, converting it into a floating point number to perform the final calculation described by the formula that we previously seen.
The output will then be composed of two coordinates, latitude and longitude, expressed according to the desired format.
ตัวอย่างที่สองพิจารณาตีความและการจัดรูปแบบของข้อมูลตำแหน่งที่ตั้งโดย SIM908ปัญหาเรื่องข้อมูล GPS ได้ว่า ถึงแม้ว่าสถานที่เก็บข้อมูลไม่ซ้ำกัน มีหลายรูปแบบเพื่ออธิบายมันสามารถเกิดขึ้นได้ดังนั้นปัญหาการค้นหาตนเองด้วยรูปแบบความเสี่ยงจะสับสน ด้วยเหตุนี้จึงเป็นความสำคัญต่อการวิเคราะห์รูปแบบที่ใช้ SIM908 และวิธีคุณสามารถแปลงเป็นรูปแบบอื่น ๆ ซึ่งยังใช้ (เช่นการใช้ Google) ใช้ SIM908 เป็นรูปแบบที่อธิบายไว้ โดย ddmm.mmmm ชื่อย่อ ในขณะที่บริการ (Google Maps) และอุปกรณ์อื่นๆ ใช้ dd.dddddd ทศนิยม สิบที่ใช้กันอย่างแพร่หลาย มี easir การจัดการ การคำนวณระยะทางและความเร็วในการจึงจำเป็นต้องทราบความสัมพันธ์ระหว่างรูปแบบสองเพื่อการใช้คุณต้องการ ตามความต้องการความสัมพันธ์ระหว่างรูปแบบเหล่านี้สองจะแสดง โดยใช้สูตรต่อไปนี้:dd.dddddd = dd + mm.mmmm 60จำไว้ว่า รีแสดงพิกัดเป็นสายอักขระ คุณจำเป็นต้องใช้วิธีการแปลงพิกัดในรูปแบบตัวเลขเหล่านี้ถ้าคุณต้องการใช้ในสูตรฟังก์ชันเหล่านี้อย่างใดอย่างหนึ่งอยู่ภายในไลบรารี stdlib.h สามารถรวมกับคำสั่งต่อไปนี้:#รวม < stdlib.h >ภายในไลบรารี คุณสามารถดูการทำงานatof (อักขระค่า const * str)ที่ส่งกลับค่าลอยตัวที่ประกอบด้วยค่าที่แสดง ด้วยสายอักขระ To better understand what is expressed in this section let’s analyze the example.The example proposed shows how to convert the format of the SIM908 ddmm.mmmm into the widely used dd.dddd format.Firstly, to differentiate it from the previous example, we have chosen to perform the geolocation only after the user’s request it through a specific command via the serial communication.Specifically, when the user wants to know his position, expressed in dd.dddd coordinates, he will send the string “GPS” through serial communication. The shield will respond with two values , latitude and longitude, in the Google compatible format (simply insert these data into the search bar of Google Maps to display the location on the map.)For the interpretation of the messages sent via the serial port, at each iteration of the loop we save all the characters on that port within a char array.Then using the commandstrcmp(inSerial, “GPS”)you will go checking if the array actually contains the predetermined “GPS” command.In case yes, you can enter the portion of the code that executes on that command. After the commands to request the longitude and latitude in the native SIM908 -which we already analyzed in the previous example – we find the convert function, used to convert the coordinates.This function has been developed on purpose and is available at the end of the code.This function divides the string into the two parts: dd and mm.mmm.The first problem you encounter concerns the part relative to degrees (the first part), described by the dd: this is not always composed of two characters! If the number is between 0 and 9, this part will be represented with a single character, and the output will be dmm.mmmm instead ddmm.mmmm.To discriminate these two situations we check for the dot within the string, checking if this is present in position 3 or 4 (remember that in the array positions starts at 0).This can be done with the function – again, developed on purpose and available at the end of the code –int strpos (char *str, char *target )that returns an integer representing the position in which the *target character is found in the string *str.Once obtained this information we can extract the one or two characters for the first part of the string.Similarly we extract the second part related to mm.mmm information, converting it into a floating point number to perform the final calculation described by the formula that we previously seen.The output will then be composed of two coordinates, latitude and longitude, expressed according to the desired format.
การแปล กรุณารอสักครู่..
