Csr location class shows location and satellite information, which supports H13467 + ST F103RB/NXP LCP1549 boards now.
Dependents: CsrLocationDemo CsrLocationDemo
Fork of CsrLocation by
CsrLocation.h@9:e6f22b1a7797, 2014-08-11 (annotated)
- Committer:
- zhjcpi
- Date:
- Mon Aug 11 03:45:07 2014 +0000
- Revision:
- 9:e6f22b1a7797
- Parent:
- 8:fa29f8455134
- Child:
- 10:4c7c2901d7b0
Add wakeup pin definition in LCP1768 project.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zhjcpi | 0:aba381fc8158 | 1 | |
zhjcpi | 0:aba381fc8158 | 2 | /* CsrLocation class for mbed Microcontroller |
zhjcpi | 0:aba381fc8158 | 3 | * Copyright 2014 CSR plc |
zhjcpi | 0:aba381fc8158 | 4 | */ |
zhjcpi | 0:aba381fc8158 | 5 | |
zhjcpi | 0:aba381fc8158 | 6 | |
zhjcpi | 0:aba381fc8158 | 7 | #ifndef CSRLOCATION_H |
zhjcpi | 0:aba381fc8158 | 8 | #define CSRLOCATION_H |
zhjcpi | 0:aba381fc8158 | 9 | |
zhjcpi | 0:aba381fc8158 | 10 | |
zhjcpi | 0:aba381fc8158 | 11 | #define CSR_LOC_SDK_VER "CSR-LOC-SDK-0.5" |
zhjcpi | 0:aba381fc8158 | 12 | |
zhjcpi | 2:d4fe184925f2 | 13 | typedef uint16_t CsrResult; |
zhjcpi | 0:aba381fc8158 | 14 | #define CSR_RESULT_SUCCESS ((CsrResult) 0x0000) |
zhjcpi | 0:aba381fc8158 | 15 | #define CSR_RESULT_FAILURE ((CsrResult) 0xFFFF) |
zhjcpi | 0:aba381fc8158 | 16 | |
zhjcpi | 3:71690f7bb480 | 17 | #ifdef TARGET_LPC1768 |
zhjcpi | 3:71690f7bb480 | 18 | #define PINMAP_UART_DEBUG_TX USBTX |
zhjcpi | 3:71690f7bb480 | 19 | #define PINMAP_UART_DEBUG_RX USBRX |
zhjcpi | 3:71690f7bb480 | 20 | #define PINMAP_UART_LOC_TX D8 |
zhjcpi | 3:71690f7bb480 | 21 | #define PINMAP_UART_LOC_RX D9 |
zhjcpi | 3:71690f7bb480 | 22 | #define PINMAP_GPIO_LOC_ONOFF D11 |
zhjcpi | 3:71690f7bb480 | 23 | #define PINMAP_GPIO_LOC_RESET D12 |
zhjcpi | 9:e6f22b1a7797 | 24 | #define PINMAP_GPIO_LOC_WAKEUP D3 |
zhjcpi | 7:1fde78f27d5b | 25 | #define PINMAP_GPIO_BTN D6 |
zhjcpi | 7:1fde78f27d5b | 26 | #define PINMAP_GPIO_TEST D10 |
zhjcpi | 3:71690f7bb480 | 27 | #define LOC_LED1 LED1 |
zhjcpi | 3:71690f7bb480 | 28 | #define LOC_LED2 LED2 |
zhjcpi | 3:71690f7bb480 | 29 | #define DBG_SERIAL_TYPE RawSerial |
zhjcpi | 3:71690f7bb480 | 30 | #define LOC_SERIAL_TYPE RawSerial |
zhjcpi | 3:71690f7bb480 | 31 | #elif defined(TARGET_LPC1549) || defined(TARGET_NUCLEO_F103RB) |
zhjcpi | 3:71690f7bb480 | 32 | #define PINMAP_UART_DEBUG_TX D1 |
zhjcpi | 3:71690f7bb480 | 33 | #define PINMAP_UART_DEBUG_RX D0 |
zhjcpi | 3:71690f7bb480 | 34 | #define PINMAP_UART_LOC_TX D8 |
zhjcpi | 3:71690f7bb480 | 35 | #define PINMAP_UART_LOC_RX D2 |
zhjcpi | 5:219dfc2905dc | 36 | #define PINMAP_GPIO_LOC_ONOFF D9 |
zhjcpi | 9:e6f22b1a7797 | 37 | #define PINMAP_GPIO_LOC_RESET D4 |
zhjcpi | 5:219dfc2905dc | 38 | #define PINMAP_GPIO_LOC_WAKEUP D3 |
zhjcpi | 7:1fde78f27d5b | 39 | #define PINMAP_GPIO_BTN D6 |
zhjcpi | 7:1fde78f27d5b | 40 | #define PINMAP_GPIO_TEST D10 |
zhjcpi | 6:aed3c66b39d9 | 41 | #define LOC_LED1 D7 |
zhjcpi | 6:aed3c66b39d9 | 42 | #define LOC_LED2 D5 |
zhjcpi | 3:71690f7bb480 | 43 | #define DBG_SERIAL_TYPE Serial |
zhjcpi | 3:71690f7bb480 | 44 | #define LOC_SERIAL_TYPE RawSerial |
zhjcpi | 3:71690f7bb480 | 45 | #endif |
zhjcpi | 3:71690f7bb480 | 46 | |
zhjcpi | 3:71690f7bb480 | 47 | |
zhjcpi | 0:aba381fc8158 | 48 | /* OSP protocol related definitions */ |
zhjcpi | 0:aba381fc8158 | 49 | #define MAX_VERSION_LENGTH 80 |
zhjcpi | 0:aba381fc8158 | 50 | |
zhjcpi | 0:aba381fc8158 | 51 | /* OSP message header */ |
zhjcpi | 0:aba381fc8158 | 52 | #define OSP_MSG_HEAD0 (0xA0) |
zhjcpi | 0:aba381fc8158 | 53 | #define OSP_MSG_HEAD1 (0xA2) |
zhjcpi | 0:aba381fc8158 | 54 | /* OSP message footer */ |
zhjcpi | 0:aba381fc8158 | 55 | #define OSP_MSG_TAIL0 (0xB0) |
zhjcpi | 0:aba381fc8158 | 56 | #define OSP_MSG_TAIL1 (0xB3) |
zhjcpi | 0:aba381fc8158 | 57 | |
zhjcpi | 0:aba381fc8158 | 58 | /* NMEA message header */ |
zhjcpi | 0:aba381fc8158 | 59 | #define NMEA_MSG_HEAD0 ('$') |
zhjcpi | 0:aba381fc8158 | 60 | #define NMEA_MSG_HEAD1 ('G') |
zhjcpi | 0:aba381fc8158 | 61 | /* NMEA message footer */ |
zhjcpi | 0:aba381fc8158 | 62 | #define NMEA_MSG_TAIL0 ('*') |
zhjcpi | 0:aba381fc8158 | 63 | |
zhjcpi | 2:d4fe184925f2 | 64 | #define CSR_SWAPIN16(bytestream) (((uint16_t)*((bytestream)+0) << 8) | ((uint16_t)*((bytestream)+1))) |
zhjcpi | 0:aba381fc8158 | 65 | |
zhjcpi | 0:aba381fc8158 | 66 | #define CSR_SWAPIN32(bytestream)\ |
zhjcpi | 2:d4fe184925f2 | 67 | ( ((uint32_t)*((bytestream)+0) << 24)\ |
zhjcpi | 2:d4fe184925f2 | 68 | | ((uint32_t)*((bytestream)+1) << 16)\ |
zhjcpi | 2:d4fe184925f2 | 69 | | ((uint32_t)*((bytestream)+2) << 8)\ |
zhjcpi | 2:d4fe184925f2 | 70 | | ((uint32_t)*((bytestream)+3) )) |
zhjcpi | 0:aba381fc8158 | 71 | |
zhjcpi | 0:aba381fc8158 | 72 | |
zhjcpi | 0:aba381fc8158 | 73 | /* import macros for little endian: */ |
zhjcpi | 0:aba381fc8158 | 74 | /* NOTE: must use {} around these macros when calling in a loop */ |
zhjcpi | 0:aba381fc8158 | 75 | #define BINARY_IMPORT_UINT8(bytestream) ( *((bytestream)++)) |
zhjcpi | 2:d4fe184925f2 | 76 | #define BINARY_IMPORT_UINT16(bytestream) ((uint16_t) CSR_SWAPIN16((bytestream))); bytestream+=2 |
zhjcpi | 2:d4fe184925f2 | 77 | #define BINARY_IMPORT_UINT32(bytestream) ((uint32_t) CSR_SWAPIN32((bytestream))); bytestream+=4 |
zhjcpi | 2:d4fe184925f2 | 78 | #define BINARY_IMPORT_SINT32(bytestream) ((int32_t) CSR_SWAPIN32((bytestream))); bytestream+=4 |
zhjcpi | 0:aba381fc8158 | 79 | |
zhjcpi | 0:aba381fc8158 | 80 | |
zhjcpi | 0:aba381fc8158 | 81 | #define OSP_MAKE_MSG_ID(mid, sid) ((((mid) & 0xFF) << 8) | ((sid) & 0xFF)) |
zhjcpi | 0:aba381fc8158 | 82 | |
zhjcpi | 0:aba381fc8158 | 83 | #define OSP_MSG_SW_VERSION OSP_MAKE_MSG_ID(0x06, 0x0) |
zhjcpi | 0:aba381fc8158 | 84 | #define OSP_MSG_OK_TO_SEND OSP_MAKE_MSG_ID(0x12, 0x0) |
zhjcpi | 0:aba381fc8158 | 85 | #define OSP_MSG_GEODETIC_NAVIGATION OSP_MAKE_MSG_ID(0x29, 0x0) |
zhjcpi | 0:aba381fc8158 | 86 | #define OSP_MSG_MULTI_CONSTELLATION OSP_MAKE_MSG_ID(0x43, 0x0) |
zhjcpi | 0:aba381fc8158 | 87 | #define OSP_MSG_GNSS_NAV_DATA OSP_MAKE_MSG_ID(0x43, 0x01) |
zhjcpi | 0:aba381fc8158 | 88 | #define OSP_MSG_GNSS_SAT_DATA OSP_MAKE_MSG_ID(0x43, 0x10) |
zhjcpi | 0:aba381fc8158 | 89 | #define OSP_MSG_HW_CONFIG_REQ OSP_MAKE_MSG_ID(0x47, 0x0) |
zhjcpi | 0:aba381fc8158 | 90 | #define OSP_MSG_PWR_MODE_RSP OSP_MAKE_MSG_ID(0x5A, 0x0) |
zhjcpi | 0:aba381fc8158 | 91 | #define OSP_MSG_PWR_MODE_FPM_RSP OSP_MAKE_MSG_ID(0x5A, 0x0) |
zhjcpi | 0:aba381fc8158 | 92 | #define OSP_MSG_PWR_MODE_LPM_RSP OSP_MAKE_MSG_ID(0x5A, 0x6) |
zhjcpi | 0:aba381fc8158 | 93 | |
zhjcpi | 0:aba381fc8158 | 94 | |
zhjcpi | 0:aba381fc8158 | 95 | #define GNSS_SAT_DATA_NUM_OF_SATS (15) |
zhjcpi | 0:aba381fc8158 | 96 | #define CODEC_GLO_MAX_CHANNELS (14) |
zhjcpi | 0:aba381fc8158 | 97 | /* The end of OSP protocol definitions */ |
zhjcpi | 0:aba381fc8158 | 98 | |
zhjcpi | 0:aba381fc8158 | 99 | |
zhjcpi | 0:aba381fc8158 | 100 | #define LOC_MAX_GNSS_SVS (32) |
zhjcpi | 0:aba381fc8158 | 101 | #define LOC_GLO_FREQ_OFFSET (77) |
zhjcpi | 0:aba381fc8158 | 102 | #define LOC_GLO_FREQ_ID_START (70) |
zhjcpi | 0:aba381fc8158 | 103 | #define LOC_GLO_FREQ_ID_END (83) |
zhjcpi | 0:aba381fc8158 | 104 | #define LOC_NUM_OF_GLO_FREQ_CHANNELS (1+LOC_GLO_FREQ_ID_END-LOC_GLO_FREQ_ID_START) |
zhjcpi | 0:aba381fc8158 | 105 | |
zhjcpi | 0:aba381fc8158 | 106 | #define MAX_PORT_NUM_STRING_LENGTH (16) |
zhjcpi | 0:aba381fc8158 | 107 | #define MAX_SERIAL_BUF_LEN (2048) |
zhjcpi | 0:aba381fc8158 | 108 | #define MAX_SERIAL_PKT_LEN (512) |
zhjcpi | 0:aba381fc8158 | 109 | |
zhjcpi | 0:aba381fc8158 | 110 | #define BAUDRATE_NMEA 4800 |
zhjcpi | 0:aba381fc8158 | 111 | #define BAUDRATE_OSP 115200 |
zhjcpi | 0:aba381fc8158 | 112 | |
zhjcpi | 0:aba381fc8158 | 113 | #define PROTO_CHECK_TIMEOUT (2.0) |
zhjcpi | 0:aba381fc8158 | 114 | |
zhjcpi | 0:aba381fc8158 | 115 | /** Indicates the outputted location information */ |
zhjcpi | 0:aba381fc8158 | 116 | #define LOC_OUTPUT_LOCATION (1) |
zhjcpi | 0:aba381fc8158 | 117 | /* Indicates the outputted sv status information */ |
zhjcpi | 0:aba381fc8158 | 118 | #define LOC_OUTPUT_SV_STATUS (2) |
zhjcpi | 0:aba381fc8158 | 119 | |
zhjcpi | 3:71690f7bb480 | 120 | #if 0 |
zhjcpi | 3:71690f7bb480 | 121 | #define CSR_LOG_INFO printf |
zhjcpi | 3:71690f7bb480 | 122 | #else |
zhjcpi | 0:aba381fc8158 | 123 | #define CSR_LOG_INFO(...) \ |
zhjcpi | 0:aba381fc8158 | 124 | {\ |
zhjcpi | 0:aba381fc8158 | 125 | if(csrLocInst.pSerialDebug != NULL)\ |
zhjcpi | 0:aba381fc8158 | 126 | {\ |
zhjcpi | 0:aba381fc8158 | 127 | (csrLocInst.pSerialDebug->printf(__VA_ARGS__));\ |
zhjcpi | 0:aba381fc8158 | 128 | }\ |
zhjcpi | 0:aba381fc8158 | 129 | } |
zhjcpi | 3:71690f7bb480 | 130 | #endif |
zhjcpi | 0:aba381fc8158 | 131 | |
zhjcpi | 0:aba381fc8158 | 132 | /** Location enent definitions */ |
zhjcpi | 0:aba381fc8158 | 133 | typedef enum |
zhjcpi | 0:aba381fc8158 | 134 | { |
zhjcpi | 0:aba381fc8158 | 135 | /** Start result event */ |
zhjcpi | 0:aba381fc8158 | 136 | CSR_LOC_EVENT_START_RESULT, |
zhjcpi | 0:aba381fc8158 | 137 | /** Stop result event */ |
zhjcpi | 0:aba381fc8158 | 138 | CSR_LOC_EVENT_STOP_RESULT, |
zhjcpi | 0:aba381fc8158 | 139 | }eCsrLocEventType; |
zhjcpi | 0:aba381fc8158 | 140 | |
zhjcpi | 0:aba381fc8158 | 141 | /** Power mode selection */ |
zhjcpi | 0:aba381fc8158 | 142 | typedef enum |
zhjcpi | 0:aba381fc8158 | 143 | { |
zhjcpi | 0:aba381fc8158 | 144 | /** full power mode */ |
zhjcpi | 0:aba381fc8158 | 145 | PWR_FULL, |
zhjcpi | 0:aba381fc8158 | 146 | /** Low power push to fix mode */ |
zhjcpi | 0:aba381fc8158 | 147 | PWR_PTF, |
zhjcpi | 0:aba381fc8158 | 148 | }ePowerMode; |
zhjcpi | 0:aba381fc8158 | 149 | |
zhjcpi | 3:71690f7bb480 | 150 | /** Power mode selection */ |
zhjcpi | 3:71690f7bb480 | 151 | typedef enum |
zhjcpi | 3:71690f7bb480 | 152 | { |
zhjcpi | 3:71690f7bb480 | 153 | /** NMEA protocol */ |
zhjcpi | 3:71690f7bb480 | 154 | PROTO_NMEA, |
zhjcpi | 3:71690f7bb480 | 155 | /** OSP protocol */ |
zhjcpi | 3:71690f7bb480 | 156 | PROTO_OSP, |
zhjcpi | 3:71690f7bb480 | 157 | }eProto; |
zhjcpi | 3:71690f7bb480 | 158 | |
zhjcpi | 0:aba381fc8158 | 159 | /* Protocol detection state */ |
zhjcpi | 0:aba381fc8158 | 160 | typedef enum |
zhjcpi | 0:aba381fc8158 | 161 | { |
zhjcpi | 0:aba381fc8158 | 162 | STATE_START1, /* Indicates the first byte of the OSP or NMEA message header*/ |
zhjcpi | 0:aba381fc8158 | 163 | STATE_START2, /* Indicates the second byte of the OSP or NMEA message header */ |
zhjcpi | 0:aba381fc8158 | 164 | STATE_SIZE1, /* Indicates the first byte of the OSP message length */ |
zhjcpi | 0:aba381fc8158 | 165 | STATE_SIZE2, /* Indicates the second byte of the OSP message length */ |
zhjcpi | 0:aba381fc8158 | 166 | STATE_PAYLOAD, /* Indicates the start of payload of the OSP message */ |
zhjcpi | 0:aba381fc8158 | 167 | STATE_CHECKSUM1, /* Indicates the first byte of the OSP message checksum */ |
zhjcpi | 0:aba381fc8158 | 168 | STATE_CHECKSUM2, /* Indicates the second byte of the OSP message checksum */ |
zhjcpi | 0:aba381fc8158 | 169 | STATE_END1, /* Indicates the first byte of the OSP or NMEA message footer */ |
zhjcpi | 0:aba381fc8158 | 170 | STATE_END2 /* Indicates the second byte of the OSP message footer */ |
zhjcpi | 0:aba381fc8158 | 171 | }eProtoDetState; |
zhjcpi | 0:aba381fc8158 | 172 | |
zhjcpi | 0:aba381fc8158 | 173 | /* Csr Location state */ |
zhjcpi | 0:aba381fc8158 | 174 | typedef enum |
zhjcpi | 0:aba381fc8158 | 175 | { |
zhjcpi | 0:aba381fc8158 | 176 | CSR_LOC_STATE_IDLE, |
zhjcpi | 0:aba381fc8158 | 177 | CSR_LOC_STATE_RUN, |
zhjcpi | 0:aba381fc8158 | 178 | }eCsrLocState; |
zhjcpi | 0:aba381fc8158 | 179 | |
zhjcpi | 0:aba381fc8158 | 180 | /* Locatin chip protocol detection state */ |
zhjcpi | 0:aba381fc8158 | 181 | typedef enum |
zhjcpi | 0:aba381fc8158 | 182 | { |
zhjcpi | 0:aba381fc8158 | 183 | PROTO_STATE_DET_INVALID = 0, |
zhjcpi | 0:aba381fc8158 | 184 | PROTO_STATE_DET_OSP, |
zhjcpi | 0:aba381fc8158 | 185 | PROTO_STATE_DET_NMEA, |
zhjcpi | 3:71690f7bb480 | 186 | // PROTO_STATE_SWI_OSP_FROM_NMEA, |
zhjcpi | 0:aba381fc8158 | 187 | PROTO_STATE_DET_OSP_FROM_NMEA, |
zhjcpi | 3:71690f7bb480 | 188 | // PROTO_STATE_SWI_NMEA_FROM_OSP, |
zhjcpi | 3:71690f7bb480 | 189 | PROTO_STATE_DET_NMEA_FROM_OSP, |
zhjcpi | 0:aba381fc8158 | 190 | PROTO_STATE_DET_OK, |
zhjcpi | 0:aba381fc8158 | 191 | }eProtoState; |
zhjcpi | 0:aba381fc8158 | 192 | |
zhjcpi | 0:aba381fc8158 | 193 | /* Locaiton chip status */ |
zhjcpi | 0:aba381fc8158 | 194 | typedef enum |
zhjcpi | 0:aba381fc8158 | 195 | { |
zhjcpi | 0:aba381fc8158 | 196 | /* Location chip is going to hibernation mode and cannot accept message any more */ |
zhjcpi | 0:aba381fc8158 | 197 | ENGINE_STATUS_NOTOK2SEND, |
zhjcpi | 0:aba381fc8158 | 198 | /* Locaitn come back from hibernation mode and can accept message now */ |
zhjcpi | 0:aba381fc8158 | 199 | ENGINE_STATUS_OK2SEND |
zhjcpi | 0:aba381fc8158 | 200 | }eEngineStatus; |
zhjcpi | 0:aba381fc8158 | 201 | |
zhjcpi | 0:aba381fc8158 | 202 | /* OSP data type to be sent to location chip */ |
zhjcpi | 0:aba381fc8158 | 203 | typedef enum |
zhjcpi | 0:aba381fc8158 | 204 | { |
zhjcpi | 0:aba381fc8158 | 205 | SEND_DATA_TYPE_OSP_STOP_REQ, |
zhjcpi | 0:aba381fc8158 | 206 | SEND_DATA_TYPE_OSP_VER_REQ, |
zhjcpi | 0:aba381fc8158 | 207 | SEND_DATA_TYPE_OSP_LPM_REQ, |
zhjcpi | 0:aba381fc8158 | 208 | SEND_DATA_TYPE_OSP_FPM_REQ, |
zhjcpi | 0:aba381fc8158 | 209 | SEND_DATA_TYPE_OSP_SWITCH2NMEA_REQ, |
zhjcpi | 3:71690f7bb480 | 210 | SEND_DATA_TYPE_NMEA_SWITCH2OSP_REQ, |
zhjcpi | 3:71690f7bb480 | 211 | SEND_DATA_TYPE_NMEA_STOP_REQ |
zhjcpi | 0:aba381fc8158 | 212 | }eSendDataType; |
zhjcpi | 0:aba381fc8158 | 213 | |
zhjcpi | 3:71690f7bb480 | 214 | typedef struct GpsTime |
zhjcpi | 0:aba381fc8158 | 215 | { |
zhjcpi | 0:aba381fc8158 | 216 | /** Week part of GPS time */ |
zhjcpi | 2:d4fe184925f2 | 217 | uint16_t gps_week; |
zhjcpi | 0:aba381fc8158 | 218 | /** Time of second part of GPS time */ |
zhjcpi | 2:d4fe184925f2 | 219 | uint32_t tow; |
zhjcpi | 3:71690f7bb480 | 220 | }tGpsTime; |
zhjcpi | 3:71690f7bb480 | 221 | |
zhjcpi | 3:71690f7bb480 | 222 | /** Structure to hold Position Response Message Information. */ |
zhjcpi | 3:71690f7bb480 | 223 | typedef struct LocPosResp |
zhjcpi | 3:71690f7bb480 | 224 | { |
zhjcpi | 3:71690f7bb480 | 225 | union |
zhjcpi | 3:71690f7bb480 | 226 | { |
zhjcpi | 3:71690f7bb480 | 227 | tGpsTime gpsTime; |
zhjcpi | 3:71690f7bb480 | 228 | float utcTime; |
zhjcpi | 3:71690f7bb480 | 229 | }u; |
zhjcpi | 0:aba381fc8158 | 230 | /** Latitude */ |
zhjcpi | 2:d4fe184925f2 | 231 | double lat; |
zhjcpi | 0:aba381fc8158 | 232 | /** Longitude */ |
zhjcpi | 2:d4fe184925f2 | 233 | double lon; |
zhjcpi | 0:aba381fc8158 | 234 | /** Altitude */ |
zhjcpi | 2:d4fe184925f2 | 235 | double alt; |
zhjcpi | 0:aba381fc8158 | 236 | } tLocPosResp; |
zhjcpi | 0:aba381fc8158 | 237 | |
zhjcpi | 0:aba381fc8158 | 238 | /** Structure to hold Satellite Information. */ |
zhjcpi | 0:aba381fc8158 | 239 | typedef struct LocSvInfo |
zhjcpi | 0:aba381fc8158 | 240 | { |
zhjcpi | 0:aba381fc8158 | 241 | /** Prn or svId */ |
zhjcpi | 2:d4fe184925f2 | 242 | uint8_t prn; |
zhjcpi | 0:aba381fc8158 | 243 | /** The ratio of carrier and noise */ |
zhjcpi | 2:d4fe184925f2 | 244 | float cno; |
zhjcpi | 0:aba381fc8158 | 245 | /** elevation */ |
zhjcpi | 2:d4fe184925f2 | 246 | float elevation; |
zhjcpi | 0:aba381fc8158 | 247 | /** azimuth */ |
zhjcpi | 2:d4fe184925f2 | 248 | float azimuth; |
zhjcpi | 0:aba381fc8158 | 249 | /** satellite state */ |
zhjcpi | 2:d4fe184925f2 | 250 | uint16_t state; |
zhjcpi | 0:aba381fc8158 | 251 | } tLocSvInfo; |
zhjcpi | 0:aba381fc8158 | 252 | |
zhjcpi | 0:aba381fc8158 | 253 | /** Structure to hold Satellite Information for GLONASS */ |
zhjcpi | 0:aba381fc8158 | 254 | typedef struct LocGloSvInfo |
zhjcpi | 0:aba381fc8158 | 255 | { |
zhjcpi | 0:aba381fc8158 | 256 | /** Prn or svId */ |
zhjcpi | 2:d4fe184925f2 | 257 | uint8_t prn; |
zhjcpi | 0:aba381fc8158 | 258 | /** Slot number */ |
zhjcpi | 2:d4fe184925f2 | 259 | uint8_t sno; |
zhjcpi | 0:aba381fc8158 | 260 | /** The ratio of carrier and noise */ |
zhjcpi | 2:d4fe184925f2 | 261 | float cno; |
zhjcpi | 0:aba381fc8158 | 262 | /** elevation */ |
zhjcpi | 2:d4fe184925f2 | 263 | float elevation; |
zhjcpi | 0:aba381fc8158 | 264 | /** azimuth */ |
zhjcpi | 2:d4fe184925f2 | 265 | float azimuth; |
zhjcpi | 0:aba381fc8158 | 266 | /** satellite state */ |
zhjcpi | 2:d4fe184925f2 | 267 | uint16_t state; |
zhjcpi | 0:aba381fc8158 | 268 | } tLocGloSvInfo; |
zhjcpi | 0:aba381fc8158 | 269 | |
zhjcpi | 0:aba381fc8158 | 270 | /** Structure to hold Satellite Status Information. */ |
zhjcpi | 0:aba381fc8158 | 271 | typedef struct LocSvStatus |
zhjcpi | 0:aba381fc8158 | 272 | { |
zhjcpi | 0:aba381fc8158 | 273 | /** Week part of GPS time */ |
zhjcpi | 2:d4fe184925f2 | 274 | uint16_t gps_week; |
zhjcpi | 0:aba381fc8158 | 275 | /** Time of second part of GPS time */ |
zhjcpi | 2:d4fe184925f2 | 276 | uint32_t tow; |
zhjcpi | 0:aba381fc8158 | 277 | /** Time of millisecond part of GPS time */ |
zhjcpi | 2:d4fe184925f2 | 278 | uint32_t tow_sub_ms; |
zhjcpi | 0:aba381fc8158 | 279 | |
zhjcpi | 0:aba381fc8158 | 280 | /**Number of GPS SVs currently visible **/ |
zhjcpi | 2:d4fe184925f2 | 281 | uint8_t numOfSVs; |
zhjcpi | 0:aba381fc8158 | 282 | /**Number of GLONASS SVs currently visible **/ |
zhjcpi | 2:d4fe184925f2 | 283 | uint8_t numOfGloSVs; |
zhjcpi | 0:aba381fc8158 | 284 | /** GPS SVs information */ |
zhjcpi | 0:aba381fc8158 | 285 | tLocSvInfo svList[LOC_MAX_GNSS_SVS]; |
zhjcpi | 0:aba381fc8158 | 286 | /** GLONASS SVs information */ |
zhjcpi | 0:aba381fc8158 | 287 | tLocGloSvInfo gloSvList[LOC_NUM_OF_GLO_FREQ_CHANNELS]; |
zhjcpi | 0:aba381fc8158 | 288 | /** Bit mask indicating which SVs have ephemeris data **/ |
zhjcpi | 2:d4fe184925f2 | 289 | uint32_t ephemerisMask; |
zhjcpi | 0:aba381fc8158 | 290 | /** Bit mask indicating which GLONASS SVs have ephemeris data **/ |
zhjcpi | 2:d4fe184925f2 | 291 | uint32_t gloEphemerisMask; |
zhjcpi | 0:aba381fc8158 | 292 | /** Bit mask indicating which SVs were used in latest sent fix **/ |
zhjcpi | 2:d4fe184925f2 | 293 | uint32_t svUsedInFixMask; |
zhjcpi | 0:aba381fc8158 | 294 | /** Bit mask indicating which GLONASS SVs were used in latest sent fix **/ |
zhjcpi | 2:d4fe184925f2 | 295 | uint32_t gloSvUsedInFixMask; |
zhjcpi | 0:aba381fc8158 | 296 | /** Bit mask indicating which QZSS SVs were used in latest sent fix **/ |
zhjcpi | 2:d4fe184925f2 | 297 | uint32_t qzssSvUsedInFixMask; |
zhjcpi | 0:aba381fc8158 | 298 | /** Bit mask indicating which SBAS SVs were used in latest sent fix **/ |
zhjcpi | 2:d4fe184925f2 | 299 | uint32_t sbasSvUsedInFixMask; |
zhjcpi | 0:aba381fc8158 | 300 | } tLocSvStatus; |
zhjcpi | 0:aba381fc8158 | 301 | |
zhjcpi | 0:aba381fc8158 | 302 | |
zhjcpi | 0:aba381fc8158 | 303 | /** Applicaiton register this out callback function and CsrLocaiton class will pass outputted information to application */ |
zhjcpi | 2:d4fe184925f2 | 304 | typedef void (*csr_app_output_callback)(uint32_t msgId, void * const pMsgData, uint32_t msgLength); |
zhjcpi | 0:aba381fc8158 | 305 | |
zhjcpi | 0:aba381fc8158 | 306 | /** Applicaiton register this event callback function and CsrLocaiton class will pass internal porcessing event to application */ |
zhjcpi | 2:d4fe184925f2 | 307 | typedef void (*csr_app_event_callback)(eCsrLocEventType event, uint32_t data); |
zhjcpi | 0:aba381fc8158 | 308 | |
zhjcpi | 0:aba381fc8158 | 309 | /** tCsrLocConfig structure |
zhjcpi | 0:aba381fc8158 | 310 | * Application needs to decides and pass the configuration into CsrLocation class. |
zhjcpi | 0:aba381fc8158 | 311 | */ |
zhjcpi | 0:aba381fc8158 | 312 | typedef struct CsrLocConfig |
zhjcpi | 0:aba381fc8158 | 313 | { |
zhjcpi | 0:aba381fc8158 | 314 | /** Debug serial port to print debug information */ |
zhjcpi | 3:71690f7bb480 | 315 | DBG_SERIAL_TYPE *pSerialDebug; |
zhjcpi | 0:aba381fc8158 | 316 | /** location serail port to communicate between mbed host side and location chip */ |
zhjcpi | 3:71690f7bb480 | 317 | LOC_SERIAL_TYPE *pSerialLoc; |
zhjcpi | 0:aba381fc8158 | 318 | /** GPIO pin to control location chip on, a rising edge is uset to activate location chip. Please note, before activate chip, reset pin should be pull high */ |
zhjcpi | 0:aba381fc8158 | 319 | DigitalOut *pPinOnoff; |
zhjcpi | 0:aba381fc8158 | 320 | /** GPIO pin to control location chip reset, low level will keep location chip in hibernation state and high level will permit location chip to be activated */ |
zhjcpi | 0:aba381fc8158 | 321 | DigitalOut *pPinReset; |
zhjcpi | 8:fa29f8455134 | 322 | /** GPIO pin to detect if the chip is still wakeup */ |
zhjcpi | 8:fa29f8455134 | 323 | DigitalIn *pWakeup; |
zhjcpi | 0:aba381fc8158 | 324 | }tCsrLocConfig; |
zhjcpi | 0:aba381fc8158 | 325 | |
zhjcpi | 0:aba381fc8158 | 326 | /* General OSP mesasge format */ |
zhjcpi | 0:aba381fc8158 | 327 | typedef struct OspMsg |
zhjcpi | 0:aba381fc8158 | 328 | { |
zhjcpi | 2:d4fe184925f2 | 329 | uint32_t msgId; |
zhjcpi | 2:d4fe184925f2 | 330 | uint32_t length; |
zhjcpi | 2:d4fe184925f2 | 331 | uint8_t payload[4]; |
zhjcpi | 0:aba381fc8158 | 332 | } tOspMsg; |
zhjcpi | 0:aba381fc8158 | 333 | |
zhjcpi | 0:aba381fc8158 | 334 | /* keep the internal data of CsrLocation class */ |
zhjcpi | 0:aba381fc8158 | 335 | typedef struct CsrLocInst |
zhjcpi | 0:aba381fc8158 | 336 | { |
zhjcpi | 2:d4fe184925f2 | 337 | bool bStopFlag; |
zhjcpi | 2:d4fe184925f2 | 338 | bool bPwrModeRsp; |
zhjcpi | 2:d4fe184925f2 | 339 | bool bVerRsp; |
zhjcpi | 0:aba381fc8158 | 340 | |
zhjcpi | 3:71690f7bb480 | 341 | eProto proto; |
zhjcpi | 0:aba381fc8158 | 342 | eCsrLocState locState; |
zhjcpi | 0:aba381fc8158 | 343 | eProtoState protoState; |
zhjcpi | 0:aba381fc8158 | 344 | ePowerMode pwrMode; |
zhjcpi | 2:d4fe184925f2 | 345 | uint32_t baudRate; |
zhjcpi | 2:d4fe184925f2 | 346 | int32_t computedCheckSum; |
zhjcpi | 2:d4fe184925f2 | 347 | int32_t checksum; |
zhjcpi | 2:d4fe184925f2 | 348 | int32_t msgSize; |
zhjcpi | 2:d4fe184925f2 | 349 | int32_t decodeIndex; |
zhjcpi | 0:aba381fc8158 | 350 | eProtoDetState protoDetState; |
zhjcpi | 0:aba381fc8158 | 351 | Timeout *pTimeoutChk; /* timeout process */ |
zhjcpi | 2:d4fe184925f2 | 352 | bool bTimeoutFlag; |
zhjcpi | 0:aba381fc8158 | 353 | eEngineStatus engStatus; |
zhjcpi | 0:aba381fc8158 | 354 | |
zhjcpi | 0:aba381fc8158 | 355 | tLocSvStatus svStatus; /* 2 kind of messages contribute the svStaus */ |
zhjcpi | 0:aba381fc8158 | 356 | |
zhjcpi | 3:71690f7bb480 | 357 | DBG_SERIAL_TYPE *pSerialDebug; |
zhjcpi | 3:71690f7bb480 | 358 | LOC_SERIAL_TYPE *pSerialLoc; |
zhjcpi | 0:aba381fc8158 | 359 | DigitalOut *pPinOnoff; |
zhjcpi | 0:aba381fc8158 | 360 | DigitalOut *pPinReset; |
zhjcpi | 8:fa29f8455134 | 361 | DigitalIn *pWakeup; |
zhjcpi | 0:aba381fc8158 | 362 | |
zhjcpi | 2:d4fe184925f2 | 363 | uint8_t serialBuf[MAX_SERIAL_BUF_LEN]; /* buffer the serial data from uart callback function */ |
zhjcpi | 2:d4fe184925f2 | 364 | uint8_t serialPkt[MAX_SERIAL_PKT_LEN]; /* decoded osp data */ |
zhjcpi | 2:d4fe184925f2 | 365 | uint32_t in; |
zhjcpi | 2:d4fe184925f2 | 366 | uint32_t out; |
zhjcpi | 0:aba381fc8158 | 367 | |
zhjcpi | 0:aba381fc8158 | 368 | csr_app_output_callback appOutCb; |
zhjcpi | 0:aba381fc8158 | 369 | csr_app_event_callback appEventCb; |
zhjcpi | 0:aba381fc8158 | 370 | }tCsrLocInst; |
zhjcpi | 0:aba381fc8158 | 371 | |
zhjcpi | 0:aba381fc8158 | 372 | /** CsrLocation class. |
zhjcpi | 0:aba381fc8158 | 373 | * A location interface to control location chip and get position and satellite information. |
zhjcpi | 0:aba381fc8158 | 374 | */ |
zhjcpi | 0:aba381fc8158 | 375 | class CsrLocation |
zhjcpi | 0:aba381fc8158 | 376 | { |
zhjcpi | 0:aba381fc8158 | 377 | public: |
zhjcpi | 0:aba381fc8158 | 378 | /** Constructor: CsrLocaiton |
zhjcpi | 0:aba381fc8158 | 379 | * Create the CsrLocation, accept specified configuration |
zhjcpi | 0:aba381fc8158 | 380 | * @param pLocConfig Configuration including debug serial port, location communication serail port, onoff pin, reset pin |
zhjcpi | 0:aba381fc8158 | 381 | */ |
zhjcpi | 0:aba381fc8158 | 382 | CsrLocation(tCsrLocConfig *pLocConfig); |
zhjcpi | 0:aba381fc8158 | 383 | |
zhjcpi | 0:aba381fc8158 | 384 | /** Destructor: CsrLocation |
zhjcpi | 0:aba381fc8158 | 385 | * Free allocated resource |
zhjcpi | 0:aba381fc8158 | 386 | */ |
zhjcpi | 0:aba381fc8158 | 387 | ~CsrLocation(); |
zhjcpi | 0:aba381fc8158 | 388 | |
zhjcpi | 0:aba381fc8158 | 389 | /** Register output callback and enent callback functions |
zhjcpi | 0:aba381fc8158 | 390 | * @param app_output_cb CsrLocation class output the loaction and satellite information to application |
zhjcpi | 0:aba381fc8158 | 391 | * @param app_event_cb CsrLocation class output the start and stop result to application |
zhjcpi | 0:aba381fc8158 | 392 | */ |
zhjcpi | 0:aba381fc8158 | 393 | void CsrLocRegOutput(csr_app_output_callback app_output_cb, csr_app_event_callback app_event_cb); |
zhjcpi | 0:aba381fc8158 | 394 | |
zhjcpi | 0:aba381fc8158 | 395 | /** hw reset to get location chip into hibernation mode */ |
zhjcpi | 0:aba381fc8158 | 396 | void CsrLocReset(void); |
zhjcpi | 0:aba381fc8158 | 397 | |
zhjcpi | 0:aba381fc8158 | 398 | /** Start location request, activate location chip */ |
zhjcpi | 3:71690f7bb480 | 399 | void CsrLocStart(ePowerMode pwrMode, eProto proto); |
zhjcpi | 0:aba381fc8158 | 400 | |
zhjcpi | 0:aba381fc8158 | 401 | /** Process location data from chip and update location and satellite information */ |
zhjcpi | 0:aba381fc8158 | 402 | void CsrLocUpdate(void); |
zhjcpi | 0:aba381fc8158 | 403 | |
zhjcpi | 0:aba381fc8158 | 404 | /** Stop location request, get location chip into hibernation mode */ |
zhjcpi | 0:aba381fc8158 | 405 | void CsrLocStop(void); |
zhjcpi | 0:aba381fc8158 | 406 | |
zhjcpi | 0:aba381fc8158 | 407 | /** Speical for low power PTF mode. |
zhjcpi | 0:aba381fc8158 | 408 | * During low power PTF mode, after reporting position, chip will go to hibernation mode automatically. |
zhjcpi | 0:aba381fc8158 | 409 | * After 30 seconds, chip will recover and report position again. Then chip will go to hibernation mode again. |
zhjcpi | 0:aba381fc8158 | 410 | * During the hibernation, application can call CsrLocLpmGetPos to get position immediately and no need to wait for the whole interval. |
zhjcpi | 0:aba381fc8158 | 411 | */ |
zhjcpi | 0:aba381fc8158 | 412 | void CsrLocLpmGetPos(void); |
zhjcpi | 0:aba381fc8158 | 413 | |
zhjcpi | 0:aba381fc8158 | 414 | /* A debug interface to switch location chip protocol from OSP at 115200bps to NMEA at 4800bps */ |
zhjcpi | 0:aba381fc8158 | 415 | void CsrLocDebugSwitch2Nmea(void); |
zhjcpi | 0:aba381fc8158 | 416 | |
zhjcpi | 0:aba381fc8158 | 417 | private: |
zhjcpi | 0:aba381fc8158 | 418 | /* Internal kept data */ |
zhjcpi | 0:aba381fc8158 | 419 | tCsrLocInst csrLocInst; |
zhjcpi | 0:aba381fc8158 | 420 | |
zhjcpi | 0:aba381fc8158 | 421 | /* Initialize the serial port and open it */ |
zhjcpi | 0:aba381fc8158 | 422 | void _CsrLocUartInit(void); |
zhjcpi | 0:aba381fc8158 | 423 | |
zhjcpi | 0:aba381fc8158 | 424 | /* Process the raw stream from location seraial port */ |
zhjcpi | 0:aba381fc8158 | 425 | void _CsrLocProcessRawStream(void); |
zhjcpi | 0:aba381fc8158 | 426 | |
zhjcpi | 3:71690f7bb480 | 427 | /* Detect the OSP protocol detection timeout */ |
zhjcpi | 3:71690f7bb480 | 428 | void _CsrLocDetProtoOspTimeout(void); |
zhjcpi | 0:aba381fc8158 | 429 | |
zhjcpi | 0:aba381fc8158 | 430 | /* Detect the NMEA protocol outputted from location serial port */ |
zhjcpi | 3:71690f7bb480 | 431 | void _CsrLocDetProtoNmeaTimeout(void); |
zhjcpi | 3:71690f7bb480 | 432 | |
zhjcpi | 3:71690f7bb480 | 433 | /* Process the raw NMEA stream, remove the NMEA header, tail, and save the NMEA data into interal buffer */ |
zhjcpi | 3:71690f7bb480 | 434 | void _CsrLocProcessRawNmeaStream(uint8_t data); |
zhjcpi | 0:aba381fc8158 | 435 | |
zhjcpi | 0:aba381fc8158 | 436 | /* Process the raw OSP stream, remove the OSP header, size, check sum, and save the OSP data into interal buffer */ |
zhjcpi | 2:d4fe184925f2 | 437 | void _CsrLocProcessRawOspStream(uint8_t data); |
zhjcpi | 0:aba381fc8158 | 438 | |
zhjcpi | 3:71690f7bb480 | 439 | /* Process the saved nmea data and decode them */ |
zhjcpi | 3:71690f7bb480 | 440 | void _CsrLocProcessRawNmeaPkt(void); |
zhjcpi | 3:71690f7bb480 | 441 | |
zhjcpi | 0:aba381fc8158 | 442 | /* Process the saved OSP data and decode them */ |
zhjcpi | 0:aba381fc8158 | 443 | void _CsrLocProcessRawOspPkt(void); |
zhjcpi | 0:aba381fc8158 | 444 | |
zhjcpi | 0:aba381fc8158 | 445 | /* Calculate the OSP message size to allcate buffer to save the decoded OSP data */ |
zhjcpi | 2:d4fe184925f2 | 446 | uint32_t _CsrLocCalcMsgSize(void); |
zhjcpi | 0:aba381fc8158 | 447 | |
zhjcpi | 0:aba381fc8158 | 448 | /* Decode OSP data into pakcet data structure */ |
zhjcpi | 2:d4fe184925f2 | 449 | CsrResult _CsrLocDecodeOspPkt( uint8_t *payload, uint32_t payload_length, uint32_t *message_id, void *message_structure, uint32_t *message_length); |
zhjcpi | 0:aba381fc8158 | 450 | |
zhjcpi | 0:aba381fc8158 | 451 | /* Process the decode OSP packet and pass to application when needed */ |
zhjcpi | 0:aba381fc8158 | 452 | void _CsrLocProcessOspPkt(tOspMsg *pOspMsg); |
zhjcpi | 0:aba381fc8158 | 453 | |
zhjcpi | 0:aba381fc8158 | 454 | /* Timeout process, such as detect OSP and NMEA protocol */ |
zhjcpi | 0:aba381fc8158 | 455 | void _CsrLocTimeout(void); |
zhjcpi | 0:aba381fc8158 | 456 | |
zhjcpi | 0:aba381fc8158 | 457 | /* Location serial port data recevier */ |
zhjcpi | 0:aba381fc8158 | 458 | void _CsrLocRxHandler(void); |
zhjcpi | 0:aba381fc8158 | 459 | |
zhjcpi | 0:aba381fc8158 | 460 | /* Send special OSP messges to location chip */ |
zhjcpi | 0:aba381fc8158 | 461 | void _CsrLocSendData(eSendDataType type); |
zhjcpi | 0:aba381fc8158 | 462 | |
zhjcpi | 0:aba381fc8158 | 463 | /* Trigger a pulse on the onoff pin */ |
zhjcpi | 0:aba381fc8158 | 464 | void _CsrLocHwOnoff(void); |
zhjcpi | 0:aba381fc8158 | 465 | |
zhjcpi | 0:aba381fc8158 | 466 | /* Trigger a reset on the reset pin */ |
zhjcpi | 0:aba381fc8158 | 467 | void _CsrLocHwReset(void); |
zhjcpi | 8:fa29f8455134 | 468 | |
zhjcpi | 8:fa29f8455134 | 469 | /* Detect wakeup status on the wakeup pin */ |
zhjcpi | 8:fa29f8455134 | 470 | bool _CsrLocIsWakeup(void); |
zhjcpi | 8:fa29f8455134 | 471 | |
zhjcpi | 0:aba381fc8158 | 472 | }; |
zhjcpi | 0:aba381fc8158 | 473 | |
zhjcpi | 0:aba381fc8158 | 474 | |
zhjcpi | 0:aba381fc8158 | 475 | |
zhjcpi | 0:aba381fc8158 | 476 | #endif /* CSRLOCATION_H */ |
zhjcpi | 3:71690f7bb480 | 477 |