local fork

Dependencies:   Socket USBHostWANDongle_bleedingedge lwip-sys lwip

Dependents:   Encrypted

Fork of VodafoneUSBModem_bleedingedge by Donatien Garnier

Committer:
donatien
Date:
Thu May 24 16:40:40 2012 +0000
Revision:
0:3b2f052c333b
Initial Commit

Who changed what in which revision?

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