]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/net/cellular/CellularModem/link/LinkMonitor.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / net / cellular / CellularModem / link / LinkMonitor.h
1 /* LinkMonitor.h */
2 /* Copyright (C) 2012 mbed.org, MIT License
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5  * and associated documentation files (the "Software"), to deal in the Software without restriction,
6  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
7  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in all copies or
11  * substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
18  */
19
20 #ifndef LINKMONITOR_H_
21 #define LINKMONITOR_H_
22
23 #include "core/fwk.h"
24
25 #include "rtos.h"
26
27 #include "at/ATCommandsInterface.h"
28
29 /** Component to monitor link quality
30  *
31  */
32 class LinkMonitor : protected IATCommandsProcessor
33 {
34 public:
35   /** Create LinkMonitor instance
36      @param pIf Pointer to the ATCommandsInterface instance to use
37    */
38   LinkMonitor(ATCommandsInterface* pIf);
39
40   /** Initialize monitor
41    */
42   int init(bool gsm = true);
43
44   /** Registration State
45   */  
46   enum REGISTRATION_STATE
47   {
48     REGISTRATION_STATE_UNKNOWN, //!< Unknown
49     REGISTRATION_STATE_REGISTERING, //!< Registering
50     REGISTRATION_STATE_DENIED, //!< Denied
51     REGISTRATION_STATE_NO_SIGNAL, //!< No Signal
52     REGISTRATION_STATE_HOME_NETWORK, //!< Registered on home network
53     REGISTRATION_STATE_ROAMING //!< Registered on roaming network
54   };
55
56   /** Bearer type
57   */
58   enum BEARER
59   {
60     BEARER_UNKNOWN, //!< Unknown
61     BEARER_GSM, //!< GSM (2G)
62     BEARER_EDGE, //!< EDGE (2.5G)
63     BEARER_UMTS, //!< UMTS (3G)
64     BEARER_HSPA, //!< HSPA (3G+)
65     BEARER_LTE //!< LTE (4G)
66   };
67   
68   /** Get link state
69     @param pRssi pointer to store the current RSSI in dBm, between -51 dBm and -113 dBm if known; -51 dBm means -51 dBm or more; -113 dBm means -113 dBm or less; 0 if unknown
70     @param pRegistrationState pointer to store the current registration state
71     @param pBearer pointer to store the current bearer
72     @return 0 on success, error code on failure
73   */
74   int getState(int* pRssi, REGISTRATION_STATE* pRegistrationState, BEARER* pBearer);
75   
76   /** Get my phone number
77     @param phoneNumber pointer to store the current phoneNumber
78     @return 0 on success, error code on failure
79   */
80   int getPhoneNumber(char* phoneNumber);
81 protected:
82   //IATCommandsProcessor
83   virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line);
84   virtual int onNewEntryPrompt(ATCommandsInterface* pInst);
85   
86 private:
87   ATCommandsInterface* m_pIf;
88   
89   int m_rssi;
90   bool m_gsm;
91   REGISTRATION_STATE m_registrationState;
92   BEARER m_bearer;
93   char m_phoneNumber[16];
94 };
95
96 #endif /* LINKMONITOR_H_ */