This commit is contained in:
2024-10-17 20:28:43 +03:00
parent 4c7a1758d6
commit ef84b7d7f9
8 changed files with 335 additions and 76 deletions

View File

@ -73,18 +73,21 @@ func (fc *FlexClient) StartFlexClient() {
addr, err := net.ResolveTCPAddr("tcp", fc.Address+":"+fc.Port)
if err != nil {
fc.Log.Error("cannot resolve Telnet Client address")
fc.Log.Error("Cannot resolve Telnet Client address")
}
fc.LogWriter = bufio.NewWriter(os.Stdout)
fc.Timeout = 600 * time.Second
fc.Log.Infof("Trying to connect to flex radio at %s:%s", fc.Address, fc.Port)
fc.Conn, err = net.DialTCP("tcp", nil, addr)
if err != nil {
fc.Log.Errorf("could not connect to flex radio on %s, exiting...", Cfg.Flex.IP)
fc.Log.Errorf("Could not connect to flex radio on %s, exiting...", Cfg.Flex.IP)
os.Exit(1)
}
fc.Log.Infof("connected to flex radio at %s:%s", fc.Address, fc.Port)
fc.Log.Infof("Connected to flex radio at %s:%s", fc.Address, fc.Port)
go func() {
for message := range fc.SpotChan {
@ -154,11 +157,11 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) {
flexSpot.Priority = "5"
} else if spot.NewMode {
flexSpot.Color = "#f9a908"
flexSpot.Priority = "1"
flexSpot.Priority = "2"
flexSpot.BackgroundColor = "#000000"
} else if spot.NewBand {
flexSpot.Color = "#f9f508"
flexSpot.Priority = "1"
flexSpot.Priority = "3"
flexSpot.BackgroundColor = "#000000"
} else if !spot.NewBand && !spot.NewMode && !spot.NewDXCC && !spot.CallsignWorked {
flexSpot.Color = "#eaeaea"
@ -166,7 +169,7 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) {
flexSpot.BackgroundColor = "#000000"
}
flexSpot.Comment = flexSpot.Comment + "[" + flexSpot.Mode + "] [" + flexSpot.SpotterCallsign + "]"
flexSpot.Comment = flexSpot.Comment + " [" + flexSpot.Mode + "] [" + flexSpot.SpotterCallsign + "]"
flexSpot.Comment = strings.ReplaceAll(flexSpot.Comment, " ", "\u00A0")
srcFlexSpot, err := fc.Repo.FindDXSameBand(flexSpot)
@ -175,7 +178,9 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) {
}
// send FlexSpot to HTTP Server
fc.FlexSpotChan <- flexSpot
if Cfg.General.HTTPServer {
fc.FlexSpotChan <- flexSpot
}
var stringSpot string
if srcFlexSpot.DX == "" {
@ -198,9 +203,7 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) {
}
if Cfg.General.FlexRadioSpot {
fc.SendSpot(stringSpot)
}
fc.SendSpot(stringSpot)
}
func (fc *FlexClient) SendSpot(stringSpot string) {
@ -212,7 +215,7 @@ func (fc *FlexClient) ReadLine() {
for {
message, err := fc.Reader.ReadString(byte('\n'))
if err != nil {
fc.Log.Errorf("error reading message from flexradio closing program: %s", err)
fc.Log.Errorf("Error reading message from flexradio closing program: %s", err)
os.Exit(1)
}
@ -223,7 +226,7 @@ func (fc *FlexClient) ReadLine() {
spot, _ := fc.Repo.FindSpotByCommandNumber(respSpot[1])
_, err := fc.Repo.UpdateFlexSpotNumberByID(respSpot[2], *spot)
if err != nil {
fc.Log.Errorf("could not update flex spot number in database: %s", err)
fc.Log.Errorf("Could not update flex spot number in database: %s", err)
}
}
@ -264,3 +267,18 @@ func (fc *FlexClient) Write(data string) (n int, err error) {
}
return
}
func (fc *FlexClient) parseMessage(message string) {
msgType := string(message[0])
switch msgType {
case "R":
// reply
case "S":
// status
case "V":
// Version
case "M":
// Message
}
}