update index
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
@@ -33,6 +34,8 @@ type Stats struct {
|
||||
TotalContacts int `json:"totalContacts"`
|
||||
ClusterStatus string `json:"clusterStatus"`
|
||||
FlexStatus string `json:"flexStatus"`
|
||||
MyCallsign string `json:"myCallsign"`
|
||||
Mode string `json:"mode"`
|
||||
Filters Filters `json:"filters"`
|
||||
}
|
||||
|
||||
@@ -46,6 +49,11 @@ type APIResponse struct {
|
||||
Success bool `json:"success"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
type SendCallsignRequest struct {
|
||||
Callsign string `json:"callsign"`
|
||||
}
|
||||
|
||||
func NewHTTPServer(flexRepo *FlexDXClusterRepository, contactRepo *Log4OMContactsRepository,
|
||||
@@ -81,6 +89,7 @@ func (s *HTTPServer) setupRoutes() {
|
||||
api.HandleFunc("/send-command", s.sendCommand).Methods("POST", "OPTIONS")
|
||||
api.HandleFunc("/filters", s.updateFilters).Methods("POST", "OPTIONS")
|
||||
api.HandleFunc("/shutdown", s.shutdownApp).Methods("POST", "OPTIONS")
|
||||
api.HandleFunc("/send-callsign", s.handleSendCallsign).Methods("POST", "OPTIONS")
|
||||
|
||||
// Serve static files (dashboard)
|
||||
s.Router.PathPrefix("/").Handler(http.FileServer(http.Dir("./static")))
|
||||
@@ -145,6 +154,7 @@ func (s *HTTPServer) getStats(w http.ResponseWriter, r *http.Request) {
|
||||
TotalContacts: contacts,
|
||||
ClusterStatus: clusterStatus,
|
||||
FlexStatus: flexStatus,
|
||||
MyCallsign: Cfg.General.Callsign, // Nouveau
|
||||
Filters: Filters{
|
||||
Skimmer: Cfg.Cluster.Skimmer,
|
||||
FT8: Cfg.Cluster.FT8,
|
||||
@@ -270,6 +280,47 @@ func (s *HTTPServer) updateFilters(w http.ResponseWriter, r *http.Request) {
|
||||
s.sendJSON(w, APIResponse{Success: true, Data: map[string]string{"message": "Filters updated successfully"}})
|
||||
}
|
||||
|
||||
func (s *HTTPServer) handleSendCallsign(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Callsign string `json:"callsign"`
|
||||
Frequency string `json:"frequency"`
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
s.sendJSON(w, APIResponse{Success: false, Error: "Invalid request"})
|
||||
return
|
||||
}
|
||||
|
||||
if req.Callsign == "" {
|
||||
s.sendJSON(w, APIResponse{Success: false, Error: "Callsign is required"})
|
||||
return
|
||||
}
|
||||
|
||||
// Envoyer l'indicatif à Log4OM via UDP
|
||||
SendUDPMessage("<CALLSIGN>" + req.Callsign)
|
||||
s.Log.Infof("Sent callsign %s to Log4OM via UDP (127.0.0.1:2241)", req.Callsign)
|
||||
|
||||
// Tuner la radio Flex sur la fréquence si elle est fournie
|
||||
if req.Frequency != "" && s.FlexClient != nil && s.FlexClient.IsConnected {
|
||||
// Commande TUNE pour le slice 0 selon l'API FlexRadio
|
||||
tuneCmd := fmt.Sprintf("C%v|slice tune 0 %s", CommandNumber, req.Frequency)
|
||||
s.FlexClient.Write(tuneCmd)
|
||||
CommandNumber++
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
modeCmd := fmt.Sprintf("C%v|slice s 0 mode=%s", CommandNumber, req.Mode)
|
||||
s.FlexClient.Write(modeCmd)
|
||||
CommandNumber++
|
||||
s.Log.Infof("Sent TUNE command to Flex: %s", tuneCmd)
|
||||
}
|
||||
|
||||
s.sendJSON(w, APIResponse{
|
||||
Success: true,
|
||||
Message: "Callsign sent to Log4OM and radio tuned",
|
||||
Data: map[string]string{"callsign": req.Callsign, "frequency": req.Frequency},
|
||||
})
|
||||
}
|
||||
|
||||
func (s *HTTPServer) sendJSON(w http.ResponseWriter, data interface{}) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(data)
|
||||
|
Reference in New Issue
Block a user