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.
at/ATCommandsInterface.h@59:593fb493172f, 2012-10-24 (annotated)
- Committer:
- donatien
- Date:
- Wed Oct 24 14:13:49 2012 +0000
- Revision:
- 59:593fb493172f
- Parent:
- 52:bd474c9fe51e
- Child:
- 79:a6ac8206a58d
- Disabling/Re-enabling of unsollicited response codes between commands to avoid having unsollicited result codes mixed up with commands responses; - Suppressed 100ms guard time in ATCommandsInterface; - Fixed race condition in ATCommandsInterface
Who changed what in which revision?
User | Revision | Line number | New 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 | |
donatien | 0:3b2f052c333b | 85 | bool isOpen(); |
donatien | 0:3b2f052c333b | 86 | |
donatien | 0:3b2f052c333b | 87 | class ATResult |
donatien | 0:3b2f052c333b | 88 | { |
donatien | 0:3b2f052c333b | 89 | public: |
donatien | 0:3b2f052c333b | 90 | enum { AT_OK, AT_ERROR, AT_CONNECT, AT_CMS_ERROR, AT_CME_ERROR } result; |
donatien | 0:3b2f052c333b | 91 | int code; |
donatien | 0:3b2f052c333b | 92 | }; |
donatien | 0:3b2f052c333b | 93 | |
donatien | 0:3b2f052c333b | 94 | int executeSimple(const char* command, ATResult* pResult, uint32_t timeout=1000); |
donatien | 0:3b2f052c333b | 95 | int execute(const char* command, IATCommandsProcessor* pProcessor, ATResult* pResult, uint32_t timeout=1000); |
donatien | 59:593fb493172f | 96 | |
donatien | 0:3b2f052c333b | 97 | int registerEventsHandler(IATEventsHandler* pHdlr); |
donatien | 0:3b2f052c333b | 98 | int deregisterEventsHandler(IATEventsHandler* pHdlr); |
donatien | 0:3b2f052c333b | 99 | |
donatien | 0:3b2f052c333b | 100 | //Commands that can be called during onNewATResponseLine callback, additionally to close() |
donatien | 0:3b2f052c333b | 101 | //Access to this method is protected (can ONLY be called on processing thread during IATCommandsProcessor::onNewATResponseLine execution) |
donatien | 0:3b2f052c333b | 102 | int sendData(const char* data); |
donatien | 0:3b2f052c333b | 103 | |
donatien | 0:3b2f052c333b | 104 | static void staticCallback(void const* p); |
donatien | 0:3b2f052c333b | 105 | private: |
donatien | 59:593fb493172f | 106 | int executeInternal(const char* command, IATCommandsProcessor* pProcessor, ATResult* pResult, uint32_t timeout=1000); |
donatien | 59:593fb493172f | 107 | |
donatien | 0:3b2f052c333b | 108 | int tryReadLine(); |
donatien | 0:3b2f052c333b | 109 | int trySendCommand(); |
donatien | 0:3b2f052c333b | 110 | int processReadLine(); |
donatien | 0:3b2f052c333b | 111 | int processEntryPrompt(); |
donatien | 59:593fb493172f | 112 | |
donatien | 59:593fb493172f | 113 | void enableEvents(); |
donatien | 59:593fb493172f | 114 | void disableEvents(); |
donatien | 0:3b2f052c333b | 115 | |
donatien | 0:3b2f052c333b | 116 | int ATResultToReturnCode(ATResult result); //Helper |
donatien | 0:3b2f052c333b | 117 | |
donatien | 0:3b2f052c333b | 118 | virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line); //Default implementation for simple commands handling |
donatien | 0:3b2f052c333b | 119 | virtual int onNewEntryPrompt(ATCommandsInterface* pInst); //Default implementation (just sends Ctrl+Z to exit the prompt) |
donatien | 0:3b2f052c333b | 120 | |
donatien | 0:3b2f052c333b | 121 | void process(); //Processing thread |
donatien | 0:3b2f052c333b | 122 | |
donatien | 0:3b2f052c333b | 123 | IOStream* m_pStream; |
ashleymills | 41:8bec5a8ea878 | 124 | |
ashleymills | 41:8bec5a8ea878 | 125 | bool m_open; //< TRUE when the AT interface is open, and FALSE when it is not. |
donatien | 0:3b2f052c333b | 126 | |
donatien | 0:3b2f052c333b | 127 | const char* m_transactionCommand; |
donatien | 0:3b2f052c333b | 128 | const char* m_transactionData; |
donatien | 0:3b2f052c333b | 129 | |
donatien | 0:3b2f052c333b | 130 | IATCommandsProcessor* m_pTransactionProcessor; |
donatien | 0:3b2f052c333b | 131 | ATResult m_transactionResult; |
donatien | 0:3b2f052c333b | 132 | |
donatien | 0:3b2f052c333b | 133 | enum { IDLE, COMMAND_SENT, READING_RESULT, ABORTED } m_transactionState; |
donatien | 0:3b2f052c333b | 134 | |
ashleymills | 52:bd474c9fe51e | 135 | char m_inputBuf[AT_INPUT_BUF_SIZE]; // Stores characters received from the modem. |
ashleymills | 52:bd474c9fe51e | 136 | int m_inputPos; // Current position of fill pointer in the input buffer. |
donatien | 0:3b2f052c333b | 137 | |
donatien | 0:3b2f052c333b | 138 | Mutex m_transactionMtx; |
donatien | 0:3b2f052c333b | 139 | |
ashleymills | 52:bd474c9fe51e | 140 | // These are RTOS queues, concurrent access protected. In this case both only contain an integer. |
ashleymills | 52:bd474c9fe51e | 141 | Mail<int,1> m_env2AT; // used by calling function to inform processing thread of events |
ashleymills | 52:bd474c9fe51e | 142 | Mail<int,1> m_AT2Env; // used by processing thread to inform calling function of events |
donatien | 0:3b2f052c333b | 143 | |
ashleymills | 52:bd474c9fe51e | 144 | IATEventsHandler* m_eventsHandlers[MAX_AT_EVENTS_HANDLERS]; // all registered events handlers |
donatien | 0:3b2f052c333b | 145 | |
donatien | 0:3b2f052c333b | 146 | Mutex m_processingMtx; |
donatien | 0:3b2f052c333b | 147 | Thread m_processingThread; |
donatien | 0:3b2f052c333b | 148 | |
donatien | 59:593fb493172f | 149 | Mutex m_eventsMgmtMtx; //Lock events use within the calling thread |
donatien | 59:593fb493172f | 150 | Mutex m_eventsProcessingMtx; //Lock events use within the processing thread |
donatien | 0:3b2f052c333b | 151 | }; |
donatien | 0:3b2f052c333b | 152 | |
donatien | 0:3b2f052c333b | 153 | #endif /* ATCOMMANDSINTERFACE_H_ */ |