Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ATCommandsInterface.h
00001 /* ATCommandsInterface.h */ 00002 /* 00003 Copyright (C) 2012 ARM Limited. 00004 00005 Permission is hereby granted, free of charge, to any person obtaining a copy of 00006 this software and associated documentation files (the "Software"), to deal in 00007 the Software without restriction, including without limitation the rights to 00008 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 00009 of the Software, and to permit persons to whom the Software is furnished to do 00010 so, subject to the following conditions: 00011 00012 The above copyright notice and this permission notice shall be included in all 00013 copies or substantial portions of the Software. 00014 00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00021 SOFTWARE. 00022 */ 00023 00024 #ifndef ATCOMMANDSINTERFACE_H_ 00025 #define ATCOMMANDSINTERFACE_H_ 00026 00027 #include "core/fwk.h" 00028 #include "rtos.h" 00029 00030 #define MAX_AT_EVENTS_HANDLERS 8 00031 00032 class ATCommandsInterface; 00033 00034 /** Interface implemented by components handling AT events 00035 * 00036 */ 00037 class IATEventsHandler 00038 { 00039 protected: 00040 virtual bool isATCodeHandled(const char* atCode) = 0; //Is this AT code handled 00041 virtual void onDispatchStart() = 0; 00042 virtual void onDispatchStop() = 0; 00043 virtual void onEvent(const char* atCode, const char* evt) = 0; 00044 friend class ATCommandsInterface; 00045 }; 00046 00047 /** Interface implemented by components executing complex AT commands 00048 * 00049 */ 00050 class IATCommandsProcessor 00051 { 00052 protected: 00053 virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line) = 0; 00054 virtual int onNewEntryPrompt(ATCommandsInterface* pInst) = 0; 00055 friend class ATCommandsInterface; 00056 }; 00057 00058 #define AT_INPUT_BUF_SIZE 64 00059 00060 //Signals to be sent to the processing thread 00061 #define AT_SIG_PROCESSING_START 1 00062 #define AT_SIG_PROCESSING_STOP 2 00063 //Messages to be sent to the processing thread 00064 #define AT_CMD_READY 1 00065 #define AT_TIMEOUT 2 00066 #define AT_STOP 3 00067 //Messages to be sent from the processing thread 00068 #define AT_RESULT_READY 1 00069 00070 /** AT Commands interface class 00071 * 00072 */ 00073 class ATCommandsInterface : protected IATCommandsProcessor 00074 { 00075 public: 00076 ATCommandsInterface(IOStream* pStream); 00077 00078 //Open connection to AT Interface in order to execute command & register/unregister events 00079 int open(); 00080 00081 //Initialize AT link 00082 int init(); 00083 00084 //Close connection 00085 int close(); 00086 00087 bool isOpen(); 00088 00089 class ATResult 00090 { 00091 public: 00092 enum { AT_OK, AT_ERROR, AT_CONNECT, AT_CMS_ERROR, AT_CME_ERROR } result; 00093 int code; 00094 }; 00095 00096 int executeSimple(const char* command, ATResult* pResult, uint32_t timeout=1000); 00097 int execute(const char* command, IATCommandsProcessor* pProcessor, ATResult* pResult, uint32_t timeout=1000); 00098 int registerEventsHandler(IATEventsHandler* pHdlr); 00099 int deregisterEventsHandler(IATEventsHandler* pHdlr); 00100 00101 //Commands that can be called during onNewATResponseLine callback, additionally to close() 00102 //Access to this method is protected (can ONLY be called on processing thread during IATCommandsProcessor::onNewATResponseLine execution) 00103 int sendData(const char* data); 00104 00105 static void staticCallback(void const* p); 00106 private: 00107 int tryReadLine(); 00108 int trySendCommand(); 00109 int processReadLine(); 00110 int processEntryPrompt(); 00111 00112 int ATResultToReturnCode(ATResult result); //Helper 00113 00114 virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line); //Default implementation for simple commands handling 00115 virtual int onNewEntryPrompt(ATCommandsInterface* pInst); //Default implementation (just sends Ctrl+Z to exit the prompt) 00116 00117 void process(); //Processing thread 00118 00119 IOStream* m_pStream; 00120 bool m_open; 00121 00122 const char* m_transactionCommand; 00123 const char* m_transactionData; 00124 00125 IATCommandsProcessor* m_pTransactionProcessor; 00126 ATResult m_transactionResult; 00127 00128 enum { IDLE, COMMAND_SENT, READING_RESULT, ABORTED } m_transactionState; 00129 00130 char m_inputBuf[AT_INPUT_BUF_SIZE]; 00131 int m_inputPos; 00132 00133 Mutex m_transactionMtx; 00134 00135 Mail<int,1> m_env2AT; 00136 Mail<int,1> m_AT2Env; 00137 00138 IATEventsHandler* m_eventsHandlers[MAX_AT_EVENTS_HANDLERS]; 00139 00140 Mutex m_processingMtx; 00141 Thread m_processingThread; 00142 00143 Mutex m_eventsMtx; 00144 }; 00145 00146 #endif /* ATCOMMANDSINTERFACE_H_ */
Generated on Tue Jul 12 2022 17:50:55 by
