diff --git a/cmd/display.go b/cmd/display.go index 1d9616c..623f1ce 100644 --- a/cmd/display.go +++ b/cmd/display.go @@ -82,6 +82,9 @@ func SprintColumnTitles(logLine LogLine) (output string){ // SprintLogInColumn displays the logLine in column mode func SprintLogInColumn(logLine LogLine) (output string){ notes := "" + if logLine.Frequency != "" { + notes = notes + "QRG: " + logLine.Frequency + " " + } if logLine.Comment != "" { notes = notes + "[" + logLine.Comment + "] " } diff --git a/cmd/parse_line.go b/cmd/parse_line.go index 67898be..1e471d9 100644 --- a/cmd/parse_line.go +++ b/cmd/parse_line.go @@ -17,8 +17,11 @@ limitations under the License. import ( + "fmt" "regexp" + "strconv" "strings" + //"fmt" ) //TODO: validate a record for minimal values @@ -36,8 +39,8 @@ type LogLine struct { Mode string ModeType string Band string - BandLowerLimit float32 - BandUpperLimit float32 + BandLowerLimit float64 + BandUpperLimit float64 Frequency string Time string Call string @@ -56,7 +59,7 @@ var regexpIsTimePart = regexp.MustCompile("^[0-5]{1}[0-9]{1}$|^[1-9]{1}$") var regexpIsOMname = regexp.MustCompile("^@") var regexpIsGridLoc = regexp.MustCompile("^#") var regexpIsRst = regexp.MustCompile("^[\\d]{1,3}$") -var regexpIsFreq = regexp.MustCompile("^[\\d]+.[\\d]+$") +var regexpIsFreq = regexp.MustCompile("^[\\d]+\\.[\\d]+$") // ParseLine cuts a FLE line into useful bits func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg string){ @@ -126,11 +129,18 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg // Is it a Frequency? if regexpIsFreq.MatchString(element) { - //TODO: check if we are in the band limits (is a band defined?) - //TODO: how do we handle/report errors - //TODO: take only 3 decimal digits - //TODO: update the column display - logLine.Frequency = element + var qrg float64 + qrg,_ = strconv.ParseFloat(element, 32) + if (logLine.BandLowerLimit != 0.0) && (logLine.BandUpperLimit != 0.0){ + if (qrg >= logLine.BandLowerLimit) && (qrg <= logLine.BandUpperLimit) { + logLine.Frequency = fmt.Sprintf("%.3f",qrg) + } else { + logLine.Frequency = "" + errorMsg = errorMsg + " Frequency " + element + " is invalid for " + logLine.Band + " band" + } + } else { + errorMsg = errorMsg + " Unable to load frequency " + element + ": no band defined." + } continue } @@ -242,6 +252,9 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg _, logLine.RSTrcvd = getDefaultReport(logLine.Mode) } + //For debug purposes + //fmt.Println("\n", SprintLogRecord(logLine)) + return logLine, errorMsg } diff --git a/cmd/parse_line_test.go b/cmd/parse_line_test.go index 413dd80..71f5426 100644 --- a/cmd/parse_line_test.go +++ b/cmd/parse_line_test.go @@ -69,8 +69,13 @@ func TestParseLine(t *testing.T) { }, { "Parse frequency", - args{ inputStr: "14.453 on4kjm", previousLine: LogLine{ Mode: "SSB", Band: "20m"}}, - LogLine{ Band: "20m", Frequency: "14.453", Call: "ON4KJM" ,Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "", + args{ inputStr: "14.153 on4kjm", previousLine: LogLine{ Mode: "SSB", Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35}}, + LogLine{ Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35, Frequency: "14.153", Call: "ON4KJM" ,Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "", + }, + { + "Parse frequency out of limit", + args{ inputStr: "14.453 on4kjm", previousLine: LogLine{ Mode: "SSB", Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35}}, + LogLine{ Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35, Call: "ON4KJM" ,Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, " Frequency 14.453 is invalid for 20m band", }, { "parse partial RST (sent) - CW", diff --git a/cmd/validate.go b/cmd/validate.go index 1691f99..4cf3597 100644 --- a/cmd/validate.go +++ b/cmd/validate.go @@ -115,7 +115,7 @@ func ValidateDate(inputStr string) (ref, errorMsg string) { } //IsBand retuns true if the passed input string is a valid string -func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float32) { +func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float64) { switch strings.ToLower(inputStr) { case "2190m": return true, 0.1357, 0.1378 diff --git a/cmd/validate_test.go b/cmd/validate_test.go index 234e71b..a217433 100644 --- a/cmd/validate_test.go +++ b/cmd/validate_test.go @@ -274,8 +274,8 @@ func TestIsBand(t *testing.T) { name string args args wantResult bool - wantLowerLimit float32 - wantUpperLimit float32 + wantLowerLimit float64 + wantUpperLimit float64 }{ { "invalid band",