UbloxModem.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* VodafoneUSBModem.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. #ifndef UBLOXMODEM_H_
  20. #define UBLOXMODEM_H_
  21. #include "core/fwk.h"
  22. #include "at/ATCommandsInterface.h"
  23. #include "ip/PPPIPInterface.h"
  24. #include "sms/GSMSMSInterface.h"
  25. #include "sms/CDMASMSInterface.h"
  26. #include "ussd/USSDInterface.h"
  27. #include "link/LinkMonitor.h"
  28. #include "CellularModem.h"
  29. class genericAtProcessor : public IATCommandsProcessor
  30. {
  31. public:
  32. genericAtProcessor();
  33. const char* getResponse(void);
  34. private:
  35. virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line);
  36. virtual int onNewEntryPrompt(ATCommandsInterface* pInst);
  37. protected:
  38. char str[256];
  39. int i;
  40. };
  41. /** u-blox WCDMA modem (LISA-U200)
  42. */
  43. class UbloxModem: public CellularModem
  44. {
  45. public:
  46. /** Create u-blox API instance
  47. @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line
  48. @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true
  49. */
  50. UbloxModem(IOStream* atStream, IOStream* pppStream);
  51. //Internet-related functions
  52. /** Open a 3G internet connection
  53. @return 0 on success, error code on failure
  54. */
  55. virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
  56. /** Close the internet connection
  57. @return 0 on success, error code on failure
  58. */
  59. virtual int disconnect();
  60. /** Send a SM
  61. @param number The receiver's phone number
  62. @param message The message to send
  63. @return 0 on success, error code on failure
  64. */
  65. virtual int sendSM(const char* number, const char* message);
  66. /** Receive a SM
  67. @param number Pointer to a buffer to store the sender's phone number (must be at least 17 characters-long, including the sapce for the null-terminating char)
  68. @param message Pointer to a buffer to store the the incoming message
  69. @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
  70. @return 0 on success, error code on failure
  71. */
  72. virtual int getSM(char* number, char* message, size_t maxLength);
  73. /** Get the number of SMs in the incoming box
  74. @param pCount pointer to store the number of unprocessed SMs on
  75. @return 0 on success, error code on failure
  76. */
  77. virtual int getSMCount(size_t* pCount);
  78. /** Send a USSD command & wait for its result
  79. @param command The command to send
  80. @param result Buffer in which to store the result
  81. @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
  82. @return 0 on success, error code on failure
  83. */
  84. int sendUSSD(const char* command, char* result, size_t maxLength);
  85. /** Get link state
  86. @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
  87. @param pRegistrationState pointer to store the current registration state
  88. @param pBearer pointer to store the current bearer
  89. @return 0 on success, error code on failure
  90. */
  91. int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer);
  92. int getPhoneNumber(char* phoneNumber);
  93. /** Get the ATCommandsInterface instance
  94. @return Pointer to the ATCommandsInterface instance
  95. */
  96. virtual ATCommandsInterface* getATCommandsInterface();
  97. protected:
  98. /** Initialise dongle.
  99. * The following actions are performed:
  100. * 1) Start AT interface thread
  101. * 2) Wait for network registration
  102. */
  103. virtual int init();
  104. /** De-initialise dongle.
  105. * The following actions are performed:
  106. * 1) Tear down PPP session
  107. * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised
  108. * 3) Close the AT commands interface
  109. */
  110. virtual int cleanup();
  111. private:
  112. ATCommandsInterface m_at; //< Interface to AT commands processing
  113. CDMASMSInterface m_CdmaSms; //< Interface to SMS manager (send/receive etc)
  114. GSMSMSInterface m_GsmSms; //< Interface to SMS manager (send/receive etc)
  115. USSDInterface m_ussd; //< Interface to USSD manager (send etc)
  116. LinkMonitor m_linkMonitor; //< Interface to link monitor (RSSI)
  117. PPPIPInterface m_ppp; //< Interface to PPP conection manager (IP assignment etc)
  118. bool m_ipInit; //< Has PPIPInterface object (m_ppp) been initialised? true/false
  119. bool m_smsInit; //< Has SMSInterface object (m_sms) been initialised? true/false
  120. bool m_ussdInit; //< Has USSDInterface object (m_ussd) been initialised? true/false
  121. bool m_linkMonitorInit; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false
  122. bool m_atOpen; //< Is the interface to the ATCommandsInterface open? true/false
  123. protected:
  124. bool m_onePort;
  125. enum { LISA_C200, LISA_U200, SARA_G350, UNKNOWN } m_type;
  126. };
  127. #include "WANDongle.h"
  128. #include "serial/usb/USBSerialStream.h"
  129. class UbloxUSBModem: public UbloxModem
  130. {
  131. public:
  132. UbloxUSBModem();
  133. virtual int init();
  134. virtual int cleanup();
  135. virtual int power(bool enable) { return 1; }
  136. private:
  137. WANDongle m_dongle; //< Interface to USB connected WAN dongle
  138. USBSerialStream m_atStream; //< Serial interface to AT channel on modem
  139. USBSerialStream m_pppStream; //< Serial interface to PPP channel on modem
  140. bool m_dongleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false
  141. };
  142. #include "serial/io/IOSerialStream.h"
  143. class UbloxSerModem: public UbloxModem
  144. {
  145. public:
  146. UbloxSerModem();
  147. virtual int power(bool enable) { return 1; }
  148. private:
  149. RawSerial m_Serial;
  150. IOSerialStream m_atStream; //< Serial interface to AT channel on modem
  151. };
  152. #endif /* UBLOXMODEM_H_ */