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