Vodafone K3770/K3772-Z modems driver & networking library
Dependencies: Socket USBHostWANDongle lwip-sys lwip
Dependents: VodafoneUSBModemHTTPClientTest VodafoneUSBModemNTPClientTest VodafoneUSBModemSMSTest VodafoneUSBModemUSSDTest ... more
Fork of VodafoneUSBModem_bleedingedge by
This is the driver for the Vodafone K3700 & K3772-Z Dongles:
More details and instructions can be found here.
Diff: VodafoneUSBModem.cpp
- Revision:
- 26:d37501dc6c61
- Parent:
- 23:21046ba01b7b
- Child:
- 27:37d3ac289e86
diff -r 6f3b97dc4295 -r d37501dc6c61 VodafoneUSBModem.cpp --- 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() ) {