Files
KlipperAnywhere/internal/protocol/protocol.go
T
2026-05-14 02:27:26 +01:00

93 lines
3.8 KiB
Go

package protocol
const (
MessageHTTPRequest = "http_request"
MessageHTTPResponse = "http_response"
MessageHeartbeat = "heartbeat"
MessageConfigSync = "config_sync"
MessageAgentUpdate = "agent_update"
MessageError = "error"
)
type Header struct {
Name string `json:"name"`
Values []string `json:"values"`
}
type Message struct {
ID string `json:"id"`
Type string `json:"type"`
Target string `json:"target,omitempty"`
CameraName string `json:"camera_name,omitempty"`
CameraKind string `json:"camera_kind,omitempty"`
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
Headers []Header `json:"headers,omitempty"`
Body string `json:"body,omitempty"`
WSMessageType int `json:"ws_message_type,omitempty"`
Status int `json:"status,omitempty"`
Error string `json:"error,omitempty"`
End bool `json:"end,omitempty"`
Health *Health `json:"health,omitempty"`
Settings *Settings `json:"settings,omitempty"`
Update *AgentUpdateRequest `json:"update,omitempty"`
}
type Health struct {
AgentVersion string `json:"agent_version"`
Hostname string `json:"hostname"`
MoonrakerURL string `json:"moonraker_url"`
MoonrakerReachable bool `json:"moonraker_reachable"`
MoonrakerState string `json:"moonraker_state,omitempty"`
MoonrakerMessage string `json:"moonraker_message,omitempty"`
PrintStatus *PrintStatus `json:"print_status,omitempty"`
UIURL string `json:"ui_url,omitempty"`
UIAutoDetect bool `json:"ui_auto_detect"`
UIReachable bool `json:"ui_reachable"`
UISource string `json:"ui_source,omitempty"`
ControlMode string `json:"control_mode,omitempty"`
CheckedAtUnix int64 `json:"checked_at_unix"`
Cameras []CameraHealth `json:"cameras,omitempty"`
}
type Settings struct {
ControlMode string `json:"control_mode,omitempty"`
UIURL string `json:"ui_url,omitempty"`
UIAutoDetect bool `json:"ui_auto_detect"`
}
type AgentUpdateRequest struct {
ReleaseURL string `json:"release_url,omitempty"`
Version string `json:"version,omitempty"`
}
type PrintStatus struct {
State string `json:"state,omitempty"`
Filename string `json:"filename,omitempty"`
Message string `json:"message,omitempty"`
Progress float64 `json:"progress,omitempty"`
PrintDuration float64 `json:"print_duration,omitempty"`
TotalDuration float64 `json:"total_duration,omitempty"`
FilamentUsed float64 `json:"filament_used,omitempty"`
EstimatedTimeRemaining float64 `json:"estimated_time_remaining,omitempty"`
CurrentLayer int `json:"current_layer,omitempty"`
TotalLayer int `json:"total_layer,omitempty"`
MoonrakerStatus map[string]any `json:"moonraker_status,omitempty"`
MoonrakerMetadata map[string]any `json:"moonraker_metadata,omitempty"`
MoonrakerMetadataFilename string `json:"moonraker_metadata_filename,omitempty"`
LayerSource string `json:"layer_source,omitempty"`
}
type CameraHealth struct {
Name string `json:"name"`
Source string `json:"source,omitempty"`
Service string `json:"service,omitempty"`
Location string `json:"location,omitempty"`
AspectRatio string `json:"aspect_ratio,omitempty"`
Rotation int `json:"rotation,omitempty"`
FlipHorizontal bool `json:"flip_horizontal,omitempty"`
FlipVertical bool `json:"flip_vertical,omitempty"`
HasSnapshot bool `json:"has_snapshot"`
HasStream bool `json:"has_stream"`
}