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
func SprintLogInColumn(logLine LogLine) (output string){
notes := ""
if logLine.Frequency != "" {
notes = notes + "QRG: " + logLine.Frequency + " "
}
if logLine.Comment != "" {
notes = notes + "[" + logLine.Comment + "] "
}

@ -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
}

@ -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",

@ -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

@ -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",

Loading…
Cancel
Save