Add UART SET_LOG_LEVEL for runtime master ESP-IDF logging.
Expose the command via goTool CLI/REST and dashboard controls so log verbosity can be tuned without reflashing. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -74,6 +74,17 @@ type restartAPIResponse struct {
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type logLevelAPIResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Level uint32 `json:"level"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type logLevelAPIRequest struct {
|
||||
Write bool `json:"write"`
|
||||
Level uint32 `json:"level"`
|
||||
}
|
||||
|
||||
type otaAPIResponse struct {
|
||||
Success bool `json:"success"`
|
||||
BytesWritten uint32 `json:"bytes_written,omitempty"`
|
||||
@@ -125,6 +136,16 @@ func mountServeAPI(mux *http.ServeMux, link *managedSerial, hub *wsHub, streamCt
|
||||
}
|
||||
serveRestart(w, r, link)
|
||||
})
|
||||
mux.HandleFunc("/api/log-level", func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
serveLogLevelGet(w, r, link)
|
||||
case http.MethodPost:
|
||||
serveLogLevelPost(w, r, link)
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
})
|
||||
mux.HandleFunc("/api/ota", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
@@ -280,6 +301,43 @@ func applyDeadzoneToSlaves(link *managedSerial, deadzone uint32) (uint32, error)
|
||||
return updated, nil
|
||||
}
|
||||
|
||||
func serveLogLevelGet(w http.ResponseWriter, r *http.Request, link *managedSerial) {
|
||||
resp, err := link.SetLogLevel(false, 0)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusServiceUnavailable, logLevelAPIResponse{Error: err.Error()})
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, logLevelAPIResponse{
|
||||
Success: resp.GetSuccess(),
|
||||
Level: resp.GetLevel(),
|
||||
})
|
||||
}
|
||||
|
||||
func serveLogLevelPost(w http.ResponseWriter, r *http.Request, link *managedSerial) {
|
||||
var body logLevelAPIRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
writeJSON(w, http.StatusBadRequest, logLevelAPIResponse{Error: "invalid JSON"})
|
||||
return
|
||||
}
|
||||
if !body.Write {
|
||||
writeJSON(w, http.StatusBadRequest, logLevelAPIResponse{Error: "write must be true"})
|
||||
return
|
||||
}
|
||||
if body.Level > 5 {
|
||||
writeJSON(w, http.StatusBadRequest, logLevelAPIResponse{Error: "level must be 0–5"})
|
||||
return
|
||||
}
|
||||
resp, err := link.SetLogLevel(true, body.Level)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusServiceUnavailable, logLevelAPIResponse{Error: err.Error()})
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, logLevelAPIResponse{
|
||||
Success: resp.GetSuccess(),
|
||||
Level: resp.GetLevel(),
|
||||
})
|
||||
}
|
||||
|
||||
func serveRestart(w http.ResponseWriter, r *http.Request, link *managedSerial) {
|
||||
var body restartAPIRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user