esp8266 websocket and socket

Committer:
metabi814
Date:
Fri Jun 12 10:06:12 2015 +0000
Revision:
0:46166e7d81a8
ESP8266 socket and websocket ; -set ip ; -set mac

Who changed what in which revision?

UserRevisionLine numberNew contents of line
metabi814 0:46166e7d81a8 1 /*
metabi814 0:46166e7d81a8 2 modem.h
metabi814 0:46166e7d81a8 3 2014 Copyright (c) Seeed Technology Inc. All right reserved.
metabi814 0:46166e7d81a8 4
metabi814 0:46166e7d81a8 5 Author:lawliet zou(lawliet.zou@gmail.com)
metabi814 0:46166e7d81a8 6 2014-2-24
metabi814 0:46166e7d81a8 7
metabi814 0:46166e7d81a8 8 This library is free software; you can redistribute it and/or
metabi814 0:46166e7d81a8 9 modify it under the terms of the GNU Lesser General Public
metabi814 0:46166e7d81a8 10 License as published by the Free Software Foundation; either
metabi814 0:46166e7d81a8 11 version 2.1 of the License, or (at your option) any later version.
metabi814 0:46166e7d81a8 12
metabi814 0:46166e7d81a8 13 This library is distributed in the hope that it will be useful,
metabi814 0:46166e7d81a8 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
metabi814 0:46166e7d81a8 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
metabi814 0:46166e7d81a8 16 Lesser General Public License for more details.
metabi814 0:46166e7d81a8 17
metabi814 0:46166e7d81a8 18 You should have received a copy of the GNU Lesser General Public
metabi814 0:46166e7d81a8 19 License along with this library; if not, write to the Free Software
metabi814 0:46166e7d81a8 20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
metabi814 0:46166e7d81a8 21 */
metabi814 0:46166e7d81a8 22
metabi814 0:46166e7d81a8 23 #ifndef __MODEM_H__
metabi814 0:46166e7d81a8 24 #define __MODEM_H__
metabi814 0:46166e7d81a8 25
metabi814 0:46166e7d81a8 26 #include "mbed.h"
metabi814 0:46166e7d81a8 27
metabi814 0:46166e7d81a8 28 #define DEFAULT_TIMEOUT 5
metabi814 0:46166e7d81a8 29
metabi814 0:46166e7d81a8 30 enum DataType {
metabi814 0:46166e7d81a8 31 CMD = 0,
metabi814 0:46166e7d81a8 32 DATA = 1,
metabi814 0:46166e7d81a8 33 };
metabi814 0:46166e7d81a8 34
metabi814 0:46166e7d81a8 35 /** Modem class.
metabi814 0:46166e7d81a8 36 * Used for Modem communication. attention that Modem module communicate with MCU in serial protocol
metabi814 0:46166e7d81a8 37 */
metabi814 0:46166e7d81a8 38 class Modem
metabi814 0:46166e7d81a8 39 {
metabi814 0:46166e7d81a8 40
metabi814 0:46166e7d81a8 41 public:
metabi814 0:46166e7d81a8 42 /** Create Modem Instance
metabi814 0:46166e7d81a8 43 * @param tx uart transmit pin to communicate with Modem
metabi814 0:46166e7d81a8 44 * @param rx uart receive pin to communicate with Modem
metabi814 0:46166e7d81a8 45 * @param baudRate baud rate of uart communication
metabi814 0:46166e7d81a8 46 */
metabi814 0:46166e7d81a8 47 Modem(PinName tx, PinName rx, int baudRate) : serialModem(tx, rx) {
metabi814 0:46166e7d81a8 48 serialModem.baud(baudRate);
metabi814 0:46166e7d81a8 49 };
metabi814 0:46166e7d81a8 50
metabi814 0:46166e7d81a8 51 Serial serialModem;
metabi814 0:46166e7d81a8 52 protected:
metabi814 0:46166e7d81a8 53 /** Power on Modem
metabi814 0:46166e7d81a8 54 */
metabi814 0:46166e7d81a8 55 void preInit(void);
metabi814 0:46166e7d81a8 56
metabi814 0:46166e7d81a8 57 /** check serialModem is readable or not
metabi814 0:46166e7d81a8 58 * @returns
metabi814 0:46166e7d81a8 59 * true on readable
metabi814 0:46166e7d81a8 60 * false on not readable
metabi814 0:46166e7d81a8 61 */
metabi814 0:46166e7d81a8 62 bool readable();
metabi814 0:46166e7d81a8 63
metabi814 0:46166e7d81a8 64 /** read one byte from serialModem
metabi814 0:46166e7d81a8 65 * @returns
metabi814 0:46166e7d81a8 66 * one byte read from serialModem
metabi814 0:46166e7d81a8 67 */
metabi814 0:46166e7d81a8 68 char readByte(void);
metabi814 0:46166e7d81a8 69
metabi814 0:46166e7d81a8 70 /** read from Modem module and save to buffer array
metabi814 0:46166e7d81a8 71 * @param buffer buffer array to save what read from Modem module
metabi814 0:46166e7d81a8 72 * @param count the maximal bytes number read from Modem module
metabi814 0:46166e7d81a8 73 * @param timeOut time to wait for reading from Modem module
metabi814 0:46166e7d81a8 74 * @returns
metabi814 0:46166e7d81a8 75 * 0 on success
metabi814 0:46166e7d81a8 76 * -1 on error
metabi814 0:46166e7d81a8 77 */
metabi814 0:46166e7d81a8 78 int readBuffer(char* buffer,int count, unsigned int timeOut);
metabi814 0:46166e7d81a8 79
metabi814 0:46166e7d81a8 80
metabi814 0:46166e7d81a8 81 /** clean Buffer
metabi814 0:46166e7d81a8 82 * @param buffer buffer to clean
metabi814 0:46166e7d81a8 83 * @param count number of bytes to clean
metabi814 0:46166e7d81a8 84 */
metabi814 0:46166e7d81a8 85 void cleanBuffer(char* buffer, int count);
metabi814 0:46166e7d81a8 86
metabi814 0:46166e7d81a8 87 /** send AT command to Modem module
metabi814 0:46166e7d81a8 88 * @param cmd command array which will be send to GPRS module
metabi814 0:46166e7d81a8 89 */
metabi814 0:46166e7d81a8 90 void sendCmd(const char* cmd);
metabi814 0:46166e7d81a8 91
metabi814 0:46166e7d81a8 92 /**send "AT" to Modem module
metabi814 0:46166e7d81a8 93 */
metabi814 0:46166e7d81a8 94 void sendATTest(void);
metabi814 0:46166e7d81a8 95
metabi814 0:46166e7d81a8 96 /** compare the response from GPRS module with a string
metabi814 0:46166e7d81a8 97 * @param resp buffer to be compared
metabi814 0:46166e7d81a8 98 * @param len length that will be compared
metabi814 0:46166e7d81a8 99 * @param timeout waiting seconds till timeout
metabi814 0:46166e7d81a8 100 */
metabi814 0:46166e7d81a8 101 bool respCmp(const char *resp, unsigned int len, unsigned int timeout);
metabi814 0:46166e7d81a8 102
metabi814 0:46166e7d81a8 103 /** check Modem module response before time out
metabi814 0:46166e7d81a8 104 * @param *resp correct response which Modem module will return
metabi814 0:46166e7d81a8 105 * @param *timeout waiting seconds till timeout
metabi814 0:46166e7d81a8 106 * @returns
metabi814 0:46166e7d81a8 107 * 0 on success
metabi814 0:46166e7d81a8 108 * -1 on error
metabi814 0:46166e7d81a8 109 */
metabi814 0:46166e7d81a8 110 int waitForResp(const char *resp, unsigned int timeout,DataType type);
metabi814 0:46166e7d81a8 111
metabi814 0:46166e7d81a8 112 /** send AT command to GPRS module and wait for correct response
metabi814 0:46166e7d81a8 113 * @param *cmd AT command which will be send to GPRS module
metabi814 0:46166e7d81a8 114 * @param *resp correct response which GPRS module will return
metabi814 0:46166e7d81a8 115 * @param *timeout waiting seconds till timeout
metabi814 0:46166e7d81a8 116 * @returns
metabi814 0:46166e7d81a8 117 * 0 on success
metabi814 0:46166e7d81a8 118 * -1 on error
metabi814 0:46166e7d81a8 119 */
metabi814 0:46166e7d81a8 120 int sendCmdAndWaitForResp(const char* data, const char *resp, unsigned timeout,DataType type);
metabi814 0:46166e7d81a8 121
metabi814 0:46166e7d81a8 122 Timer timeCnt;
metabi814 0:46166e7d81a8 123
metabi814 0:46166e7d81a8 124 private:
metabi814 0:46166e7d81a8 125
metabi814 0:46166e7d81a8 126 };
metabi814 0:46166e7d81a8 127
metabi814 0:46166e7d81a8 128 #endif