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
ATCommandsInterface.h
00001 /* ATCommandsInterface.h */ 00002 /* Copyright (C) 2012 mbed.org, MIT License 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00005 * and associated documentation files (the "Software"), to deal in the Software without restriction, 00006 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00007 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00008 * furnished to do so, subject to the following conditions: 00009 * 00010 * The above copyright notice and this permission notice shall be included in all copies or 00011 * substantial portions of the Software. 00012 * 00013 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00014 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00015 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00016 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00017 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00018 */ 00019 00020 #ifndef ATCOMMANDSINTERFACE_H_ 00021 #define ATCOMMANDSINTERFACE_H_ 00022 00023 #include "core/fwk.h" 00024 #include "rtos.h" 00025 00026 #define MAX_AT_EVENTS_HANDLERS 4 00027 00028 class ATCommandsInterface; 00029 00030 /** Interface implemented by components handling AT events 00031 * 00032 */ 00033 class IATEventsHandler 00034 { 00035 protected: 00036 virtual bool isATCodeHandled(const char* atCode) = 0; //Is this AT code handled 00037 virtual void onDispatchStart() = 0; 00038 virtual void onDispatchStop() = 0; 00039 virtual char* getEventsEnableCommand() = 0; 00040 virtual char* getEventsDisableCommand() = 0; 00041 virtual void onEvent(const char* atCode, const char* evt) = 0; 00042 friend class ATCommandsInterface; 00043 }; 00044 00045 /** Interface implemented by components executing complex AT commands 00046 * 00047 */ 00048 class IATCommandsProcessor 00049 { 00050 protected: 00051 virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line) = 0; 00052 virtual int onNewEntryPrompt(ATCommandsInterface* pInst) = 0; 00053 friend class ATCommandsInterface; 00054 }; 00055 00056 #define AT_INPUT_BUF_SIZE 192//64 00057 00058 //Signals to be sent to the processing thread 00059 #define AT_SIG_PROCESSING_START 1 00060 #define AT_SIG_PROCESSING_STOP 2 00061 //Messages to be sent to the processing thread 00062 #define AT_CMD_READY 1 00063 #define AT_TIMEOUT 2 00064 #define AT_STOP 3 00065 //Messages to be sent from the processing thread 00066 #define AT_RESULT_READY 1 00067 00068 /** AT Commands interface class 00069 * 00070 */ 00071 class ATCommandsInterface : protected IATCommandsProcessor 00072 { 00073 public: 00074 ATCommandsInterface(IOStream* pStream); 00075 00076 //Open connection to AT Interface in order to execute command & register/unregister events 00077 int open(); 00078 00079 //Initialize AT link 00080 int init(); 00081 00082 //Close connection 00083 int close(); 00084 00085 // pause at processing 00086 void pause(); 00087 void restart(); 00088 00089 bool isOpen(); 00090 00091 class ATResult 00092 { 00093 public: 00094 enum { AT_OK, AT_ERROR, AT_CONNECT, AT_CMS_ERROR, AT_CME_ERROR } result; 00095 int code; 00096 }; 00097 00098 int executeSimple(const char* command, ATResult* pResult, uint32_t timeout=1000); 00099 int execute(const char* command, IATCommandsProcessor* pProcessor, ATResult* pResult, uint32_t timeout=1000); 00100 00101 int registerEventsHandler(IATEventsHandler* pHdlr); 00102 int deregisterEventsHandler(IATEventsHandler* pHdlr); 00103 00104 //Commands that can be called during onNewATResponseLine callback, additionally to close() 00105 //Access to this method is protected (can ONLY be called on processing thread during IATCommandsProcessor::onNewATResponseLine execution) 00106 int sendData(const char* data); 00107 00108 static void staticCallback(void const* p); 00109 private: 00110 int executeInternal(const char* command, IATCommandsProcessor* pProcessor, ATResult* pResult, uint32_t timeout=1000); 00111 00112 int tryReadLine(); 00113 int trySendCommand(); 00114 int processReadLine(); 00115 int processEntryPrompt(); 00116 00117 void enableEvents(); 00118 void disableEvents(); 00119 00120 int ATResultToReturnCode(ATResult result); //Helper 00121 00122 virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line); //Default implementation for simple commands handling 00123 virtual int onNewEntryPrompt(ATCommandsInterface* pInst); //Default implementation (just sends Ctrl+Z to exit the prompt) 00124 00125 void process(); //Processing thread 00126 00127 IOStream* m_pStream; 00128 00129 bool m_open; //< TRUE when the AT interface is open, and FALSE when it is not. 00130 00131 const char* m_transactionCommand; 00132 const char* m_transactionData; 00133 00134 IATCommandsProcessor* m_pTransactionProcessor; 00135 ATResult m_transactionResult; 00136 00137 enum { IDLE, COMMAND_SENT, READING_RESULT, ABORTED } m_transactionState; 00138 00139 char m_inputBuf[AT_INPUT_BUF_SIZE]; // Stores characters received from the modem. 00140 int m_inputPos; // Current position of fill pointer in the input buffer. 00141 00142 Mutex m_transactionMtx; // used to lock access to the serial stream sending AT commands 00143 00144 // These are RTOS queues, concurrent access protected. In this case both only contain an integer. 00145 Mail<int,1> m_env2AT; // used by calling function to inform processing thread of events 00146 Mail<int,1> m_AT2Env; // used by processing thread to inform calling function of events 00147 00148 IATEventsHandler* m_eventsHandlers[MAX_AT_EVENTS_HANDLERS]; // all registered events handlers 00149 00150 Mutex m_processingMtx; // not sure why you need a lock for the processing thread, as nobody else accesses it 00151 Thread m_processingThread; // this is the at parsing thread, i.e the function process() 00152 00153 Mutex m_eventsMgmtMtx; // locks access to event handler management (adding/removing handlers) 00154 Mutex m_eventsProcessingMtx; //Lock events use within the processing thread 00155 }; 00156 00157 #endif /* ATCOMMANDSINTERFACE_H_ */
Generated on Tue Jul 12 2022 12:11:27 by 1.7.2