diff --git a/cmd/parse_line.go b/cmd/parse_line.go index 153a0c7..68fb217 100644 --- a/cmd/parse_line.go +++ b/cmd/parse_line.go @@ -45,6 +45,8 @@ type LogLine struct { GridLoc string RSTsent string RSTrcvd string + WWFF string + SOTA string } var regexpIsFullTime = regexp.MustCompile("^[0-2]{1}[0-9]{3}$") @@ -68,6 +70,8 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg previousLine.Call = "" previousLine.RSTsent = "" previousLine.RSTrcvd = "" + previousLine.SOTA = "" + previousLine.WWFF = "" logLine = previousLine //TODO: what happens when we have <> or when there are multiple comments @@ -195,6 +199,20 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg } continue } + + // Is it a WWFF to WWFF reference? + workRef, wwffErr := ValidateWwff(element) + if wwffErr == "" { + logLine.WWFF = workRef + continue + } + + // Is it a WWFF to WWFF reference? + workRef, sotaErr := ValidateSota(element) + if sotaErr == "" { + logLine.SOTA = workRef + continue + } } //If we come here, we could not make sense of what we found @@ -241,28 +259,12 @@ func SprintLogRecord(logLine LogLine) (output string){ output = output + "GridLoc " + logLine.GridLoc + "\n" output = output + "RSTsent " + logLine.RSTsent + "\n" output = output + "RSTrcvd " + logLine.RSTrcvd + "\n" + output = output + "SOTA " + logLine.SOTA + "\n" + output = output + "WWFF " + logLine.WWFF + "\n" return output } -func getDefaultReport(mode string) (modeType, defaultReport string) { - modeType = "" - defaultReport = "" - - switch mode { - case "SSB", "AM", "FM" : - modeType = "PHONE" - defaultReport = "59" - case "CW", "RTTY", "PSK": - modeType = "CW" - defaultReport = "599" - case "JT65", "JT9", "JT6M", "JT4", "JT44", "FSK441", "FT8", "ISCAT", "MSK144", "QRA64", "T10", "WSPR" : - modeType = "DIGITAL" - defaultReport = "-10" - } - return modeType, defaultReport -} - func lookupMode(lookup string) bool { switch lookup { diff --git a/cmd/parse_line_test.go b/cmd/parse_line_test.go index b44e3e9..767cb7d 100644 --- a/cmd/parse_line_test.go +++ b/cmd/parse_line_test.go @@ -122,11 +122,6 @@ func TestHappyParseLine(t *testing.T) { wantLogLine LogLine wantErrorMsg string }{ - -// 4 g3noh -// 2m fm -// 1227 gw4gte -// 8 gw0tlk/m gwff-0021 { "test1", args{ inputStr: "1202 g4elz", @@ -139,6 +134,24 @@ func TestHappyParseLine(t *testing.T) { previousLine: LogLine{ Time: "1202", Mode: "CW", ModeType: "CW", Band: "40m", BandLowerLimit: 7, BandUpperLimit: 7.3}}, LogLine{ Time: "1204", Call: "G3NOH", Band: "40m", BandLowerLimit: 7, BandUpperLimit: 7.3, Mode: "CW", ModeType: "CW", Comment: "PSE QSL Direct", RSTsent: "599", RSTrcvd: "599"}, "", }, + { + "test3", + args{ inputStr: "1227 gw4gte ", + previousLine: LogLine{ Time: "1202", Mode: "FM", ModeType: "PHONE", Band: "2m", BandLowerLimit: 144, BandUpperLimit: 148}}, + LogLine{ Time: "1227", Call: "GW4GTE", Band: "2m", BandLowerLimit: 144, BandUpperLimit: 148, Mode: "FM", ModeType: "PHONE", Comment: "Dave", RSTsent: "59", RSTrcvd: "59"}, "", + }, + { + "test4", + args{ inputStr: "8 gw0tlk/m gwff-0021", + previousLine: LogLine{ Time: "1227", Mode: "FM", ModeType: "PHONE", Band: "2m", BandLowerLimit: 144, BandUpperLimit: 148}}, + LogLine{ Time: "1228", Call: "GW0TLK/M", Band: "2m", BandLowerLimit: 144, BandUpperLimit: 148, Mode: "FM", ModeType: "PHONE", WWFF: "GWFF-0021", RSTsent: "59", RSTrcvd: "59"}, "", + }, + { + "test5", + args{ inputStr: "7 dl0dan/p dlff-0002 dl/al-044", + previousLine: LogLine{ Time: "1220", Mode: "FM", ModeType: "PHONE", Band: "2m", BandLowerLimit: 144, BandUpperLimit: 148}}, + LogLine{ Time: "1227", Call: "DL0DAN/P", Band: "2m", BandLowerLimit: 144, BandUpperLimit: 148, Mode: "FM", ModeType: "PHONE", WWFF: "DLFF-0002", SOTA: "DL/AL-044", RSTsent: "59", RSTrcvd: "59"}, "", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/cmd/validate.go b/cmd/validate.go index be516b7..1691f99 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -115,7 +115,6 @@ func ValidateDate(inputStr string) (ref, errorMsg string) { } //IsBand retuns true if the passed input string is a valid string -//TODO: return the frequencies func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float32) { switch strings.ToLower(inputStr) { case "2190m": @@ -180,4 +179,23 @@ func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float32) { return true, 241000, 250000 } return false, 0, 0 -} \ No newline at end of file +} + + +func getDefaultReport(mode string) (modeType, defaultReport string) { + modeType = "" + defaultReport = "" + + switch mode { + case "SSB", "AM", "FM" : + modeType = "PHONE" + defaultReport = "59" + case "CW", "RTTY", "PSK": + modeType = "CW" + defaultReport = "599" + case "JT65", "JT9", "JT6M", "JT4", "JT44", "FSK441", "FT8", "ISCAT", "MSK144", "QRA64", "T10", "WSPR" : + modeType = "DIGITAL" + defaultReport = "-10" + } + return modeType, defaultReport +}