Y SI / Mbed OS lib_Transmission_TCP_example

Dependencies:   lib_Transmission

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "main.h"
00002 
00003 int main(void)
00004 {
00005     transmission.ip(true, "192.168.1.25", 80);
00006     while(1) Led = transmission.recv();
00007 }
00008 
00009 string transmission_processing(string cmd)
00010 {
00011     pc.write(cmd.c_str(), cmd.size());
00012     ostringstream ssend;
00013     ssend << fixed;
00014     ssend.precision(2);
00015     if(cmd.empty());
00016     else if(cmd == "*IDN?")
00017         ssend << MBED_PROJECT << ", Mbed OS " << MBED_VERSION << ", Version dated, " << __DATE__ << ", " << __TIME__;
00018     else if(cmd == "IP?")
00019         ssend << "IP(" << transmission.ip() << ")";
00020     else if(cmd == "IP:ALL?")
00021         ssend << "IP(" << transmission.ip(transmission.ip()) << ")";
00022     else if(cmd.find("HEAD /") != string::npos)
00023         ssend << transmission.http.RETURN_OK << "Content-Type: text/html; charset=utf-8\r\nAccess-Control-Allow-Origin: *\r\n\r\n";
00024     else if(cmd.find("GET / HTTP") != string::npos)
00025         ssend << transmission.http.RETURN_OK << "Content-Type: text/html; charset=utf-8\r\nAccess-Control-Allow-Origin: *\r\n\r\n<!DOCTYPE html>\r\n<html>\r\n\t<head>\r\n\t\t<title>" << MBED_PROJECT << "</title>\r\n\t\t<meta http-equiv=refresh content=10>\r\n\t</head>\r\n\t<body style=background-color:dimgray>\r\n\t\t<center>\r\n\t\t\t<h1>" << MBED_PROJECT << "</h1>\r\n\t\t\t<p>" << time(NULL) << "</p>\r\n\t\t</center>\r\n\t</body>\r\n</html>";
00026     else if(cmd.find("GET /FAVICON.ICO HTTP") != string::npos)
00027         ssend << transmission.http.RETURN_OK << "Content-Type: image/svg+xml\r\nAccess-Control-Allow-Origin: *\r\n\r\n<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 100 100\" style=\"background-color:steelblue\" xmlns=\"http://www.w3.org/2000/svg\"><title>" << MBED_PROJECT << "</title><text x=\"0\" y=\"85\" textLength=\"100\" font-weight=\"bold\" font-size=\"110\" lengthAdjust=\"spacingAndGlyphs\" fill=\"white\" stroke=\"skyblue\">EL</text></svg>";
00028     else if(cmd[cmd.size()-1] == '?')
00029         ssend << "incorrect requeste [" << cmd << "]";
00030     return ssend.str();
00031 }