serveur WEB sur carte SD pour TestBed , lit des tensions les met dans un fichier htm et l\'envoie . on peut agir sur les ES .

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HTTPled.h Source File

HTTPled.h

00001 #ifndef HTTPLED_H
00002 #define HTTPLED_H
00003 
00004 #include "HTTPServer.h"
00005 
00006  //  inspiration de staticpage , mais pour interagir avec la carte 
00007 //   on agit sur les e/s de la carte mbed , on finit en retournant une page  vide qui repointe en static 
00008 class HTTPledData : public HTTPData {
00009   public: int left;  };
00010 
00011 /**
00012  * This class Provide a Handler to send Static HTTP Pages from the bin file.
00013  */
00014 class HTTPled : public HTTPHandler {
00015   public:
00016     /**
00017      * Constructer takes the pagename and the pagedata.
00018      * As long as the pagedata is NULL terminated you have not to tell the data length.
00019      * But if you want to send binary data you should tell us the size.
00020      */
00021   
00022     HTTPled(const char *path, const char *page, int length = 0)
00023      : HTTPHandler(path), _page(page) {
00024       _size = (length)?length:strlen(_page);
00025     }
00026 
00027     HTTPled(HTTPServer *server, const char *path, const char *page, int length = 0)
00028      : HTTPHandler(path), _page(page) {
00029       _size = (length)?length:strlen(_page);
00030       server->addHandler(this);
00031     }
00032 
00033   private:
00034     /**
00035      * A this Static Page is requested!
00036      * Prepare a datastorage helper "HTTPledHelper" to store the left data size.
00037      * And return HTTP_OK
00038      */
00039     virtual HTTPStatus init(HTTPConnection *con) const {
00040       HTTPledData *data = new HTTPledData();
00041       con->data = data;
00042       data->left = _size;
00043       con->setLength(_size);
00044       return HTTP_OK;
00045     }
00046 
00047     /**
00048      * Send the maximum data out to the client. 
00049      * If the file is complete transmitted close connection by returning HTTP_SuccessEnded
00050      */
00051     virtual HTTPHandle send(HTTPConnection *con, int maximum) const {
00052       HTTPledData *data = static_cast<HTTPledData *>(con->data);
00053       int len = min(maximum, data->left);
00054       err_t err;
00055       led5 = !led5;               // la on fait du travail sur les e/s
00056       do {
00057         err = con->write((void*)&_page[_size - data->left], len, 1);
00058         if(err == ERR_MEM) {
00059           len >>= 1;
00060         }
00061       } while(err == ERR_MEM && len > 1);
00062       if(err == ERR_OK) {
00063         data->left -= len;
00064       }
00065       return (data->left)? HTTP_Success : HTTP_SuccessEnded;
00066     }
00067 
00068     /** Pointer to the page data */
00069     const char *_page;
00070     
00071     /** page data size*/
00072     int   _size;
00073 };
00074 
00075 #endif