kopia lustrzana https://github.com/pjalocha/esp32-ogn-tracker
Optimize part of the HTTP code by sending larger chunks
rodzic
9ca6cb9913
commit
c56159119c
|
@ -24,20 +24,20 @@
|
||||||
// ============================================================================================================
|
// ============================================================================================================
|
||||||
|
|
||||||
static void SelectList(httpd_req_t *Req, const char *Name, const char **List, int Size, int Sel=0)
|
static void SelectList(httpd_req_t *Req, const char *Name, const char **List, int Size, int Sel=0)
|
||||||
{ char Line[8];
|
{ char Line[64]; int Len;
|
||||||
httpd_resp_sendstr_chunk(Req, "<select name=\"");
|
Len =Format_String(Line, "<select name=\"");
|
||||||
httpd_resp_sendstr_chunk(Req, Name);
|
Len+=Format_String(Line+Len, Name);
|
||||||
httpd_resp_sendstr_chunk(Req, "\">\n");
|
Len+=Format_String(Line+Len, "\">\n");
|
||||||
for(int Idx=0; Idx<Size; Idx++)
|
|
||||||
{ httpd_resp_sendstr_chunk(Req, "<option value=\"");
|
|
||||||
int Len=Format_UnsDec(Line, (uint16_t)Idx);
|
|
||||||
httpd_resp_send_chunk(Req, Line, Len);
|
httpd_resp_send_chunk(Req, Line, Len);
|
||||||
httpd_resp_sendstr_chunk(Req, "\"");
|
for(int Idx=0; Idx<Size; Idx++)
|
||||||
if(Idx==Sel) httpd_resp_sendstr_chunk(Req, " selected>");
|
{ Len =Format_String(Line, "<option value=\"");
|
||||||
else httpd_resp_sendstr_chunk(Req, ">");
|
Len+=Format_UnsDec(Line+Len, (uint16_t)Idx);
|
||||||
httpd_resp_sendstr_chunk(Req, List[Idx]);
|
Len+=Format_String(Line+Len, "\"");
|
||||||
httpd_resp_sendstr_chunk(Req, "</option>\n");
|
if(Idx==Sel) Len+=Format_String(Line+Len, " selected>");
|
||||||
}
|
else Len+=Format_String(Line+Len, ">");
|
||||||
|
Len+=Format_String(Line+Len, List[Idx]);
|
||||||
|
Len+=Format_String(Line+Len, "</option>\n");
|
||||||
|
httpd_resp_send_chunk(Req, Line, Len); }
|
||||||
httpd_resp_sendstr_chunk(Req, "</select>\n"); }
|
httpd_resp_sendstr_chunk(Req, "</select>\n"); }
|
||||||
|
|
||||||
static void ParmForm_Info(httpd_req_t *Req) // produce HTML form for aircraft parameters
|
static void ParmForm_Info(httpd_req_t *Req) // produce HTML form for aircraft parameters
|
||||||
|
@ -299,37 +299,38 @@ static uint8_t BattCapacity(uint16_t mVolt)
|
||||||
return (mVolt-3600+2)/5; }
|
return (mVolt-3600+2)/5; }
|
||||||
|
|
||||||
static void Table_Batt(httpd_req_t *Req)
|
static void Table_Batt(httpd_req_t *Req)
|
||||||
{ char Line[16]; int Len;
|
{ char Line[128]; int Len;
|
||||||
|
|
||||||
httpd_resp_sendstr_chunk(Req, "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n");
|
httpd_resp_sendstr_chunk(Req, "<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">\n");
|
||||||
httpd_resp_sendstr_chunk(Req, "<tr><th><b>Battery</th><td></td></tr>\n");
|
httpd_resp_sendstr_chunk(Req, "<tr><th><b>Battery</th><td></td></tr>\n");
|
||||||
|
|
||||||
httpd_resp_sendstr_chunk(Req, "<td>Voltage</td><td align=\"right\">");
|
Len =Format_String(Line, "<td>Voltage</td><td align=\"right\">");
|
||||||
#ifdef WITH_MAVLINK
|
#ifdef WITH_MAVLINK
|
||||||
Len=Format_UnsDec(Line, MAVLINK_BattVolt, 4, 3);
|
Len+=Format_UnsDec(Line+Len, MAVLINK_BattVolt, 4, 3);
|
||||||
#else
|
#else
|
||||||
Len=Format_UnsDec(Line, BatteryVoltage>>8, 4, 3); // print the battery voltage readout
|
Len+=Format_UnsDec(Line+Len, BatteryVoltage>>8, 4, 3); // print the battery voltage readout
|
||||||
#endif
|
#endif
|
||||||
|
Len+=Format_String(Line+Len, " V</td></tr>\n");
|
||||||
httpd_resp_send_chunk(Req, Line, Len);
|
httpd_resp_send_chunk(Req, Line, Len);
|
||||||
httpd_resp_sendstr_chunk(Req, " V</td></tr>\n");
|
|
||||||
|
|
||||||
httpd_resp_sendstr_chunk(Req, "<tr><td>Capacity</td><td align=\"right\">");
|
Len =Format_String(Line, "<tr><td>Capacity</td><td align=\"right\">");
|
||||||
#ifdef WITH_MAVLINK
|
#ifdef WITH_MAVLINK
|
||||||
uint8_t Cap=MAVLINK_BattCap; // [%] from the drone's telemetry
|
uint8_t Cap=MAVLINK_BattCap; // [%] from the drone's telemetry
|
||||||
#else
|
#else
|
||||||
uint8_t Cap=BattCapacity(BatteryVoltage>>8); // [%] est. battery capacity based on the voltage readout
|
uint8_t Cap=BattCapacity(BatteryVoltage>>8); // [%] est. battery capacity based on the voltage readout
|
||||||
#endif
|
#endif
|
||||||
Len=Format_UnsDec(Line, (uint16_t)Cap);
|
Len+=Format_UnsDec(Line+Len, (uint16_t)Cap);
|
||||||
|
Len+=Format_String(Line+Len, " %</td></tr>\n");
|
||||||
httpd_resp_send_chunk(Req, Line, Len);
|
httpd_resp_send_chunk(Req, Line, Len);
|
||||||
httpd_resp_sendstr_chunk(Req, " %</td></tr>\n");
|
|
||||||
|
|
||||||
#ifdef WITH_BQ
|
#ifdef WITH_BQ
|
||||||
uint8_t Status = BQ.readStatus(); // read status register
|
uint8_t Status = BQ.readStatus(); // read status register
|
||||||
uint8_t State = (Status>>4)&0x03; // charging status
|
uint8_t State = (Status>>4)&0x03; // charging status
|
||||||
const char *StateName[4] = { "Charge OFF" , "Pre-charge", "Charging", "Full" } ;
|
const char *StateName[4] = { "Charge OFF" , "Pre-charge", "Charging", "Full" } ;
|
||||||
httpd_resp_sendstr_chunk(Req, "<tr><td>State</td><td align=\"right\">");
|
Len =Format_String(Line, "<tr><td>State</td><td align=\"right\">");
|
||||||
httpd_resp_sendstr_chunk(Req, StateName[State]);
|
Len+=Format_String(Line+Len, StateName[State]);
|
||||||
httpd_resp_sendstr_chunk(Req, "</td></tr>\n");
|
Len+=Format_String(Line+Len, "</td></tr>\n");
|
||||||
|
httpd_resp_send_chunk(Req, Line, Len);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_AXP
|
#ifdef WITH_AXP
|
||||||
|
@ -342,26 +343,26 @@ static void Table_Batt(httpd_req_t *Req)
|
||||||
uint32_t OutCharge=AXP.readBatteryOutCharge();
|
uint32_t OutCharge=AXP.readBatteryOutCharge();
|
||||||
|
|
||||||
int16_t Current = InpCurr-OutCurr;
|
int16_t Current = InpCurr-OutCurr;
|
||||||
httpd_resp_sendstr_chunk(Req, "<tr><td>Current</td><td align=\"right\">");
|
Len =Format_String(Line, "<tr><td>Current</td><td align=\"right\">");
|
||||||
Len=Format_SignDec(Line, Current, 3);
|
Len+=Format_SignDec(Line+Len, Current, 3);
|
||||||
|
Len+=Format_String(Line+Len, " mA</td></tr>\n");
|
||||||
httpd_resp_send_chunk(Req, Line, Len);
|
httpd_resp_send_chunk(Req, Line, Len);
|
||||||
httpd_resp_sendstr_chunk(Req, " mA</td></tr>\n");
|
|
||||||
|
|
||||||
int32_t Charge = InpCharge-OutCharge;
|
int32_t Charge = InpCharge-OutCharge;
|
||||||
httpd_resp_sendstr_chunk(Req, "<tr><td>Charge</td><td align=\"right\">");
|
Len =Format_String(Line, "<tr><td>Charge</td><td align=\"right\">");
|
||||||
Len=Format_UnsDec(Line, (((int64_t)Charge<<12)+562)/1125, 2, 1);
|
Len+=Format_UnsDec(Line+Len, (((int64_t)Charge<<12)+562)/1125, 2, 1);
|
||||||
|
Len+=Format_String(Line+Len, " mAh</td></tr>\n");
|
||||||
httpd_resp_send_chunk(Req, Line, Len);
|
httpd_resp_send_chunk(Req, Line, Len);
|
||||||
httpd_resp_sendstr_chunk(Req, " mAh</td></tr>\n");
|
|
||||||
|
|
||||||
httpd_resp_sendstr_chunk(Req, "<tr><td>USB volt.</td><td align=\"right\">");
|
Len =Format_String(Line, "<tr><td>USB volt.</td><td align=\"right\">");
|
||||||
Len=Format_UnsDec(Line, Vbus, 4, 3);
|
Len+=Format_UnsDec(Line+Len, Vbus, 4, 3);
|
||||||
|
Len+=Format_String(Line+Len, " V</td></tr>\n");
|
||||||
httpd_resp_send_chunk(Req, Line, Len);
|
httpd_resp_send_chunk(Req, Line, Len);
|
||||||
httpd_resp_sendstr_chunk(Req, " V</td></tr>\n");
|
|
||||||
|
|
||||||
httpd_resp_sendstr_chunk(Req, "<tr><td>USB curr.</td><td align=\"right\">");
|
Len =Format_String(Line, "<tr><td>USB curr.</td><td align=\"right\">");
|
||||||
Len=Format_UnsDec(Line, VbusCurr, 4, 3);
|
Len+=Format_UnsDec(Line+Len, VbusCurr, 4, 3);
|
||||||
|
Len+=Format_String(Line+Len, " A</td></tr>\n");
|
||||||
httpd_resp_send_chunk(Req, Line, Len);
|
httpd_resp_send_chunk(Req, Line, Len);
|
||||||
httpd_resp_sendstr_chunk(Req, " A</td></tr>\n");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
httpd_resp_sendstr_chunk(Req, "</table>\n"); }
|
httpd_resp_sendstr_chunk(Req, "</table>\n"); }
|
||||||
|
|
Ładowanie…
Reference in New Issue