package main import ( "fmt" "regexp" "strconv" "strings" _ "github.com/mattn/go-sqlite3" log "github.com/sirupsen/logrus" ) type TelnetSpot struct { DX string Spotter string Frequency string Mode string Band string Time string DXCC string Comment string CommandNumber int FlexSpotNumber int NewDXCC bool NewBand bool NewMode bool CallsignWorked bool } func ProcessTelnetSpot(re *regexp.Regexp, spotRaw string, SpotChan chan TelnetSpot, log *log.Logger) { match := re.FindStringSubmatch(spotRaw) if len(match) != 0 { spot := TelnetSpot{ DX: match[3], Spotter: match[1], Frequency: match[2], Mode: match[4], Comment: strings.Trim(match[5], " "), Time: match[6], } spot.GetBand() spot.GuessMode() spot.DXCC, _ = CheckClubogDXCC(spot.DX) spot.CallsignWorked = false spot.NewBand = false spot.NewMode = false spot.NewDXCC = false contactRepo := NewLog4OMContactsRepository(Cfg.SQLite.SQLitePath, log) defer contactRepo.db.Close() contacts, _ := contactRepo.ListByCountry(spot.DXCC) contactsMode, _ := contactRepo.ListByCountryMode(spot.DXCC, spot.Mode) contactsBand, _ := contactRepo.ListByCountryBand(spot.DXCC, spot.Band) contactsCall, _ := contactRepo.ListByCallSign(spot.DX, spot.Band, spot.Mode) if len(contacts) == 0 { switch spot.DXCC { case "997": spot.NewDXCC = false case "1000": spot.NewDXCC = false default: spot.NewDXCC = true } } else if len(contactsMode) == 0 { spot.NewMode = true } else if len(contactsBand) == 0 { spot.NewBand = true } else if len(contactsCall) > 0 { spot.CallsignWorked = true } if spot.NewDXCC { log.Infof("(** New DXCC **) DX: %s - Spotter: %s - Freq: %s - Band: %s - Mode: %s - Comment: %s - Time: %s - Command: %v, FlexSpot: %v", spot.DX, spot.Spotter, spot.Frequency, spot.Band, spot.Mode, spot.Comment, spot.Time, spot.CommandNumber, spot.FlexSpotNumber) } if !spot.NewDXCC && spot.NewBand && spot.NewMode { log.Infof("(** New Band/Mode **) DX: %s - Spotter: %s - Freq: %s - Band: %s - Mode: %s - Comment: %s - Time: %s - DXCC: %s", spot.DX, spot.Spotter, spot.Frequency, spot.Band, spot.Mode, spot.Comment, spot.Time, spot.DXCC) } if !spot.NewDXCC && spot.NewBand && !spot.NewMode { log.Infof("(** New Band **) DX: %s - Spotter: %s - Freq: %s - Band: %s - Mode: %s - Comment: %s - Time: %s - DXCC: %s", spot.DX, spot.Spotter, spot.Frequency, spot.Band, spot.Mode, spot.Comment, spot.Time, spot.DXCC) } if !spot.NewDXCC && !spot.NewBand && spot.NewMode { log.Infof("(** New Mode **) DX: %s - Spotter: %s - Freq: %s - Band: %s - Mode: %s - Comment: %s - Time: %s - DXCC: %s", spot.DX, spot.Spotter, spot.Frequency, spot.Band, spot.Mode, spot.Comment, spot.Time, spot.DXCC) } if !spot.NewDXCC && !spot.NewBand && !spot.NewMode && spot.CallsignWorked { log.Infof("(** Worked **) DX: %s - Spotter: %s - Freq: %s - Band: %s - Mode: %s - Comment: %s - Time: %s - DXCC: %s", spot.DX, spot.Spotter, spot.Frequency, spot.Band, spot.Mode, spot.Comment, spot.Time, spot.DXCC) } if !spot.NewDXCC && !spot.NewBand && !spot.NewMode { log.Infof("DX: %s - Spotter: %s - Freq: %s - Band: %s - Mode: %s - Comment: %s - Time: %s - DXCC: %s", spot.DX, spot.Spotter, spot.Frequency, spot.Band, spot.Mode, spot.Comment, spot.Time, spot.DXCC) } // send spot to SpotChan to Flex Client to send the spot to Flex radio SpotChan <- spot } } func (spot *TelnetSpot) GetBand() { switch true { case strings.HasPrefix(spot.Frequency, "1.8"): spot.Band = "160M" if spot.Mode == "SSB" { spot.Mode = "LSB" } case strings.HasPrefix(spot.Frequency, "3"): spot.Band = "80M" if spot.Mode == "SSB" { spot.Mode = "LSB" } case strings.HasPrefix(spot.Frequency, "7"): spot.Band = "40M" if spot.Mode == "SSB" { spot.Mode = "LSB" } case strings.HasPrefix(spot.Frequency, "10"): spot.Band = "30M" case strings.HasPrefix(spot.Frequency, "14"): spot.Band = "20M" if spot.Mode == "SSB" { spot.Mode = "USB" } case strings.HasPrefix(spot.Frequency, "18"): spot.Band = "17M" if spot.Mode == "SSB" { spot.Mode = "USB" } case strings.HasPrefix(spot.Frequency, "21"): spot.Band = "15M" if spot.Mode == "SSB" { spot.Mode = "USB" } case strings.HasPrefix(spot.Frequency, "24"): spot.Band = "12M" if spot.Mode == "SSB" { spot.Mode = "USB" } case strings.HasPrefix(spot.Frequency, "28"): spot.Band = "10M" if spot.Mode == "SSB" { spot.Mode = "USB" } case strings.HasPrefix(spot.Frequency, "29"): spot.Band = "10M" if spot.Mode == "SSB" { spot.Mode = "USB" } default: spot.Band = "N/A" } } func (spot *TelnetSpot) GuessMode() { if spot.Mode == "" { freqInt, err := strconv.ParseFloat(spot.Frequency, 32) if err != nil { fmt.Println("could not convert frequency string in float64:", err) } switch spot.Band { case "160M": if freqInt <= 1840 && freqInt >= 1800 { spot.Mode = "CW" } case "40M": if freqInt <= 7074 && freqInt >= 7000 { spot.Mode = "CW" } else if freqInt <= 7079 && freqInt > 7074 { spot.Mode = "FT8" } else if freqInt <= 7079 && freqInt > 7074 { spot.Mode = "FT8" } else if freqInt <= 7079 && freqInt > 7074 { spot.Mode = "FT8" } } } }