@@ -80,39 +80,44 @@ NBConnectionHandler::NBConnectionHandler(char const * pin, char const * apn, cha
8080 PUBLIC MEMBER FUNCTIONS
8181 ******************************************************************************/
8282
83- unsigned long NBConnectionHandler::getTime () {
83+ unsigned long NBConnectionHandler::getTime ()
84+ {
8485 return _nb.getTime ();
8586}
8687
8788NetworkConnectionState NBConnectionHandler::check ()
8889{
89-
9090 unsigned long const now = millis ();
9191 unsigned int const connectionTickTimeInterval = CHECK_INTERVAL_TABLE[static_cast <unsigned int >(_netConnectionState)];
9292
9393 if ((now - _lastConnectionTickTime) > connectionTickTimeInterval)
9494 {
9595 _lastConnectionTickTime = now;
9696
97- switch (_netConnectionState) {
98- case NetworkConnectionState::INIT: {
99- if (_nb.begin (_pin, _apn, _login, _pass) == NB_READY) {
97+ switch (_netConnectionState)
98+ {
99+ case NetworkConnectionState::INIT:
100+ {
101+ if (_nb.begin (_pin, _apn, _login, _pass) == NB_READY)
102+ {
100103 Debug.print (DBG_INFO, " SIM card ok" );
101104 _nb.setTimeout (NB_TIMEOUT);
102105 changeConnectionState (NetworkConnectionState::CONNECTING);
103- } else {
106+ }
107+ else
108+ {
104109 Debug.print (DBG_ERROR, " SIM not present or wrong PIN" );
105110 }
106111 }
107112 break ;
108113
109- case NetworkConnectionState::CONNECTING: {
110- // NOTE: Blocking Call when 4th parameter == true
114+ case NetworkConnectionState::CONNECTING:
115+ {
111116 NB_NetworkStatus_t networkStatus;
112117 networkStatus = _nb_gprs.attachGPRS (true );
113118 Debug.print (DBG_DEBUG, " GPRS.attachGPRS(): %d" , networkStatus);
114- if (networkStatus == NB_NetworkStatus_t::ERROR) {
115- // NO FURTHER ACTION WILL FOLLOW THIS
119+ if (networkStatus == NB_NetworkStatus_t::ERROR)
120+ {
116121 changeConnectionState (NetworkConnectionState::ERROR);
117122 return _netConnectionState;
118123 }
@@ -121,36 +126,41 @@ NetworkConnectionState NBConnectionHandler::check()
121126 // pingResult = _nb_gprs.ping("time.arduino.cc");
122127 // Debug.print(DBG_INFO, "NB.ping(): %d", pingResult);
123128 // if (pingResult < 0) {
124- if (pingResult < 0 ) {
129+ if (pingResult < 0 )
130+ {
125131 Debug.print (DBG_ERROR, " PING failed" );
126132 Debug.print (DBG_INFO, " Retrying in \" %d\" milliseconds" , connectionTickTimeInterval);
127133 return _netConnectionState;
128- } else {
134+ }
135+ else
136+ {
129137 Debug.print (DBG_INFO, " Connected to GPRS Network" );
130138 changeConnectionState (NetworkConnectionState::CONNECTED);
131139 return _netConnectionState;
132140 }
133141 }
134142 break ;
135- case NetworkConnectionState::CONNECTED: {
143+ case NetworkConnectionState::CONNECTED:
144+ {
136145 int const nb_is_access_alive = _nb.isAccessAlive ();
137146 Debug.print (DBG_VERBOSE, " GPRS.isAccessAlive(): %d" , nb_is_access_alive);
138- if (nb_is_access_alive != 1 ) {
147+ if (nb_is_access_alive != 1 )
148+ {
139149 changeConnectionState (NetworkConnectionState::DISCONNECTED);
140150 return _netConnectionState;
141151 }
142152 Debug.print (DBG_VERBOSE, " Connected to Cellular Network" );
143153 }
144154 break ;
145- case NetworkConnectionState::DISCONNECTED: {
146- // _nb_gprs.detachGPRS();
147- if (_keep_alive) {
155+ case NetworkConnectionState::DISCONNECTED:
156+ {
157+ if (_keep_alive)
158+ {
148159 Debug.print (DBG_VERBOSE, " keep alive > INIT" );
149160 changeConnectionState (NetworkConnectionState::INIT);
150161 } else {
151162 changeConnectionState (NetworkConnectionState::CLOSED);
152163 }
153- // changeConnectionState(NetworkConnectionState::CONNECTING);
154164 }
155165 break ;
156166 }
0 commit comments