kopia lustrzana https://github.com/cyoung/stratux
Clean up old Stratus AHRS RE tools.
FF opened their AHRS-over-GDL90, not needed.pull/827/head
rodzic
37911bc692
commit
9db076f8d3
|
@ -1,87 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"github.com/gonum/plot"
|
|
||||||
"github.com/gonum/plot/plotter"
|
|
||||||
"github.com/gonum/plot/plotutil"
|
|
||||||
"github.com/gonum/plot/vg"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type XY struct {
|
|
||||||
X float64
|
|
||||||
Y float64
|
|
||||||
}
|
|
||||||
|
|
||||||
func imageWriter() {
|
|
||||||
for {
|
|
||||||
p, err := plot.New()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
p.Title.Text = "AHRS Plot"
|
|
||||||
p.X.Label.Text = "Roll"
|
|
||||||
p.Y.Label.Text = "Pitch"
|
|
||||||
|
|
||||||
file, err := os.Open("ahrs_table.log")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
|
||||||
|
|
||||||
vals := make([]XY, 0)
|
|
||||||
for scanner.Scan() {
|
|
||||||
l := scanner.Text()
|
|
||||||
x := strings.Split(l, ",")
|
|
||||||
if len(x) < 3 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
roll, err := strconv.ParseFloat(x[0], 64)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
pitch, err := strconv.ParseFloat(x[1], 64)
|
|
||||||
if err != nil {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
v := XY{X: roll, Y: pitch}
|
|
||||||
vals = append(vals, v)
|
|
||||||
}
|
|
||||||
vals_XY := make(plotter.XYs, len(vals))
|
|
||||||
for i := 0; i < len(vals); i++ {
|
|
||||||
vals_XY[i].X = vals[i].X
|
|
||||||
vals_XY[i].Y = vals[i].Y
|
|
||||||
}
|
|
||||||
err = plotutil.AddScatters(p, "First", vals_XY)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
if err := p.Save(8*vg.Inch, 8*vg.Inch, "out.png"); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
go imageWriter()
|
|
||||||
http.Handle("/", http.FileServer(http.Dir(".")))
|
|
||||||
err := http.ListenAndServe(":8080", nil)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("managementInterface ListenAndServe: %s\n", err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
time.Sleep(1 * time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,109 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"net"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
SITUATION_URL = "http://127.0.0.1/getSituation"
|
|
||||||
)
|
|
||||||
|
|
||||||
type MySituation struct {
|
|
||||||
AHRSRoll float64
|
|
||||||
AHRSPitch float64
|
|
||||||
}
|
|
||||||
|
|
||||||
var Location MySituation
|
|
||||||
|
|
||||||
var situationMutex *sync.Mutex
|
|
||||||
|
|
||||||
func chkErr(err error) {
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("error: %s\n", err.Error())
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var currentAHRSString string
|
|
||||||
|
|
||||||
func listener() {
|
|
||||||
t := time.Now()
|
|
||||||
addr := net.UDPAddr{Port: 41504, IP: net.ParseIP("0.0.0.0")}
|
|
||||||
conn, err := net.ListenUDP("udp", &addr)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("error listening: %s\n", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer conn.Close()
|
|
||||||
for {
|
|
||||||
buf := make([]byte, 1024)
|
|
||||||
n, _, err := conn.ReadFrom(buf)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Err receive: %s\n", err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
buf_encoded := make([]byte, hex.EncodedLen(n))
|
|
||||||
hex.Encode(buf_encoded, buf[:n])
|
|
||||||
t2 := time.Now()
|
|
||||||
time_diff := t2.Sub(t)
|
|
||||||
t = t2
|
|
||||||
|
|
||||||
fmt.Sprintf("%d,%s\n", time_diff/time.Millisecond, buf_encoded)
|
|
||||||
currentAHRSString = string(buf_encoded)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func situationUpdater() {
|
|
||||||
situationUpdateTicker := time.NewTicker(100 * time.Millisecond)
|
|
||||||
for {
|
|
||||||
<-situationUpdateTicker.C
|
|
||||||
situationMutex.Lock()
|
|
||||||
|
|
||||||
resp, err := http.Get(SITUATION_URL)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("HTTP GET error: %s\n", err.Error())
|
|
||||||
situationMutex.Unlock()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("HTTP GET body error: %s\n", err.Error())
|
|
||||||
resp.Body.Close()
|
|
||||||
situationMutex.Unlock()
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// fmt.Printf("body: %s\n", string(body))
|
|
||||||
err = json.Unmarshal(body, &Location)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("HTTP JSON unmarshal error: %s\n", err.Error())
|
|
||||||
}
|
|
||||||
resp.Body.Close()
|
|
||||||
situationMutex.Unlock()
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
situationMutex = &sync.Mutex{}
|
|
||||||
|
|
||||||
go listener()
|
|
||||||
go situationUpdater()
|
|
||||||
|
|
||||||
tm := time.NewTicker(125 * time.Millisecond)
|
|
||||||
for {
|
|
||||||
<-tm.C
|
|
||||||
fmt.Printf("%f,%f,%s\n", Location.AHRSRoll, Location.AHRSPitch, currentAHRSString)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
t := time.Now()
|
|
||||||
addr := net.UDPAddr{Port: 41504, IP: net.ParseIP("0.0.0.0")}
|
|
||||||
conn, err := net.ListenUDP("udp", &addr)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("ffMonitor(): error listening: %s\n", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer conn.Close()
|
|
||||||
for {
|
|
||||||
buf := make([]byte, 1024)
|
|
||||||
n, _, err := conn.ReadFrom(buf)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Err receive: %s\n", err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
buf_encoded := make([]byte, hex.EncodedLen(n))
|
|
||||||
hex.Encode(buf_encoded, buf[:n])
|
|
||||||
t2 := time.Now()
|
|
||||||
time_diff := t2.Sub(t)
|
|
||||||
t = t2
|
|
||||||
|
|
||||||
fmt.Printf("%d,%s\n", time_diff/time.Millisecond, buf_encoded)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"encoding/hex"
|
|
||||||
"fmt"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if len(os.Args) < 2 {
|
|
||||||
fmt.Printf("%s: <file>\n", os.Args[0])
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.Open(os.Args[1])
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("error: %s\n", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer f.Close()
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(f)
|
|
||||||
|
|
||||||
// Open a socket.
|
|
||||||
BROADCAST_IPv4 := net.IPv4(255, 255, 255, 255)
|
|
||||||
|
|
||||||
// addr, _ := net.ResolveUDPAddr("udp", "192.168.10.10:41501")
|
|
||||||
// laddr, _ := net.ResolveUDPAddr("udp", "192.168.10.1:58814")
|
|
||||||
// conn, err := net.DialUDP("udp", laddr, addr)
|
|
||||||
conn, err := net.DialUDP("udp", nil, &net.UDPAddr{
|
|
||||||
IP: BROADCAST_IPv4,
|
|
||||||
Port: 41504,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("DialUDP(): %s\n", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for scanner.Scan() {
|
|
||||||
s := scanner.Text()
|
|
||||||
x := strings.Split(s, ",")
|
|
||||||
if len(x) < 2 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
i, err := strconv.ParseInt(x[0], 10, 32)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("error parsing '%s': %s.\n", x[0], err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
buf := make([]byte, hex.DecodedLen(len(x[1])))
|
|
||||||
n, err := hex.Decode(buf, []byte(x[1]))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("error parsing '%s': %s.\n", x[1], err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Printf("sleeping %dms, sending %s\n", i, x[1])
|
|
||||||
time.Sleep(time.Duration(i) * time.Millisecond)
|
|
||||||
conn.Write(buf[:n])
|
|
||||||
}
|
|
||||||
}
|
|
Ładowanie…
Reference in New Issue