Oxford CWM Team / ESP8266_MDM_LIB

Dependents:   ESP8266_MDM_LIB

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ESP8266_mdm.h Source File

ESP8266_mdm.h

Go to the documentation of this file.
00001 /**
00002  *@section DESCRIPTION
00003  * ESP8266_mdm  Library
00004  * This sets up the ESP8266 as a server or client.
00005  * It detect \r\n sequence from the ESP8266 to chunk the response into lines. This then drives a state machine.
00006  *@section LICENSE
00007  * Copyright (c) 2016, Malcolm McCulloch
00008  *
00009  * Permission is hereby granted, free of charge, to any person obtaining a copy
00010  * of this software and associated documentation files (the "Software"), to deal
00011  * in the Software without restriction, including without limitation the rights
00012  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013  * copies of the Software, and to permit persons to whom the Software is
00014  * furnished to do so, subject to the following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included in
00017  * all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025  * THE SOFTWARE.
00026  * @file "ESP8266_mdm.h"
00027  */
00028 #ifndef ESP8266_MDM_H
00029 #define ESP8266_MDM_H
00030 #include <mbed.h>
00031 #define FUNCNAME "ESP8266_mdm"
00032 #include "defs.h "
00033 
00034 #define BUFF_SIZE 256
00035 
00036 /** \brief A library for the base of the solar nano grid controllers.
00037  *
00038  *   This library contains the code to drive batteries, hub etc.
00039  */
00040 class ESP8266_mdm
00041 {
00042 public:
00043 
00044     // *********************
00045     // * Public variables: *
00046     // *********************
00047 
00048     // *********************
00049     // * Public hardware: *
00050     // *********************
00051 
00052 
00053 
00054     // *********************
00055     // * Public interrupts: *
00056     // *********************
00057 
00058     // *********************
00059     // * Public functions: *
00060     // *********************
00061 
00062     /**
00063     * Constructor:
00064     * @param esp A pointer to the serial connection to the esp.
00065     * @param server =1 for server, 0 for client
00066     */
00067     ESP8266_mdm(RawSerial *esp, int server, RawSerial *pc, PinName rstPn);
00068     
00069     /**
00070     * Device has received a byte
00071     */
00072     void dev_recv();
00073 
00074 protected:
00075 
00076     
00077     // *********************
00078     // * Protected variables: *
00079     // *********************
00080     RawSerial *esp;        /**< The serial port */
00081     int server;         /**< Tells if server or not */
00082     RawSerial *pc;
00083     PinName rstPn;
00084     
00085     char **command;
00086     char **responseRequired;
00087     int maxState;
00088     
00089     volatile int state;
00090     volatile int ready;
00091     char* buffer;
00092     int bufferPnt;
00093     
00094 
00095     static  char* startCmnds[10];
00096     static  char* startResp[10];
00097     static  int startMaxState;
00098 
00099     int timeOut;
00100 
00101     // *********************
00102     // * Protected hardware: *
00103     // *********************
00104     DigitalOut* reset;
00105      Timer *last;
00106 
00107     // *********************
00108     // * Protected interrupts: *
00109     // *********************
00110 
00111 
00112     // *********************
00113     // * Protected functions: *
00114     // *********************
00115 
00116 
00117 
00118     /**
00119     * Loops through until state = maxState;
00120     */
00121     void doLoop(int initState);
00122 
00123     /**
00124     * Checks if pattern is in test. Returns 1 for true, 0 for no. -1 if busy. -2 ERROR
00125     *
00126     */
00127     int OKResponse(char *test, const char *pattern);
00128 
00129 };
00130 
00131 #endif