Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NyFileSystems libMiMic mbed-rtos mbed
main.cpp
- Committer:
- nyatla
- Date:
- 2013-06-20
- Revision:
- 12:218b57d9a6d4
- Parent:
- 10:80c05810f911
- Child:
- 19:66d729b94d16
File content as of revision 12:218b57d9a6d4:
/**
* @file * This is ModLocalFileSystem sample program.
*
* <pre>
* 1. Compile this program and write to your mbed.
* 2. Write files for testing to mbed disk.
* 2. Access via web browser to http://192.168.0.39/local/<filename>
* 3. You can see <filename> file on browser.
* </pre>
*/
#include "mbed.h"
#include "SDFileSystem.h"
#include "mimic.h"
#include "utils/PlatformInfo.h"
DigitalOut mbedled(LED1);
DigitalOut lpcxled(P0_22);
/**
* local filesystem support.
*/
LocalFileSystem2 lf("local");
SDFileSystem sd(p5, p6, p7, p8,"sd");
unsigned int p;
/**
* MiMic RemoteMCU httpd.<br/>
* Number of simultaneous connections:4
* <p>Service list</p>
* <pre>
* /local/ - mbed LocalFileSystem
* </pre>
*/
class FsHttpd:public MiMic::Httpd
{
private:
ModLocalFileSystem modlocal;
ModLocalFileSystem modsd;
public:
FsHttpd(NetConfig& i_cfg):Httpd(i_cfg._inst.services.http_port)
{
//bind local file system path to /local/*
modlocal.setParam("local");
modsd.setParam("sd");
}
virtual void onRequest(HttpdConnection& i_connection)
{
p++;
switch(PlatformInfo::getPlatformType()){
case PlatformInfo::PF_MBED:
mbedled = p%2;
break;
case PlatformInfo::PF_LPCXPRESSO:
lpcxled = p%2;
break;
}
//try to ModLocalFileSystem
if(this->modlocal.execute(i_connection)){
return;
}
//try to ModLocalFileSystem(SD)
if(this->modsd.execute(i_connection)){
return;
}
//Otherwise, Send simple top index page.
i_connection.sendHeader(200,"text/html",NULL);
if(i_connection.isMethodType(Http::MT_GET)){
i_connection.sendBodyF(
"<!DOCTYPE html>"
"<html lang=\"ja\">"
"<head></head>"
"<body>"
"<h1>This is MiMic Server!</h1>"
"<hr/>"
"<ul>"
"<li><a href=\"/local/\">mbed Local Filesystem</a></li>"
"<li><a href=\"/sd/\">SDCard</a></li>"
"</ul></body>");
}
}
};
NetConfig cfg; //create network configulation
int main()
{
Net net; //create a net instance.
//try to override setting by local file.
if(!cfg.loadFromFile("/local/mimic.cfg")){
wait_ms(1000);
cfg.loadFromFile("/sd/mimic.cfg");
}
FsHttpd httpd(cfg); //create a httpd instance.
net.start(cfg);
httpd.loop(); //start httpd loop.
return 0;
}