-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6c03cca
Showing
13 changed files
with
1,540 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.env | ||
build-vfrmap-upload.sh | ||
vfrmap.exe | ||
request_data.exe | ||
_vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
go generate github.com/lian/msfs2020-go/simconnect | ||
go generate github.com/lian/msfs2020-go/vfrmap | ||
|
||
build_time=$(date -u +'%Y-%m-%d_%T') | ||
set +e | ||
build_version=$(git describe --tags) | ||
set -e | ||
|
||
[ -f .env ] && source .env | ||
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.mapApiKeyDefault=$MAP_API_KEY -X main.buildVersion=$build_version -X main.buildTime=$build_time" -v github.com/lian/msfs2020-go/vfrmap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/lian/msfs2020-go/simconnect" | ||
) | ||
|
||
// ported from: MSFS-SDK/Samples/SimConnectSamples/RequestData/RequestData.cpp | ||
// build: GOOS=windows GOARCH=amd64 go build github.com/lian/msfs2020-go/examples/request_data | ||
|
||
type Report struct { | ||
simconnect.RecvSimobjectDataByType | ||
Title [256]byte | ||
Kohlsman float64 | ||
Altitude float64 | ||
Latitude float64 | ||
Longitude float64 | ||
} | ||
|
||
func main() { | ||
s, err := simconnect.New("Request Data") | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println("Connected to Flight Simulator!") | ||
|
||
defineID := simconnect.DWORD(0) | ||
s.AddToDataDefinition(defineID, "Title", "", simconnect.DATATYPE_STRING256) | ||
s.AddToDataDefinition(defineID, "Kohlsman setting hg", "inHg", simconnect.DATATYPE_FLOAT64) | ||
s.AddToDataDefinition(defineID, "Plane Altitude", "feet", simconnect.DATATYPE_FLOAT64) | ||
s.AddToDataDefinition(defineID, "Plane Latitude", "degrees", simconnect.DATATYPE_FLOAT64) | ||
s.AddToDataDefinition(defineID, "Plane Longitude", "degrees", simconnect.DATATYPE_FLOAT64) | ||
|
||
fmt.Println("SubscribeToSystemEvent") | ||
eventSimStartID := simconnect.DWORD(0) | ||
s.SubscribeToSystemEvent(eventSimStartID, "SimStart") | ||
|
||
requestID := simconnect.DWORD(0) | ||
s.RequestDataOnSimObjectType(requestID, defineID, 0, simconnect.SIMOBJECT_TYPE_USER) | ||
|
||
for { | ||
ppData, r1, err := s.GetNextDispatch() | ||
|
||
if r1 < 0 { | ||
if uint32(r1) == simconnect.E_FAIL { | ||
// skip error, means no new messages? | ||
continue | ||
} else { | ||
panic(fmt.Errorf("GetNextDispatch error: %d %s", r1, err)) | ||
} | ||
} | ||
|
||
recvInfo := *(*simconnect.Recv)(ppData) | ||
//fmt.Println(ppData, pcbData, recvInfo) | ||
|
||
switch recvInfo.ID { | ||
case simconnect.RECV_ID_EXCEPTION: | ||
recvErr := *(*simconnect.RecvException)(ppData) | ||
fmt.Printf("SIMCONNECT_RECV_ID_EXCEPTION %#v\n", recvErr) | ||
|
||
case simconnect.RECV_ID_OPEN: | ||
recvOpen := *(*simconnect.RecvOpen)(ppData) | ||
fmt.Println("SIMCONNECT_RECV_ID_OPEN", fmt.Sprintf("%s", recvOpen.ApplicationName)) | ||
//spew.Dump(recvOpen) | ||
case simconnect.RECV_ID_EVENT: | ||
recvEvent := *(*simconnect.RecvEvent)(ppData) | ||
fmt.Println("SIMCONNECT_RECV_ID_EVENT") | ||
//spew.Dump(recvEvent) | ||
|
||
switch recvEvent.EventID { | ||
case eventSimStartID: | ||
fmt.Println("SimStart Event") | ||
default: | ||
fmt.Println("unknown SIMCONNECT_RECV_ID_EVENT", recvEvent.EventID) | ||
} | ||
|
||
case simconnect.RECV_ID_SIMOBJECT_DATA_BYTYPE: | ||
recvData := *(*simconnect.RecvSimobjectDataByType)(ppData) | ||
fmt.Println("SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE") | ||
|
||
switch recvData.RequestID { | ||
case requestID: | ||
report := *(*Report)(ppData) | ||
fmt.Printf("REPORT: %s: GPS: %.6f,%.6f Altitude: %.0f\n", report.Title, report.Latitude, report.Longitude, report.Altitude) | ||
s.RequestDataOnSimObjectType(requestID, defineID, 0, simconnect.SIMOBJECT_TYPE_USER) | ||
} | ||
|
||
default: | ||
fmt.Println("recvInfo.dwID unknown", recvInfo.ID) | ||
} | ||
|
||
time.Sleep(500 * time.Millisecond) | ||
} | ||
|
||
fmt.Println("close") | ||
|
||
if err = s.Close(); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/lian/msfs2020-go | ||
|
||
go 1.14 | ||
|
||
require github.com/gorilla/websocket v1.4.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= | ||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package simconnect | ||
|
||
// MSFS-SDK/SimConnect\ SDK/include/SimConnect.h | ||
|
||
const E_FAIL uint32 = 0x80004005 | ||
|
||
type DWORD uint32 | ||
|
||
const UNUSED DWORD = 0xffffffff // special value to indicate unused event, ID | ||
|
||
const ( | ||
DATATYPE_INVALID DWORD = iota // invalid data type | ||
DATATYPE_INT32 // 32-bit integer number | ||
DATATYPE_INT64 // 64-bit integer number | ||
DATATYPE_FLOAT32 // 32-bit floating-point number (float) | ||
DATATYPE_FLOAT64 // 64-bit floating-point number (double) | ||
DATATYPE_STRING8 // 8-byte string | ||
DATATYPE_STRING32 // 32-byte string | ||
DATATYPE_STRING64 // 64-byte string | ||
DATATYPE_STRING128 // 128-byte string | ||
DATATYPE_STRING256 // 256-byte string | ||
DATATYPE_STRING260 // 260-byte string | ||
DATATYPE_STRINGV // variable-length string | ||
DATATYPE_INITPOSITION // see SIMCONNECT_DATA_INITPOSITION | ||
DATATYPE_MARKERSTATE // see SIMCONNECT_DATA_MARKERSTATE | ||
DATATYPE_WAYPOINT // see SIMCONNECT_DATA_WAYPOINT | ||
DATATYPE_LATLONALT // see SIMCONNECT_DATA_LATLONALT | ||
DATATYPE_XYZ // see SIMCONNECT_DATA_XYZ | ||
|
||
DATATYPE_MAX // enum limit | ||
) | ||
|
||
const ( | ||
RECV_ID_NULL DWORD = iota | ||
RECV_ID_EXCEPTION | ||
RECV_ID_OPEN | ||
RECV_ID_QUIT | ||
RECV_ID_EVENT | ||
RECV_ID_EVENT_OBJECT_ADDREMOVE | ||
RECV_ID_EVENT_FILENAME | ||
RECV_ID_EVENT_FRAME | ||
RECV_ID_SIMOBJECT_DATA | ||
RECV_ID_SIMOBJECT_DATA_BYTYPE | ||
RECV_ID_WEATHER_OBSERVATION | ||
RECV_ID_CLOUD_STATE | ||
RECV_ID_ASSIGNED_OBJECT_ID | ||
RECV_ID_RESERVED_KEY | ||
RECV_ID_CUSTOM_ACTION | ||
RECV_ID_SYSTEM_STATE | ||
RECV_ID_CLIENT_DATA | ||
RECV_ID_EVENT_WEATHER_MODE | ||
RECV_ID_AIRPORT_LIST | ||
RECV_ID_VOR_LIST | ||
RECV_ID_NDB_LIST | ||
RECV_ID_WAYPOINT_LIST | ||
RECV_ID_EVENT_MULTIPLAYER_SERVER_STARTED | ||
RECV_ID_EVENT_MULTIPLAYER_CLIENT_STARTED | ||
RECV_ID_EVENT_MULTIPLAYER_SESSION_ENDED | ||
RECV_ID_EVENT_RACE_END | ||
RECV_ID_EVENT_RACE_LAP | ||
|
||
RECV_ID_PICK | ||
) | ||
|
||
const ( | ||
SIMOBJECT_TYPE_USER DWORD = iota | ||
SIMOBJECT_TYPE_ALL | ||
SIMOBJECT_TYPE_AIRCRAFT | ||
SIMOBJECT_TYPE_HELICOPTER | ||
SIMOBJECT_TYPE_BOAT | ||
SIMOBJECT_TYPE_GROUND | ||
) | ||
|
||
type Recv struct { | ||
Size DWORD | ||
Version DWORD | ||
ID DWORD | ||
} | ||
|
||
type RecvOpen struct { | ||
Recv | ||
ApplicationName [256]byte | ||
ApplicationVersionMajor DWORD | ||
ApplicationVersionMinor DWORD | ||
ApplicationBuildMajor DWORD | ||
ApplicationBuildMinor DWORD | ||
SimConnectVersionMajor DWORD | ||
SimConnectVersionMinor DWORD | ||
SimConnectBuildMajor DWORD | ||
SimConnectBuildMinor DWORD | ||
Reserved1 DWORD | ||
Reserved2 DWORD | ||
} | ||
|
||
type RecvEvent struct { | ||
Recv | ||
//static const DWORD UNKNOWN_GROUP = DWORD_MAX; | ||
GroupID DWORD | ||
EventID DWORD | ||
Data DWORD // uEventID-dependent context | ||
} | ||
|
||
type RecvSimobjectData struct { | ||
Recv | ||
RequestID DWORD | ||
ObjectID DWORD | ||
DefineID DWORD | ||
Flags DWORD // SIMCONNECT_DATA_REQUEST_FLAG | ||
entrynumber DWORD // if multiple objects returned, this is number <entrynumber> out of <outof>. | ||
outof DWORD // note: starts with 1, not 0. | ||
DefineCount DWORD // data count (number of datums, *not* byte count) | ||
//SIMCONNECT_DATAV( dwData, dwDefineID, ); // data begins here, dwDefineCount data items | ||
} | ||
|
||
type RecvSimobjectDataByType struct { | ||
RecvSimobjectData | ||
} | ||
|
||
type RecvException struct { | ||
Recv | ||
Exception DWORD // see SIMCONNECT_EXCEPTION | ||
//static const DWORD UNKNOWN_SENDID = 0; | ||
SendID DWORD // see SimConnect_GetLastSentPacketID | ||
//static const DWORD UNKNOWN_INDEX = DWORD_MAX; | ||
Index DWORD // index of parameter that was source of error | ||
} |
Oops, something went wrong.