Skip to content

Commit a349456

Browse files
committed
Added CellularModem as an abstract base class for modem implementations
Now both UbloxUSBGSMModem and UbloxUSBCDMAModem inherit from CellularModem.
1 parent 87fbaa5 commit a349456

File tree

3 files changed

+96
-16
lines changed

3 files changed

+96
-16
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* CellularModem.h */
2+
/* Copyright (C) 2013 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 CELLULARMODEM_H_
21+
#define CELLULARMODEM_H_
22+
23+
#include "core/fwk.h"
24+
#include "at/ATCommandsInterface.h"
25+
26+
class CellularModem
27+
{
28+
public:
29+
//Internet-related functions
30+
31+
/** Open a 3G internet connection
32+
@return 0 on success, error code on failure
33+
*/
34+
virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL) = 0;
35+
36+
/** Close the internet connection
37+
@return 0 on success, error code on failure
38+
*/
39+
virtual int disconnect() = 0;
40+
41+
42+
/** Send a SM
43+
@param number The receiver's phone number
44+
@param message The message to send
45+
@return 0 on success, error code on failure
46+
*/
47+
virtual int sendSM(const char* number, const char* message) = 0;
48+
49+
50+
/** Receive a SM
51+
@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)
52+
@param message Pointer to a buffer to store the the incoming message
53+
@param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
54+
@return 0 on success, error code on failure
55+
*/
56+
virtual int getSM(char* number, char* message, size_t maxLength) = 0;
57+
58+
/** Get the number of SMs in the incoming box
59+
@param pCount pointer to store the number of unprocessed SMs on
60+
@return 0 on success, error code on failure
61+
*/
62+
virtual int getSMCount(size_t* pCount) = 0;
63+
64+
/** Get the ATCommandsInterface instance
65+
@return Pointer to the ATCommandsInterface instance
66+
*/
67+
virtual ATCommandsInterface* getATCommandsInterface() = 0;
68+
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) = 0;
75+
};
76+
77+
78+
#endif /* CELLULARMODEM_H_ */

libraries/net/cellular/UbloxUSBModem/UbloxUSBCDMAModem.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@
2727
#include "USBSerialStream.h"
2828
#include "ip/PPPIPInterface.h"
2929
#include "sms/CDMASMSInterface.h"
30+
#include "CellularModem.h"
3031

3132
/** u-blox LISA-C200 modem
3233
*/
33-
class UbloxUSBCDMAModem
34+
class UbloxUSBCDMAModem: public CellularModem
3435
{
3536
public:
3637
/** Create Sprint USB Modem (Sierra Wireless 598U) API instance
@@ -44,20 +45,20 @@ class UbloxUSBCDMAModem
4445
/** Open a 3G internet connection
4546
@return 0 on success, error code on failure
4647
*/
47-
int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
48+
virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
4849

4950
/** Close the internet connection
5051
@return 0 on success, error code on failure
5152
*/
52-
int disconnect();
53+
virtual int disconnect();
5354

5455

5556
/** Send a SM
5657
@param number The receiver's phone number
5758
@param message The message to send
5859
@return 0 on success, error code on failure
5960
*/
60-
int sendSM(const char* number, const char* message);
61+
virtual int sendSM(const char* number, const char* message);
6162

6263

6364
/** Receive a SM
@@ -66,25 +67,25 @@ class UbloxUSBCDMAModem
6667
@param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
6768
@return 0 on success, error code on failure
6869
*/
69-
int getSM(char* number, char* message, size_t maxLength);
70+
virtual int getSM(char* number, char* message, size_t maxLength);
7071

7172
/** Get the number of SMs in the incoming box
7273
@param pCount pointer to store the number of unprocessed SMs on
7374
@return 0 on success, error code on failure
7475
*/
75-
int getSMCount(size_t* pCount);
76+
virtual int getSMCount(size_t* pCount);
7677

7778
/** Get the ATCommandsInterface instance
7879
@return Pointer to the ATCommandsInterface instance
7980
*/
80-
ATCommandsInterface* getATCommandsInterface();
81+
virtual ATCommandsInterface* getATCommandsInterface();
8182

8283
/** Switch power on or off
8384
In order to use this function, a pin name must have been entered in the constructor
8485
@param enable true to switch the dongle on, false to switch it off
8586
@return 0 on success, error code on failure
8687
*/
87-
int power(bool enable);
88+
virtual int power(bool enable);
8889

8990
protected:
9091
bool power();

libraries/net/cellular/UbloxUSBModem/UbloxUSBGSMModem.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@
2929
#include "sms/GSMSMSInterface.h"
3030
#include "ussd/USSDInterface.h"
3131
#include "link/LinkMonitor.h"
32+
#include "CellularModem.h"
3233

3334
/** u-blox WCDMA modem (LISA-U200)
3435
*/
35-
class UbloxUSBGSMModem
36+
class UbloxUSBGSMModem: public CellularModem
3637
{
3738
public:
3839
/** Create u-blox API instance
@@ -46,20 +47,20 @@ class UbloxUSBGSMModem
4647
/** Open a 3G internet connection
4748
@return 0 on success, error code on failure
4849
*/
49-
int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
50+
virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL);
5051

5152
/** Close the internet connection
5253
@return 0 on success, error code on failure
5354
*/
54-
int disconnect();
55+
virtual int disconnect();
5556

5657

5758
/** Send a SM
5859
@param number The receiver's phone number
5960
@param message The message to send
6061
@return 0 on success, error code on failure
6162
*/
62-
int sendSM(const char* number, const char* message);
63+
virtual int sendSM(const char* number, const char* message);
6364

6465

6566
/** Receive a SM
@@ -68,13 +69,13 @@ class UbloxUSBGSMModem
6869
@param maxLength Maximum message length that can be stored in buffer (including null-terminating character)
6970
@return 0 on success, error code on failure
7071
*/
71-
int getSM(char* number, char* message, size_t maxLength);
72+
virtual int getSM(char* number, char* message, size_t maxLength);
7273

7374
/** Get the number of SMs in the incoming box
7475
@param pCount pointer to store the number of unprocessed SMs on
7576
@return 0 on success, error code on failure
7677
*/
77-
int getSMCount(size_t* pCount);
78+
virtual int getSMCount(size_t* pCount);
7879

7980
/** Send a USSD command & wait for its result
8081
@param command The command to send
@@ -95,14 +96,14 @@ class UbloxUSBGSMModem
9596
/** Get the ATCommandsInterface instance
9697
@return Pointer to the ATCommandsInterface instance
9798
*/
98-
ATCommandsInterface* getATCommandsInterface();
99+
virtual ATCommandsInterface* getATCommandsInterface();
99100

100101
/** Switch power on or off
101102
In order to use this function, a pin name must have been entered in the constructor
102103
@param enable true to switch the dongle on, false to switch it off
103104
@return 0 on success, error code on failure
104105
*/
105-
int power(bool enable);
106+
virtual int power(bool enable);
106107

107108
protected:
108109
bool power(); //< Turn power to USB dongle ON.

0 commit comments

Comments
 (0)