Skip to content

Commit 21825b4

Browse files
committed
Restructuring control flow for better readability
1 parent a20afc8 commit 21825b4

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/Arduino_GSMConnectionHandler.cpp

+14-15
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,25 @@ unsigned long GSMConnectionHandler::getTime()
5858

5959
NetworkConnectionState GSMConnectionHandler::update_handleInit()
6060
{
61-
if (_gsm.begin(_pin) == GSM_READY)
61+
if (_gsm.begin(_pin) != GSM_READY)
6262
{
63-
Debug.print(DBG_INFO, "SIM card ok");
64-
_gsm.setTimeout(GSM_TIMEOUT);
65-
66-
GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS(_apn, _login, _pass, true);
67-
Debug.print(DBG_DEBUG, "GPRS.attachGPRS(): %d", network_status);
68-
if (network_status == GSM3_NetworkStatus_t::ERROR)
69-
{
70-
Debug.print(DBG_ERROR, "GPRS attach failed");
71-
Debug.print(DBG_ERROR, "Make sure the antenna is connected and reset your board.");
72-
return NetworkConnectionState::ERROR;
73-
}
74-
return NetworkConnectionState::CONNECTING;
63+
Debug.print(DBG_ERROR, "SIM not present or wrong PIN");
64+
return NetworkConnectionState::ERROR;
7565
}
76-
else
66+
67+
Debug.print(DBG_INFO, "SIM card ok");
68+
_gsm.setTimeout(GSM_TIMEOUT);
69+
70+
GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS(_apn, _login, _pass, true);
71+
Debug.print(DBG_DEBUG, "GPRS.attachGPRS(): %d", network_status);
72+
if (network_status == GSM3_NetworkStatus_t::ERROR)
7773
{
78-
Debug.print(DBG_ERROR, "SIM not present or wrong PIN");
74+
Debug.print(DBG_ERROR, "GPRS attach failed");
75+
Debug.print(DBG_ERROR, "Make sure the antenna is connected and reset your board.");
7976
return NetworkConnectionState::ERROR;
8077
}
78+
79+
return NetworkConnectionState::CONNECTING;
8180
}
8281

8382
NetworkConnectionState GSMConnectionHandler::update_handleConnecting()

0 commit comments

Comments
 (0)