A library to operate the ESP8266

Dependents:   ESP8266_MDM_LIB

Committer:
epgmdm
Date:
Tue May 23 10:26:19 2017 +0000
Revision:
0:011fdf85bfc8
A working version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
epgmdm 0:011fdf85bfc8 1 /**
epgmdm 0:011fdf85bfc8 2 *@section DESCRIPTION
epgmdm 0:011fdf85bfc8 3 * ESP8266_mdm Library
epgmdm 0:011fdf85bfc8 4 * This sets up the ESP8266 as a server or client.
epgmdm 0:011fdf85bfc8 5 * It detect \r\n sequence from the ESP8266 to chunk the response into lines. This then drives a state machine.
epgmdm 0:011fdf85bfc8 6 *@section LICENSE
epgmdm 0:011fdf85bfc8 7 * Copyright (c) 2016, Malcolm McCulloch
epgmdm 0:011fdf85bfc8 8 *
epgmdm 0:011fdf85bfc8 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
epgmdm 0:011fdf85bfc8 10 * of this software and associated documentation files (the "Software"), to deal
epgmdm 0:011fdf85bfc8 11 * in the Software without restriction, including without limitation the rights
epgmdm 0:011fdf85bfc8 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
epgmdm 0:011fdf85bfc8 13 * copies of the Software, and to permit persons to whom the Software is
epgmdm 0:011fdf85bfc8 14 * furnished to do so, subject to the following conditions:
epgmdm 0:011fdf85bfc8 15 *
epgmdm 0:011fdf85bfc8 16 * The above copyright notice and this permission notice shall be included in
epgmdm 0:011fdf85bfc8 17 * all copies or substantial portions of the Software.
epgmdm 0:011fdf85bfc8 18 *
epgmdm 0:011fdf85bfc8 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
epgmdm 0:011fdf85bfc8 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
epgmdm 0:011fdf85bfc8 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
epgmdm 0:011fdf85bfc8 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
epgmdm 0:011fdf85bfc8 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
epgmdm 0:011fdf85bfc8 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
epgmdm 0:011fdf85bfc8 25 * THE SOFTWARE.
epgmdm 0:011fdf85bfc8 26 * @file "ESP8266_mdm.h"
epgmdm 0:011fdf85bfc8 27 */
epgmdm 0:011fdf85bfc8 28 #ifndef ESP8266_MDM_H
epgmdm 0:011fdf85bfc8 29 #define ESP8266_MDM_H
epgmdm 0:011fdf85bfc8 30 #include <mbed.h>
epgmdm 0:011fdf85bfc8 31 #define FUNCNAME "ESP8266_mdm"
epgmdm 0:011fdf85bfc8 32 #include "defs.h"
epgmdm 0:011fdf85bfc8 33
epgmdm 0:011fdf85bfc8 34 #define BUFF_SIZE 256
epgmdm 0:011fdf85bfc8 35
epgmdm 0:011fdf85bfc8 36 /** \brief A library for the base of the solar nano grid controllers.
epgmdm 0:011fdf85bfc8 37 *
epgmdm 0:011fdf85bfc8 38 * This library contains the code to drive batteries, hub etc.
epgmdm 0:011fdf85bfc8 39 */
epgmdm 0:011fdf85bfc8 40 class ESP8266_mdm
epgmdm 0:011fdf85bfc8 41 {
epgmdm 0:011fdf85bfc8 42 public:
epgmdm 0:011fdf85bfc8 43
epgmdm 0:011fdf85bfc8 44 // *********************
epgmdm 0:011fdf85bfc8 45 // * Public variables: *
epgmdm 0:011fdf85bfc8 46 // *********************
epgmdm 0:011fdf85bfc8 47
epgmdm 0:011fdf85bfc8 48 // *********************
epgmdm 0:011fdf85bfc8 49 // * Public hardware: *
epgmdm 0:011fdf85bfc8 50 // *********************
epgmdm 0:011fdf85bfc8 51
epgmdm 0:011fdf85bfc8 52
epgmdm 0:011fdf85bfc8 53
epgmdm 0:011fdf85bfc8 54 // *********************
epgmdm 0:011fdf85bfc8 55 // * Public interrupts: *
epgmdm 0:011fdf85bfc8 56 // *********************
epgmdm 0:011fdf85bfc8 57
epgmdm 0:011fdf85bfc8 58 // *********************
epgmdm 0:011fdf85bfc8 59 // * Public functions: *
epgmdm 0:011fdf85bfc8 60 // *********************
epgmdm 0:011fdf85bfc8 61
epgmdm 0:011fdf85bfc8 62 /**
epgmdm 0:011fdf85bfc8 63 * Constructor:
epgmdm 0:011fdf85bfc8 64 * @param esp A pointer to the serial connection to the esp.
epgmdm 0:011fdf85bfc8 65 * @param server =1 for server, 0 for client
epgmdm 0:011fdf85bfc8 66 */
epgmdm 0:011fdf85bfc8 67 ESP8266_mdm(RawSerial *esp, int server, RawSerial *pc, PinName rstPn);
epgmdm 0:011fdf85bfc8 68
epgmdm 0:011fdf85bfc8 69 /**
epgmdm 0:011fdf85bfc8 70 * Device has received a byte
epgmdm 0:011fdf85bfc8 71 */
epgmdm 0:011fdf85bfc8 72 void dev_recv();
epgmdm 0:011fdf85bfc8 73
epgmdm 0:011fdf85bfc8 74 protected:
epgmdm 0:011fdf85bfc8 75
epgmdm 0:011fdf85bfc8 76
epgmdm 0:011fdf85bfc8 77 // *********************
epgmdm 0:011fdf85bfc8 78 // * Protected variables: *
epgmdm 0:011fdf85bfc8 79 // *********************
epgmdm 0:011fdf85bfc8 80 RawSerial *esp; /**< The serial port */
epgmdm 0:011fdf85bfc8 81 int server; /**< Tells if server or not */
epgmdm 0:011fdf85bfc8 82 RawSerial *pc;
epgmdm 0:011fdf85bfc8 83 PinName rstPn;
epgmdm 0:011fdf85bfc8 84
epgmdm 0:011fdf85bfc8 85 char **command;
epgmdm 0:011fdf85bfc8 86 char **responseRequired;
epgmdm 0:011fdf85bfc8 87 int maxState;
epgmdm 0:011fdf85bfc8 88
epgmdm 0:011fdf85bfc8 89 volatile int state;
epgmdm 0:011fdf85bfc8 90 volatile int ready;
epgmdm 0:011fdf85bfc8 91 char* buffer;
epgmdm 0:011fdf85bfc8 92 int bufferPnt;
epgmdm 0:011fdf85bfc8 93
epgmdm 0:011fdf85bfc8 94
epgmdm 0:011fdf85bfc8 95 static char* startCmnds[10];
epgmdm 0:011fdf85bfc8 96 static char* startResp[10];
epgmdm 0:011fdf85bfc8 97 static int startMaxState;
epgmdm 0:011fdf85bfc8 98
epgmdm 0:011fdf85bfc8 99 int timeOut;
epgmdm 0:011fdf85bfc8 100
epgmdm 0:011fdf85bfc8 101 // *********************
epgmdm 0:011fdf85bfc8 102 // * Protected hardware: *
epgmdm 0:011fdf85bfc8 103 // *********************
epgmdm 0:011fdf85bfc8 104 DigitalOut* reset;
epgmdm 0:011fdf85bfc8 105 Timer *last;
epgmdm 0:011fdf85bfc8 106
epgmdm 0:011fdf85bfc8 107 // *********************
epgmdm 0:011fdf85bfc8 108 // * Protected interrupts: *
epgmdm 0:011fdf85bfc8 109 // *********************
epgmdm 0:011fdf85bfc8 110
epgmdm 0:011fdf85bfc8 111
epgmdm 0:011fdf85bfc8 112 // *********************
epgmdm 0:011fdf85bfc8 113 // * Protected functions: *
epgmdm 0:011fdf85bfc8 114 // *********************
epgmdm 0:011fdf85bfc8 115
epgmdm 0:011fdf85bfc8 116
epgmdm 0:011fdf85bfc8 117
epgmdm 0:011fdf85bfc8 118 /**
epgmdm 0:011fdf85bfc8 119 * Loops through until state = maxState;
epgmdm 0:011fdf85bfc8 120 */
epgmdm 0:011fdf85bfc8 121 void doLoop(int initState);
epgmdm 0:011fdf85bfc8 122
epgmdm 0:011fdf85bfc8 123 /**
epgmdm 0:011fdf85bfc8 124 * Checks if pattern is in test. Returns 1 for true, 0 for no. -1 if busy. -2 ERROR
epgmdm 0:011fdf85bfc8 125 *
epgmdm 0:011fdf85bfc8 126 */
epgmdm 0:011fdf85bfc8 127 int OKResponse(char *test, const char *pattern);
epgmdm 0:011fdf85bfc8 128
epgmdm 0:011fdf85bfc8 129 };
epgmdm 0:011fdf85bfc8 130
epgmdm 0:011fdf85bfc8 131 #endif