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 Donatien Garnier

This is the driver for the Vodafone K3700 & K3772-Z Dongles:

K3770

More details and instructions can be found here.

Committer:
ashleymills
Date:
Fri Apr 25 13:33:55 2014 +0000
Revision:
95:84f01d280c9b
Parent:
83:897a0de9d668
Updated lwip to latest mbed version.; Removed useless debug function and messages.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:3b2f052c333b 1 /* ATCommandsInterface.h */
donatien 22:06fb2a93a1f6 2 /* Copyright (C) 2012 mbed.org, MIT License
donatien 22:06fb2a93a1f6 3 *
donatien 22:06fb2a93a1f6 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
donatien 22:06fb2a93a1f6 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
donatien 22:06fb2a93a1f6 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
donatien 22:06fb2a93a1f6 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
donatien 22:06fb2a93a1f6 8 * furnished to do so, subject to the following conditions:
donatien 22:06fb2a93a1f6 9 *
donatien 22:06fb2a93a1f6 10 * The above copyright notice and this permission notice shall be included in all copies or
donatien 22:06fb2a93a1f6 11 * substantial portions of the Software.
donatien 22:06fb2a93a1f6 12 *
donatien 22:06fb2a93a1f6 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
donatien 22:06fb2a93a1f6 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
donatien 22:06fb2a93a1f6 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
donatien 22:06fb2a93a1f6 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 22:06fb2a93a1f6 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
donatien 22:06fb2a93a1f6 18 */
donatien 0:3b2f052c333b 19
donatien 0:3b2f052c333b 20 #ifndef ATCOMMANDSINTERFACE_H_
donatien 0:3b2f052c333b 21 #define ATCOMMANDSINTERFACE_H_
donatien 0:3b2f052c333b 22
donatien 0:3b2f052c333b 23 #include "core/fwk.h"
donatien 0:3b2f052c333b 24 #include "rtos.h"
donatien 0:3b2f052c333b 25
donatien 16:02db4f537955 26 #define MAX_AT_EVENTS_HANDLERS 4
donatien 0:3b2f052c333b 27
donatien 0:3b2f052c333b 28 class ATCommandsInterface;
donatien 0:3b2f052c333b 29
donatien 0:3b2f052c333b 30 /** Interface implemented by components handling AT events
donatien 0:3b2f052c333b 31 *
donatien 0:3b2f052c333b 32 */
donatien 0:3b2f052c333b 33 class IATEventsHandler
donatien 0:3b2f052c333b 34 {
donatien 0:3b2f052c333b 35 protected:
donatien 0:3b2f052c333b 36 virtual bool isATCodeHandled(const char* atCode) = 0; //Is this AT code handled
donatien 0:3b2f052c333b 37 virtual void onDispatchStart() = 0;
donatien 0:3b2f052c333b 38 virtual void onDispatchStop() = 0;
donatien 59:593fb493172f 39 virtual char* getEventsEnableCommand() = 0;
donatien 59:593fb493172f 40 virtual char* getEventsDisableCommand() = 0;
donatien 0:3b2f052c333b 41 virtual void onEvent(const char* atCode, const char* evt) = 0;
donatien 0:3b2f052c333b 42 friend class ATCommandsInterface;
donatien 0:3b2f052c333b 43 };
donatien 0:3b2f052c333b 44
donatien 0:3b2f052c333b 45 /** Interface implemented by components executing complex AT commands
donatien 0:3b2f052c333b 46 *
donatien 0:3b2f052c333b 47 */
donatien 0:3b2f052c333b 48 class IATCommandsProcessor
donatien 0:3b2f052c333b 49 {
donatien 0:3b2f052c333b 50 protected:
donatien 0:3b2f052c333b 51 virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line) = 0;
donatien 0:3b2f052c333b 52 virtual int onNewEntryPrompt(ATCommandsInterface* pInst) = 0;
donatien 0:3b2f052c333b 53 friend class ATCommandsInterface;
donatien 0:3b2f052c333b 54 };
donatien 0:3b2f052c333b 55
donatien 50:8ad4cb12749d 56 #define AT_INPUT_BUF_SIZE 192//64
donatien 0:3b2f052c333b 57
donatien 0:3b2f052c333b 58 //Signals to be sent to the processing thread
donatien 0:3b2f052c333b 59 #define AT_SIG_PROCESSING_START 1
donatien 0:3b2f052c333b 60 #define AT_SIG_PROCESSING_STOP 2
donatien 0:3b2f052c333b 61 //Messages to be sent to the processing thread
donatien 0:3b2f052c333b 62 #define AT_CMD_READY 1
donatien 0:3b2f052c333b 63 #define AT_TIMEOUT 2
donatien 0:3b2f052c333b 64 #define AT_STOP 3
donatien 0:3b2f052c333b 65 //Messages to be sent from the processing thread
donatien 0:3b2f052c333b 66 #define AT_RESULT_READY 1
donatien 0:3b2f052c333b 67
donatien 0:3b2f052c333b 68 /** AT Commands interface class
donatien 0:3b2f052c333b 69 *
donatien 0:3b2f052c333b 70 */
donatien 0:3b2f052c333b 71 class ATCommandsInterface : protected IATCommandsProcessor
donatien 0:3b2f052c333b 72 {
donatien 0:3b2f052c333b 73 public:
donatien 0:3b2f052c333b 74 ATCommandsInterface(IOStream* pStream);
donatien 0:3b2f052c333b 75
donatien 0:3b2f052c333b 76 //Open connection to AT Interface in order to execute command & register/unregister events
donatien 0:3b2f052c333b 77 int open();
donatien 0:3b2f052c333b 78
donatien 0:3b2f052c333b 79 //Initialize AT link
donatien 0:3b2f052c333b 80 int init();
donatien 0:3b2f052c333b 81
donatien 0:3b2f052c333b 82 //Close connection
donatien 0:3b2f052c333b 83 int close();
donatien 0:3b2f052c333b 84
ashleymills 79:a6ac8206a58d 85 // pause at processing
ashleymills 79:a6ac8206a58d 86 void pause();
ashleymills 79:a6ac8206a58d 87 void restart();
ashleymills 79:a6ac8206a58d 88
donatien 0:3b2f052c333b 89 bool isOpen();
donatien 0:3b2f052c333b 90
donatien 0:3b2f052c333b 91 class ATResult
donatien 0:3b2f052c333b 92 {
donatien 0:3b2f052c333b 93 public:
donatien 0:3b2f052c333b 94 enum { AT_OK, AT_ERROR, AT_CONNECT, AT_CMS_ERROR, AT_CME_ERROR } result;
donatien 0:3b2f052c333b 95 int code;
donatien 0:3b2f052c333b 96 };
donatien 0:3b2f052c333b 97
donatien 0:3b2f052c333b 98 int executeSimple(const char* command, ATResult* pResult, uint32_t timeout=1000);
donatien 0:3b2f052c333b 99 int execute(const char* command, IATCommandsProcessor* pProcessor, ATResult* pResult, uint32_t timeout=1000);
donatien 59:593fb493172f 100
donatien 0:3b2f052c333b 101 int registerEventsHandler(IATEventsHandler* pHdlr);
donatien 0:3b2f052c333b 102 int deregisterEventsHandler(IATEventsHandler* pHdlr);
donatien 0:3b2f052c333b 103
donatien 0:3b2f052c333b 104 //Commands that can be called during onNewATResponseLine callback, additionally to close()
donatien 0:3b2f052c333b 105 //Access to this method is protected (can ONLY be called on processing thread during IATCommandsProcessor::onNewATResponseLine execution)
donatien 0:3b2f052c333b 106 int sendData(const char* data);
donatien 0:3b2f052c333b 107
donatien 0:3b2f052c333b 108 static void staticCallback(void const* p);
donatien 0:3b2f052c333b 109 private:
donatien 59:593fb493172f 110 int executeInternal(const char* command, IATCommandsProcessor* pProcessor, ATResult* pResult, uint32_t timeout=1000);
donatien 59:593fb493172f 111
donatien 0:3b2f052c333b 112 int tryReadLine();
donatien 0:3b2f052c333b 113 int trySendCommand();
donatien 0:3b2f052c333b 114 int processReadLine();
donatien 0:3b2f052c333b 115 int processEntryPrompt();
donatien 59:593fb493172f 116
donatien 59:593fb493172f 117 void enableEvents();
donatien 59:593fb493172f 118 void disableEvents();
donatien 0:3b2f052c333b 119
donatien 0:3b2f052c333b 120 int ATResultToReturnCode(ATResult result); //Helper
donatien 0:3b2f052c333b 121
donatien 0:3b2f052c333b 122 virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line); //Default implementation for simple commands handling
donatien 0:3b2f052c333b 123 virtual int onNewEntryPrompt(ATCommandsInterface* pInst); //Default implementation (just sends Ctrl+Z to exit the prompt)
donatien 0:3b2f052c333b 124
donatien 0:3b2f052c333b 125 void process(); //Processing thread
donatien 0:3b2f052c333b 126
donatien 0:3b2f052c333b 127 IOStream* m_pStream;
ashleymills 41:8bec5a8ea878 128
ashleymills 41:8bec5a8ea878 129 bool m_open; //< TRUE when the AT interface is open, and FALSE when it is not.
donatien 0:3b2f052c333b 130
donatien 0:3b2f052c333b 131 const char* m_transactionCommand;
donatien 0:3b2f052c333b 132 const char* m_transactionData;
donatien 0:3b2f052c333b 133
donatien 0:3b2f052c333b 134 IATCommandsProcessor* m_pTransactionProcessor;
donatien 0:3b2f052c333b 135 ATResult m_transactionResult;
donatien 0:3b2f052c333b 136
donatien 0:3b2f052c333b 137 enum { IDLE, COMMAND_SENT, READING_RESULT, ABORTED } m_transactionState;
donatien 0:3b2f052c333b 138
ashleymills 52:bd474c9fe51e 139 char m_inputBuf[AT_INPUT_BUF_SIZE]; // Stores characters received from the modem.
ashleymills 52:bd474c9fe51e 140 int m_inputPos; // Current position of fill pointer in the input buffer.
donatien 0:3b2f052c333b 141
ashleymills 83:897a0de9d668 142 Mutex m_transactionMtx; // used to lock access to the serial stream sending AT commands
donatien 0:3b2f052c333b 143
ashleymills 52:bd474c9fe51e 144 // These are RTOS queues, concurrent access protected. In this case both only contain an integer.
ashleymills 52:bd474c9fe51e 145 Mail<int,1> m_env2AT; // used by calling function to inform processing thread of events
ashleymills 52:bd474c9fe51e 146 Mail<int,1> m_AT2Env; // used by processing thread to inform calling function of events
donatien 0:3b2f052c333b 147
ashleymills 52:bd474c9fe51e 148 IATEventsHandler* m_eventsHandlers[MAX_AT_EVENTS_HANDLERS]; // all registered events handlers
donatien 0:3b2f052c333b 149
ashleymills 83:897a0de9d668 150 Mutex m_processingMtx; // not sure why you need a lock for the processing thread, as nobody else accesses it
ashleymills 83:897a0de9d668 151 Thread m_processingThread; // this is the at parsing thread, i.e the function process()
donatien 0:3b2f052c333b 152
ashleymills 79:a6ac8206a58d 153 Mutex m_eventsMgmtMtx; // locks access to event handler management (adding/removing handlers)
donatien 59:593fb493172f 154 Mutex m_eventsProcessingMtx; //Lock events use within the processing thread
donatien 0:3b2f052c333b 155 };
donatien 0:3b2f052c333b 156
donatien 0:3b2f052c333b 157 #endif /* ATCOMMANDSINTERFACE_H_ */