Csr location class shows location and satellite information, which supports H13467 + ST F103RB/NXP LCP1549 boards now.

Dependents:   CsrLocationDemo CsrLocationDemo

Fork of CsrLocation by jie zhao

Committer:
zhjcpi
Date:
Wed Mar 26 09:16:55 2014 +0000
Revision:
2:d4fe184925f2
Parent:
1:bbaf9b8d646a
Child:
3:71690f7bb480
optimization

Who changed what in which revision?

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