protocol/aprs: refactored
This commit is contained in:
56
protocol/aprs/util.go
Normal file
56
protocol/aprs/util.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package aprs
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isDigit(b byte) bool {
|
||||
return b >= '0' && b <= '9'
|
||||
}
|
||||
|
||||
func feetToMeters(v float64) float64 {
|
||||
return v * 0.3048
|
||||
|
||||
}
|
||||
|
||||
func knotsToMetersPerSecond(v float64) float64 {
|
||||
return v * 0.514444444
|
||||
}
|
||||
|
||||
func milesToMeters(v float64) float64 {
|
||||
return v * 1609.344
|
||||
}
|
||||
|
||||
func fahrenheitToCelcius(v float64) float64 {
|
||||
return (v - 32) / 1.8
|
||||
}
|
||||
|
||||
func fillZeros(s string) string {
|
||||
s = strings.Replace(s, " ", "0", -1)
|
||||
s = strings.Replace(s, ".", "0", -1)
|
||||
return s
|
||||
}
|
||||
|
||||
func pow(n, exp int) int {
|
||||
if n <= 0 {
|
||||
return 1
|
||||
}
|
||||
|
||||
result := 1
|
||||
for i := 0; i < exp; i++ {
|
||||
result *= n
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func parseBytesWithSpaces(b []byte) (int, error) {
|
||||
for i := len(b) - 1; i >= 0; i-- {
|
||||
if b[i] == ' ' {
|
||||
b[i] = '0'
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return strconv.Atoi(string(b))
|
||||
}
|
||||
Reference in New Issue
Block a user