2020# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121# THE SOFTWARE.
2222"""
23- `adafruit_fona_gsm `
23+ `adafruit_fona_network `
2424=================================================================================
2525
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 .
2727
2828* Author(s): Brent Rubell
2929
3030"""
3131
32+ # Network types
33+ NET_GSM = 0x01
34+ NET_CDMA = 0x02
3235
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."""
3639
3740 def __init__ (self , fona , apn ):
38- """Initializes interface with 2G GSM modem .
41+ """Initializes interface with cellular network .
3942 :param adafruit_fona fona: The Adafruit FONA module we are using.
4043 :param tuple apn: Tuple containing APN name, (optional) APN username,
4144 and APN password.
4245
4346 """
4447 self ._iface = fona
4548 self ._apn = apn
46- self ._gsm_connected = False
49+ self ._network_connected = False
50+ self ._network_type = NET_CDMA
4751
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
5055
5156 def __enter__ (self ):
5257 return self
@@ -56,7 +61,7 @@ def __exit__(self, exception_type, exception_value, traceback):
5661
5762 @property
5863 def imei (self ):
59- """Returns the GSM modem's IEMI number, as a string."""
64+ """Returns the modem's IEMI number, as a string."""
6065 return self ._iface .iemi
6166
6267 @property
@@ -66,31 +71,31 @@ def iccid(self):
6671
6772 @property
6873 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
7381 return False
7482
7583 @property
7684 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 :
8287 return False
8388 return True
8489
8590 def connect (self ):
86- """Connect to GSM network."""
91+ """Connect to cellular network."""
8792 if self ._iface .set_gprs (self ._apn , True ):
88- self ._gsm_connected = True
93+ self ._network_connected = True
8994 else :
9095 # reset context for next connection attempt
9196 self ._iface .set_gprs (self ._apn , False )
9297
9398 def disconnect (self ):
94- """Disconnect from GSM network."""
99+ """Disconnect from cellular network."""
95100 self ._iface .set_gprs (self ._apn , False )
96- self ._gsm_connected = False
101+ self ._network_connected = False
0 commit comments