mirror of https://github.com/on4kjm/FLEcli.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.4 KiB
105 lines
3.4 KiB
4 years ago
|
package fleprocess
|
||
4 years ago
|
|
||
|
/*
|
||
|
Copyright © 2020 Jean-Marc Meessen, ON4KJM <on4kjm@gmail.com>
|
||
|
|
||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
you may not use this file except in compliance with the License.
|
||
|
You may obtain a copy of the License at
|
||
|
|
||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
Unless required by applicable law or agreed to in writing, software
|
||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
See the License for the specific language governing permissions and
|
||
|
limitations under the License.
|
||
|
*/
|
||
|
|
||
4 years ago
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
4 years ago
|
// OutputAdif generates and writes data in ADIF format
|
||
|
func OutputAdif(outputFile string, fullLog []LogLine, isWWFF bool, isSOTA bool) {
|
||
4 years ago
|
|
||
4 years ago
|
//convert the log data to an in-memory ADIF file
|
||
4 years ago
|
adifData := buildAdif(fullLog, isWWFF, isSOTA)
|
||
4 years ago
|
|
||
|
//write to a file
|
||
4 years ago
|
writeFile(outputFile, adifData)
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
// buildAdif creates the adif file in memory ready to be printed
|
||
4 years ago
|
func buildAdif(fullLog []LogLine, isWWFF bool, isSOTA bool) (adifList []string) {
|
||
4 years ago
|
//Print the fixed header
|
||
|
adifList = append(adifList, "ADIF Export for Fast Log Entry by DF3CB")
|
||
|
adifList = append(adifList, "<PROGRAMID:3>FLE")
|
||
4 years ago
|
adifList = append(adifList, "<ADIF_VER:5>3.1.0")
|
||
4 years ago
|
adifList = append(adifList, "<EOH>")
|
||
|
|
||
|
for _, logLine := range fullLog {
|
||
4 years ago
|
var adifLine strings.Builder
|
||
|
adifLine.WriteString(adifElement("STATION_CALLSIGN", logLine.MyCall))
|
||
|
adifLine.WriteString(adifElement("CALL", logLine.Call))
|
||
|
adifLine.WriteString(adifElement("QSO_DATE", adifDate(logLine.Date)))
|
||
|
adifLine.WriteString(adifElement("TIME_ON", logLine.Time))
|
||
|
adifLine.WriteString(adifElement("BAND", logLine.Band))
|
||
|
adifLine.WriteString(adifElement("MODE", logLine.Mode))
|
||
4 years ago
|
if logLine.Frequency != "" {
|
||
4 years ago
|
adifLine.WriteString(adifElement("FREQ", logLine.Frequency))
|
||
|
}
|
||
|
adifLine.WriteString(adifElement("RST_SENT", logLine.RSTsent))
|
||
|
adifLine.WriteString(adifElement("RST_RCVD", logLine.RSTrcvd))
|
||
4 years ago
|
if logLine.Comment != "" {
|
||
4 years ago
|
adifLine.WriteString(adifElement("COMMENT", logLine.Comment))
|
||
4 years ago
|
}
|
||
|
if logLine.OMname != "" {
|
||
4 years ago
|
adifLine.WriteString(adifElement("NAME", logLine.OMname))
|
||
4 years ago
|
}
|
||
4 years ago
|
if logLine.QSLmsg != "" {
|
||
4 years ago
|
adifLine.WriteString(adifElement("QSLMSG", logLine.QSLmsg))
|
||
4 years ago
|
}
|
||
|
if isWWFF {
|
||
|
adifLine.WriteString(adifElement("MY_SIG", "WWFF"))
|
||
|
adifLine.WriteString(adifElement("MY_SIG_INFO", logLine.MyWWFF))
|
||
|
}
|
||
|
if isSOTA {
|
||
|
adifLine.WriteString(adifElement("MY_SOTA_REF", logLine.MySOTA))
|
||
|
if logLine.SOTA != "" {
|
||
|
adifLine.WriteString(adifElement("SOTA_REF", logLine.SOTA))
|
||
|
}
|
||
4 years ago
|
}
|
||
4 years ago
|
adifLine.WriteString(adifElement("OPERATOR", logLine.Operator))
|
||
4 years ago
|
if logLine.Nickname != "" {
|
||
4 years ago
|
adifLine.WriteString(adifElement("APP_EQSL_QTH_NICKNAME", logLine.Nickname))
|
||
4 years ago
|
}
|
||
4 years ago
|
adifLine.WriteString("<EOR>")
|
||
4 years ago
|
|
||
4 years ago
|
adifList = append(adifList, adifLine.String())
|
||
4 years ago
|
|
||
|
}
|
||
|
|
||
|
return adifList
|
||
|
}
|
||
|
|
||
4 years ago
|
// adifElement generated the ADIF sub-element
|
||
4 years ago
|
func adifElement(elementName, elementValue string) (element string) {
|
||
|
return fmt.Sprintf("<%s:%d>%s ", strings.ToUpper(elementName), len(elementValue), elementValue)
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
4 years ago
|
//adifDate converts a date in YYYY-MM-DD format to YYYYMMDD
|
||
|
func adifDate(inputDate string) (outputDate string) {
|
||
4 years ago
|
const FLEdateFormat = "2006-01-02"
|
||
|
date, err := time.Parse(FLEdateFormat, inputDate)
|
||
4 years ago
|
//error should never happen
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
4 years ago
|
const ADIFdateFormat = "20060102"
|
||
|
return date.Format(ADIFdateFormat)
|
||
4 years ago
|
}
|