From 9751ab8abb3fda215a1c615532081178805fabfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Farkas=20Szil=C3=A1rd?= Date: Sat, 3 Apr 2021 21:27:12 +0200 Subject: [PATCH] HTTP minimalistic CSS framework, and clean up HTML code --- main/http.cpp | 400 +++++++++++++++++++++++++++++--------------------- 1 file changed, 236 insertions(+), 164 deletions(-) diff --git a/main/http.cpp b/main/http.cpp index 0c7308d..6364245 100644 --- a/main/http.cpp +++ b/main/http.cpp @@ -44,92 +44,126 @@ static void SelectList(httpd_req_t *Req, const char *Name, const char **List, in httpd_resp_send_chunk(Req, Line, Len); } httpd_resp_sendstr_chunk(Req, "\n"); } +static void Begin_Control_Row(httpd_req_t *Req, const char *Label) +{ + httpd_resp_sendstr_chunk(Req, "
\n
\n"); +} +static void End_Control_Row(httpd_req_t *Req) +{ + httpd_resp_sendstr_chunk(Req, "\n
\n"); +} + // HTML form for the Info parameters static void ParmForm_Info(httpd_req_t *Req) { - httpd_resp_sendstr_chunk(Req, "
\n\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

Info

"); + httpd_resp_sendstr_chunk(Req, "\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "
Info
Pilot
Crew
Base airfield
Registration
Manufacturer
Model
Type
\n"); } + httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "\n"); } // HTML form for the Aircraft identification: address, address-type, aircraft-type static void ParmForm_Acft(httpd_req_t *Req) { char Line[16]; - httpd_resp_sendstr_chunk(Req, "
\n\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

Aircraft

"); + httpd_resp_sendstr_chunk(Req, "\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); + Begin_Control_Row(Req, "Addr-Type"); const char *AddrTypeTable[4] = { "Random", "ICAO", "FLARM", "OGN" } ; - httpd_resp_sendstr_chunk(Req, "\n"); + End_Control_Row(Req); + Begin_Control_Row(Req, "Acft-Type"); const char *AcftTypeTable[16] = { "Unknown", "(moto)Glider", "Tow-plane", "Helicopter", "Parachute", "Drop-plane", "Hang-glider", "Para-glider", "Powered-aircraft", "Jet-aircraft", "UFO", "Balloon", "Airship", "UAV/drone", "Ground support", "Static object" } ; - httpd_resp_sendstr_chunk(Req, "\n"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "
Aircraft
Address>16)); Format_Hex(Line+2, (uint16_t)Parameters.Address); httpd_resp_send_chunk(Req, Line, 6); - httpd_resp_sendstr_chunk(Req, "\">
Addr-Type\n"); SelectList(Req, "AddrType", AddrTypeTable, 4, Parameters.AddrType); - httpd_resp_sendstr_chunk(Req, "
Acft-Type\n"); SelectList(Req, "AcftType", AcftTypeTable, 16, Parameters.AcftType); - httpd_resp_sendstr_chunk(Req, "
\n"); } + httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "\n"); } static void ParmForm_GPS(httpd_req_t *Req) // produce HTML form for GPS parameters { char Line[16]; int Len; - httpd_resp_sendstr_chunk(Req, "
\n\n"); #ifdef WITH_GPS_UBX - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

GPS: UBX

"); #else #ifdef WITH_GPS_MTK - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

GPS: MTK

"); #else - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

GPS

"); #endif #endif + httpd_resp_sendstr_chunk(Req, "\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); - - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "
GPS: UBX
GPS: MTK
GPS
Nav. rate [Hz]
Nav. mode
Geoid-Separ.\n"); + Begin_Control_Row(Req, "Geoid-Separ."); const char *GeoidSeparTable[2] = { "GPS", "Override" } ; SelectList(Req, "manGeoidSepar", GeoidSeparTable, 2, Parameters.manGeoidSepar); @@ -138,127 +172,166 @@ static void ParmForm_GPS(httpd_req_t *Req) // produce HTML form for GPS paramet Len=Format_SignDec(Line, Parameters.GeoidSepar, 2, 1, 1); httpd_resp_send_chunk(Req, Line, Len); httpd_resp_sendstr_chunk(Req, "\">\n"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "
GNSS mode
PPS delay [ms]
\n"); } + httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "\n"); } static void ParmForm_Other(httpd_req_t *Req) // produce HTML form for aircraft parameters { char Line[16]; int Len; - httpd_resp_sendstr_chunk(Req, "
\n\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

