ST / X_NUCLEO_GNSS1A1

Dependents:   TeseoLocation

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Teseo.h Source File

Teseo.h

Go to the documentation of this file.
00001 /**
00002 *******************************************************************************
00003 * @file    Teseo.h
00004 * @author  AST / Central Lab
00005 * @version V1.0.0
00006 * @date    May-2017
00007 * @brief   Teseo Location Class
00008 *
00009 *******************************************************************************
00010 * @attention
00011 *
00012 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00013 *
00014 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00015 * You may not use this file except in compliance with the License.
00016 * You may obtain a copy of the License at:
00017 *
00018 *        http://www.st.com/software_license_agreement_liberty_v2
00019 *
00020 * Redistribution and use in source and binary forms, with or without modification,
00021 * are permitted provided that the following conditions are met:
00022 *   1. Redistributions of source code must retain the above copyright notice,
00023 *      this list of conditions and the following disclaimer.
00024 *   2. Redistributions in binary form must reproduce the above copyright notice,
00025 *      this list of conditions and the following disclaimer in the documentation
00026 *      and/or other materials provided with the distribution.
00027 *   3. Neither the name of STMicroelectronics nor the names of its contributors
00028 *      may be used to endorse or promote products derived from this software
00029 *      without specific prior written permission.
00030 *
00031 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00032 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00033 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00034 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00035 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00036 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00037 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00038 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00039 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00040 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00041 *
00042 ********************************************************************************
00043 */
00044 
00045 #ifndef __TESEO_H__
00046 #define __TESEO_H__
00047 
00048 #include "mbed.h"
00049 #include "GPSProviderImplBase.h"
00050 
00051 #include "TeseoConfig.h"
00052 #include "NMEAParser.h"
00053 
00054 #define STD_UART_BAUD               9600//    9600
00055 #define FWU_UART_BAUD               115200
00056 #define TESEO_I2C_ADDRESS           0x3A
00057 #define POWERON_STABLE_SIGNAL_DELAY_MS  150
00058 
00059 /** Indicates the outputted location information */
00060 #define LOC_OUTPUT_LOCATION             (1)
00061 #define LOC_OUTPUT_NMEA                 (2)
00062 #define LOC_OUTPUT_PSTM                 (3)
00063 
00064 /**
00065  * @brief Constant that indicates the maximum number of nmea messages to be processed.
00066  */
00067 #define NMEA_MSGS_NUM 6 //Note: update this constant coherently to eMsg enum type
00068 
00069 /**
00070  * @brief Constant that indicates the maximum number of proprietary nmea messages to be processed.
00071  */
00072 #define PSTM_NMEA_MSGS_NUM 5 //Note: update this constant coherently to ePSTMsg enum type
00073 
00074 /**
00075  * @brief Constant that indicates the maximum number of positions that can be stored.
00076  */
00077 #define MAX_STOR_POS 64
00078    
00079 /**
00080  * @brief Constant that indicates the lenght of the buffer that stores the GPS data read by the GPS expansion.
00081  */
00082 
00083 #define TESEO_RXBUF_LEN     256//90
00084 #define TESEO_RXQUEUE_LEN   8
00085 
00086 /**
00087  * @brief Enumeration structure that containes the two success states of a process
00088  */
00089 typedef enum {
00090   TESEO_STATUS_SUCCESS = 0, /**< Success status */
00091   TESEO_STATUS_FAILURE = 1  /**< Failure status */
00092 } eStatus;
00093 
00094 /** Location event definitions */
00095 typedef enum {
00096     /** Start result event */
00097     TESEO_LOC_EVENT_START_RESULT,
00098     /** Stop result event */
00099     TESEO_LOC_EVENT_STOP_RESULT,
00100 } eTeseoLocEventType;
00101 
00102 /** Teseo Location state */
00103 typedef enum {
00104     TESEO_LOC_STATE_IDLE,
00105     TESEO_LOC_STATE_RUN,
00106     TESEO_LOC_STATE_FEATURE,
00107     TESEO_LOC_STATE_DEBUG
00108 } eTeseoLocState;
00109 
00110 /**
00111  * @brief Enumeration structure that containes the two states of a debug process
00112  */
00113 typedef enum {
00114   DEBUG_OFF = 0, /**< In this case, nothing will be printed on the console (nmea strings, positions and so on) */
00115   DEBUG_ON = 1   /**< In this case, nmea strings and just acquired positions will be printed on the console */
00116 } eDebugState;
00117 
00118 /**
00119  * @brief Data structure that contains the driver informations
00120  */
00121 typedef struct TeseoData {
00122   eDebugState debug;      /**< Debug status */
00123   GPGGA_Infos gpgga_data; /**< $GPGGA Data holder */
00124   GNS_Infos   gns_data;   /**< $--GNS Data holder */
00125   GPGST_Infos gpgst_data; /**< $GPGST Data holder */
00126   GPRMC_Infos gprmc_data; /**< $GPRMC Data holder */
00127   GSA_Infos   gsa_data;   /**< $--GSA Data holder */
00128   GSV_Infos   gsv_data;   /**< $--GSV Data holder */
00129   
00130   Geofence_Infos geofence_data; /**< Geofence Data holder */
00131   Odometer_Infos odo_data;      /**< Odometer Data holder */
00132   Datalog_Infos datalog_data;   /**< Datalog Data holder */
00133   
00134   Ack_Info ack;                 /**<  */
00135 
00136 } tTeseoData;
00137 
00138 /** Application register this out callback function and Teseo class will pass outputted information to application */
00139 typedef void (*teseo_app_output_callback)(uint32_t msgId, uint32_t msgType, tTeseoData *pData);
00140 /** Application register this event callback function and Teseo class will pass internal processing event to application */
00141 typedef void (*teseo_app_event_callback)(eTeseoLocEventType event, uint32_t data);
00142 
00143 class Teseo : public GPSProviderImplBase {
00144 public:
00145 
00146   typedef enum {
00147     TEST,
00148     GETSWVER,
00149     FORCESTANDBY,
00150     RFTESTON,
00151     RFTESTOFF,
00152     LOWPOWER,
00153     FWUPDATE
00154   } eCmd;
00155 
00156   /** NMEA messages types */
00157   typedef enum {
00158     GPGGA,
00159     GNS,
00160     GPGST,
00161     GPRMC,
00162     GSA,
00163     GSV,
00164   } eMsg;
00165   
00166   /** NMEA proprietary messages types */
00167   typedef enum {
00168     PSTMGEOFENCE,
00169     PSTMODO,
00170     PSTMDATALOG,
00171     PSTMSGL,
00172     PSTMSAVEPAR
00173   } ePSTMsg;
00174 
00175 private:
00176 
00177   eTeseoLocState _locState;
00178     
00179   DigitalOut    _loc_led2;
00180   DigitalOut    _reset;
00181   DigitalOut    _pps;
00182   DigitalOut    _wakeup;
00183   PinName       _uartRx;
00184   PinName       _uartTx;
00185   
00186   BufferedSerial *_uart;
00187   I2C           *_i2c;
00188         
00189   tTeseoData pData;
00190   GPGGA_Infos stored_positions[MAX_STOR_POS];
00191 
00192   int FwWaitAck();
00193 
00194   Thread *serialStreamThread;
00195 
00196   /**
00197    * Command string
00198    */
00199   char _teseoCmd[TESEO_RXBUF_LEN];
00200 
00201   /**
00202    * Message struct
00203    */
00204   struct _teseoMsg {
00205     uint8_t len;
00206     uint8_t buf[TESEO_RXBUF_LEN];
00207   };
00208   
00209 public:
00210   
00211   /** Constructor: Teseo
00212    * Create the Teseo, accept specified configuration
00213    *
00214    * @param [in] resetPin
00215    *             GPIO pin to control location chip reset.
00216    * @param [in] wakeupPin
00217    *             GPIO pin to detect if the chip is still wakeup.
00218    * @param [in] ppsPin
00219    *             GPIO pin... .
00220    * @param [in] uartTxPin
00221    *             GPIO pin for serial Tx channel between the host and the GNSS controller.
00222    * @param [in] uartRxPin
00223    *             GPIO pin for serial Rx channel between the host and the GNSS controller.
00224    */
00225   Teseo(PinName resetPin,
00226         PinName wakeupPin,
00227         PinName ppsPin,
00228         PinName uartTxPin,
00229         PinName uartRxPin);
00230 
00231   /** Constructor: Teseo
00232    * Create the Teseo, accept specified configuration
00233    *
00234    * @param [in] resetPin
00235    *             GPIO pin to control location chip reset.
00236    * @param [in] wakeupPin
00237    *             GPIO pin to detect if the chip is still wakeup.
00238    * @param [in] ppsPin
00239    *             GPIO pin... .
00240    * @param [in] uartTxPin
00241    *             GPIO pin for serial Tx channel between the host and the GNSS controller.
00242    * @param [in] uartRxPin
00243    *             GPIO pin for serial Rx channel between the host and the GNSS controller.
00244    * @param [in] i2cBus
00245    *             I2C Bus not supported yet.
00246    */
00247   Teseo(PinName resetPin,
00248         PinName wakeupPin,
00249         PinName ppsPin,
00250         PinName uartTxPin,
00251         PinName uartRxPin,
00252         I2C    *i2cBus);
00253   
00254   /** Register output callback and event callback functions
00255    * @param app_output_cb Teseo class output the location and satellite information to application
00256    * @param app_event_cb Teseo class output the start and stop result to application
00257    */
00258   void TeseoLocRegOutput(teseo_app_output_callback app_output_cb, teseo_app_event_callback app_event_cb);
00259   
00260   void SendCommand(Teseo::eCmd c);
00261   void SendCommand(char *cmd);
00262   
00263   int EnableLowPower();
00264   
00265   void ReadSentence(Teseo::eMsg msg);
00266     
00267   eStatus WakeStatus(void){
00268     return _wakeup.read() ? TESEO_STATUS_SUCCESS : TESEO_STATUS_FAILURE;
00269   }
00270      
00271   void ReadProcess(void);
00272 
00273 private:
00274   
00275   virtual bool setPowerMode(GPSProvider::PowerMode_t pwrMode);
00276   virtual void start(void);
00277   virtual void stop(void);
00278   virtual void process(void);
00279   virtual void reset(void);
00280   virtual const GPSProvider::LocationUpdateParams_t *getLastLocation(void) const;
00281 
00282   gps_provider_error_t cfgMessageList(int level);
00283   gps_provider_error_t saveConfigParams(void);
00284   
00285   /** Set NMEA stream verbosity */
00286   virtual void setVerboseMode(int level);
00287 
00288   /** Geofencing */
00289   virtual bool isGeofencingSupported(void);
00290   virtual gps_provider_error_t enableGeofence(void);
00291   virtual gps_provider_error_t configGeofences(GPSGeofence *geofences[], unsigned geofenceCount);
00292   virtual gps_provider_error_t geofenceReq(void);
00293   gps_provider_error_t cfgGeofenceCircle(void);
00294 
00295   /** Datalogging */
00296   virtual bool isDataloggingSupported(void);
00297   virtual gps_provider_error_t enableDatalog(void);
00298   virtual gps_provider_error_t configDatalog(GPSDatalog *datalog);
00299   virtual gps_provider_error_t startDatalog(void);
00300   virtual gps_provider_error_t stopDatalog(void);
00301   virtual gps_provider_error_t eraseDatalog(void);
00302   virtual gps_provider_error_t logReqStatus(void);
00303   virtual gps_provider_error_t logReqQuery(GPSProvider::LogQueryParams_t &logReqQuery);
00304   
00305   /* Odometer */
00306   virtual bool isOdometerSupported(void);
00307   virtual gps_provider_error_t enableOdo(void);
00308   virtual gps_provider_error_t startOdo(unsigned alarmDistance);
00309   virtual gps_provider_error_t stopOdo(void);
00310   virtual gps_provider_error_t resetOdo(void);
00311 
00312   void _InitUART(int br = STD_UART_BAUD);
00313   void _ResetFast(void);
00314   void _Reset(void);
00315   void _SendString(char *buf, int len);
00316   int _WakeUp();
00317   int _CRC(char *buf, int size);
00318 
00319   /**
00320    * @brief  This function gets a chunck of NMEA messages
00321    * @param  msg NMEA message to search for
00322    * @retval eStatus TESEO_STATUS_SUCCESS if the parse process goes ok, TESEO_FAILURE if it doesn't
00323    */
00324   eStatus _GetMsg(Teseo::eMsg msg, uint8_t *buffer);
00325   /**
00326    * @brief  This function gets a chunck of PSTM NMEA messages
00327    * @param  msg PSTM NMEA message to search for
00328    * @retval eStatus TESEO_STATUS_SUCCESS if the parse process goes ok, TESEO_FAILURE if it doesn't
00329    */
00330   void _GetPSTMsg(Teseo::ePSTMsg msg, uint8_t *buffer);
00331   void _GetLocationMsg(Teseo::eMsg msg, uint8_t *buffer);
00332   
00333   void _LocLed2Set(void){
00334     _loc_led2.write(1);
00335   }
00336   void _LocLed2Reset(void){
00337     _loc_led2.write(0);
00338   }
00339   
00340   void outputHandler(uint32_t msgId, uint32_t msgType, tTeseoData *pData);
00341   void eventHandler(eTeseoLocEventType event, uint32_t data);
00342   
00343   teseo_app_output_callback appOutCb;
00344   teseo_app_event_callback appEventCb;
00345   
00346   MemoryPool<struct _teseoMsg, TESEO_RXQUEUE_LEN> mpool;
00347   Queue<struct _teseoMsg, TESEO_RXQUEUE_LEN> queue;
00348 };
00349 
00350 #endif /*__TESEO_H__*/