This version has the index file and data pages on a SD card (512Mbyte) it does not suffer from the autorun problem when directly writtin to the mbed flash memory It makes readings from one solar panel for open and loaded voltages every 'interval' seconds Every readingsPerPage a new web page is created and indexed on a readings web page Activty is shown by the flashing blue led (0.5s) means it is connected and output via the serial over usb port. Data is preserved on subsequent power ups by incrementing file number. PMR 15/9/10 */

Dependencies:   EthernetNetIf NTPClient_NetServices mbed SDFileSystem

Committer:
pmr1
Date:
Sat Sep 18 13:31:41 2010 +0000
Revision:
0:d6b2d5c4c48f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmr1 0:d6b2d5c4c48f 1
pmr1 0:d6b2d5c4c48f 2 /*
pmr1 0:d6b2d5c4c48f 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
pmr1 0:d6b2d5c4c48f 4
pmr1 0:d6b2d5c4c48f 5 Permission is hereby granted, free of charge, to any person obtaining a copy
pmr1 0:d6b2d5c4c48f 6 of this software and associated documentation files (the "Software"), to deal
pmr1 0:d6b2d5c4c48f 7 in the Software without restriction, including without limitation the rights
pmr1 0:d6b2d5c4c48f 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pmr1 0:d6b2d5c4c48f 9 copies of the Software, and to permit persons to whom the Software is
pmr1 0:d6b2d5c4c48f 10 furnished to do so, subject to the following conditions:
pmr1 0:d6b2d5c4c48f 11
pmr1 0:d6b2d5c4c48f 12 The above copyright notice and this permission notice shall be included in
pmr1 0:d6b2d5c4c48f 13 all copies or substantial portions of the Software.
pmr1 0:d6b2d5c4c48f 14
pmr1 0:d6b2d5c4c48f 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pmr1 0:d6b2d5c4c48f 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pmr1 0:d6b2d5c4c48f 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pmr1 0:d6b2d5c4c48f 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pmr1 0:d6b2d5c4c48f 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pmr1 0:d6b2d5c4c48f 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pmr1 0:d6b2d5c4c48f 21 THE SOFTWARE.
pmr1 0:d6b2d5c4c48f 22 */
pmr1 0:d6b2d5c4c48f 23
pmr1 0:d6b2d5c4c48f 24 /**
pmr1 0:d6b2d5c4c48f 25 HTTP Request Handler header file.
pmr1 0:d6b2d5c4c48f 26 */
pmr1 0:d6b2d5c4c48f 27
pmr1 0:d6b2d5c4c48f 28 #ifndef HTTP_REQUEST_HANDLER_H
pmr1 0:d6b2d5c4c48f 29 #define HTTP_REQUEST_HANDLER_H
pmr1 0:d6b2d5c4c48f 30
pmr1 0:d6b2d5c4c48f 31 #include "api/TCPSocket.h"
pmr1 0:d6b2d5c4c48f 32 //#include "HTTPServer.h"
pmr1 0:d6b2d5c4c48f 33
pmr1 0:d6b2d5c4c48f 34 #include "mbed.h"
pmr1 0:d6b2d5c4c48f 35 #include "core/netservice.h"
pmr1 0:d6b2d5c4c48f 36
pmr1 0:d6b2d5c4c48f 37 #include <string>
pmr1 0:d6b2d5c4c48f 38 using std::string;
pmr1 0:d6b2d5c4c48f 39
pmr1 0:d6b2d5c4c48f 40 #include <map>
pmr1 0:d6b2d5c4c48f 41 using std::map;
pmr1 0:d6b2d5c4c48f 42
pmr1 0:d6b2d5c4c48f 43 ///HTTP Server's generic request handler
pmr1 0:d6b2d5c4c48f 44 class HTTPRequestHandler : public NetService
pmr1 0:d6b2d5c4c48f 45 {
pmr1 0:d6b2d5c4c48f 46 public:
pmr1 0:d6b2d5c4c48f 47 ///Instantiated by the HTTP Server
pmr1 0:d6b2d5c4c48f 48 HTTPRequestHandler(const char* rootPath, const char* path, TCPSocket* pTCPSocket);
pmr1 0:d6b2d5c4c48f 49 virtual ~HTTPRequestHandler();
pmr1 0:d6b2d5c4c48f 50
pmr1 0:d6b2d5c4c48f 51 //protected:
pmr1 0:d6b2d5c4c48f 52 virtual void doGet() = 0;
pmr1 0:d6b2d5c4c48f 53 virtual void doPost() = 0;
pmr1 0:d6b2d5c4c48f 54 virtual void doHead() = 0;
pmr1 0:d6b2d5c4c48f 55
pmr1 0:d6b2d5c4c48f 56 virtual void onReadable() = 0; //Data has been read
pmr1 0:d6b2d5c4c48f 57 virtual void onWriteable() = 0; //Data has been written & buf is free
pmr1 0:d6b2d5c4c48f 58 virtual void onTimeout(); //Connection has timed out
pmr1 0:d6b2d5c4c48f 59 virtual void onClose() = 0; //Connection is closing
pmr1 0:d6b2d5c4c48f 60
pmr1 0:d6b2d5c4c48f 61 virtual void close(); //Close socket and destroy data
pmr1 0:d6b2d5c4c48f 62
pmr1 0:d6b2d5c4c48f 63 protected:
pmr1 0:d6b2d5c4c48f 64 map<string, string>& reqHeaders() /*const*/;
pmr1 0:d6b2d5c4c48f 65 string& path() /*const*/;
pmr1 0:d6b2d5c4c48f 66 int dataLen() const;
pmr1 0:d6b2d5c4c48f 67 int readData(char* buf, int len);
pmr1 0:d6b2d5c4c48f 68 string& rootPath() /*const*/;
pmr1 0:d6b2d5c4c48f 69
pmr1 0:d6b2d5c4c48f 70 void setErrCode(int errc);
pmr1 0:d6b2d5c4c48f 71 void setContentLen(int len);
pmr1 0:d6b2d5c4c48f 72
pmr1 0:d6b2d5c4c48f 73 map<string, string>& respHeaders();
pmr1 0:d6b2d5c4c48f 74 int writeData(const char* buf, int len);
pmr1 0:d6b2d5c4c48f 75
pmr1 0:d6b2d5c4c48f 76 void setTimeout(int ms);
pmr1 0:d6b2d5c4c48f 77 void resetTimeout();
pmr1 0:d6b2d5c4c48f 78
pmr1 0:d6b2d5c4c48f 79 private:
pmr1 0:d6b2d5c4c48f 80 void readHeaders(); //Called at instanciation
pmr1 0:d6b2d5c4c48f 81 void writeHeaders(); //Called at the first writeData call
pmr1 0:d6b2d5c4c48f 82 void onTCPSocketEvent(TCPSocketEvent e);
pmr1 0:d6b2d5c4c48f 83
pmr1 0:d6b2d5c4c48f 84 TCPSocket* m_pTCPSocket;
pmr1 0:d6b2d5c4c48f 85 map<string, string> m_reqHeaders;
pmr1 0:d6b2d5c4c48f 86 map<string, string> m_respHeaders;
pmr1 0:d6b2d5c4c48f 87 string m_rootPath;
pmr1 0:d6b2d5c4c48f 88 string m_path;
pmr1 0:d6b2d5c4c48f 89 int m_errc; //Response code
pmr1 0:d6b2d5c4c48f 90
pmr1 0:d6b2d5c4c48f 91 Timeout m_watchdog;
pmr1 0:d6b2d5c4c48f 92 int m_timeout;
pmr1 0:d6b2d5c4c48f 93
pmr1 0:d6b2d5c4c48f 94 bool m_closed;
pmr1 0:d6b2d5c4c48f 95 bool m_headersSent;
pmr1 0:d6b2d5c4c48f 96
pmr1 0:d6b2d5c4c48f 97 int readLine(char* str, int maxLen);
pmr1 0:d6b2d5c4c48f 98
pmr1 0:d6b2d5c4c48f 99 };
pmr1 0:d6b2d5c4c48f 100
pmr1 0:d6b2d5c4c48f 101 #endif