Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,37 @@
|
||||
package participanthandler
|
||||
|
||||
import "time"
|
||||
|
||||
// ChangeAbcProtection ändert den ABC-Schutzstatus eines Geräts.
|
||||
// equipmentNumber: Die Nummer des Geräts, dessen ABC-Schutzstatus geändert werden soll.
|
||||
// abcProtection: Der neue Status des ABC-Schutzes (true für aktiv, false für inaktiv).
|
||||
// Rückgabewert: Gibt einen Fehler zurück, falls die Änderung fehlschlägt.
|
||||
func (c *ParticipantHandler) ChangeAbcProtection(equipmentNumber int, abcProtection bool) error {
|
||||
// Erstellen einer Anfrage zur Änderung des ABC-Schutzstatus
|
||||
req := AbcProtectionChangeRequest{
|
||||
Data: struct {
|
||||
Header struct {
|
||||
EquipmentNumber int `json:"equipmentNumber"`
|
||||
TimeStamp int `json:"timeStamp"`
|
||||
} `json:"header"`
|
||||
NbcProtectionActive bool `json:"nbcProtectionActive"`
|
||||
}{
|
||||
Header: struct {
|
||||
EquipmentNumber int `json:"equipmentNumber"`
|
||||
TimeStamp int `json:"timeStamp"`
|
||||
}{
|
||||
EquipmentNumber: equipmentNumber,
|
||||
TimeStamp: int(time.Now().UnixMilli()),
|
||||
},
|
||||
NbcProtectionActive: abcProtection,
|
||||
},
|
||||
TypeID: 7,
|
||||
}
|
||||
|
||||
// Senden der Anfrage über den MariusSocket
|
||||
if err := c.MariusSocket.WriteJSON(req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package participanthandler
|
||||
|
||||
import (
|
||||
"log"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
// degreesToRadians konvertiert Grad in Radiant.
|
||||
// degrees: Der Winkel in Grad.
|
||||
// Rückgabewert: Der Winkel in Radiant.
|
||||
func degreesToRadians(degrees float64) float64 {
|
||||
return degrees * (math.Pi / 180)
|
||||
}
|
||||
|
||||
// ChangePosition ändert die Position eines Geräts.
|
||||
// equipmentNumber: Die Nummer des Geräts, dessen Position geändert werden soll.
|
||||
// geoPosition: Die neue geografische Position des Geräts.
|
||||
// Rückgabewert: Gibt einen Fehler zurück, falls die Änderung fehlschlägt.
|
||||
func (c *ParticipantHandler) ChangePosition(equipmentNumber int, geoPosition *GeoPosition) error {
|
||||
log.Println(equipmentNumber, geoPosition)
|
||||
|
||||
// Erstellen einer Anfrage zur Änderung der Position
|
||||
req := PositionChangeRequest{
|
||||
Data: struct {
|
||||
Header struct {
|
||||
EquipmentNumber int `json:"equipmentNumber"`
|
||||
TimeStamp int `json:"timeStamp"`
|
||||
} `json:"header"`
|
||||
GeoPosition struct {
|
||||
Lon float64 `json:"lon"`
|
||||
Lat float64 `json:"lat"`
|
||||
Z float64 `json:"z"`
|
||||
} `json:"geoPosition"`
|
||||
}{
|
||||
Header: struct {
|
||||
EquipmentNumber int `json:"equipmentNumber"`
|
||||
TimeStamp int `json:"timeStamp"`
|
||||
}{
|
||||
EquipmentNumber: equipmentNumber,
|
||||
TimeStamp: int(time.Now().UnixMilli()),
|
||||
},
|
||||
GeoPosition: struct {
|
||||
Lon float64 `json:"lon"`
|
||||
Lat float64 `json:"lat"`
|
||||
Z float64 `json:"z"`
|
||||
}{
|
||||
Lon: degreesToRadians(geoPosition.Lng),
|
||||
Lat: degreesToRadians(geoPosition.Lat),
|
||||
Z: 0.0,
|
||||
},
|
||||
},
|
||||
TypeID: 21,
|
||||
}
|
||||
|
||||
// Senden der Anfrage über den MariusSocket
|
||||
if err := c.MariusSocket.WriteJSON(req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package participanthandler
|
||||
|
||||
import "log"
|
||||
|
||||
// CheckIfParticipantIsValid überprüft, ob ein Teilnehmer gültig ist.
|
||||
// equipmentNumber: Die Nummer des Geräts, dessen Gültigkeit überprüft werden soll.
|
||||
// Rückgabewert: Gibt eine Struktur zurück, die die Gültigkeit des Teilnehmers und seine Daten enthält.
|
||||
func (c *ParticipantHandler) CheckIfParticipantIsValid(equipmentNumber int) CheckIfParticipantIsValidReturn {
|
||||
// Erstellen einer Anfrage zur Überprüfung der Teilnehmergültigkeit
|
||||
req := CheckIfParticipantIsValidRequest{Type: "baseDlRequest", UUID: "UUID"}
|
||||
|
||||
// Senden der Anfrage über das ParticipantManagement
|
||||
c.ParticipantManagement.WriteJSON(req)
|
||||
|
||||
var res CheckIfParticipantIsValidResponse
|
||||
for {
|
||||
// Lesen der Antwort vom ParticipantManagement
|
||||
err := c.ParticipantManagement.ReadJSON(&res)
|
||||
if err != nil {
|
||||
log.Fatal("CheckIfParticipantIsValidRequest - Error getting participant data:", err)
|
||||
}
|
||||
|
||||
// Überprüfen, ob die Antwort den erwarteten Typ hat
|
||||
if res.Type == "participantBaseData" {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var participantData *CheckIfParticipantIsValidReturn
|
||||
// Durchlaufen der Teilnehmerdaten, um den passenden Teilnehmer zu finden
|
||||
for _, participant := range res.Data {
|
||||
if participant.EquipmentNumber == equipmentNumber {
|
||||
participantData = &CheckIfParticipantIsValidReturn{
|
||||
TacticalIdentifier: participant.TacticalIdentifier,
|
||||
Designator: participant.Designator,
|
||||
EquipmentNumber: participant.EquipmentNumber,
|
||||
Valid: true,
|
||||
PartyId: participant.PartyID,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Falls kein passender Teilnehmer gefunden wurde, wird eine ungültige Struktur zurückgegeben
|
||||
if participantData == nil {
|
||||
participantData = &CheckIfParticipantIsValidReturn{
|
||||
TacticalIdentifier: "",
|
||||
Designator: "",
|
||||
EquipmentNumber: 0,
|
||||
Valid: false,
|
||||
PartyId: 0,
|
||||
}
|
||||
}
|
||||
|
||||
return *participantData
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package participanthandler
|
||||
|
||||
import "log"
|
||||
|
||||
func (c *ParticipantHandler) GetAllParticipants() []*CheckIfParticipantIsValidReturn {
|
||||
// Erstellen einer Anfrage zur Überprüfung der Teilnehmergültigkeit
|
||||
req := CheckIfParticipantIsValidRequest{Type: "baseDlRequest", UUID: "UUID"}
|
||||
|
||||
// Senden der Anfrage über das ParticipantManagement
|
||||
c.ParticipantManagement.WriteJSON(req)
|
||||
|
||||
var res CheckIfParticipantIsValidResponse
|
||||
for {
|
||||
// Lesen der Antwort vom ParticipantManagement
|
||||
err := c.ParticipantManagement.ReadJSON(&res)
|
||||
if err != nil {
|
||||
log.Fatal("CheckIfParticipantIsValidRequest - Error getting participant data:", err)
|
||||
}
|
||||
|
||||
// Überprüfen, ob die Antwort den erwarteten Typ hat
|
||||
if res.Type == "participantBaseData" {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var participantData []*CheckIfParticipantIsValidReturn
|
||||
// Durchlaufen der Teilnehmerdaten, um den passenden Teilnehmer zu finden
|
||||
for _, participant := range res.Data {
|
||||
if participant.PartyID == 2 || participant.PartyID == 3 || participant.PartyID == 4 {
|
||||
if participant.EquipmentNumber != 0 {
|
||||
participantData = append(participantData, &CheckIfParticipantIsValidReturn{
|
||||
TacticalIdentifier: participant.TacticalIdentifier,
|
||||
Designator: participant.Designator,
|
||||
EquipmentNumber: participant.EquipmentNumber,
|
||||
Valid: true,
|
||||
PartyId: participant.PartyID,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return participantData
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package participanthandler
|
||||
|
||||
import (
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// ParticipantHandler verwaltet die Verbindungen und Anfragen für Teilnehmer.
|
||||
type ParticipantHandler struct {
|
||||
ParticipantManagement *websocket.Conn // Verbindung zum Participant Management
|
||||
MariusSocket *websocket.Conn // Verbindung zum Marius Socket
|
||||
}
|
||||
|
||||
// CheckIfParticipantIsValidRequest repräsentiert eine Anfrage zur Überprüfung der Gültigkeit eines Teilnehmers.
|
||||
type CheckIfParticipantIsValidRequest struct {
|
||||
Type string `json:"type"` // Typ der Anfrage
|
||||
UUID string `json:"uuid"` // Eindeutige Identifikationsnummer der Anfrage
|
||||
}
|
||||
|
||||
// CheckIfParticipantIsValidResponse repräsentiert die Antwort auf eine Anfrage zur Überprüfung der Gültigkeit eines Teilnehmers.
|
||||
type CheckIfParticipantIsValidResponse struct {
|
||||
Data []struct {
|
||||
AssignState int `json:"assignState"` // Zuweisungsstatus
|
||||
Designator string `json:"designator"` // Designator des Teilnehmers
|
||||
EquipmentNumber int `json:"equipmentNumber"` // Gerätenummer
|
||||
ExternalID int `json:"externalId"` // Externe ID
|
||||
HierarchyNumber int `json:"hierarchyNumber"` // Hierarchienummer
|
||||
ID int `json:"id"` // ID des Teilnehmers
|
||||
Identification string `json:"identification"` // Identifikation
|
||||
Info string `json:"info"` // Zusätzliche Informationen
|
||||
IsDeleted bool `json:"isDeleted"` // Löschstatus
|
||||
IsSimulated bool `json:"isSimulated"` // Simulationsstatus
|
||||
Name string `json:"name"` // Name des Teilnehmers
|
||||
PartyID int `json:"partyId"` // Party ID
|
||||
Properties string `json:"properties"` // Eigenschaften
|
||||
SuperiorID int `json:"superiorId"` // ID des Vorgesetzten
|
||||
Symbol string `json:"symbol"` // Symbol
|
||||
TacticalIdentifier string `json:"tacticalIdentifier"` // Taktischer Identifikator
|
||||
TypeID int `json:"typeId"` // Typ ID
|
||||
} `json:"data"` // Liste der Teilnehmerdaten
|
||||
Type string `json:"type"` // Typ der Antwort
|
||||
UUID string `json:"uuid"` // Eindeutige Identifikationsnummer der Antwort
|
||||
}
|
||||
|
||||
// CheckIfParticipantIsValidReturn repräsentiert die Rückgabewerte der Überprüfung der Gültigkeit eines Teilnehmers.
|
||||
type CheckIfParticipantIsValidReturn struct {
|
||||
TacticalIdentifier string `json:"tacticalIdentifier"` // Taktischer Identifikator
|
||||
Designator string `json:"designator"` // Designator des Teilnehmers
|
||||
EquipmentNumber int `json:"equipmentNumber"` // Gerätenummer
|
||||
Valid bool `json:"valid"` // Gültigkeitsstatus
|
||||
PartyId int `json:"partyId"` // Party ID
|
||||
}
|
||||
|
||||
// AbcProtectionChangeRequest repräsentiert eine Anfrage zur Änderung des ABC-Schutzstatus.
|
||||
type AbcProtectionChangeRequest struct {
|
||||
Data struct {
|
||||
Header struct {
|
||||
EquipmentNumber int `json:"equipmentNumber"` // Gerätenummer
|
||||
TimeStamp int `json:"timeStamp"` // Zeitstempel
|
||||
} `json:"header"`
|
||||
NbcProtectionActive bool `json:"nbcProtectionActive"` // Status des ABC-Schutzes
|
||||
} `json:"data"`
|
||||
TypeID int `json:"typeId"` // Typ ID der Anfrage
|
||||
}
|
||||
|
||||
// GeoPosition repräsentiert eine geografische Position.
|
||||
type GeoPosition struct {
|
||||
Lat float64 // Breitengrad
|
||||
Lng float64 // Längengrad
|
||||
}
|
||||
|
||||
// PositionChangeRequest repräsentiert eine Anfrage zur Änderung der Position eines Geräts.
|
||||
type PositionChangeRequest struct {
|
||||
Data struct {
|
||||
Header struct {
|
||||
EquipmentNumber int `json:"equipmentNumber"` // Gerätenummer
|
||||
TimeStamp int `json:"timeStamp"` // Zeitstempel
|
||||
} `json:"header"`
|
||||
GeoPosition struct {
|
||||
Lon float64 `json:"lon"` // Längengrad in Radiant
|
||||
Lat float64 `json:"lat"` // Breitengrad in Radiant
|
||||
Z float64 `json:"z"` // Höhe (standardmäßig 0.0)
|
||||
} `json:"geoPosition"`
|
||||
} `json:"data"`
|
||||
TypeID int `json:"typeId"` // Typ ID der Anfrage
|
||||
}
|
||||
Reference in new issue
Block a user