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.
201 lines
5.8 KiB
201 lines
5.8 KiB
4 years ago
|
package fleprocess
|
||
4 years ago
|
|
||
5 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.
|
||
|
*/
|
||
|
|
||
|
import (
|
||
4 years ago
|
"fmt"
|
||
5 years ago
|
"regexp"
|
||
|
"strings"
|
||
5 years ago
|
"time"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
var validSotaRegexp = regexp.MustCompile(`^[0-9A-Z]{1,3}/[A-Z]{2}-[\d]{3}$`)
|
||
|
|
||
|
// ValidateSota verifies whether the supplied string is a valid SOTA reference.
|
||
4 years ago
|
// The syntax is: AA/NN-CCC: Association/Name-3-digit numeric Code (e.g. G/CE-001).
|
||
5 years ago
|
func ValidateSota(inputStr string) (ref, errorMsg string) {
|
||
|
inputStr = strings.ToUpper(strings.TrimSpace(inputStr))
|
||
|
wrongInputStr := "*" + inputStr
|
||
4 years ago
|
if validSotaRegexp.MatchString(inputStr) {
|
||
|
return inputStr, ""
|
||
|
}
|
||
4 years ago
|
errorMsg = "[" + inputStr + "] is an invalid SOTA reference"
|
||
|
return wrongInputStr, errorMsg
|
||
5 years ago
|
}
|
||
|
|
||
|
var validWwffRegexp = regexp.MustCompile(`^[\d]{0,1}[A-Z]{1,2}FF-[\d]{4}$`)
|
||
|
|
||
|
// ValidateWwff verifies whether the supplied string is a valid WWFF reference.
|
||
|
// The syntax is: AAFF-CCCC: AA = national prefix, CCCC = 4-digit numeric code (e.g. ONFF-0001).
|
||
|
func ValidateWwff(inputStr string) (ref, errorMsg string) {
|
||
|
inputStr = strings.ToUpper(strings.TrimSpace(inputStr))
|
||
|
wrongInputStr := "*" + inputStr
|
||
4 years ago
|
if validWwffRegexp.MatchString(inputStr) {
|
||
|
return inputStr, ""
|
||
|
}
|
||
4 years ago
|
errorMsg = "[" + inputStr + "] is an invalid WWFF reference"
|
||
|
return wrongInputStr, errorMsg
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
var validCallRegexp = regexp.MustCompile(`[\d]{0,1}[A-Z]{1,2}\d([A-Z]{1,4}|\d{3,3}|\d{1,3}[A-Z])[A-Z]{0,5}`)
|
||
4 years ago
|
var validPrefixRegexp = regexp.MustCompile(`\A[a-zA-Z0-9]{1,3}$`)
|
||
5 years ago
|
|
||
5 years ago
|
// ValidateCall verifies whether the supplied string is a valid callsign.
|
||
5 years ago
|
// prefix and suffix are not checked for validity
|
||
|
// If it is not valid, the supicious string is prefixed with a * and an erroMsg is genrated.
|
||
|
func ValidateCall(sign string) (call, errorMsg string) {
|
||
|
sign = strings.ToUpper(strings.TrimSpace(sign))
|
||
|
sp := strings.Split(sign, "/")
|
||
|
wrongSign := "*" + sign
|
||
|
switch len(sp) {
|
||
|
case 1:
|
||
|
if validCallRegexp.MatchString(sign) {
|
||
|
return sign, ""
|
||
|
}
|
||
4 years ago
|
return wrongSign, "[" + sign + "] is an invalid call"
|
||
5 years ago
|
case 2:
|
||
|
// some ambiguity here we need to resolve, could be a prefix or a suffix
|
||
|
if validCallRegexp.MatchString(sp[0]) {
|
||
|
//Callisign with suffix (unchecked)
|
||
|
return sign, ""
|
||
4 years ago
|
}
|
||
5 years ago
|
//else we are dealing with a prefixed Callsign
|
||
4 years ago
|
//validate the part that should contain the call (sp[1])
|
||
5 years ago
|
if !validCallRegexp.MatchString(sp[1]) {
|
||
4 years ago
|
return wrongSign, "[" + sp[1] + "] is an invalid call"
|
||
5 years ago
|
}
|
||
|
//validate the prefix
|
||
|
if !validPrefixRegexp.MatchString(sp[0]) {
|
||
4 years ago
|
return wrongSign, "[" + sp[0] + "] is an invalid prefix"
|
||
5 years ago
|
}
|
||
5 years ago
|
return sign, ""
|
||
5 years ago
|
case 3:
|
||
4 years ago
|
//validate the part that should contain the call (sp[1])
|
||
5 years ago
|
if !validCallRegexp.MatchString(sp[1]) {
|
||
4 years ago
|
return wrongSign, "[" + sp[1] + "] is an invalid call"
|
||
5 years ago
|
}
|
||
|
//validate the prefix
|
||
|
if !validPrefixRegexp.MatchString(sp[0]) {
|
||
4 years ago
|
return wrongSign, "[" + sp[0] + "] is an invalid prefix"
|
||
5 years ago
|
}
|
||
|
//We don't check the suffix
|
||
|
return sign, ""
|
||
5 years ago
|
}
|
||
4 years ago
|
return wrongSign, "[" + sign + "] is invalid: too many '/'"
|
||
5 years ago
|
}
|
||
|
|
||
|
// ValidateDate verifies whether the string is a valid date (YYYY-MM-DD).
|
||
|
func ValidateDate(inputStr string) (ref, errorMsg string) {
|
||
|
|
||
|
const RFC3339FullDate = "2006-01-02"
|
||
|
|
||
|
inputStr = strings.ToUpper(strings.TrimSpace(inputStr))
|
||
|
wrongInputStr := "*" + inputStr
|
||
|
_, err := time.Parse(RFC3339FullDate, inputStr)
|
||
|
|
||
|
if err == nil {
|
||
|
return inputStr, ""
|
||
|
}
|
||
|
|
||
|
return wrongInputStr, fmt.Sprint(err)
|
||
4 years ago
|
}
|
||
|
|
||
|
//IsBand retuns true if the passed input string is a valid string
|
||
4 years ago
|
func IsBand(inputStr string) (result bool, lowerLimit, upperLimit float64, altBandName string) {
|
||
4 years ago
|
switch strings.ToLower(inputStr) {
|
||
4 years ago
|
case "2190m":
|
||
4 years ago
|
return true, 0.1357, 0.1378, "tbd"
|
||
4 years ago
|
case "630m":
|
||
4 years ago
|
return true, 0.472, 0.479, "tbd"
|
||
4 years ago
|
case "560m":
|
||
4 years ago
|
return true, 0.501, 0.504, "tbd"
|
||
4 years ago
|
case "160m":
|
||
4 years ago
|
return true, 1.8, 2.0, "1.8MHz"
|
||
4 years ago
|
case "80m":
|
||
4 years ago
|
return true, 3.5, 4.0, "3.5MHz"
|
||
4 years ago
|
case "60m":
|
||
4 years ago
|
return true, 5.06, 5.45, "5MHz"
|
||
4 years ago
|
case "40m":
|
||
4 years ago
|
return true, 7.0, 7.3, "7MHz"
|
||
4 years ago
|
case "30m":
|
||
4 years ago
|
return true, 10.1, 10.15, "10MHz"
|
||
4 years ago
|
case "20m":
|
||
4 years ago
|
return true, 14.0, 14.35, "14MHz"
|
||
4 years ago
|
case "17m":
|
||
4 years ago
|
return true, 18.068, 18.168, "18MHz"
|
||
4 years ago
|
case "15m":
|
||
4 years ago
|
return true, 21.0, 21.45, "21MHz"
|
||
4 years ago
|
case "12m":
|
||
4 years ago
|
return true, 24.890, 24.99, "24MHz"
|
||
4 years ago
|
case "10m":
|
||
4 years ago
|
return true, 28.0, 29.7, "28MHz"
|
||
4 years ago
|
case "6m":
|
||
4 years ago
|
return true, 50, 54, "50MHz"
|
||
4 years ago
|
case "4m":
|
||
4 years ago
|
return true, 70, 71, "70MHz"
|
||
4 years ago
|
case "2m":
|
||
4 years ago
|
return true, 144, 148, "144MHz"
|
||
4 years ago
|
case "1.25m":
|
||
4 years ago
|
return true, 222, 225, "222MHz"
|
||
4 years ago
|
case "70cm":
|
||
4 years ago
|
return true, 420, 450, "432MHz"
|
||
4 years ago
|
case "33cm":
|
||
4 years ago
|
return true, 902, 928, "tbd"
|
||
4 years ago
|
case "23cm":
|
||
4 years ago
|
return true, 1240, 1300, "tbd"
|
||
4 years ago
|
case "13cm":
|
||
4 years ago
|
return true, 2300, 2450, "tbd"
|
||
4 years ago
|
case "9cm":
|
||
4 years ago
|
return true, 3300, 3500, "tbd"
|
||
4 years ago
|
case "6cm":
|
||
4 years ago
|
return true, 5650, 5925, "tbd"
|
||
4 years ago
|
case "3cm":
|
||
4 years ago
|
return true, 10000, 10500, "tbd"
|
||
4 years ago
|
case "1.25cm":
|
||
4 years ago
|
return true, 24000, 24250, "tbd"
|
||
4 years ago
|
case "6mm":
|
||
4 years ago
|
return true, 47000, 47200, "tbd"
|
||
4 years ago
|
case "4mm":
|
||
4 years ago
|
return true, 75500, 81000, "tbd"
|
||
4 years ago
|
case "2.5mm":
|
||
4 years ago
|
return true, 119980, 120020, "tbd"
|
||
4 years ago
|
case "2mm":
|
||
4 years ago
|
return true, 142000, 149000, "tbd"
|
||
4 years ago
|
case "1mm":
|
||
4 years ago
|
return true, 241000, 250000, "tbd"
|
||
4 years ago
|
}
|
||
4 years ago
|
return false, 0, 0, ""
|
||
4 years ago
|
}
|
||
|
|
||
|
func getDefaultReport(mode string) (modeType, defaultReport string) {
|
||
|
modeType = ""
|
||
|
defaultReport = ""
|
||
|
|
||
|
switch mode {
|
||
4 years ago
|
case "SSB", "AM", "FM":
|
||
4 years ago
|
modeType = "PHONE"
|
||
|
defaultReport = "59"
|
||
|
case "CW", "RTTY", "PSK":
|
||
|
modeType = "CW"
|
||
|
defaultReport = "599"
|
||
4 years ago
|
case "JT65", "JT9", "JT6M", "JT4", "JT44", "FSK441", "FT8", "ISCAT", "MSK144", "QRA64", "T10", "WSPR":
|
||
4 years ago
|
modeType = "DIGITAL"
|
||
4 years ago
|
defaultReport = "-10"
|
||
4 years ago
|
}
|
||
|
return modeType, defaultReport
|
||
|
}
|