-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfig.py
168 lines (135 loc) · 3.44 KB
/
Config.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#! /usr/bin/python3
# -*- coding: utf-8 -*-
"""
Python Modul Config.py
Enthält alle Globalen Variablen
"""
import configparser
import os
import pdb
import logging
import re
import datetime
__version__ = "1.2.1"
__author__ = "HB9PAE, Peter"
__copyright__ = "Copyright 2024"
__email__ = "[email protected]"
Version = __version__
myConfig = os.path.dirname(os.path.abspath(__name__)) + "/igate.ini"
Frequ = 433775000
SR = 12
StartTime = datetime.datetime.now()
DisplayTimeout = 60
# Auslesen BME280
EN_WXDATA = False
BMEINTERVAL = 300
WXINTERVAL = 300
Temperature = 1.0
AirPressureNN = 1.0
Humidity = 1.0
WXrrd = os.path.dirname(os.path.abspath(__name__)) + "/WXrrd.rrd"
ReadBME280 = False
WxReport = False
Beacon = False
# LORA
LastMsg = "--- None ---"
RxCount = 0
PktErr = 0
# Message to APRS-IS
MsgSent = 0
PktRSSI = 0
RSSI = 0
SNR = 0
# Variablen aus igate.ini ----
CALL = "NOCALL"
PASSCODE = ""
INFO = ""
EN_APRSIS = False
LON = 0.0
LAT = 0.0
HEIGHT = 0
BEACONINTERVAL = 600
EN_BME280 = False
dirtyFlag = False
reboot = False
#APRS
AIS = ""
Login = 0
# Test auf ungültige Zeichen
def match(strg, search=re.compile(r'[^A-Z0-9.-]').search):
res = bool(search(strg))
return(True)
# Umrechnen von Dezimal-Grad zu Grad-Minuten
def grad2min(_lat, _lon) :
_latGrad = int(abs(_lat))
_latMin = 60* (_lat - _latGrad)
latstr = f"{_latGrad:d}{_latMin:.2f}"
if (_lat > 0) :
latstr = latstr.zfill(7) + "N"
else :
latstr = latstr + "S"
_lonGrad = int(abs(_lon))
_lonMin = 60.0 * (_lon - _lonGrad)
lonstr = f"{_lonGrad:d}{_lonMin:.2f}"
if (_lon > 0) :
lonstr = lonstr.zfill(8) + "E"
else :
lonstr = lonstr + "W"
return(latstr, lonstr)
def setGlobals(_conf) :
global POS
#pdb.set_trace()
for section in _conf :
for key in _conf[section] :
varname = _conf[section][key]
if (key.lower().startswith("en_") ):
#pdb.set_trace()
if (varname.lower() in [ "true", "1", "y", "yes"] ) :
varname = True
else :
varname = False
globals()[key.upper()] = varname
POS = grad2min(float(LAT), float(LON) )
def getConfig(file) :
#pdb.set_trace()
if (not os.path.isfile(file)) :
mkConfig(file)
logging.info("No Configfile found, create %s" % (file) )
#os.system('sudo reboot')
config = configparser.ConfigParser()
config.read(file)
dictionary = {}
for section in config.sections():
dictionary[section] = {}
for option in config.options(section):
dictionary[section][option] = config.get(section, option)
return(dictionary)
def mkConfig(file) :
# ---- Write Header to Configfile
now = datetime.datetime.now()
header1 = "# Konfigurtation APRS iGate\n"
header2 = "# (c) [email protected]\n"
header3 = "# Positionskoordinaten im Dezimalformat (LAT: Breitengrad,LON: Laengengrad)\n"
header4 = now.strftime("# Erstellt: %d/%m/%Y %H:%M:%S\n")
f = open(file, "w")
f.writelines(header1)
f.writelines(header2)
f.writelines(header3)
f.writelines(header4)
f.close()
# ---- Write Configuration Template
_conf=configparser.ConfigParser()
_conf["APRS-IS"] = {
"Call": "NOCALL", "Passcode" : "123456", "Info" : "LoRa iGate", "EN_APRSIS" : "False",\
"Lat" : "47.5", "Lon" : "8.5", "height" : "399",\
"BeaconInterval" : "900", "EN_BME280" : "False",\
"EN_WxData" : "False", "WebIP" : "0.0.0.0"
}
with open(file, 'a') as configfile:
_conf.write(configfile)
def main() :
myconf = getConfig("test.ini")
setGlobals(myconf)
pdb.set_trace()
if __name__ == "__main__":
main()