First iteration on parse_line completed

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent 018e2da453
commit d8bc64428e

@ -45,6 +45,8 @@ type LogLine struct {
GridLoc string GridLoc string
RSTsent string RSTsent string
RSTrcvd string RSTrcvd string
WWFF string
SOTA string
} }
var regexpIsFullTime = regexp.MustCompile("^[0-2]{1}[0-9]{3}$") 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.Call = ""
previousLine.RSTsent = "" previousLine.RSTsent = ""
previousLine.RSTrcvd = "" previousLine.RSTrcvd = ""
previousLine.SOTA = ""
previousLine.WWFF = ""
logLine = previousLine logLine = previousLine
//TODO: what happens when we have <> or when there are multiple comments //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 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 //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 + "GridLoc " + logLine.GridLoc + "\n"
output = output + "RSTsent " + logLine.RSTsent + "\n" output = output + "RSTsent " + logLine.RSTsent + "\n"
output = output + "RSTrcvd " + logLine.RSTrcvd + "\n" output = output + "RSTrcvd " + logLine.RSTrcvd + "\n"
output = output + "SOTA " + logLine.SOTA + "\n"
output = output + "WWFF " + logLine.WWFF + "\n"
return output 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 { func lookupMode(lookup string) bool {
switch lookup { switch lookup {

@ -122,11 +122,6 @@ func TestHappyParseLine(t *testing.T) {
wantLogLine LogLine wantLogLine LogLine
wantErrorMsg string wantErrorMsg string
}{ }{
// 4 g3noh <PSE QSL Direct>
// 2m fm
// 1227 gw4gte <Dave>
// 8 gw0tlk/m gwff-0021
{ {
"test1", "test1",
args{ inputStr: "1202 g4elz", 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}}, 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"}, "", 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 <Dave>",
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 { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

@ -115,7 +115,6 @@ 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
//TODO: return the frequencies
func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float32) { func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float32) {
switch strings.ToLower(inputStr) { switch strings.ToLower(inputStr) {
case "2190m": case "2190m":
@ -180,4 +179,23 @@ func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float32) {
return true, 241000, 250000 return true, 241000, 250000
} }
return false, 0, 0 return false, 0, 0
} }
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
}

Loading…
Cancel
Save