Other

"); + httpd_resp_sendstr_chunk(Req, "\n"); + Begin_Control_Row(Req, "Freq. plan"); const char *FreqPlanTable[6] = { "Auto", "Europe/Africa", "USA/Canada", "Australia/Chile", "New Zeeland", "Izrael" }; - httpd_resp_sendstr_chunk(Req, "\n"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "
Other
Freq. plan\n"); SelectList(Req, "FreqPlan", FreqPlanTable, 6, Parameters.FreqPlan); - httpd_resp_sendstr_chunk(Req, "
Tx power [dBm]
Freq.corr. [ppm]
Console baud
Verbose
Page sel. mask
\n"); } + httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "\n"); } #ifdef WITH_STRATUX static void ParmForm_Stratux(httpd_req_t *Req) // Connection to Stratux WiFi parameters and options { char Line[16]; int Len; - httpd_resp_sendstr_chunk(Req, "
\n\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

Stratux

"); + httpd_resp_sendstr_chunk(Req, "\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "
Stratux
SSID
Password
TCP host
TCP port
Tx power [dBm]>2, 2, 1); httpd_resp_send_chunk(Req, Line, Len); - httpd_resp_sendstr_chunk(Req, "\">
Min. RSSI [dBm]
\n"); } + httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "\n"); } #endif #ifdef WITH_AP static void ParmForm_AP(httpd_req_t *Req) // Wi-Fi access point parameters { char Line[16]; int Len; { char Line[16]; int Len; - httpd_resp_sendstr_chunk(Req, "
\n\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

Wi-Fi AP

"); + httpd_resp_sendstr_chunk(Req, "\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "\">"); + End_Control_Row(Req); - httpd_resp_sendstr_chunk(Req, "
Wi-Fi AP
SSID
Password
Data port
Tx power [dBm]>2, 2, 1); httpd_resp_send_chunk(Req, Line, Len); - httpd_resp_sendstr_chunk(Req, "\">
Min. RSSI [dBm]
\n"); } + httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "\n"); } #endif // ============================================================================================================ @@ -269,8 +342,8 @@ static void Table_GPS(httpd_req_t *Req) uint32_t Sec = (Time-1)%60; GPS_Position *GPS = GPS_getPosition(Sec); if(GPS==0) return; - httpd_resp_sendstr_chunk(Req, "\n\ -\n"); + httpd_resp_sendstr_chunk(Req, "

GPS

"); + httpd_resp_sendstr_chunk(Req, "
GPS
\n"); Len =Format_String(Line, "\n
Date"); Len+=Format_UnsDec(Line+Len, GPS->Year+2000 , 4); Line[Len++]='.'; @@ -361,8 +434,9 @@ static void Table_GPS(httpd_req_t *Req) #ifdef WITH_LOOKOUT static void Table_LookOut(httpd_req_t *Req) { char Line[128]; int Len; - httpd_resp_sendstr_chunk(Req, "\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

LookOut

"); + httpd_resp_sendstr_chunk(Req, "
LookOut
\n"); + httpd_resp_sendstr_chunk(Req, "\n\n"); for( uint8_t Idx=0; IdxAlloc) continue; @@ -375,15 +449,16 @@ static void Table_LookOut(httpd_req_t *Req) Len+=Format_String(Line+Len, "km\n"); httpd_resp_send_chunk(Req, Line, Len); } - httpd_resp_sendstr_chunk(Req, "
LookOutTime MarginDistance
\n"); } + httpd_resp_sendstr_chunk(Req, "
\n"); } #endif // ------------------------------------------------------------------------------------------------------------- static void Table_Relay(httpd_req_t *Req) { char Line[128]; int Len; - httpd_resp_sendstr_chunk(Req, "\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

Relay

"); + httpd_resp_sendstr_chunk(Req, "
RelayRank[sec]
\n"); + httpd_resp_sendstr_chunk(Req, "\n\n"); for( uint8_t Idx=0; Idx *Packet = RelayQueue.Packet+Idx; if(Packet->Rank==0) continue; @@ -398,15 +473,16 @@ static void Table_Relay(httpd_req_t *Req) Len+=Format_String(Line+Len, "\n"); httpd_resp_send_chunk(Req, Line, Len); } - httpd_resp_sendstr_chunk(Req, "
RelayRank[sec]
\n"); } + httpd_resp_sendstr_chunk(Req, "\n\n"); } // ------------------------------------------------------------------------------------------------------------- static void Table_RF(httpd_req_t *Req) { char Line[128]; int Len; - httpd_resp_sendstr_chunk(Req, "\n"); - Len=Format_String(Line, "
RF chip"); + httpd_resp_sendstr_chunk(Req, "

RF chip

"); + httpd_resp_sendstr_chunk(Req, "\n"); + Len=Format_String(Line, "
RF chip"); #ifdef WITH_RFM69 Len+=Format_String(Line+Len, "RFM69"); #endif @@ -466,8 +542,8 @@ static uint8_t BattCapacity(uint16_t mVolt) static void Table_Batt(httpd_req_t *Req) { char Line[128]; int Len; - httpd_resp_sendstr_chunk(Req, "\n"); - httpd_resp_sendstr_chunk(Req, "\n"); + httpd_resp_sendstr_chunk(Req, "

Battery

"); + httpd_resp_sendstr_chunk(Req, "
Battery
\n"); Len =Format_String(Line, "
Voltage"); #ifdef WITH_MAVLINK @@ -534,20 +610,55 @@ static void Table_Batt(httpd_req_t *Req) // ------------------------------------------------------------------------------------------------------------- -static void Top_Bar(httpd_req_t *Req) -{ char Line[32]; int Len; +static void Html_Start(httpd_req_t *Req, const char *Title, const uint8_t ActiveMenuIndex) +{ + httpd_resp_sendstr_chunk(Req, "\ +\n\ +\n\ +\n\ +"); + httpd_resp_sendstr_chunk(Req, Title); + httpd_resp_sendstr_chunk(Req, "\n\ +\n\ +\ +\n\ +\n\ +"); + httpd_resp_sendstr_chunk(Req, "

OGN-Tracker

\n"); - httpd_resp_sendstr_chunk(Req, "

OGN-Tracker

\n"); - httpd_resp_sendstr_chunk(Req, "EUID: "); - Len=Format_Hex(Line, getUniqueID()); - httpd_resp_send_chunk(Req, Line, Len); - httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "
\n"); - httpd_resp_sendstr_chunk(Req, "\n\ -\n\ -\n\ -\n\ -
StatusConfigurationLog files

\n"); + httpd_resp_sendstr_chunk(Req, "\n"); + + httpd_resp_sendstr_chunk(Req, "\n"); + + httpd_resp_sendstr_chunk(Req, "\n"); + + httpd_resp_sendstr_chunk(Req, "
\n"); + + httpd_resp_sendstr_chunk(Req, "
\n"); +} + +static void Html_End(httpd_req_t *Req) +{ + httpd_resp_sendstr_chunk(Req, "
\n\n\n"); + httpd_resp_send_chunk(Req, 0, 0); } // ============================================================================================================ @@ -576,56 +687,33 @@ static esp_err_t parm_get_handler(httpd_req_t *Req) Line++; } free(URL); Parameters.WriteToNVS(); } - httpd_resp_sendstr_chunk(Req, "\ -\n\ -\n\ -\n\ -\n\ -\n\ -\n\ -OGN-Tracker configuration\n\ -"); - Top_Bar(Req); + Html_Start(Req, "OGN-Tracker configuration", 2); - httpd_resp_sendstr_chunk(Req, "\n\n\n\n\n\n\n\n
\n"); ParmForm_Acft(Req); - httpd_resp_sendstr_chunk(Req, "
\n"); ParmForm_Info(Req); - httpd_resp_sendstr_chunk(Req, "
\n"); ParmForm_GPS(Req); - httpd_resp_sendstr_chunk(Req, "
\n"); #ifdef WITH_AP ParmForm_AP(Req); - httpd_resp_sendstr_chunk(Req, "
\n"); #endif #ifdef WITH_STRATUX ParmForm_Stratux(Req); - httpd_resp_sendstr_chunk(Req, "
\n"); #endif ParmForm_Other(Req); - httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "\
\n\ \n\ \n\
\n"); - // httpd_resp_sendstr_chunk(Req, "
\n"); - // httpd_resp_sendstr_chunk(Req, "\n"); - // httpd_resp_sendstr_chunk(Req, "\n"); - // httpd_resp_sendstr_chunk(Req, "
\n"); + httpd_resp_sendstr_chunk(Req, "\
\n\ \n\ \n\
\n"); - // httpd_resp_sendstr_chunk(Req, "
\n"); - // httpd_resp_sendstr_chunk(Req, "\n"); - // httpd_resp_sendstr_chunk(Req, "\n"); - // httpd_resp_sendstr_chunk(Req, "
\n"); - httpd_resp_sendstr_chunk(Req, "
\n"); - httpd_resp_sendstr_chunk(Req, "\n\n"); - httpd_resp_send_chunk(Req, 0, 0); + + Html_End(Req); if(Restart) { @@ -639,28 +727,23 @@ static esp_err_t parm_get_handler(httpd_req_t *Req) static esp_err_t top_get_handler(httpd_req_t *Req) { - httpd_resp_sendstr_chunk(Req, "\ -\n\ -\n\ -OGN-Tracker status\n\ -"); + Html_Start(Req, "OGN-Tracker status", 1); - Top_Bar(Req); + char Line[32]; int Len; + httpd_resp_sendstr_chunk(Req, "EUID: "); + Len=Format_Hex(Line, getUniqueID()); + httpd_resp_send_chunk(Req, Line, Len); + httpd_resp_sendstr_chunk(Req, "
\n"); Table_GPS(Req); - httpd_resp_sendstr_chunk(Req, "
\n"); Table_RF(Req); - httpd_resp_sendstr_chunk(Req, "
\n"); Table_Batt(Req); #ifdef WITH_LOOKOUT - httpd_resp_sendstr_chunk(Req, "
\n"); Table_LookOut(Req); #endif - httpd_resp_sendstr_chunk(Req, "
\n"); Table_Relay(Req); - httpd_resp_sendstr_chunk(Req, "\n"); - httpd_resp_sendstr_chunk(Req, 0); + Html_End(Req); return ESP_OK; } static int Format_DateTime(char *Out, time_t Time) @@ -842,17 +925,7 @@ static esp_err_t log_get_handler(httpd_req_t *Req) return SendLog_TLG(Req, FullName, Time); } } } - httpd_resp_sendstr_chunk(Req, "\ -\n\ -\n\ -\n\ -\n\ -\n\ -\n\ -OGN-Tracker log files\n\ -"); - - Top_Bar(Req); + Html_Start(Req, "OGN-Tracker log files", 3); std::vector FileList; // list of log files DIR *Dir=opendir(Path); // open the log file directory @@ -870,7 +943,7 @@ static esp_err_t log_get_handler(httpd_req_t *Req) closedir(Dir); std::sort(FileList.begin(), FileList.end()); - httpd_resp_sendstr_chunk(Req, "\n\n"); + httpd_resp_sendstr_chunk(Req, "
File[KB]Date
\n\n\n"); for(size_t Idx=0; Idx\n"); httpd_resp_send_chunk(Req, Line, Len); vTaskDelay(1); } - httpd_resp_sendstr_chunk(Req, "
File[KB]Date
\n"); + httpd_resp_sendstr_chunk(Req, "
\n"); - httpd_resp_sendstr_chunk(Req, "\n\n"); - httpd_resp_send_chunk(Req, 0, 0); + Html_End(Req); return ESP_OK; } static esp_err_t logo_get_handler(httpd_req_t *Req)