Improve default RST (mode from previous line)

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

@ -92,22 +92,14 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
// Is it a mode? // Is it a mode?
if lookupMode( strings.ToUpper(element)) { if lookupMode( strings.ToUpper(element)) {
logLine.Mode = strings.ToUpper(element) logLine.Mode = strings.ToUpper(element)
//TODO: improve this: what if the band is at the end of the line
// Set the default RST depending of the mode // Set the default RST depending of the mode
if (logLine.RSTsent == "") || (logLine.RSTrcvd == "") { if (logLine.RSTsent == "") || (logLine.RSTrcvd == "") {
switch logLine.Mode { // get default RST and Mode category
case "SSB", "AM", "FM" : modeType, defaultReport := getDefaultReport(logLine.Mode)
logLine.ModeType = "PHONE" logLine.ModeType = modeType
logLine.RSTsent = "59" logLine.RSTsent = defaultReport
logLine.RSTrcvd = "59" logLine.RSTrcvd = defaultReport
case "CW", "RTTY", "PSK":
logLine.ModeType = "CW"
logLine.RSTsent = "599"
logLine.RSTrcvd = "599"
case "JT65", "JT9", "JT6M", "JT4", "JT44", "FSK441", "FT8", "ISCAT", "MSK144", "QRA64", "T10", "WSPR" :
logLine.ModeType = "DIGITAL"
logLine.RSTsent = "-10"
logLine.RSTrcvd = "-10"
}
} else { } else {
errorMsg = errorMsg + "Double definitiion of RST" errorMsg = errorMsg + "Double definitiion of RST"
@ -210,8 +202,16 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
} }
fmt.Println(elements, len(elements)) //If no report is present, let's fill it with mode default
if logLine.RSTsent == "" {
_, logLine.RSTsent = getDefaultReport(logLine.Mode)
}
if logLine.RSTrcvd == "" {
_, logLine.RSTrcvd = getDefaultReport(logLine.Mode)
}
//Debug
fmt.Println(elements, len(elements))
fmt.Println("\n", SprintLogRecord(logLine)) fmt.Println("\n", SprintLogRecord(logLine))
return logLine, errorMsg return logLine, errorMsg
@ -245,6 +245,23 @@ func SprintLogRecord(logLine LogLine) (output string){
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 {

@ -25,52 +25,52 @@ func TestParseLine(t *testing.T) {
{ {
"Parse for time", "Parse for time",
args{ inputStr: "1314 g3noh", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "1314 g3noh", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ Time: "1314", Call: "G3NOH", Mode: "SSB",}, "", LogLine{ Time: "1314", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
}, },
{ {
"Parse partial time - 1", "Parse partial time - 1",
args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "", Mode: "SSB", }}, args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "", Mode: "SSB", }},
LogLine{ Time: "4", Call: "G3NOH", Mode: "SSB",}, "", //TODO: should fail LogLine{ Time: "4", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "", //TODO: should fail
}, },
{ {
"Parse partial time - 2", "Parse partial time - 2",
args{ inputStr: "15 g3noh", previousLine: LogLine{ Time: "1200", Mode: "SSB", }}, args{ inputStr: "15 g3noh", previousLine: LogLine{ Time: "1200", Mode: "SSB", }},
LogLine{ Time: "1215", Call: "G3NOH", Mode: "SSB",}, "", LogLine{ Time: "1215", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
}, },
{ {
"Parse partial time - 3", "Parse partial time - 3",
args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "1200", Mode: "SSB", }}, args{ inputStr: "4 g3noh", previousLine: LogLine{ Time: "1200", Mode: "SSB", }},
LogLine{ Time: "1204", Call: "G3NOH", Mode: "SSB",}, "", LogLine{ Time: "1204", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
}, },
{ {
"Parse for comment", "Parse for comment",
args{ inputStr: "4 g3noh <PSE QSL Direct>", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "4 g3noh <PSE QSL Direct>", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ Time: "4", Comment: "PSE QSL Direct", Call: "G3NOH", Mode: "SSB",}, "", LogLine{ Time: "4", Comment: "PSE QSL Direct", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
}, },
{ {
"Parse for QSL", "Parse for QSL",
args{ inputStr: "g3noh [Custom QSL message]", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "g3noh [Custom QSL message]", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ QSLmsg: "Custom QSL message", Call: "G3NOH", Mode: "SSB",}, "", LogLine{ QSLmsg: "Custom QSL message", Call: "G3NOH", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
}, },
{ {
"Wrong mode", "Wrong mode",
args{ inputStr: "cww", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "cww", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ Mode: "SSB",}, "Unable to parse cww ", LogLine{ Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "Unable to parse cww ",
}, },
{ {
"Parse OM name", "Parse OM name",
args{ inputStr: "@Jean", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "@Jean", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ OMname: "Jean", Mode: "SSB",}, "", LogLine{ OMname: "Jean", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
}, },
{ {
"Parse Grid locator", "Parse Grid locator",
args{ inputStr: "#grid", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "#grid", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ GridLoc: "grid", Mode: "SSB",}, "", LogLine{ GridLoc: "grid", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
}, },
{ {
"parse partial RST (sent) - CW", "parse partial RST (sent) - CW",
args{ inputStr: "1230 on4kjm 5", previousLine: LogLine{ Mode: "CW", ModeType: "CW"}}, args{ inputStr: "1230 on4kjm 5", previousLine: LogLine{ Mode: "CW", ModeType: "CW"}},
LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "559", Mode: "CW", ModeType: "CW"}, "", LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "559", RSTrcvd: "599", Mode: "CW", ModeType: "CW"}, "",
}, },
{ {
"parse partial RST (received) - CW", "parse partial RST (received) - CW",
@ -85,7 +85,7 @@ func TestParseLine(t *testing.T) {
{ {
"parse partial report (sent) - FM", "parse partial report (sent) - FM",
args{ inputStr: "1230 on4kjm 5", previousLine: LogLine{ Mode: "FM", ModeType: "PHONE"}}, args{ inputStr: "1230 on4kjm 5", previousLine: LogLine{ Mode: "FM", ModeType: "PHONE"}},
LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "55", Mode: "FM", ModeType: "PHONE"}, "", LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "55", RSTrcvd: "59", Mode: "FM", ModeType: "PHONE"}, "",
}, },
{ {
"parse partial report (received) - FM", "parse partial report (received) - FM",

Loading…
Cancel
Save