Qualcomm Technologies International, Ltd. / CsrLocation

Dependents:   CsrLocationDemo CsrLocationDemo

Fork of CsrLocation by jie zhao

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers createCSRGPS.cpp Source File

createCSRGPS.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2014 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "mbed.h"
00018 #include "CsrLocation.h"
00019 #include "GPSProviderImplBase.h"
00020 
00021 #ifdef TARGET_K64F
00022 #define PINMAP_UART_LOC_TX     D1
00023 #define PINMAP_UART_LOC_RX     D0
00024 #else
00025 #define PINMAP_UART_LOC_TX     D8
00026 #define PINMAP_UART_LOC_RX     D2
00027 #endif
00028 #define PINMAP_GPIO_LOC_ONOFF  D9
00029 #define PINMAP_GPIO_LOC_RESET  D4
00030 #define PINMAP_GPIO_LOC_WAKEUP D3
00031 #define PINMAP_GPIO_BTN        D5
00032 #define PINMAP_GPIO_TEST       D10
00033 #define LOC_LED1               D7
00034 #define LOC_LED2               D6
00035 
00036 static RawSerial  sSerialLoc(PINMAP_UART_LOC_TX, PINMAP_UART_LOC_RX);
00037 static DigitalOut sPinOnoff(PINMAP_GPIO_LOC_ONOFF);
00038 static DigitalOut sPinReset(PINMAP_GPIO_LOC_RESET);
00039 static DigitalIn  sWakeup(PINMAP_GPIO_LOC_WAKEUP);
00040 
00041 static void _AppOutputCallback(uint32_t msgId, void *const pMsgData, uint32_t msgLength);
00042 static void _AppEventCallback(eCsrLocEventType event, uint32_t data);
00043 
00044 extern Serial sSerialDebug;
00045 #define CSR_APP_LOG_INFO(...)   sSerialDebug.printf(__VA_ARGS__)
00046 
00047 GPSProviderImplBase *
00048 createGPSProviderInstance(void)
00049 {
00050     static CSRLocation csrGPS(sSerialLoc, sPinOnoff, sPinReset, sWakeup, &sSerialDebug);
00051 
00052     /* Register output callback and event callback functions */
00053     csrGPS.CsrLocRegOutput(_AppOutputCallback, _AppEventCallback);
00054 
00055     return &csrGPS;
00056 }
00057 
00058 void
00059 _AppOutputCallback(uint32_t msgId, void *const pMsgData, uint32_t msgLength)
00060 {
00061     switch (msgId) {
00062         case LOC_OUTPUT_LOCATION: {
00063             tLocPosResp *pPosRsp = (tLocPosResp *)pMsgData;
00064             CSR_APP_LOG_INFO("Loc: lat=%f, lon=%f, alt=%f, utctime=%llu, gps week=%d, gps tow=%d\r\n", pPosRsp->lat, pPosRsp->lon, pPosRsp->alt, pPosRsp->utcTime, pPosRsp->gpsTime.gps_week, pPosRsp->gpsTime.tow);
00065             break;
00066         }
00067         case LOC_OUTPUT_SV_STATUS: {
00068             tLocSvStatus *pSvStatus = (tLocSvStatus *)pMsgData;
00069             CSR_APP_LOG_INFO("SV:week=%u, tow=%lu, GPS Num=%u, GLO Num=%u, GPS Mask=0x%lx, GLO Mask=0x%lx\r\n",
00070                              pSvStatus->gps_week, pSvStatus->tow, pSvStatus->numOfSVs, pSvStatus->numOfGloSVs,
00071                              pSvStatus->svUsedInFixMask, pSvStatus->gloSvUsedInFixMask);
00072             break;
00073         }
00074         case LOC_OUTPUT_NMEA: {
00075             CSR_APP_LOG_INFO("%s\r\n", (char *)pMsgData);
00076             break;
00077         }
00078 
00079         default:
00080             break;
00081     }
00082 }
00083 
00084 void _AppEventCallback(eCsrLocEventType event, uint32_t data)
00085 {
00086     switch (event) {
00087         case CSR_LOC_EVENT_START_RESULT:
00088             if (data != 0) {
00089                 CSR_APP_LOG_INFO("start failed.\r\n");
00090                 // sAppCmd = APP_CMD_START_FAILED;
00091             } else {
00092                 CSR_APP_LOG_INFO("start OK.\r\n");
00093             }
00094             break;
00095         case CSR_LOC_EVENT_STOP_RESULT:
00096             if (data != 0) {
00097                 CSR_APP_LOG_INFO("stop failed.\r\n");
00098                 // sAppCmd = APP_CMD_STOP_FAILED;
00099             } else {
00100                 CSR_APP_LOG_INFO("stop OK.\r\n");
00101             }
00102             break;
00103         default:
00104             break;
00105     }
00106 }