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.
Revision 26:d37501dc6c61, committed 2012-08-29
- Comitter:
- donatien
- Date:
- Wed Aug 29 16:28:13 2012 +0000
- Parent:
- 25:6f3b97dc4295
- Child:
- 27:37d3ac289e86
- Commit message:
- Testing implementation of power gating
Changed in this revision
--- 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() ) {
--- a/VodafoneUSBModem.h Wed Aug 29 15:49:14 2012 +0000 +++ b/VodafoneUSBModem.h Wed Aug 29 16:28:13 2012 +0000 @@ -36,9 +36,9 @@ { public: /** Create Vodafone USB Modem (K3770/K3772-Z) dongle API instance - + @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line */ - VodafoneUSBModem(); + VodafoneUSBModem(PinName powerGatingPin = NC); //Internet-related functions @@ -92,11 +92,20 @@ int getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer); /** Get the ATCommandsInterface instance - @return Pointer to the ATCommandsInterface instance + @return Pointer to the ATCommandsInterface instance */ ATCommandsInterface* getATCommandsInterface(); + + /** Switch power on or off + In order to use this function, a pin name must have been entered in the constructor + @param enable true to switch the dongle on, false to switch it off + @return 0 on success, error code on failure + */ + int power(bool enable); protected: + bool power(); + int init(); private: @@ -119,6 +128,8 @@ bool m_ussdInit; bool m_linkMonitorInit; bool m_atOpen; + + PinName m_powerGatingPin; };
--- a/sms/SMSInterface.cpp Wed Aug 29 15:49:14 2012 +0000 +++ b/sms/SMSInterface.cpp Wed Aug 29 16:28:13 2012 +0000 @@ -30,14 +30,17 @@ #define DEFAULT_TIMEOUT 10000 -SMSInterface::SMSInterface(ATCommandsInterface* pIf) : m_pIf(pIf), m_msg(NULL), m_maxMsgLength(0), m_msisdn(NULL), /*m_msgCount(0),*/ -m_msgRefListCount(0), m_needsUpdate(true), m_state(SMS_IDLE) +SMSInterface::SMSInterface(ATCommandsInterface* pIf) : m_pIf(pIf), m_msg(NULL), m_maxMsgLength(0), m_msisdn(NULL) { m_pIf->registerEventsHandler(this); //Add us to the unsolicited result codes handlers } int SMSInterface::init() { + m_msgRefListCount = 0; + m_needsUpdate = true; + m_state = SMS_IDLE; + DBG("Set format"); //Set Text mode format int ret = m_pIf->executeSimple("AT+CMGF=1", NULL, DEFAULT_TIMEOUT);