-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from pennam/catM1
Add CatM1ConnectionHandler to support Portenta CAT.M1/NB IoT GNSS Shield
- Loading branch information
Showing
6 changed files
with
193 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
This file is part of ArduinoIoTCloud. | ||
Copyright 2019 ARDUINO SA (http://www.arduino.cc/) | ||
This software is released under the GNU General Public License version 3, | ||
which covers the main part of arduino-cli. | ||
The terms of this license can be found at: | ||
https://www.gnu.org/licenses/gpl-3.0.en.html | ||
You can be released from the requirements of the above licenses by purchasing | ||
a commercial license. Buying such a license is mandatory if you want to modify or | ||
otherwise use the software for commercial activities involving the Arduino | ||
software without disclosing the source code of your own applications. To purchase | ||
a commercial license, send an email to [email protected]. | ||
*/ | ||
|
||
/****************************************************************************** | ||
INCLUDE | ||
******************************************************************************/ | ||
|
||
#include "Arduino_CatM1ConnectionHandler.h" | ||
|
||
#ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */ | ||
|
||
/****************************************************************************** | ||
CTOR/DTOR | ||
******************************************************************************/ | ||
|
||
CatM1ConnectionHandler::CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat, uint32_t band, bool const keep_alive) | ||
: ConnectionHandler{keep_alive, NetworkAdapter::GSM} | ||
, _pin(pin) | ||
, _apn(apn) | ||
, _login(login) | ||
, _pass(pass) | ||
, _rat(rat) | ||
, _band(band) | ||
{ | ||
|
||
} | ||
|
||
/****************************************************************************** | ||
PUBLIC MEMBER FUNCTIONS | ||
******************************************************************************/ | ||
|
||
unsigned long CatM1ConnectionHandler::getTime() | ||
{ | ||
return GSM.getTime(); | ||
} | ||
|
||
/****************************************************************************** | ||
PROTECTED MEMBER FUNCTIONS | ||
******************************************************************************/ | ||
|
||
NetworkConnectionState CatM1ConnectionHandler::update_handleInit() | ||
{ | ||
return NetworkConnectionState::CONNECTING; | ||
} | ||
|
||
NetworkConnectionState CatM1ConnectionHandler::update_handleConnecting() | ||
{ | ||
if(!GSM.begin(_pin, _apn, _login, _pass, _rat, _band)) | ||
{ | ||
Debug.print(DBG_ERROR, F("The board was not able to register to the network...")); | ||
return NetworkConnectionState::ERROR; | ||
} | ||
Debug.print(DBG_INFO, F("Connected to Network")); | ||
return NetworkConnectionState::CONNECTED; | ||
} | ||
|
||
NetworkConnectionState CatM1ConnectionHandler::update_handleConnected() | ||
{ | ||
int const is_gsm_access_alive = GSM.isConnected(); | ||
if (is_gsm_access_alive != 1) | ||
{ | ||
return NetworkConnectionState::DISCONNECTED; | ||
} | ||
return NetworkConnectionState::CONNECTED; | ||
} | ||
|
||
NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnecting() | ||
{ | ||
GSM.disconnect(); | ||
return NetworkConnectionState::DISCONNECTED; | ||
} | ||
|
||
NetworkConnectionState CatM1ConnectionHandler::update_handleDisconnected() | ||
{ | ||
if (_keep_alive) | ||
{ | ||
return NetworkConnectionState::INIT; | ||
} | ||
else | ||
{ | ||
return NetworkConnectionState::CLOSED; | ||
} | ||
} | ||
|
||
#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
This file is part of ArduinoIoTCloud. | ||
Copyright 2019 ARDUINO SA (http://www.arduino.cc/) | ||
This software is released under the GNU General Public License version 3, | ||
which covers the main part of arduino-cli. | ||
The terms of this license can be found at: | ||
https://www.gnu.org/licenses/gpl-3.0.en.html | ||
You can be released from the requirements of the above licenses by purchasing | ||
a commercial license. Buying such a license is mandatory if you want to modify or | ||
otherwise use the software for commercial activities involving the Arduino | ||
software without disclosing the source code of your own applications. To purchase | ||
a commercial license, send an email to [email protected]. | ||
*/ | ||
|
||
#ifndef ARDUINO_CATM1_CONNECTION_HANDLER_H_ | ||
#define ARDUINO_CATM1_CONNECTION_HANDLER_H_ | ||
|
||
/****************************************************************************** | ||
INCLUDE | ||
******************************************************************************/ | ||
|
||
#include "Arduino_ConnectionHandler.h" | ||
|
||
|
||
#ifdef BOARD_HAS_CATM1_NBIOT /* Only compile if the board has CatM1 BN-IoT */ | ||
|
||
/****************************************************************************** | ||
CLASS DECLARATION | ||
******************************************************************************/ | ||
|
||
class CatM1ConnectionHandler : public ConnectionHandler | ||
{ | ||
public: | ||
|
||
CatM1ConnectionHandler(const char * pin, const char * apn, const char * login, const char * pass, RadioAccessTechnologyType rat = CATM1, uint32_t band = BAND_3 | BAND_20 | BAND_19, bool const keep_alive = true); | ||
|
||
|
||
virtual unsigned long getTime() override; | ||
virtual Client & getClient() override { return _gsm_client; }; | ||
virtual UDP & getUDP() override { return _gsm_udp; }; | ||
|
||
|
||
protected: | ||
|
||
virtual NetworkConnectionState update_handleInit () override; | ||
virtual NetworkConnectionState update_handleConnecting () override; | ||
virtual NetworkConnectionState update_handleConnected () override; | ||
virtual NetworkConnectionState update_handleDisconnecting() override; | ||
virtual NetworkConnectionState update_handleDisconnected () override; | ||
|
||
|
||
private: | ||
|
||
const char * _pin; | ||
const char * _apn; | ||
const char * _login; | ||
const char * _pass; | ||
|
||
RadioAccessTechnologyType _rat; | ||
uint32_t _band; | ||
|
||
GSMUDP _gsm_udp; | ||
GSMClient _gsm_client; | ||
}; | ||
|
||
#endif /* #ifdef BOARD_HAS_CATM1_NBIOT */ | ||
|
||
#endif /* #ifndef ARDUINO_CATM1_CONNECTION_HANDLER_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters