From 23814440c7d6f20bb5b1cf224f8eec8fb43c5ea1 Mon Sep 17 00:00:00 2001 From: Jean-Marc MEESSEN Date: Mon, 29 Jun 2020 22:29:42 +0200 Subject: [PATCH] Write Adif line --- cmd/adif_write.go | 56 ++++++++++++++++++++++++++++++++++++++++-- cmd/adif_write_test.go | 33 +++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 cmd/adif_write_test.go diff --git a/cmd/adif_write.go b/cmd/adif_write.go index d1a7934..dd8e75a 100644 --- a/cmd/adif_write.go +++ b/cmd/adif_write.go @@ -1,5 +1,10 @@ package cmd +import ( + "fmt" + "strings" +) + /* Copyright © 2020 Jean-Marc Meessen, ON4KJM @@ -18,6 +23,53 @@ limitations under the License. func writeAdif(outputFile string, fullLog []LogLine) { -// TODO: create an array of strings first -// TODO: write the array list to file + // TODO: create an array of strings first + // TODO: write the array list to file +} + +func buildAdif(fullLog []LogLine) (adifList []string) { + //Print the fixed header + adifList = append(adifList, "ADIF Export for Fast Log Entry by DF3CB") + adifList = append(adifList, "FLE") + adifList = append(adifList, "3.0.6") + adifList = append(adifList, "") + + //ON4KJM/P + //S57LC + //20200524 + //1310 + //20m + //CW + //14.045 + //599 599 + //WWFF ONFF-0259 ON4KJM ONFF-0259-1 + for _, logLine := range fullLog { + adifLine := "" + adifLine = adifLine + adifElement("STATION_CALLSIGN", logLine.MyCall) + adifLine = adifLine + adifElement("CALL", logLine.Call) + //TODO: strip the delimiters of the date + adifLine = adifLine + adifElement("QSO_DATE", logLine.Date) + adifLine = adifLine + adifElement("TIME_ON", logLine.Time) + adifLine = adifLine + adifElement("BAND", logLine.Band) + adifLine = adifLine + adifElement("MODE", logLine.Mode) + if logLine.Frequency != "" { + adifLine = adifLine + adifElement("FREQ", logLine.Frequency) + } + adifLine = adifLine + adifElement("RST_SENT", logLine.RSTsent) + adifLine = adifLine + adifElement("RST_RCVD", logLine.RSTrcvd) + adifLine = adifLine + adifElement("MY_SIG", "WWFF") + adifLine = adifLine + adifElement("MY_SIG_INFO", logLine.MyWWFF) + adifLine = adifLine + adifElement("OPERATOR", logLine.Operator) + adifLine = adifLine + adifElement("BAND", logLine.Band) + //EQSL nickname?? + adifLine = adifLine + "" + adifList = append(adifList, adifLine) + + } + + return adifList +} + +func adifElement(elementName, elementValue string) (element string) { + return fmt.Sprintf("<%s:%d>%s ", strings.ToUpper(elementName), len(elementValue), elementValue) } diff --git a/cmd/adif_write_test.go b/cmd/adif_write_test.go new file mode 100644 index 0000000..5409fd3 --- /dev/null +++ b/cmd/adif_write_test.go @@ -0,0 +1,33 @@ +package cmd + +import "testing" + +func Test_adifElement(t *testing.T) { + type args struct { + elementName string + elementValue string + } + tests := []struct { + name string + args args + wantElement string + }{ + { + "case 1", + args{elementName: "station_callsign", elementValue: "ON4KJM/P"}, + "ON4KJM/P ", + }, + { + "case 2", + args{elementName: "time_ON", elementValue: "1310"}, + "1310 ", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if gotElement := adifElement(tt.args.elementName, tt.args.elementValue); gotElement != tt.wantElement { + t.Errorf("adifElement() = %v, want %v", gotElement, tt.wantElement) + } + }) + } +}