Report parsing complete for Phone and CW

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent 4fdbb50aca
commit 571371faf5

@ -32,6 +32,7 @@ type LogLine struct {
QslMsg string QslMsg string
Nickname string Nickname string
Mode string Mode string
ModeType string
Band string Band string
BandLowerLimit float32 BandLowerLimit float32
BandUpperLimit float32 BandUpperLimit float32
@ -46,11 +47,11 @@ type LogLine struct {
RSTrcvd string RSTrcvd string
} }
var regexpIsBand = regexp.MustCompile("m$")
var regexpIsFullTime = regexp.MustCompile("^[0-2]{1}[0-9]{3}$") var regexpIsFullTime = regexp.MustCompile("^[0-2]{1}[0-9]{3}$")
var regexpIsTimePart = regexp.MustCompile("^[0-5]{1}[0-9]{1}$|^[1-9]{1}$") 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}$")
// 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){
@ -59,6 +60,9 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
//Flag telling that we are processing data to the right of the callsign //Flag telling that we are processing data to the right of the callsign
isRightOfCall := false isRightOfCall := false
//Flag used to know if we are parsing the Sent RST (first) or received RST (second)
haveSentRST := false
//TODO: Make something more intelligent //TODO: Make something more intelligent
//TODO: What happens if we have partial lines //TODO: What happens if we have partial lines
previousLine.Call = "" previousLine.Call = ""
@ -92,12 +96,15 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
if (logLine.RSTsent == "") || (logLine.RSTrcvd == "") { if (logLine.RSTsent == "") || (logLine.RSTrcvd == "") {
switch logLine.Mode { switch logLine.Mode {
case "SSB", "AM", "FM" : case "SSB", "AM", "FM" :
logLine.ModeType = "PHONE"
logLine.RSTsent = "59" logLine.RSTsent = "59"
logLine.RSTrcvd = "59" logLine.RSTrcvd = "59"
case "CW", "RTTY", "PSK": case "CW", "RTTY", "PSK":
logLine.ModeType = "CW"
logLine.RSTsent = "599" logLine.RSTsent = "599"
logLine.RSTrcvd = "599" logLine.RSTrcvd = "599"
case "JT65", "JT9", "JT6M", "JT4", "JT44", "FSK441", "FT8", "ISCAT", "MSK144", "QRA64", "T10", "WSPR" : case "JT65", "JT9", "JT6M", "JT4", "JT44", "FSK441", "FT8", "ISCAT", "MSK144", "QRA64", "T10", "WSPR" :
logLine.ModeType = "DIGITAL"
logLine.RSTsent = "-10" logLine.RSTsent = "-10"
logLine.RSTrcvd = "-10" logLine.RSTrcvd = "-10"
} }
@ -161,8 +168,41 @@ func ParseLine(inputStr string, previousLine LogLine) (logLine LogLine, errorMsg
if isRightOfCall { if isRightOfCall {
//This is probably a RST //This is probably a RST
//TODO: is it a number (or a data report) if regexpIsRst.MatchString(element) {
//TODO: it is sent or rcvd workRST := ""
switch len(element) {
case 1:
if logLine.ModeType == "CW" {
workRST = "5" + element + "9"
} else {
if logLine.ModeType == "PHONE" {
workRST = "5" + element
}
}
case 2:
if logLine.ModeType == "CW" {
workRST = element + "9"
} else {
if logLine.ModeType == "PHONE" {
workRST = element
}
}
case 3:
if logLine.ModeType == "CW" {
workRST = element
} else {
workRST = "*" + element
errorMsg = errorMsg + "Invalid report (" + element + ") for " + logLine.ModeType + " mode "
}
}
if haveSentRST {
logLine.RSTrcvd = workRST
} else {
logLine.RSTsent = workRST
haveSentRST = true
}
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
@ -188,6 +228,7 @@ func SprintLogRecord(logLine LogLine) (output string){
output = output + "QslMsg " + logLine.QslMsg + "\n" output = output + "QslMsg " + logLine.QslMsg + "\n"
output = output + "Nickname " + logLine.Nickname + "\n" output = output + "Nickname " + logLine.Nickname + "\n"
output = output + "Mode " + logLine.Mode + "\n" output = output + "Mode " + logLine.Mode + "\n"
output = output + "ModeType " + logLine.ModeType + "\n"
output = output + "Band " + logLine.Band + "\n" output = output + "Band " + logLine.Band + "\n"
output = output + " Lower " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n" output = output + " Lower " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n"
output = output + " Upper " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n" output = output + " Upper " + fmt.Sprintf("%f", logLine.BandLowerLimit) + "\n"

@ -20,7 +20,7 @@ func TestParseLine(t *testing.T) {
{ {
"Parse band and mode only", "Parse band and mode only",
args{ inputStr: "40M cw", previousLine: LogLine{ Mode: "SSB", }}, args{ inputStr: "40M cw", previousLine: LogLine{ Mode: "SSB", }},
LogLine{ Band: "40m", BandLowerLimit: 7, BandUpperLimit: 7.3, Mode: "CW", RSTsent: "599", RSTrcvd: "599"}, "", LogLine{ Band: "40m", BandLowerLimit: 7, BandUpperLimit: 7.3, Mode: "CW", ModeType: "CW", RSTsent: "599", RSTrcvd: "599"}, "",
}, },
{ {
"Parse for time", "Parse for time",
@ -68,9 +68,34 @@ func TestParseLine(t *testing.T) {
LogLine{ GridLoc: "grid", Mode: "SSB",}, "", LogLine{ GridLoc: "grid", Mode: "SSB",}, "",
}, },
{ {
"parse partial RST", "parse partial RST (sent) - CW",
args{ inputStr: "1230 on4kjm 5", previousLine: LogLine{ Mode: "CW", }}, args{ inputStr: "1230 on4kjm 5", previousLine: LogLine{ Mode: "CW", ModeType: "CW"}},
LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "559", Mode: "CW",}, "", LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "559", Mode: "CW", ModeType: "CW"}, "",
},
{
"parse partial RST (received) - CW",
args{ inputStr: "1230 on4kjm 5 44", previousLine: LogLine{ Mode: "CW", ModeType: "CW"}},
LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "559", RSTrcvd: "449", Mode: "CW", ModeType: "CW"}, "",
},
{
"parse full RST (received) - CW",
args{ inputStr: "1230 on4kjm 5 448", previousLine: LogLine{ Mode: "CW", ModeType: "CW"}},
LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "559", RSTrcvd: "448", Mode: "CW", ModeType: "CW"}, "",
},
{
"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"}, "",
},
{
"parse partial report (received) - FM",
args{ inputStr: "1230 on4kjm 5 44", previousLine: LogLine{ Mode: "FM", ModeType: "PHONE"}},
LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "55", RSTrcvd: "44", Mode: "FM", ModeType: "PHONE"}, "",
},
{
"Incompatible report",
args{ inputStr: "1230 on4kjm 5 599", previousLine: LogLine{ Mode: "FM", ModeType: "PHONE"}},
LogLine{ Call: "ON4KJM", Time: "1230", RSTsent: "55", RSTrcvd: "*599", Mode: "FM", ModeType: "PHONE"}, "Invalid report (599) for PHONE mode ",
}, },
} }
for _, tt := range tests { for _, tt := range tests {

@ -12,7 +12,7 @@
## Input processing ## Input processing
* [ ] infer rst * [ ] infer RST
* [ ] DATE keyword is now optional * [ ] DATE keyword is now optional
* [ ] New MYGRID keyword * [ ] New MYGRID keyword
* [ ] Create the logic to take over from the previous line * [ ] Create the logic to take over from the previous line
@ -22,3 +22,7 @@
* [ ] Support date increment * [ ] Support date increment
* [ ] decode and check frequency * [ ] decode and check frequency
## Later
* [ ] Process contest reports
* [ ] Infer digital mode report

Loading…
Cancel
Save