This repository has been archived by the owner on Mar 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMAVControlSettings.py
76 lines (63 loc) · 2.47 KB
/
MAVControlSettings.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
class Settings:
def __init__(self):
self.load()
def load(self):
with open('settings.json', 'r') as f:
raw_settings = json.load(f)
# MavConnection
self.MavConnection.ip = raw_settings["MavConnection"]["ip"]
self.MavConnection.port = raw_settings["MavConnection"]["port"]
self.MavConnection.mavlink_version = raw_settings["MavConnection"]["mavlink_version"]
self.MavConnection.initial_sysid = raw_settings["MavConnection"]["initial_sysid"]
# Sockets
self.Sockets.namespace = raw_settings["Sockets"]["namespace"]
self.Sockets.async_mode = raw_settings["Sockets"]["async_mode"]
# Frontend
self.Frontend.name = raw_settings["Frontend"]["name"]
self.Frontend.password = raw_settings["Frontend"]["password"]
try:
self.Frontend.allowControl = raw_settings["Frontend"]["allowControl"]
except KeyError:
self.Frontend.allowControl = "True"
# Backend
self.Backend.known_mavlink_packets_file = raw_settings["Backend"]["known_mavlink_packets_file"]
with open(self.Backend.known_mavlink_packets_file, 'r') as f:
self.Backend.known_mavlink_packets = json.load(f)
def save(self):
save_settings = {
"MavConnection": {
"ip": self.MavConnection.ip,
"port": self.MavConnection.port,
"mavlink_version": self.MavConnection.mavlink_version,
"initial_sysid": self.MavConnection.initial_sysid,
},
"Sockets": {
"namespace": self.Sockets.namespace,
"async_mode": self.Sockets.async_mode,
},
"Frontend": {
"name": self.Frontend.name,
"password": self.Frontend.password,
"allowControl": self.Frontend.allowControl,
},
"Backend": {
"known_mavlink_packets_file": self.Backend.known_mavlink_packets_file,
},
}
with open('settings.json', 'w') as f:
json.dump(save_settings, f, indent=4)
class MavConnection:
ip = None
port = None
mavlink_version = None
initial_sysid = None
class Sockets:
namespace = None
async_mode = None
class Frontend:
name = None
password = None
class Backend:
known_mavlink_packets_file = None
known_mavlink_packets = None