Michael Bestas | 3a0209e | 2023-05-04 01:15:47 +0300 | [diff] [blame^] | 1 | /* Copyright (c) 2013-2017 The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
| 12 | * * Neither the name of The Linux Foundation nor the names of its |
| 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef GPS_EXTENDED_H |
| 30 | #define GPS_EXTENDED_H |
| 31 | |
| 32 | /** |
| 33 | * @file |
| 34 | * @brief C++ declarations for GPS types |
| 35 | */ |
| 36 | |
| 37 | #include <gps_extended_c.h> |
| 38 | #if defined(USE_GLIB) || defined(OFF_TARGET) |
| 39 | #include <string.h> |
| 40 | #endif |
| 41 | |
| 42 | #ifdef __cplusplus |
| 43 | extern "C" { |
| 44 | #endif /* __cplusplus */ |
| 45 | |
| 46 | |
| 47 | |
| 48 | struct LocPosMode |
| 49 | { |
| 50 | LocPositionMode mode; |
| 51 | LocGpsPositionRecurrence recurrence; |
| 52 | uint32_t min_interval; |
| 53 | uint32_t preferred_accuracy; |
| 54 | uint32_t preferred_time; |
| 55 | bool share_position; |
| 56 | char credentials[14]; |
| 57 | char provider[8]; |
| 58 | GnssPowerMode powerMode; |
| 59 | uint32_t timeBetweenMeasurements; |
| 60 | LocPosMode(LocPositionMode m, LocGpsPositionRecurrence recr, |
| 61 | uint32_t gap, uint32_t accu, uint32_t time, |
| 62 | bool sp, const char* cred, const char* prov, |
| 63 | GnssPowerMode pMode = GNSS_POWER_MODE_INVALID, |
| 64 | uint32_t tbm = 0) : |
| 65 | mode(m), recurrence(recr), |
| 66 | min_interval(gap < GPS_MIN_POSSIBLE_FIX_INTERVAL_MS ? |
| 67 | GPS_MIN_POSSIBLE_FIX_INTERVAL_MS : gap), |
| 68 | preferred_accuracy(accu), preferred_time(time), |
| 69 | share_position(sp), powerMode(pMode), |
| 70 | timeBetweenMeasurements(tbm) { |
| 71 | memset(credentials, 0, sizeof(credentials)); |
| 72 | memset(provider, 0, sizeof(provider)); |
| 73 | if (NULL != cred) { |
| 74 | memcpy(credentials, cred, sizeof(credentials)-1); |
| 75 | } |
| 76 | if (NULL != prov) { |
| 77 | memcpy(provider, prov, sizeof(provider)-1); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | inline LocPosMode() : |
| 82 | mode(LOC_POSITION_MODE_MS_BASED), |
| 83 | recurrence(LOC_GPS_POSITION_RECURRENCE_PERIODIC), |
| 84 | min_interval(GPS_DEFAULT_FIX_INTERVAL_MS), |
| 85 | preferred_accuracy(50), preferred_time(120000), |
| 86 | share_position(true), powerMode(GNSS_POWER_MODE_INVALID), |
| 87 | timeBetweenMeasurements(GPS_DEFAULT_FIX_INTERVAL_MS) { |
| 88 | memset(credentials, 0, sizeof(credentials)); |
| 89 | memset(provider, 0, sizeof(provider)); |
| 90 | } |
| 91 | |
| 92 | inline bool equals(const LocPosMode &anotherMode) const |
| 93 | { |
| 94 | return anotherMode.mode == mode && |
| 95 | anotherMode.recurrence == recurrence && |
| 96 | anotherMode.min_interval == min_interval && |
| 97 | anotherMode.preferred_accuracy == preferred_accuracy && |
| 98 | anotherMode.preferred_time == preferred_time && |
| 99 | anotherMode.powerMode == powerMode && |
| 100 | anotherMode.timeBetweenMeasurements == timeBetweenMeasurements && |
| 101 | !strncmp(anotherMode.credentials, credentials, sizeof(credentials)-1) && |
| 102 | !strncmp(anotherMode.provider, provider, sizeof(provider)-1); |
| 103 | } |
| 104 | |
| 105 | void logv() const; |
| 106 | }; |
| 107 | |
| 108 | |
| 109 | #ifdef __cplusplus |
| 110 | } |
| 111 | #endif /* __cplusplus */ |
| 112 | |
| 113 | #endif /* GPS_EXTENDED_H */ |
| 114 | |