Skip to content

Commit d100535

Browse files
committed
add option to use custom weather data
1 parent 6b6d968 commit d100535

File tree

7 files changed

+78
-86
lines changed

7 files changed

+78
-86
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ resource.syso
99

1010
# testing files
1111
config.json
12+
checkwx.json
1213
mission.miz
1314
realweather.miz
1415
tmp/

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ each parameter.
6060
"log": "logfile.log" // path of log file, "" disables
6161
},
6262
"metar": {
63-
"icao": "KDLH", // ICAO of the aiport to fetch METAR from
64-
"runway-elevation": 0, // elevation of runway in meters MSL
65-
"remarks": "", // addtional remarks for METAR, customization only
66-
"add-to-brief": true // add METAR text to bottom of mission brief
63+
"icao": "KDLH", // ICAO of the aiport to fetch METAR from
64+
"runway-elevation": 0, // elevation of runway in meters MSL
65+
"remarks": "", // addtional remarks for METAR, customization only
66+
"add-to-brief": true, // add METAR text to bottom of mission brief
67+
"use-custom-data": false // use custom data from checkwx.json file
6768
},
6869
"options": {
6970
"update-time": true, // set to false to disable time being updated
@@ -133,6 +134,13 @@ each parameter.
133134
* `add-to-brief`: boolean
134135
* If true, Real Weather will add the generated METAR to the bottom of your
135136
mission brief.
137+
* `use-custom-data`: boolean
138+
* If true, Real Weather will load METAR data from a checkwx.json file
139+
instead of accessing the CheckWX API. This data must be in the same format
140+
CheckWX would provide. See [examples/checkwx.json](examples/checkwx.json)
141+
and [checkwxapi.com](https://www.checkwxapi.com/documentation/metar) for
142+
more info. Only the parameters shown in the example are currently
143+
supported.
136144
* `options`
137145
* `update-time`: boolean
138146
* Disable/enable Real Weather modifying your mission time.

checkwx.json

Lines changed: 0 additions & 79 deletions
This file was deleted.

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Configuration struct {
3232
RunwayElevation int `json:"runway-elevation"`
3333
Remarks string `json:"remarks"`
3434
AddToBrief bool `json:"add-to-brief"`
35+
UseCustomData bool `json:"use-custom-data"`
3536
} `json:"metar"`
3637
Options struct {
3738
UpdateTime bool `json:"update-time"`

config/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"icao": "UGKO",
1010
"runway-elevation": 160,
1111
"remarks": "RMK Generated by DCS Real Weather",
12-
"add-to-brief": true
12+
"add-to-brief": true,
13+
"use-custom-data": false
1314
},
1415
"options": {
1516
"update-time": true,

examples/checkwx.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"results": 1,
3+
"data": [
4+
{
5+
"icao": "UGKO",
6+
"barometer": {
7+
"hg": 30.15
8+
},
9+
"clouds": [
10+
{
11+
"code": "OVC",
12+
"meters": 549
13+
},
14+
{
15+
"code": "BKN",
16+
"meters": 1372
17+
}
18+
],
19+
"dewpoint": {
20+
"celsius": 11
21+
},
22+
"observed": "2024-04-13T01:00:00",
23+
"station": {
24+
"geometry": {
25+
"coordinates": [
26+
42.482393,
27+
42.176768
28+
]
29+
}
30+
},
31+
"temperature": {
32+
"celsius": 12
33+
},
34+
"visibility": {
35+
"meters_float": 8000
36+
},
37+
"wind": {
38+
"degrees": 220,
39+
"speed_mps": 2,
40+
"gust_mps": 0
41+
}
42+
}
43+
]
44+
}

main.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
//go:generate goversioninfo versioninfo/versioninfo.json
44

55
import (
6+
"bytes"
67
"encoding/json"
78
"flag"
89
"fmt"
@@ -108,17 +109,32 @@ func getWx() weather.WeatherData {
108109
var err error
109110
var data weather.WeatherData
110111

112+
// use value from config if exists. CLI argument will override a false
113+
// parameter in the config
114+
if config.Get().METAR.UseCustomData {
115+
debugCheckWx = true
116+
}
117+
111118
if debugCheckWx {
112-
log.Println("Debugging CheckWx. Reading data from file...")
119+
log.Println("Using custom weather data from file...")
113120
b, err := os.ReadFile("checkwx.json")
114121
if err != nil {
115122
log.Fatalf("Could not read checkwx.json: %v", err)
116123
}
124+
125+
var minify bytes.Buffer
126+
if err := json.Compact(&minify, b); err == nil {
127+
log.Println("Read weather data: ", minify.String())
128+
} else {
129+
log.Println("Couldn't minify custom weather data:", err)
130+
}
131+
117132
err = json.Unmarshal(b, &data)
118133
if err != nil {
119134
log.Fatalf("Could not parse checkwx.json: %v", err)
120135
}
121-
log.Println("Parsed weather data")
136+
log.Println("Parsed weather data: ")
137+
122138
} else {
123139
data, err = weather.GetWeather(config.Get().METAR.ICAO, config.Get().APIKey)
124140
if err != nil {

0 commit comments

Comments
 (0)