UbloxUSBCDMAModem.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /* UbloxUSBCDMAModem.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 UBLOXUSBCDMAMODEM_H_
  20. #define UBLOXUSBCDMAMODEM_H_
  21. #include "core/fwk.h"
  22. #include "WANDongle.h"
  23. #include "at/ATCommandsInterface.h"
  24. #include "USBSerialStream.h"
  25. #include "ip/PPPIPInterface.h"
  26. #include "sms/CDMASMSInterface.h"
  27. #include "CellularModem.h"
  28. /** u-blox LISA-C200 modem
  29. */
  30. class UbloxUSBCDMAModem: public CellularModem
  31. {
  32. public:
  33. /** Create Sprint USB Modem (Sierra Wireless 598U) API instance
  34. @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line
  35. @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true
  36. */
  37. UbloxUSBCDMAModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true, int serial = 0);
  38. //Internet-related functions
  39. /** Open a 3G internet connection
  40. @return 0 on success, error code on failure
  41. */
  42. virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
  43. /** Close the internet connection
  44. @return 0 on success, error code on failure
  45. */
  46. virtual int disconnect();
  47. /** Send a SM
  48. @param number The receiver's phone number
  49. @param message The message to send
  50. @return 0 on success, error code on failure
  51. */
  52. virtual int sendSM(const char* number, const char* message);
  53. /** Receive a SM
  54. @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)
  55. @param message Pointer to a buffer to store the the incoming message
  56. @param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
  57. @return 0 on success, error code on failure
  58. */
  59. virtual int getSM(char* number, char* message, size_t maxLength);
  60. /** Get the number of SMs in the incoming box
  61. @param pCount pointer to store the number of unprocessed SMs on
  62. @return 0 on success, error code on failure
  63. */
  64. virtual int getSMCount(size_t* pCount);
  65. /** Get the ATCommandsInterface instance
  66. @return Pointer to the ATCommandsInterface instance
  67. */
  68. virtual ATCommandsInterface* getATCommandsInterface();
  69. /** Switch power on or off
  70. In order to use this function, a pin name must have been entered in the constructor
  71. @param enable true to switch the dongle on, false to switch it off
  72. @return 0 on success, error code on failure
  73. */
  74. virtual int power(bool enable);
  75. protected:
  76. bool power();
  77. int init();
  78. int cleanup();
  79. private:
  80. WANDongle m_dongle;
  81. USBSerialStream m_stream;
  82. ATCommandsInterface m_at;
  83. CDMASMSInterface m_sms;
  84. PPPIPInterface m_ppp;
  85. bool m_dongleConnected;
  86. bool m_ipInit;
  87. bool m_smsInit;
  88. bool m_atOpen;
  89. PinName m_powerGatingPin;
  90. bool m_powerGatingOnWhenPinHigh;
  91. };
  92. #endif /* UBLOXUSBCDMAMODEM_H_ */