mirror of
https://github.com/on4kjm/FLEcli.git
synced 2025-01-31 14:51:04 +01:00
Improve default RST (mode from previous line)
This commit is contained in:
parent
0c45dcfbc1
commit
018e2da453
2 changed files with 43 additions and 26 deletions
|
@ -92,22 +92,14 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
|
|||
// Is it a mode?
|
||||
if lookupMode( 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
|
||||
if (logLine.RSTsent == "") || (logLine.RSTrcvd == "") {
|
||||
switch logLine.Mode {
|
||||
case "SSB", "AM", "FM" :
|
||||
logLine.ModeType = "PHONE"
|
||||
logLine.RSTsent = "59"
|
||||
logLine.RSTrcvd = "59"
|
||||
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"
|
||||
}
|
||||
// get default RST and Mode category
|
||||
modeType, defaultReport := getDefaultReport(logLine.Mode)
|
||||
logLine.ModeType = modeType
|
||||
logLine.RSTsent = defaultReport
|
||||
logLine.RSTrcvd = defaultReport
|
||||
|
||||
} else {
|
||||
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))
|
||||
|
||||
return logLine, errorMsg
|
||||
|
@ -245,6 +245,23 @@ func SprintLogRecord(logLine LogLine) (output string){
|
|||
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 {
|
||||
|
|
|
@ -25,52 +25,52 @@ func TestParseLine(t *testing.T) {
|
|||
{
|
||||
"Parse for time",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
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",
|
||||
args{ inputStr: "@Jean", previousLine: LogLine{ Mode: "SSB", }},
|
||||
LogLine{ OMname: "Jean", Mode: "SSB",}, "",
|
||||
LogLine{ OMname: "Jean", Mode: "SSB", RSTsent: "59", RSTrcvd: "59"}, "",
|
||||
},
|
||||
{
|
||||
"Parse Grid locator",
|
||||
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",
|
||||
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",
|
||||
|
@ -85,7 +85,7 @@ func TestParseLine(t *testing.T) {
|
|||
{
|
||||
"parse partial report (sent) - FM",
|
||||
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",
|
||||
|
|
Loading…
Reference in a new issue