-
Notifications
You must be signed in to change notification settings - Fork 0
/
opensimdash.go
51 lines (41 loc) · 1.35 KB
/
opensimdash.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
package main
import (
"log"
"net/http"
"os"
"runtime"
"github.com/jake-dog/opensimdash/codemasters"
"github.com/jake-dog/opensimdash/hid"
)
var logger = log.New(os.Stdout, "", log.LstdFlags|log.LUTC|log.Lshortfile)
func main() {
// We're doing a lot of system calls here so minimum three system threads
runtime.GOMAXPROCS(3)
// TODO need to make this configurable, and catch errors it throws
go http.ListenAndServe(":8080", nil)
// Handle USB device add/remove
r := hid.Registrar(logger)
AddSubscriber(r) // Register for Windows WM_DEVICECHANGE events
// Create a new UDP connection to read telemetry
// TODO this all needs to be configurable/optional/etc.
s, err := NewTelemetry("") // Defaults to ":20777"
if err != nil {
logger.Println(err)
os.Exit(-1)
}
// Loop receive packet from UDP client, and ship them off to HID and WebSocket
// TODO this all needs to be configurable/optional/etc.
rcv := make([]byte, codemasters.DirtPacketSize) // Maybe 1500 (standard frame)
p := &codemasters.DirtPacket{} // TODO oh well obviously...
for {
// Retrieve a packet
if err := s.DecodePacket(p, rcv); err != nil {
logger.Println(err)
break // TODO probably need better than this for error handling...
}
// Send data to websocket clients
ws.SendPack(p)
// Send data to any connected USB HID devices
r.SendPack(p)
}
}