Implement complete frequency loading

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent 247f869bf5
commit 872cfd99ce

@ -82,6 +82,9 @@ func SprintColumnTitles(logLine LogLine) (output string){
// SprintLogInColumn displays the logLine in column mode // SprintLogInColumn displays the logLine in column mode
func SprintLogInColumn(logLine LogLine) (output string){ func SprintLogInColumn(logLine LogLine) (output string){
notes := "" notes := ""
if logLine.Frequency != "" {
notes = notes + "QRG: " + logLine.Frequency + " "
}
if logLine.Comment != "" { if logLine.Comment != "" {
notes = notes + "[" + logLine.Comment + "] " notes = notes + "[" + logLine.Comment + "] "
} }

@ -17,8 +17,11 @@ limitations under the License.
import ( import (
"fmt"
"regexp" "regexp"
"strconv"
"strings" "strings"
//"fmt"
) )
//TODO: validate a record for minimal values //TODO: validate a record for minimal values
@ -36,8 +39,8 @@ type LogLine struct {
Mode string Mode string
ModeType string ModeType string
Band string Band string
BandLowerLimit float32 BandLowerLimit float64
BandUpperLimit float32 BandUpperLimit float64
Frequency string Frequency string
Time string Time string
Call 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 regexpIsOMname = regexp.MustCompile("^@")
var regexpIsGridLoc = regexp.MustCompile("^#") var regexpIsGridLoc = regexp.MustCompile("^#")
var regexpIsRst = regexp.MustCompile("^[\\d]{1,3}$") 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 // ParseLine cuts a FLE line into useful bits
func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg string){ 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? // Is it a Frequency?
if regexpIsFreq.MatchString(element) { if regexpIsFreq.MatchString(element) {
//TODO: check if we are in the band limits (is a band defined?) var qrg float64
//TODO: how do we handle/report errors qrg,_ = strconv.ParseFloat(element, 32)
//TODO: take only 3 decimal digits if (logLine.BandLowerLimit != 0.0) && (logLine.BandUpperLimit != 0.0){
//TODO: update the column display if (qrg >= logLine.BandLowerLimit) && (qrg <= logLine.BandUpperLimit) {
logLine.Frequency = element 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 continue
} }
@ -242,6 +252,9 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
_, logLine.RSTrcvd = getDefaultReport(logLine.Mode) _, logLine.RSTrcvd = getDefaultReport(logLine.Mode)
} }
//For debug purposes
//fmt.Println("\n", SprintLogRecord(logLine))
return logLine, errorMsg return logLine, errorMsg
} }

@ -69,8 +69,13 @@ func TestParseLine(t *testing.T) {
}, },
{ {
"Parse frequency", "Parse frequency",
args{ inputStr: "14.453 on4kjm", previousLine: LogLine{ Mode: "SSB", Band: "20m"}}, args{ inputStr: "14.153 on4kjm", previousLine: LogLine{ Mode: "SSB", Band: "20m", BandLowerLimit: 14.0, BandUpperLimit: 14.35}},
LogLine{ Band: "20m", Frequency: "14.453", Call: "ON4KJM" ,Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "", 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", "parse partial RST (sent) - CW",

@ -115,7 +115,7 @@ func ValidateDate(inputStr string) (ref, errorMsg string) {
} }
//IsBand retuns true if the passed input string is a valid 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) { switch strings.ToLower(inputStr) {
case "2190m": case "2190m":
return true, 0.1357, 0.1378 return true, 0.1357, 0.1378

@ -274,8 +274,8 @@ func TestIsBand(t *testing.T) {
name string name string
args args args args
wantResult bool wantResult bool
wantLowerLimit float32 wantLowerLimit float64
wantUpperLimit float32 wantUpperLimit float64
}{ }{
{ {
"invalid band", "invalid band",

Loading…
Cancel
Save