Demo
Dependents: A_TeseoLocationNEW A_TeseoLocation
Middlewares/NMEAUtils.c@0:a77f1f1f8318, 2018-11-09 (annotated)
- Committer:
- apalmieri
- Date:
- Fri Nov 09 17:06:11 2018 +0000
- Revision:
- 0:a77f1f1f8318
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
apalmieri | 0:a77f1f1f8318 | 1 | /** |
apalmieri | 0:a77f1f1f8318 | 2 | ******************************************************************************* |
apalmieri | 0:a77f1f1f8318 | 3 | * @file NMEA_utils.c |
apalmieri | 0:a77f1f1f8318 | 4 | * @author AST / Central Lab |
apalmieri | 0:a77f1f1f8318 | 5 | * @version V1.0.0 |
apalmieri | 0:a77f1f1f8318 | 6 | * @date 18-May-2017 |
apalmieri | 0:a77f1f1f8318 | 7 | * @brief NMEA utilities |
apalmieri | 0:a77f1f1f8318 | 8 | * |
apalmieri | 0:a77f1f1f8318 | 9 | ******************************************************************************* |
apalmieri | 0:a77f1f1f8318 | 10 | * @attention |
apalmieri | 0:a77f1f1f8318 | 11 | * |
apalmieri | 0:a77f1f1f8318 | 12 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
apalmieri | 0:a77f1f1f8318 | 13 | * |
apalmieri | 0:a77f1f1f8318 | 14 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
apalmieri | 0:a77f1f1f8318 | 15 | * You may not use this file except in compliance with the License. |
apalmieri | 0:a77f1f1f8318 | 16 | * You may obtain a copy of the License at: |
apalmieri | 0:a77f1f1f8318 | 17 | * |
apalmieri | 0:a77f1f1f8318 | 18 | * http://www.st.com/software_license_agreement_liberty_v2 |
apalmieri | 0:a77f1f1f8318 | 19 | * |
apalmieri | 0:a77f1f1f8318 | 20 | * Redistribution and use in source and binary forms, with or without modification, |
apalmieri | 0:a77f1f1f8318 | 21 | * are permitted provided that the following conditions are met: |
apalmieri | 0:a77f1f1f8318 | 22 | * 1. Redistributions of source code must retain the above copyright notice, |
apalmieri | 0:a77f1f1f8318 | 23 | * this list of conditions and the following disclaimer. |
apalmieri | 0:a77f1f1f8318 | 24 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
apalmieri | 0:a77f1f1f8318 | 25 | * this list of conditions and the following disclaimer in the documentation |
apalmieri | 0:a77f1f1f8318 | 26 | * and/or other materials provided with the distribution. |
apalmieri | 0:a77f1f1f8318 | 27 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
apalmieri | 0:a77f1f1f8318 | 28 | * may be used to endorse or promote products derived from this software |
apalmieri | 0:a77f1f1f8318 | 29 | * without specific prior written permission. |
apalmieri | 0:a77f1f1f8318 | 30 | * |
apalmieri | 0:a77f1f1f8318 | 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
apalmieri | 0:a77f1f1f8318 | 32 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
apalmieri | 0:a77f1f1f8318 | 33 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
apalmieri | 0:a77f1f1f8318 | 34 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
apalmieri | 0:a77f1f1f8318 | 35 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
apalmieri | 0:a77f1f1f8318 | 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
apalmieri | 0:a77f1f1f8318 | 37 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
apalmieri | 0:a77f1f1f8318 | 38 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
apalmieri | 0:a77f1f1f8318 | 39 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
apalmieri | 0:a77f1f1f8318 | 40 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
apalmieri | 0:a77f1f1f8318 | 41 | * |
apalmieri | 0:a77f1f1f8318 | 42 | ******************************************************************************** |
apalmieri | 0:a77f1f1f8318 | 43 | */ |
apalmieri | 0:a77f1f1f8318 | 44 | |
apalmieri | 0:a77f1f1f8318 | 45 | #include "string.h" |
apalmieri | 0:a77f1f1f8318 | 46 | #include "NMEAUtils.h" |
apalmieri | 0:a77f1f1f8318 | 47 | |
apalmieri | 0:a77f1f1f8318 | 48 | /** @defgroup Middlewares |
apalmieri | 0:a77f1f1f8318 | 49 | * @brief Contains all platform independent modules (eg. NMEA Sentence Parser, ...). |
apalmieri | 0:a77f1f1f8318 | 50 | * @{ |
apalmieri | 0:a77f1f1f8318 | 51 | */ |
apalmieri | 0:a77f1f1f8318 | 52 | |
apalmieri | 0:a77f1f1f8318 | 53 | /** @defgroup ST |
apalmieri | 0:a77f1f1f8318 | 54 | * @{ |
apalmieri | 0:a77f1f1f8318 | 55 | */ |
apalmieri | 0:a77f1f1f8318 | 56 | |
apalmieri | 0:a77f1f1f8318 | 57 | /** @defgroup LIB_NMEA |
apalmieri | 0:a77f1f1f8318 | 58 | * @{ |
apalmieri | 0:a77f1f1f8318 | 59 | */ |
apalmieri | 0:a77f1f1f8318 | 60 | |
apalmieri | 0:a77f1f1f8318 | 61 | /** @defgroup NMEA_UTILS |
apalmieri | 0:a77f1f1f8318 | 62 | * @{ |
apalmieri | 0:a77f1f1f8318 | 63 | */ |
apalmieri | 0:a77f1f1f8318 | 64 | |
apalmieri | 0:a77f1f1f8318 | 65 | /** @addtogroup NMEA_UTILS_PUBLIC_FUNCTIONS |
apalmieri | 0:a77f1f1f8318 | 66 | * @{ |
apalmieri | 0:a77f1f1f8318 | 67 | */ |
apalmieri | 0:a77f1f1f8318 | 68 | /** |
apalmieri | 0:a77f1f1f8318 | 69 | * @brief Scans a string with UTC info and fills all fields of a |
apalmieri | 0:a77f1f1f8318 | 70 | * UTC_Info struct |
apalmieri | 0:a77f1f1f8318 | 71 | * @param utc_str NMEA UTC string |
apalmieri | 0:a77f1f1f8318 | 72 | * @param utc The UTC_Info struct to fill |
apalmieri | 0:a77f1f1f8318 | 73 | * @retval None |
apalmieri | 0:a77f1f1f8318 | 74 | */ |
apalmieri | 0:a77f1f1f8318 | 75 | void scan_utc (char* utc_str, UTC_Info* utc) { |
apalmieri | 0:a77f1f1f8318 | 76 | |
apalmieri | 0:a77f1f1f8318 | 77 | sscanf(utc_str, "%d", &utc->utc); |
apalmieri | 0:a77f1f1f8318 | 78 | |
apalmieri | 0:a77f1f1f8318 | 79 | utc->hh = (utc->utc / 10000); |
apalmieri | 0:a77f1f1f8318 | 80 | utc->mm = (utc->utc - (utc->hh * 10000)) / 100; |
apalmieri | 0:a77f1f1f8318 | 81 | utc->ss = utc->utc - ((utc->hh * 10000) + (utc->mm * 100)); |
apalmieri | 0:a77f1f1f8318 | 82 | |
apalmieri | 0:a77f1f1f8318 | 83 | return; |
apalmieri | 0:a77f1f1f8318 | 84 | } |
apalmieri | 0:a77f1f1f8318 | 85 | |
apalmieri | 0:a77f1f1f8318 | 86 | /** |
apalmieri | 0:a77f1f1f8318 | 87 | * @brief Scans a bidimensional array with longitude and latitude infos and |
apalmieri | 0:a77f1f1f8318 | 88 | * fills the relative fields of a Coords struct |
apalmieri | 0:a77f1f1f8318 | 89 | * @param xy_str NMEA string with latitude and longitude infos |
apalmieri | 0:a77f1f1f8318 | 90 | * @param str_offset NMEA string with latitude and longitude infos |
apalmieri | 0:a77f1f1f8318 | 91 | * @param utc The Coords struct to fill |
apalmieri | 0:a77f1f1f8318 | 92 | * @retval None |
apalmieri | 0:a77f1f1f8318 | 93 | */ |
apalmieri | 0:a77f1f1f8318 | 94 | void scan_xy (char* xy_str, uint8_t str_offset, Coords* xy) |
apalmieri | 0:a77f1f1f8318 | 95 | { |
apalmieri | 0:a77f1f1f8318 | 96 | //printf("NMEA (xy_str): %s\n\r", xy_str); |
apalmieri | 0:a77f1f1f8318 | 97 | sscanf(xy_str, "%lf", &xy->lat); |
apalmieri | 0:a77f1f1f8318 | 98 | sscanf(xy_str+str_offset, "%c", &xy->ns); |
apalmieri | 0:a77f1f1f8318 | 99 | sscanf(xy_str+(2*str_offset), "%lf", &xy->lon); |
apalmieri | 0:a77f1f1f8318 | 100 | sscanf(xy_str+(3*str_offset), "%c", &xy->ew); |
apalmieri | 0:a77f1f1f8318 | 101 | |
apalmieri | 0:a77f1f1f8318 | 102 | return; |
apalmieri | 0:a77f1f1f8318 | 103 | } |
apalmieri | 0:a77f1f1f8318 | 104 | |
apalmieri | 0:a77f1f1f8318 | 105 | /** |
apalmieri | 0:a77f1f1f8318 | 106 | * @} |
apalmieri | 0:a77f1f1f8318 | 107 | */ |
apalmieri | 0:a77f1f1f8318 | 108 | |
apalmieri | 0:a77f1f1f8318 | 109 | /** |
apalmieri | 0:a77f1f1f8318 | 110 | * @} |
apalmieri | 0:a77f1f1f8318 | 111 | */ |
apalmieri | 0:a77f1f1f8318 | 112 | |
apalmieri | 0:a77f1f1f8318 | 113 | /** |
apalmieri | 0:a77f1f1f8318 | 114 | * @} |
apalmieri | 0:a77f1f1f8318 | 115 | */ |
apalmieri | 0:a77f1f1f8318 | 116 | |
apalmieri | 0:a77f1f1f8318 | 117 | /** |
apalmieri | 0:a77f1f1f8318 | 118 | * @} |
apalmieri | 0:a77f1f1f8318 | 119 | */ |
apalmieri | 0:a77f1f1f8318 | 120 | |
apalmieri | 0:a77f1f1f8318 | 121 | /** |
apalmieri | 0:a77f1f1f8318 | 122 | * @} |
apalmieri | 0:a77f1f1f8318 | 123 | */ |