From 5b406438688ea6ee427bddd3cb3716e2cb8caa95 Mon Sep 17 00:00:00 2001 From: Nic Heath Date: Tue, 19 Mar 2024 15:23:24 -0500 Subject: [PATCH] Add support for MY_CNTY adif tag. (#128) * Add support for exporting MY_CNTY using mycounty in the header e.g. 'mycounty Ham County'. * Add MyCounty to displayLog in the nice console summary. --------- Co-authored-by: Jean-Marc MEESSEN --- fleprocess/adif_write.go | 3 +++ fleprocess/adif_write_test.go | 4 ++-- fleprocess/displayLog.go | 4 ++++ fleprocess/load_file.go | 13 +++++++++++++ fleprocess/load_file_test.go | 5 +++++ fleprocess/parse_line.go | 1 + 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/fleprocess/adif_write.go b/fleprocess/adif_write.go index c81a18b..a7e3d20 100644 --- a/fleprocess/adif_write.go +++ b/fleprocess/adif_write.go @@ -93,6 +93,9 @@ func buildAdif(fullLog []LogLine, adifParams AdifParams) (adifList []string) { if logLine.MyGrid != "" { adifLine.WriteString(adifElement("MY_GRIDSQUARE", logLine.MyGrid)) } + if logLine.MyCounty != "" { + adifLine.WriteString(adifElement("MY_CNTY", logLine.MyCounty)) + } if logLine.Nickname != "" { adifLine.WriteString(adifElement("APP_EQSL_QTH_NICKNAME", logLine.Nickname)) } diff --git a/fleprocess/adif_write_test.go b/fleprocess/adif_write_test.go index bd27398..74b84c8 100644 --- a/fleprocess/adif_write_test.go +++ b/fleprocess/adif_write_test.go @@ -96,7 +96,7 @@ func Test_buildAdif(t *testing.T) { sampleFilledLogPOTA := []LogLine{ {MyCall: "ON4KJM/P", Call: "S57LC", Date: "2020-05-24", Time: "1310", Band: "20m", Frequency: "14.045", Mode: "CW", RSTsent: "599", RSTrcvd: "599", MyPOTA: "ON-00259", Operator: "ON4KJM", Nickname: "ON-00259-1"}, - {MyCall: "ON4KJM/P", Call: "ON4LY", Date: "2020-05-24", Time: "1312", Band: "20m", Mode: "CW", RSTsent: "559", RSTrcvd: "599", MyPOTA: "ON-00259", Operator: "ON4KJM"}, + {MyCall: "ON4KJM/P", Call: "ON4LY", Date: "2020-05-24", Time: "1312", Band: "20m", Mode: "CW", RSTsent: "559", RSTrcvd: "599", MyPOTA: "ON-00259", Operator: "ON4KJM", MyCounty: "Ham County"}, } expectedOutputPOTA := []string{ @@ -105,7 +105,7 @@ func Test_buildAdif(t *testing.T) { "3.1.0", "", "ON4KJM/P S57LC 20200524 1310 20m CW 14.045 599 599 POTA ON-00259 ON4KJM ON-00259-1 ", - "ON4KJM/P ON4LY 20200524 1312 20m CW 559 599 POTA ON-00259 ON4KJM ", + "ON4KJM/P ON4LY 20200524 1312 20m CW 559 599 POTA ON-00259 ON4KJM Ham County ", } sampleFilledLogPOTA2 := []LogLine{ diff --git a/fleprocess/displayLog.go b/fleprocess/displayLog.go index c6886a4..a96252c 100644 --- a/fleprocess/displayLog.go +++ b/fleprocess/displayLog.go @@ -79,6 +79,10 @@ func SprintHeaderValues(logLine LogLine) string { output.WriteString("MyGrid " + logLine.MyGrid + "\n") } + if logLine.MyCounty != "" { + output.WriteString("MyCounty " + logLine.MyCounty + "\n") + } + return output.String() } diff --git a/fleprocess/load_file.go b/fleprocess/load_file.go index 2fd9bac..024af7e 100644 --- a/fleprocess/load_file.go +++ b/fleprocess/load_file.go @@ -64,6 +64,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL regexpHeaderMySota := regexp.MustCompile(`(?i)^mysota\s+`) regexpHeaderMyPota := regexp.MustCompile(`(?i)^mypota\s+`) regexpHeaderMyGrid := regexp.MustCompile(`(?i)^mygrid\s+`) + regexpHeaderMyCounty := regexp.MustCompile(`(?i)^mycounty\s+`) regexpHeaderQslMsg := regexp.MustCompile(`(?i)^qslmsg\s+`) regexpHeaderNickname := regexp.MustCompile(`(?i)^nickname\s+`) @@ -73,6 +74,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL headerMySOTA := "" headerMyPOTA := "" headerMyGrid := "" + headerMyCounty := "" headerQslMsg := "" headerNickname := "" //headerDate := "" @@ -245,6 +247,16 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL continue } + //My County + if regexpHeaderMyCounty.MatchString(eachline) { + myMyCountyList := regexpHeaderMyCounty.Split(eachline, -1) + if len(myMyCountyList[1]) > 0 { + headerMyCounty = myMyCountyList[1] + } + //If there is no data after the marker, we just skip the data. + continue + } + //QSL Message if regexpHeaderQslMsg.MatchString(eachline) { myQslMsgList := regexpHeaderQslMsg.Split(eachline, -1) @@ -283,6 +295,7 @@ func LoadFile(inputFilename string, isInterpolateTime bool) (filleFullLog []LogL previousLogLine.MyPOTA = headerMyPOTA previousLogLine.MySOTA = headerMySOTA previousLogLine.MyGrid = headerMyGrid + previousLogLine.MyCounty = headerMyCounty previousLogLine.QSLmsg = headerQslMsg //previousLogLine.QslMsg is redundant previousLogLine.Nickname = headerNickname diff --git a/fleprocess/load_file_test.go b/fleprocess/load_file_test.go index 29e984e..6f2a5bd 100644 --- a/fleprocess/load_file_test.go +++ b/fleprocess/load_file_test.go @@ -42,6 +42,7 @@ func TestLoadFile_happyCase(t *testing.T) { dataArray = append(dataArray, "mySota on/on-001") dataArray = append(dataArray, "myPota k-0802") dataArray = append(dataArray, "myGrid jo50") + dataArray = append(dataArray, "myCounty Ham County") dataArray = append(dataArray, "QslMsg This is a QSL message") dataArray = append(dataArray, " ") dataArray = append(dataArray, " #Log") @@ -87,6 +88,10 @@ func TestLoadFile_happyCase(t *testing.T) { if loadedLogFile[0].QSLmsg != expectedValue { t.Errorf("Not the expected QSL Message from Header value: %s (expecting %s)", loadedLogFile[0].QSLmsg, expectedValue) } + expectedValue = "Ham County" + if loadedLogFile[0].MyCounty != expectedValue { + t.Errorf("Not the expected MyCounty from Header value: %s (expecting %s)", loadedLogFile[0].MyCounty, expectedValue) + } expectedValue = "IK5ZVE/5" if loadedLogFile[0].Call != expectedValue { t.Errorf("Not the expected Call[0] value: %s (expecting %s)", loadedLogFile[0].Call, expectedValue) diff --git a/fleprocess/parse_line.go b/fleprocess/parse_line.go index c0e4181..07ea668 100644 --- a/fleprocess/parse_line.go +++ b/fleprocess/parse_line.go @@ -34,6 +34,7 @@ type LogLine struct { MyPota string MySota string MyGrid string + MyCounty string QslMsgFromHeader string Nickname string Mode string