20
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
# THE SOFTWARE.
22
22
"""
23
- `adafruit_fona_gsm `
23
+ `adafruit_fona_network `
24
24
=================================================================================
25
25
26
- Interface for 2G GSM cellular modems such as the Adafruit FONA808 .
26
+ Interface for connecting to and interacting with GSM and CDMA cellular networks .
27
27
28
28
* Author(s): Brent Rubell
29
29
30
30
"""
31
31
32
+ # Network types
33
+ NET_GSM = 0x01
34
+ NET_CDMA = 0x02
32
35
33
- class GSM :
34
- """Interface for interacting with FONA 2G GSM modems.
35
- """
36
+
37
+ class CELLULAR :
38
+ """Interface for connecting to and interacting with GSM and CDMA cellular networks."""
36
39
37
40
def __init__ (self , fona , apn ):
38
- """Initializes interface with 2G GSM modem .
41
+ """Initializes interface with cellular network .
39
42
:param adafruit_fona fona: The Adafruit FONA module we are using.
40
43
:param tuple apn: Tuple containing APN name, (optional) APN username,
41
44
and APN password.
42
45
43
46
"""
44
47
self ._iface = fona
45
48
self ._apn = apn
46
- self ._gsm_connected = False
49
+ self ._network_connected = False
50
+ self ._network_type = NET_CDMA
47
51
48
- # Enable GPS module
49
- self ._iface .gps = True
52
+ if not self ._iface .version == 0x4 or self ._iface .version == 0x5 :
53
+ self ._network_type = NET_GSM
54
+ self ._iface .gps = True
50
55
51
56
def __enter__ (self ):
52
57
return self
@@ -56,7 +61,7 @@ def __exit__(self, exception_type, exception_value, traceback):
56
61
57
62
@property
58
63
def imei (self ):
59
- """Returns the GSM modem's IEMI number, as a string."""
64
+ """Returns the modem's IEMI number, as a string."""
60
65
return self ._iface .iemi
61
66
62
67
@property
@@ -66,31 +71,31 @@ def iccid(self):
66
71
67
72
@property
68
73
def is_attached (self ):
69
- """Returns if the modem is attached to the network
70
- and the GPS has a fix."""
71
- if self ._iface .gps == 3 and self ._iface .network_status == 1 :
72
- return True
74
+ """Returns if the modem is attached to the network."""
75
+ if self ._network_type == NET_GSM :
76
+ if self ._iface .gps == 3 and self ._iface .network_status == 1 :
77
+ return True
78
+ else : # Attach CDMA network
79
+ if self ._iface .ue_system_info == 1 and self ._iface .network_status == 1 :
80
+ return True
73
81
return False
74
82
75
83
@property
76
84
def is_connected (self ):
77
- """Returns if attached to GSM
78
- and an IP Addresss was obtained.
79
-
80
- """
81
- if not self ._gsm_connected :
85
+ """Returns if attached to network and an IP Addresss was obtained."""
86
+ if not self ._network_connected :
82
87
return False
83
88
return True
84
89
85
90
def connect (self ):
86
- """Connect to GSM network."""
91
+ """Connect to cellular network."""
87
92
if self ._iface .set_gprs (self ._apn , True ):
88
- self ._gsm_connected = True
93
+ self ._network_connected = True
89
94
else :
90
95
# reset context for next connection attempt
91
96
self ._iface .set_gprs (self ._apn , False )
92
97
93
98
def disconnect (self ):
94
- """Disconnect from GSM network."""
99
+ """Disconnect from cellular network."""
95
100
self ._iface .set_gprs (self ._apn , False )
96
- self ._gsm_connected = False
101
+ self ._network_connected = False
0 commit comments