USB Host Library for Sprint Dongles

Dependencies:   Socket USBHostWANDongleSprint lwip-sys lwip

Dependents:   SprintUSBModemWebsocketTest SprintUSBModemHTTPClientTest SprintUSBModemNTPClientTest SprintUSBModemSMSTest ... more

Fork of SprintUSBModem_bleedingedge by Donatien Garnier

Committer:
donatien
Date:
Mon Dec 10 18:23:49 2012 +0000
Revision:
14:f6f17843e5ef
Parent:
10:35496211da8f
Separate USB/Sprint dev flows, fix regression in mbed rev. 41+ lib

Who changed what in which revision?

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