Write Adif line

pull/2/head
Jean-Marc MEESSEN 4 years ago
parent 8cae1aa940
commit 23814440c7

@ -1,5 +1,10 @@
package cmd package cmd
import (
"fmt"
"strings"
)
/* /*
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com> Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
@ -18,6 +23,53 @@ limitations under the License.
func writeAdif(outputFile string, fullLog []LogLine) { func writeAdif(outputFile string, fullLog []LogLine) {
// TODO: create an array of strings first // TODO: create an array of strings first
// TODO: write the array list to file // 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, "<PROGRAMID:3>FLE")
adifList = append(adifList, "<ADIF_VER:5>3.0.6")
adifList = append(adifList, "<EOH>")
//<STATION_CALLSIGN:8>ON4KJM/P
//<CALL:5>S57LC
//<QSO_DATE:8>20200524
//<TIME_ON:4>1310
//<BAND:3>20m
//<MODE:2>CW
//<FREQ:6>14.045
//<RST_SENT:3>599 <RST_RCVD:3>599
//<MY_SIG:4>WWFF <MY_SIG_INFO:9>ONFF-0259 <OPERATOR:6>ON4KJM <APP_EQSL_QTH_NICKNAME:11>ONFF-0259-1 <EOR>
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 + "<EOR>"
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)
} }

@ -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"},
"<STATION_CALLSIGN:8>ON4KJM/P ",
},
{
"case 2",
args{elementName: "time_ON", elementValue: "1310"},
"<TIME_ON:4>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)
}
})
}
}
Loading…
Cancel
Save