Skip to content

Commit

Permalink
Pota support (#73)
Browse files Browse the repository at this point in the history
* Add POTA processing
* add end to end POTA test
* allow tabs to be a valid separator in the header section
  • Loading branch information
jmMeessen authored Dec 4, 2021
1 parent 82ee44d commit 61c42d1
Show file tree
Hide file tree
Showing 31 changed files with 529 additions and 193 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '^1.15.2'
go-version: '^1.17.2'
- run: go mod download
- name: Validates GO releaser config
uses: goreleaser/goreleaser-action@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
run: git fetch --prune --unshallow
- uses: actions/setup-go@v2
with:
go-version: '^1.15.2'
go-version: '^1.17.2'
- name: Release via goreleaser
uses: goreleaser/goreleaser-action@master
with:
Expand Down
24 changes: 13 additions & 11 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
builds:
- goos:
- linux
- windows
- darwin
- binary: FLEcli

goos:
- linux
- windows
- darwin
goarch:
- 386
- amd64
- arm
- arm64
- '386'
- amd64
- arm
- arm64
goarm:
- 6
- '6'

ignore:
- goos: darwin
goarch: 386
- goos: windows
goarch: amd64

ldflags:
- -s -w -X FLEcli/flecmd.version={{.Version}} -X FLEcli/flecmd.commit={{.Commit}} -X FLEcli/flecmd.date={{.Date}} -X=FLEcli/flecmd.builtBy=goReleaser
env:
Expand All @@ -26,8 +30,6 @@ dockers:
- goos: linux
goarch: amd64
goarm: ''
binaries:
- FLEcli
image_templates:
- "on4kjm/flecli:latest"
- "on4kjm/flecli:{{ .Tag }}"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dep: ## Get the dependencies
@go mod download

lint: ## Lint Golang files
@go get -u golang.org/x/lint/golint
@go install golang.org/x/lint/golint
@golint -set_exit_status ./...

vet: ## Run go vet
Expand Down
22 changes: 14 additions & 8 deletions flecmd/adif.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
var outputFilename string
var isWWFFcli bool
var isSOTAcli bool
var isPOTAcli bool
var isOverwrite bool

// adifCmd is executed when choosing the adif option (load and generate adif file)
Expand All @@ -37,10 +38,11 @@ var adifCmd = &cobra.Command{
// and usage of using your command. For example:

RunE: func(cmd *cobra.Command, args []string) error {

//if args is empty, throw an error
if len(args) == 0 {
//TODO: fix this ugly statement (because I am lazy)
return fmt.Errorf("Missing input file %s", "")
return fmt.Errorf("missing input file %s", "")
}
inputFilename = args[0]
if len(args) == 2 {
Expand All @@ -50,13 +52,16 @@ var adifCmd = &cobra.Command{
return fmt.Errorf("Too many arguments.%s", "")
}

err := fleprocess.ProcessAdifCommand(
inputFilename,
outputFilename,
isInterpolateTime,
isWWFFcli,
isSOTAcli,
isOverwrite)
var adifParam = new(fleprocess.AdifParams)
adifParam.InputFilename = inputFilename
adifParam.OutputFilename = outputFilename
adifParam.IsInterpolateTime = isInterpolateTime
adifParam.IsSOTA = isSOTAcli
adifParam.IsPOTA = isPOTAcli
adifParam.IsWWFF = isWWFFcli
adifParam.IsOverwrite = isOverwrite

err := fleprocess.ProcessAdifCommand(*adifParam)
if err != nil {
fmt.Println("\nUnable to generate ADIF file:")
fmt.Println(err)
Expand All @@ -73,5 +78,6 @@ func init() {
adifCmd.PersistentFlags().BoolVarP(&isInterpolateTime, "interpolate", "i", false, "Interpolates the missing time entries.")
adifCmd.PersistentFlags().BoolVarP(&isWWFFcli, "wwff", "w", false, "Generates a WWFF ready ADIF file.")
adifCmd.PersistentFlags().BoolVarP(&isSOTAcli, "sota", "s", false, "Generates a SOTA ready ADIF file.")
adifCmd.PersistentFlags().BoolVarP(&isPOTAcli, "pota", "p", false, "Generates a POTA ready ADIF file.")
adifCmd.PersistentFlags().BoolVarP(&isOverwrite, "overwrite", "o", false, "Overwrites the output file if it exisits")
}
61 changes: 40 additions & 21 deletions fleprocess/adif_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,83 @@ import (
"strings"
)

//AdifParams is holding all the parameters required to generate an ADIF file
type AdifParams struct {
InputFilename string
OutputFilename string
IsInterpolateTime bool
IsWWFF bool
IsSOTA bool
IsPOTA bool
IsOverwrite bool
}

//ProcessAdifCommand loads an FLE input to produce an adif file (eventually in WWFF format). It is called from the COBRA interface
func ProcessAdifCommand(inputFilename, outputFilename string, isInterpolateTime, isWWFFcli, isSOTAcli, isOverwrite bool) error {
//inputFilename, outputFilename string, isInterpolateTime, isWWFFcli, IsSOTA, isPOTAcli, isOverwrite bool
func ProcessAdifCommand(adifParams AdifParams) error {

//Validate of build the output filenaem
var verifiedOutputFilename string
var err error

if verifiedOutputFilename, err = buildOutputFilename(outputFilename, inputFilename, isOverwrite, ".adi"); err != nil {
if verifiedOutputFilename, err = buildOutputFilename(adifParams.OutputFilename, adifParams.InputFilename, adifParams.IsOverwrite, ".adi"); err != nil {
return err
}

//Load the input file
var loadedLogFile []LogLine
var isLoadedOK bool

if loadedLogFile, isLoadedOK = LoadFile(inputFilename, isInterpolateTime); isLoadedOK == false {
return fmt.Errorf("There were input file parsing errors. Could not generate ADIF file")
if loadedLogFile, isLoadedOK = LoadFile(adifParams.InputFilename, adifParams.IsInterpolateTime); !isLoadedOK {
return fmt.Errorf("there were input file parsing errors. Could not generate ADIF file")
}

//Check if we have all the necessary data
if err := validateDataforAdif(loadedLogFile, isWWFFcli, isSOTAcli); err != nil {
if err := validateDataforAdif(loadedLogFile, adifParams); err != nil {
return err
}

//Write the output file with the checked data
OutputAdif(verifiedOutputFilename, loadedLogFile, isWWFFcli, isSOTAcli)
OutputAdif(verifiedOutputFilename, loadedLogFile, adifParams)

//If we reached this point, everything was processed OK and the file generated
return nil
}

//validateDataforAdif checks whether all the required data is present
//The details of the mandatory files can be found at http://wwff.co/rules-faq/confirming-and-sending-log/
func validateDataforAdif(loadedLogFile []LogLine, isWWFFcli, isSOTAcli bool) error {
func validateDataforAdif(loadedLogFile []LogLine, adifParams AdifParams) error {

//do we have QSOs at all?
if len(loadedLogFile) == 0 {
return fmt.Errorf("No QSO found")
return fmt.Errorf("no QSO found")
}

//MySOTA, MyWWFF and MyCall are header values. If missing on the first line, it will be missing at every line
//MySOTA, MyWWFF, MyPOTA and MyCall are header values. If missing on the first line, it will be missing at every line
if loadedLogFile[0].MyCall == "" {
return fmt.Errorf("Missing MyCall")
return fmt.Errorf("missing MyCall")
}
if isSOTAcli {
if adifParams.IsSOTA {
if loadedLogFile[0].MySOTA == "" {
return fmt.Errorf("Missing MY-SOTA reference")
return fmt.Errorf("missing MY-SOTA reference")
}
}
if isWWFFcli {
if adifParams.IsWWFF {
if loadedLogFile[0].MyWWFF == "" {
return fmt.Errorf("Missing MY-WWFF reference")
return fmt.Errorf("missing MY-WWFF reference")
}
if loadedLogFile[0].Operator == "" {
return fmt.Errorf("Missing Operator call sign")
return fmt.Errorf("missing Operator call sign")
}
}
if adifParams.IsPOTA {
if loadedLogFile[0].MyPOTA == "" {
return fmt.Errorf("missing MY-POTA reference")
}
if loadedLogFile[0].Operator == "" {
return fmt.Errorf("missing Operator call sign")
}
}

var errorsBuffer strings.Builder
//We accumulate the errors messages
for i := 0; i < len(loadedLogFile); i++ {
Expand All @@ -93,31 +112,31 @@ func validateDataforAdif(loadedLogFile []LogLine, isWWFFcli, isSOTAcli bool) err

if loadedLogFile[i].Date == "" {
if errorsBuffer.String() != "" {
errorsBuffer.WriteString(fmt.Sprintf(", "))
errorsBuffer.WriteString(", ")
}
errorsBuffer.WriteString(fmt.Sprintf("missing date %s", errorLocation))
}
if loadedLogFile[i].Band == "" {
if errorsBuffer.String() != "" {
errorsBuffer.WriteString(fmt.Sprintf(", "))
errorsBuffer.WriteString(", ")
}
errorsBuffer.WriteString(fmt.Sprintf("missing band %s", errorLocation))
}
if loadedLogFile[i].Mode == "" {
if errorsBuffer.String() != "" {
errorsBuffer.WriteString(fmt.Sprintf(", "))
errorsBuffer.WriteString(", ")
}
errorsBuffer.WriteString(fmt.Sprintf("missing mode %s", errorLocation))
}
if loadedLogFile[i].Call == "" {
if errorsBuffer.String() != "" {
errorsBuffer.WriteString(fmt.Sprintf(", "))
errorsBuffer.WriteString(", ")
}
errorsBuffer.WriteString(fmt.Sprintf("missing call %s", errorLocation))
}
if loadedLogFile[i].Time == "" {
if errorsBuffer.String() != "" {
errorsBuffer.WriteString(fmt.Sprintf(", "))
errorsBuffer.WriteString(", ")
}
errorsBuffer.WriteString(fmt.Sprintf("missing QSO time %s", errorLocation))
}
Expand Down
Loading

0 comments on commit 61c42d1

Please sign in to comment.