UbloxUSBGSMModem.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 UBLOXUSBGSMMODEM_H_
  20. #define UBLOXUSBGSMMODEM_H_
  21. #include "core/fwk.h"
  22. #include "WANDongle.h"
  23. #include "at/ATCommandsInterface.h"
  24. #include "serial/usb/USBSerialStream.h"
  25. #include "ip/PPPIPInterface.h"
  26. #include "sms/GSMSMSInterface.h"
  27. #include "ussd/USSDInterface.h"
  28. #include "link/LinkMonitor.h"
  29. #include "CellularModem.h"
  30. /** u-blox WCDMA modem (LISA-U200)
  31. */
  32. class UbloxUSBGSMModem: public CellularModem
  33. {
  34. public:
  35. /** Create u-blox API instance
  36. @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line
  37. @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true
  38. */
  39. UbloxUSBGSMModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true);
  40. //Internet-related functions
  41. /** Open a 3G internet connection
  42. @return 0 on success, error code on failure
  43. */
  44. virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
  45. /** Close the internet connection
  46. @return 0 on success, error code on failure
  47. */
  48. virtual int disconnect();
  49. /** Send a SM
  50. @param number The receiver's phone number
  51. @param message The message to send
  52. @return 0 on success, error code on failure
  53. */
  54. virtual int sendSM(const char* number, const char* message);
  55. /** Receive a SM
  56. @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)
  57. @param message Pointer to a buffer to store the the incoming message
  58. @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
  59. @return 0 on success, error code on failure
  60. */
  61. virtual int getSM(char* number, char* message, size_t maxLength);
  62. /** Get the number of SMs in the incoming box
  63. @param pCount pointer to store the number of unprocessed SMs on
  64. @return 0 on success, error code on failure
  65. */
  66. virtual int getSMCount(size_t* pCount);
  67. /** Send a USSD command & wait for its result
  68. @param command The command to send
  69. @param result Buffer in which to store the result
  70. @param maxLength Maximum result length that can be stored in buffer (including null-terminating character)
  71. @return 0 on success, error code on failure
  72. */
  73. int sendUSSD(const char* command, char* result, size_t maxLength);
  74. /** Get link state
  75. @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
  76. @param pRegistrationState pointer to store the current registration state
  77. @param pBearer pointer to store the current bearer
  78. @return 0 on success, error code on failure
  79. */
  80. int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer);
  81. /** Get the ATCommandsInterface instance
  82. @return Pointer to the ATCommandsInterface instance
  83. */
  84. virtual ATCommandsInterface* getATCommandsInterface();
  85. /** Switch power on or off
  86. In order to use this function, a pin name must have been entered in the constructor
  87. @param enable true to switch the dongle on, false to switch it off
  88. @return 0 on success, error code on failure
  89. */
  90. virtual int power(bool enable);
  91. protected:
  92. bool power(); //< Turn power to USB dongle ON.
  93. /** Initialise dongle.
  94. * The following actions are performed:
  95. * 1) Power up
  96. * 2) Establish USB connection to dongle
  97. * 3) Start AT interface thread
  98. * 4) Wait for network registration
  99. */
  100. int init();
  101. /** De-initialise dongle.
  102. * The following actions are performed:
  103. * 1) Tear down PPP session
  104. * 2) Set SMS,USSD, and LinkMonitor subsystems to un-initialised
  105. * 3) Close the AT commands interface
  106. * 4) Tear down the USB connection to dongle
  107. */
  108. int cleanup();
  109. private:
  110. WANDongle m_dongle; //< Interface to USB connected WAN dongle
  111. USBSerialStream m_atStream; //< Serial interface to AT channel on modem
  112. USBSerialStream m_pppStream; //< Serial interface to PPP channel on modem
  113. ATCommandsInterface m_at; //< Interface to AT commands processing
  114. GSMSMSInterface m_sms; //< 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_dongleConnected; //< Is the dongle physically connected (does the USB stack respond)? true/false
  119. bool m_ipInit; //< Has PPIPInterface object (m_ppp) been initialised? true/false
  120. bool m_smsInit; //< Has SMSInterface object (m_sms) been initialised? true/false
  121. bool m_ussdInit; //< Has USSDInterface object (m_ussd) been initialised? true/false
  122. bool m_linkMonitorInit; //< Has LinkMonitor object (m_linkMonitor) been initialised? true/false
  123. bool m_atOpen; //< Is the interface to the ATCommandsInterface open? true/false
  124. PinName m_powerGatingPin; //< Pin which toggles power gating
  125. bool m_powerGatingOnWhenPinHigh; //< Semantics of power gating (whether high or low toggles power gating)
  126. };
  127. #endif /* UBLOXMODEM_H_ */