lib_Transmission_TCP_example
Dependencies: lib_Transmission
main.cpp@1:b9a16f894120, 2022-06-30 (annotated)
- Committer:
- YSI
- Date:
- Thu Jun 30 16:19:14 2022 +0200
- Revision:
- 1:b9a16f894120
- Parent:
- 0:bfe0a20512f3
test up lib_Transmission
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
YSI | 0:bfe0a20512f3 | 1 | #include "main.h" |
YSI | 0:bfe0a20512f3 | 2 | |
YSI | 0:bfe0a20512f3 | 3 | int main(void) |
YSI | 0:bfe0a20512f3 | 4 | { |
YSI | 1:b9a16f894120 | 5 | transmission.ip(true, "192.168.1.25", 80); |
YSI | 0:bfe0a20512f3 | 6 | while(1) Led = transmission.recv(); |
YSI | 0:bfe0a20512f3 | 7 | } |
YSI | 0:bfe0a20512f3 | 8 | |
YSI | 0:bfe0a20512f3 | 9 | string transmission_processing(string cmd) |
YSI | 0:bfe0a20512f3 | 10 | { |
YSI | 1:b9a16f894120 | 11 | pc.write(cmd.c_str(), cmd.size()); |
YSI | 0:bfe0a20512f3 | 12 | ostringstream ssend; |
YSI | 0:bfe0a20512f3 | 13 | ssend << fixed; |
YSI | 0:bfe0a20512f3 | 14 | ssend.precision(2); |
YSI | 0:bfe0a20512f3 | 15 | if(cmd.empty()); |
YSI | 0:bfe0a20512f3 | 16 | else if(cmd == "*IDN?") |
YSI | 0:bfe0a20512f3 | 17 | ssend << MBED_PROJECT << ", Mbed OS " << MBED_VERSION << ", Version dated, " << __DATE__ << ", " << __TIME__; |
YSI | 0:bfe0a20512f3 | 18 | else if(cmd == "IP?") |
YSI | 0:bfe0a20512f3 | 19 | ssend << "IP(" << transmission.ip() << ")"; |
YSI | 0:bfe0a20512f3 | 20 | else if(cmd == "IP:ALL?") |
YSI | 0:bfe0a20512f3 | 21 | ssend << "IP(" << transmission.ip(transmission.ip()) << ")"; |
YSI | 0:bfe0a20512f3 | 22 | else if(cmd.find("HEAD /") != string::npos) |
YSI | 0:bfe0a20512f3 | 23 | ssend << transmission.http.RETURN_OK << "Content-Type: text/html; charset=utf-8\r\nAccess-Control-Allow-Origin: *\r\n\r\n"; |
YSI | 0:bfe0a20512f3 | 24 | else if(cmd.find("GET / HTTP") != string::npos) |
YSI | 0:bfe0a20512f3 | 25 | 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>"; |
YSI | 0:bfe0a20512f3 | 26 | else if(cmd.find("GET /FAVICON.ICO HTTP") != string::npos) |
YSI | 0:bfe0a20512f3 | 27 | 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>"; |
YSI | 0:bfe0a20512f3 | 28 | else if(cmd[cmd.size()-1] == '?') |
YSI | 0:bfe0a20512f3 | 29 | ssend << "incorrect requeste [" << cmd << "]"; |
YSI | 0:bfe0a20512f3 | 30 | return ssend.str(); |
YSI | 0:bfe0a20512f3 | 31 | } |