Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Socket USBHostWANDongle lwip-sys lwip
Dependents: VodafoneUSBModemHTTPClientTest VodafoneUSBModemNTPClientTest VodafoneUSBModemSMSTest VodafoneUSBModemUSSDTest ... more
Fork of VodafoneUSBModem_bleedingedge by
Diff: VodafoneUSBModem.cpp
- Revision:
- 26:d37501dc6c61
- Parent:
- 23:21046ba01b7b
- Child:
- 27:37d3ac289e86
--- a/VodafoneUSBModem.cpp Wed Aug 29 15:49:14 2012 +0000
+++ b/VodafoneUSBModem.cpp Wed Aug 29 16:28:13 2012 +0000
@@ -26,12 +26,16 @@
#include "VodafoneUSBModem.h"
-VodafoneUSBModem::VodafoneUSBModem() : m_dongle(),
+VodafoneUSBModem::VodafoneUSBModem(PinName powerGatingPin /*= NC*/) : m_dongle(),
m_atStream(m_dongle.getSerial(1)), m_pppStream(m_dongle.getSerial(0)), m_at(&m_atStream),
m_sms(&m_at), m_ussd(&m_at), m_linkMonitor(&m_at), m_ppp(&m_pppStream),
-m_dongleConnected(false), m_ipInit(false), m_smsInit(false), m_ussdInit(false), m_linkMonitorInit(false), m_atOpen(false)
+m_dongleConnected(false), m_ipInit(false), m_smsInit(false), m_ussdInit(false), m_linkMonitorInit(false), m_atOpen(false),
+m_powerGatingPin(powerGatingPin)
{
-
+ if( m_powerGatingPin != NC )
+ {
+ power(false); //Dongle will have to be powered on manually
+ }
}
class CREGProcessor : public IATCommandsProcessor
@@ -445,10 +449,55 @@
return &m_at;
}
+int VodafoneUSBModem::power(bool enable)
+{
+ if( m_powerGatingPin == NC )
+ {
+ return NET_INVALID; //A pin name has not been provided in the constructor
+ }
+
+ if(!enable && m_ppp.isConnected())
+ {
+ WARN("Data connection is still open"); //Try to encourage good behaviour from the user
+ m_ppp.disconnect();
+ }
+
+ DigitalOut powerGatingOut(m_powerGatingPin);
+ powerGatingOut = enable;
+ if(!enable) //Will force components to re-init
+ {
+ m_dongleConnected = false;
+ m_smsInit = false;
+ m_ussdInit = false;
+ m_linkMonitorInit = false;
+ m_atOpen = false;
+ //We don't reset m_ipInit as PPPIPInterface::init() only needs to be called once
+ }
+
+ return OK;
+}
+
+bool VodafoneUSBModem::power()
+{
+ if( m_powerGatingPin == NC )
+ {
+ return true; //Assume power is always on
+ }
+
+ DigitalOut powerGatingOut(m_powerGatingPin);
+ return powerGatingOut;
+}
+
int VodafoneUSBModem::init()
{
if( !m_dongleConnected )
{
+ if(!power())
+ {
+ //Obviously cannot initialize the dongle if it is disconnected...
+ ERR("Power is off");
+ return NET_INVALID;
+ }
m_dongleConnected = true;
while( !m_dongle.connected() )
{

Vodafone K3770 3G Modem