-
Notifications
You must be signed in to change notification settings - Fork 0
/
chirp2bc125.go
76 lines (62 loc) · 1.79 KB
/
chirp2bc125.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"encoding/csv"
"flag"
"fmt"
"os"
"strconv"
)
func main() {
inputFileName := flag.String("input", "", "Path to the input Chirp CSV file")
outputFileName := flag.String("output", "", "Path to the output bc125 CSV file")
startNumber := flag.Int("start-number", 1, "Starting number for the first column")
flag.Parse()
if *inputFileName == "" || *outputFileName == "" {
fmt.Println("Both input and output file paths are required.")
return
}
inputFile, err := os.Open(*inputFileName)
if err != nil {
fmt.Printf("Error opening input file: %v\n", err)
return
}
defer inputFile.Close()
outputFile, err := os.Create(*outputFileName)
if err != nil {
fmt.Printf("Error creating output file: %v\n", err)
return
}
defer outputFile.Close()
csvReader := csv.NewReader(inputFile)
csvWriter := csv.NewWriter(outputFile)
header := []string{"Channel", "Name", "Frequency", "Modulation", "CTCSS/DCS", "Delay", "Lockout", "Priority"}
csvWriter.Write(header)
i := *startNumber
for {
row, err := csvReader.Read()
if err != nil {
break
}
location := strconv.Itoa(i)
ctcssDcs := convertCTCSSDcs(row[5], row[6])
writeRowToCSV(csvWriter, location, row[1], row[2], row[10], ctcssDcs)
i++
}
csvWriter.Flush()
if err := csvWriter.Error(); err != nil {
fmt.Printf("Error writing to output file: %v\n", err)
}
fmt.Println("Conversion completed.")
}
func convertCTCSSDcs(tone, rToneFreq string) string {
if (tone == "Tone" || tone == "SQL") && rToneFreq != "" {
f, err := strconv.ParseFloat(rToneFreq, 64)
if err == nil {
return fmt.Sprintf("%.1f Hz", f)
}
}
return "none"
}
func writeRowToCSV(csvWriter *csv.Writer, location, name, frequency, mode, ctcssDcs string) {
csvWriter.Write([]string{location, name, frequency, mode, ctcssDcs, "2", "no", "no"})
}