Commit 03c5ff878000de12e42cc5d025acd1475cd29462
1 parent
7c59b9c4
Exists in
dev
delete utils folder
Showing
21 changed files
with
4 additions
and
2056 deletions
Show diff stats
src/core/pyros_django/observation_manager/A_ImagesCalibrator.py renamed to src/core/pyros_django/bdf_process/A_BDFProcessor.py
@@ -30,7 +30,7 @@ import glob | @@ -30,7 +30,7 @@ import glob | ||
30 | import shutil | 30 | import shutil |
31 | import guitastro | 31 | import guitastro |
32 | 32 | ||
33 | -class A_ImagesCalibrator(Agent): | 33 | +class A_BDFProcessor(Agent): |
34 | 34 | ||
35 | # - All possible running states | 35 | # - All possible running states |
36 | RUNNING_NOTHING = 0 | 36 | RUNNING_NOTHING = 0 |
@@ -333,6 +333,6 @@ class A_ImagesCalibrator(Agent): | @@ -333,6 +333,6 @@ class A_ImagesCalibrator(Agent): | ||
333 | 333 | ||
334 | if __name__ == "__main__": | 334 | if __name__ == "__main__": |
335 | 335 | ||
336 | - agent = build_agent(A_ImagesCalibrator) | 336 | + agent = build_agent(A_BDFProcessor) |
337 | print(agent) | 337 | print(agent) |
338 | agent.run() | 338 | agent.run() |
src/core/pyros_django/observation_manager/A_ImagesProcessor.py renamed to src/core/pyros_django/img_process/A_ImgProcessor.py
@@ -42,7 +42,7 @@ import glob | @@ -42,7 +42,7 @@ import glob | ||
42 | import shutil | 42 | import shutil |
43 | import guitastro | 43 | import guitastro |
44 | 44 | ||
45 | -class A_ImagesProcessor(Agent): | 45 | +class A_ImgProcessor(Agent): |
46 | 46 | ||
47 | # - All possible running states | 47 | # - All possible running states |
48 | RUNNING_NOTHING = 0 | 48 | RUNNING_NOTHING = 0 |
@@ -371,6 +371,6 @@ class A_ImagesProcessor(Agent): | @@ -371,6 +371,6 @@ class A_ImagesProcessor(Agent): | ||
371 | if __name__ == "__main__": | 371 | if __name__ == "__main__": |
372 | args = parse_args(sys.argv[1:]) | 372 | args = parse_args(sys.argv[1:]) |
373 | #args = vars(parser.parse_args()) | 373 | #args = vars(parser.parse_args()) |
374 | - agent = build_agent(A_ImagesProcessor, param_constr=args) | 374 | + agent = build_agent(A_ImgProcessor, param_constr=args) |
375 | print(agent) | 375 | print(agent) |
376 | agent.run() | 376 | agent.run() |
src/core/pyros_django/utils/JDManipulator.py deleted
@@ -1,116 +0,0 @@ | @@ -1,116 +0,0 @@ | ||
1 | -from django.conf import settings | ||
2 | -import datetime | ||
3 | -import time | ||
4 | -from decimal import * | ||
5 | - | ||
6 | -JD_VALUE = 86400 | ||
7 | -TIMESTAMP_JD = 2440587.500000 | ||
8 | -DAILY_SECOND = 1 / 86400 | ||
9 | -SECOND_DIV = 86400 | ||
10 | - | ||
11 | -def getSimTime(): | ||
12 | - current_time = datetime.datetime.now() | ||
13 | - if current_time.minute == 59: | ||
14 | - current_time = current_time.replace(hour=(current_time.hour + 1), minute=0, second=10) | ||
15 | - else: | ||
16 | - if current_time.second >= 50: | ||
17 | - current_time = current_time.replace(minute=current_time.minute + 1, second=10) | ||
18 | - else: | ||
19 | - current_time = current_time.replace(second=(current_time.second + 10)) | ||
20 | - | ||
21 | - return (time.mktime(current_time.timetuple())) | ||
22 | - | ||
23 | - | ||
24 | -SIM_TIME_START = getSimTime() | ||
25 | - | ||
26 | -def JulianSeconds(value): | ||
27 | - return (Decimal(value) / SECOND_DIV) | ||
28 | - | ||
29 | -def getPreciseCurrentTime(): | ||
30 | - return (Decimal(getCurrentTime())) | ||
31 | - | ||
32 | -def getPreciseNightStart(): | ||
33 | - return (Decimal(getNightStart())) | ||
34 | - | ||
35 | -def getPreciseNightEnd(): | ||
36 | - return (Decimal(getNightEnd())) | ||
37 | - | ||
38 | -def secondsToJulianDate(time_seconds): | ||
39 | - return (time_seconds / 86400 + TIMESTAMP_JD) | ||
40 | - | ||
41 | -def secondsToPreciseJulianDate(time_seconds): | ||
42 | - return (Decimal(time_seconds) / 86400 + Decimal(TIMESTAMP_JD)) | ||
43 | - | ||
44 | -def julianSecondsToSeconds(seconds_julian): | ||
45 | - return seconds_julian * 86400 | ||
46 | - | ||
47 | -def julianDateToSeconds(time_julian): | ||
48 | - return ((time_julian - TIMESTAMP_JD) * 86400) | ||
49 | - | ||
50 | -def getCurrentTime(): | ||
51 | - current_time = datetime.datetime.now() | ||
52 | - return (time.mktime(current_time.timetuple())) | ||
53 | - | ||
54 | -def getNextDefaultNightStart(): | ||
55 | - current_time = datetime.datetime.now() | ||
56 | - if (current_time.hour >= 18): | ||
57 | - current_time += datetime.timedelta(days=1) | ||
58 | - current_time = current_time.replace(hour=18, minute=0, second=0, microsecond=0) | ||
59 | - return (time.mktime(current_time.timetuple())) | ||
60 | - | ||
61 | -def getNextDefaultNightEnd(): | ||
62 | - current_time = datetime.datetime.now() | ||
63 | - if (current_time.hour >= 18): | ||
64 | - current_time += datetime.timedelta(days=2) | ||
65 | - else: | ||
66 | - current_time += datetime.timedelta(days=1) | ||
67 | - current_time = current_time.replace(hour=6, minute=0, second=0, microsecond=0) | ||
68 | - return (time.mktime(current_time.timetuple())) | ||
69 | - | ||
70 | -def getDefaultNightStart(): | ||
71 | - current_time = datetime.datetime.now() | ||
72 | - print("*********************") | ||
73 | - print("*********************") | ||
74 | - print("current time is", current_time) | ||
75 | - print("SIM_TIME_START", SIM_TIME_START) | ||
76 | - print("*********************") | ||
77 | - print("*********************") | ||
78 | - if settings.SIMULATOR: | ||
79 | - if settings.SIMULATOR: | ||
80 | - return SIM_TIME_START | ||
81 | - if current_time.minute == 59: | ||
82 | - current_time = current_time.replace(hour=(current_time.hour + 1), minute=0, second=10) | ||
83 | - else: | ||
84 | - if current_time.second > 50: | ||
85 | - current_time = current_time.replace(minute=current_time.minute + 1, second=10) | ||
86 | - else: | ||
87 | - current_time = current_time.replace(second=(current_time.second + 10)) | ||
88 | - else: | ||
89 | - current_time = current_time.replace(hour=18, minute=0, second=0, microsecond=0) | ||
90 | - return (time.mktime(current_time.timetuple())) | ||
91 | - | ||
92 | -def getDefaultNightEnd(): | ||
93 | - current_time = datetime.datetime.now() | ||
94 | - current_time += datetime.timedelta(days=1) | ||
95 | - current_time = current_time.replace(hour=6, minute=0, second=0, microsecond=0) | ||
96 | - return (time.mktime(current_time.timetuple())) | ||
97 | - | ||
98 | -def datetimeToJulianDate(current_time): | ||
99 | - return (time.mktime(current_time.timetuple()) / JD_VALUE + TIMESTAMP_JD) | ||
100 | - | ||
101 | - | ||
102 | -''' TODO ''' | ||
103 | -def getNightStart(): | ||
104 | - return (getDefaultNightStart()) | ||
105 | - | ||
106 | -''' TODO ''' | ||
107 | -def getNightEnd(): | ||
108 | - return (getDefaultNightEnd()) | ||
109 | - | ||
110 | -''' TODO ''' | ||
111 | -def getNextNightStart(): | ||
112 | - return (getNextDefaultNightStart()) | ||
113 | - | ||
114 | -''' TODO ''' | ||
115 | -def getNextNightEnd(): | ||
116 | - return (getNextNightEnd()) | ||
117 | \ No newline at end of file | 0 | \ No newline at end of file |
src/core/pyros_django/utils/Logger.py deleted
@@ -1,44 +0,0 @@ | @@ -1,44 +0,0 @@ | ||
1 | -from django.conf import settings | ||
2 | -import logging | ||
3 | - | ||
4 | -# If django project is in /src/ : | ||
5 | -#RELATIVE_PATH_TO_LOG_DIR = '../logs/' | ||
6 | -#logging.basicConfig(filename='%s/../logs/pyros.log'%(settings.BASE_DIR), format='-> At : [%(asctime)s]\n\t By module [%(module)s] logger : [%(name)s] : "%(message)s"', level=logging.DEBUG) | ||
7 | -# If django project is in /src/core/pyros_django/ : | ||
8 | -RELATIVE_PATH_TO_LOG_DIR = '../../../logs' | ||
9 | -logging.basicConfig(filename = f'{settings.BASE_DIR}/{RELATIVE_PATH_TO_LOG_DIR}/pyros.log', | ||
10 | - format = '-> At : [%(asctime)s]\n\t By module [%(module)s] logger : [%(name)s] : "%(message)s"', | ||
11 | - level = logging.DEBUG) | ||
12 | -#logging.basicConfig(filename='%s/../../../logs/pyros.log'%(settings.BASE_DIR), format='-> At : [%(asctime)s]\n\t By module [%(module)s] logger : [%(name)s] : "%(message)s"', level=logging.DEBUG) | ||
13 | - | ||
14 | -def setupLogger(logger_name, log_file, level=logging.INFO): | ||
15 | - l = logging.getLogger(logger_name) | ||
16 | - formatter = logging.Formatter('[%(message)s] at %(filename)s : %(lineno)s') | ||
17 | - #fileHandler = logging.FileHandler('%s/../logs/%s.log'%(settings.BASE_DIR, log_file), mode='w') | ||
18 | - fileHandler = logging.FileHandler(f'{settings.BASE_DIR}/{RELATIVE_PATH_TO_LOG_DIR}/{log_file}.log', mode='w') | ||
19 | - fileHandler.setFormatter(formatter) | ||
20 | - # streamHandler = logging.StreamHandler() | ||
21 | - # streamHandler.setFormatter(formatter) | ||
22 | - | ||
23 | - l.setLevel(level) | ||
24 | - l.addHandler(fileHandler) | ||
25 | - # l.addHandler(streamHandler) | ||
26 | - return (logging.getLogger(logger_name)) | ||
27 | - | ||
28 | - | ||
29 | -class Logger: | ||
30 | - def __init__(self, name: str, file: str): | ||
31 | - super().__init__() | ||
32 | - self.logger = setupLogger(name, file) | ||
33 | - | ||
34 | - def log(self, message): | ||
35 | - if settings.DEBUG: | ||
36 | - self.logger.info(message) | ||
37 | - | ||
38 | - def info(self, message: str): | ||
39 | - if settings.DEBUG: | ||
40 | - self.logger.info(message) | ||
41 | - | ||
42 | - def debug(self, message: str): | ||
43 | - if settings.DEBUG: | ||
44 | - self.logger.debug(message) |
src/core/pyros_django/utils/__init__.py deleted
src/core/pyros_django/utils/highPrecision.py deleted
@@ -1,45 +0,0 @@ | @@ -1,45 +0,0 @@ | ||
1 | -from decimal import * | ||
2 | - | ||
3 | - | ||
4 | -PRECISION = Decimal(0.0000000001) | ||
5 | - | ||
6 | -''' | ||
7 | - Compare the two decimal, according to the given precision | ||
8 | -''' | ||
9 | - | ||
10 | - | ||
11 | -def is_nearby_equal(a: Decimal, b: Decimal, precision=PRECISION): | ||
12 | - return (True if abs(b - a) < precision else False) | ||
13 | - | ||
14 | - | ||
15 | -''' | ||
16 | - Compare the two decimal, according to the given precision | ||
17 | -''' | ||
18 | - | ||
19 | - | ||
20 | -def is_nearby_sup_or_equal(a: Decimal, b: Decimal, precision=PRECISION): | ||
21 | - if (a > b): | ||
22 | - return True | ||
23 | - return (True if abs(b - a) < precision else False) | ||
24 | - | ||
25 | - | ||
26 | -''' | ||
27 | - Compare the two decimal, according to the given precision | ||
28 | -''' | ||
29 | - | ||
30 | - | ||
31 | -def is_nearby_less_or_equal(a: Decimal, b: Decimal, precision=PRECISION): | ||
32 | - if (a < b): | ||
33 | - return True | ||
34 | - return (True if abs(b - a) < precision else False) | ||
35 | - | ||
36 | - | ||
37 | -''' | ||
38 | - Check if decimal is between | ||
39 | -''' | ||
40 | - | ||
41 | - | ||
42 | -def is_between(a: Decimal, b: Decimal, c: Decimal, precision=PRECISION): | ||
43 | - if is_nearby_less_or_equal(a, b) and is_nearby_less_or_equal(b, c): | ||
44 | - return True | ||
45 | - return False | ||
46 | \ No newline at end of file | 0 | \ No newline at end of file |
src/core/pyros_django/utils/plc/guitalens_observatory/driver_came.py deleted
@@ -1,122 +0,0 @@ | @@ -1,122 +0,0 @@ | ||
1 | -# -*- coding: utf-8 -*- | ||
2 | -import RPi.GPIO as io | ||
3 | -import time | ||
4 | - | ||
5 | -def do_open_roof(pin_cmd_open_bcm=27, debug_level=0): | ||
6 | - """Ouvre le toit avec un moteur de toit Came. | ||
7 | - | ||
8 | -Exemple: | ||
9 | - | ||
10 | -import driver_came ; driver_came.do_open_roof(27,2) | ||
11 | -""" | ||
12 | - | ||
13 | - io.setwarnings(False) | ||
14 | - io.setmode(io.BCM) #set up GPIO using BCM numbering | ||
15 | - io.setup(pin_cmd_open_bcm,io.OUT) # make pin an output (=arduino 27 open) | ||
16 | - | ||
17 | - io.output(pin_cmd_open_bcm,1) | ||
18 | - time.sleep(3) | ||
19 | - io.output(pin_cmd_open_bcm,0) | ||
20 | - | ||
21 | - err=0 | ||
22 | - return err | ||
23 | - | ||
24 | -def do_stop_roof(pin_cmd_stop_bcm=4, debug_level=0): | ||
25 | - """Stope le toit avec un moteur de toit Came. | ||
26 | - | ||
27 | -Exemple: | ||
28 | - | ||
29 | -import driver_came ; driver_came.do_stop_roof(4,2) | ||
30 | -""" | ||
31 | - | ||
32 | - io.setwarnings(False) | ||
33 | - io.setmode(io.BCM) #set up GPIO using BCM numbering | ||
34 | - io.setup(pin_cmd_stop_bcm,io.OUT) # make pin an output (=arduino 25 stop) | ||
35 | - | ||
36 | - io.output(pin_cmd_stop_bcm,1) | ||
37 | - time.sleep(3) | ||
38 | - io.output(pin_cmd_stop_bcm,0) | ||
39 | - | ||
40 | - err=0 | ||
41 | - return err | ||
42 | - | ||
43 | -def do_close_roof(pin_cmd_close_bcm=23, debug_level=0): | ||
44 | - """Ferme le toit avec un moteur de toit Came. | ||
45 | - | ||
46 | -Exemple: | ||
47 | - | ||
48 | -import driver_came ; driver_came.do_close_roof(23,2) | ||
49 | -""" | ||
50 | - | ||
51 | - io.setwarnings(False) | ||
52 | - io.setmode(io.BCM) #set up GPIO using BCM numbering | ||
53 | - io.setup(pin_cmd_close_bcm,io.OUT) # make pin an output (=arduino 29 close) | ||
54 | - | ||
55 | - io.output(pin_cmd_close_bcm,1) | ||
56 | - time.sleep(3) | ||
57 | - io.output(pin_cmd_close_bcm,0) | ||
58 | - | ||
59 | - err=0 | ||
60 | - return err | ||
61 | - | ||
62 | -def get_data(pin_chk_power_bcm=26, pin_sw_manu_bcm=22, pin_sw_closed_bcm=5, pin_sw_opened_bcm=6, debug_level=0): | ||
63 | - """Lecture des etats des switchs du moteur de toit Came. | ||
64 | -Retourne un tuple, dans l'ordre: Un code de validitรฉ, | ||
65 | - | ||
66 | -Exemple: | ||
67 | - | ||
68 | -import driver_came ; driver_came.get_data(26,22,5,6,2) | ||
69 | -""" | ||
70 | - | ||
71 | - io.setwarnings(False) | ||
72 | - io.setmode(io.BCM) #set up GPIO using BCM numbering | ||
73 | - io.setup(pin_chk_power_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 48 24V) | ||
74 | - io.setup(pin_sw_manu_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 31 manu/auto) | ||
75 | - io.setup(pin_sw_closed_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 39 closed) | ||
76 | - io.setup(pin_sw_opened_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 41 opened) | ||
77 | - | ||
78 | - pin48 = io.input(pin_chk_power_bcm) | ||
79 | - pin31 = io.input(pin_sw_manu_bcm) | ||
80 | - pin39 = io.input(pin_sw_closed_bcm) | ||
81 | - pin41 = io.input(pin_sw_opened_bcm) | ||
82 | - if (debug_level==2): | ||
83 | - print("=== Bit states ===") | ||
84 | - disp ="pin48,gpio26,power24V ="+str(pin48)+"pin31,gpio22,auto/manu ="+str(pin31)+" pin39,gpio5,closed ="+str(pin39)+" pin41,gpio6,opened ="+str(pin41) | ||
85 | - print(disp) | ||
86 | - | ||
87 | - # === return | ||
88 | - err = 0 | ||
89 | - power_came = 0 | ||
90 | - if ( pin48==0 ): | ||
91 | - power_came_msg = "24Volts" | ||
92 | - power_came = 1 | ||
93 | - else: | ||
94 | - power_came_msg = "0Volt" | ||
95 | - err = err +1 | ||
96 | - if ( pin31==1 ): | ||
97 | - mode_came= 1 | ||
98 | - mode_came_msg = "Auto" | ||
99 | - else: | ||
100 | - mode_came = 0 | ||
101 | - mode_came_msg = "Manual" | ||
102 | - roof_state = -1 | ||
103 | - roof_state_msg = "Unknown" | ||
104 | - if ( (pin39==1) and (pin41==1) ): | ||
105 | - err = err + 2 | ||
106 | - roof_state_msg = "NoPower" | ||
107 | - elif ( (pin39==0) and (pin41==0) ): | ||
108 | - roof_state = 2 | ||
109 | - roof_state_msg = "Intermediate" | ||
110 | - elif ( (pin39==1) and (pin41==0) ): | ||
111 | - roof_state = 0 | ||
112 | - roof_state_msg = "Closed" | ||
113 | - elif ( (pin39==0) and (pin41==1) ): | ||
114 | - roof_state = 1 | ||
115 | - roof_state_msg = "Opened" | ||
116 | - | ||
117 | - if (debug_level>=1): | ||
118 | - print("=== Came states ===") | ||
119 | - print("power={} mode={} state={}".format(power_came_msg, mode_came_msg, roof_state_msg)); | ||
120 | - | ||
121 | - return err, power_came, mode_came, roof_state, power_came_msg, mode_came_msg, roof_state_msg, pin48, pin39, pin41,pin31 | ||
122 | - |
src/core/pyros_django/utils/plc/guitalens_observatory/driver_cv7.py deleted
@@ -1,123 +0,0 @@ | @@ -1,123 +0,0 @@ | ||
1 | -# -*- coding: utf-8 -*- | ||
2 | -# == pour donner les droits d'acces a /dev/ttS0 | ||
3 | -# gedit /boot/cmdline.txt & | ||
4 | -# effacer console=serial0,115200 | ||
5 | -# == a priori il n'est pas necessaire de faire les deux lignes suivantes | ||
6 | -# usermod -a -G tty pi | ||
7 | -# chmod 777 /dev/ttyS0 | ||
8 | - | ||
9 | -import time | ||
10 | -import serial | ||
11 | -import RPi.GPIO as io | ||
12 | - | ||
13 | -def get_data(port="/dev/ttyS0",pin_vin_bcm=25, debug_level=0): | ||
14 | - """Lecture d'une trame du capteur meteo CV7. | ||
15 | -Retourne un tuple, dans l'ordre: Un code de validitรฉ, la vitesse du vent en m/s, la direction relative du vent en degre, la tempรฉrature en ยฐC, la trame IIMWV lue, la trame WIXDR lue. Le code de validitรฉ =0 si la trame est valide, =1 si Vin n'est pas detecte, =2 si les trames ne sont pas valides. | ||
16 | - | ||
17 | -Exemple: | ||
18 | - | ||
19 | -import driver_cv7 ; driver_cv7.get_data("/dev/ttyS0", 25,2) | ||
20 | -""" | ||
21 | - | ||
22 | - # === verify 12V power supply if it is possible | ||
23 | - power_mife = 1 | ||
24 | - if (pin_vin_bcm>0): | ||
25 | - io.setmode(io.BCM) #set up GPIO using BCM numbering | ||
26 | - io.setup(pin_vin_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 35->34 SWO_T60 = Vin) | ||
27 | - pin34 = io.input(pin_vin_bcm) | ||
28 | - power_mife = 1-pin34 | ||
29 | - if (debug_level==2): | ||
30 | - print("=== Voltage intput ===") | ||
31 | - disp ="pin34,35,gpio25,Vin="+str(pin34)+ " (0=12V 1=0V)" | ||
32 | - print(disp) | ||
33 | - err = 0 | ||
34 | - if ( power_mife==1 ): | ||
35 | - power_mife_msg = "12Volts" | ||
36 | - power_mife = 1 | ||
37 | - else: | ||
38 | - power_mife_msg = "0Volt" | ||
39 | - power_mife = 0 | ||
40 | - err = err +1 | ||
41 | - | ||
42 | - # === get the raw frame | ||
43 | - serialerror=0 | ||
44 | - try: | ||
45 | - ser = serial.Serial( | ||
46 | - port=port, | ||
47 | - baudrate = 4800, | ||
48 | - parity=serial.PARITY_NONE, | ||
49 | - stopbits=serial.STOPBITS_ONE, | ||
50 | - bytesize=serial.EIGHTBITS, | ||
51 | - timeout=0, | ||
52 | - ) | ||
53 | - if ser.isOpen(): | ||
54 | - serialerror=0 | ||
55 | - else: | ||
56 | - serialerror=1 | ||
57 | - except: | ||
58 | - serialerror=2 | ||
59 | - else: | ||
60 | - if ser.isOpen(): | ||
61 | - time.sleep(0.1) | ||
62 | - ser.flush() | ||
63 | - raw_str="" | ||
64 | - for i in range(0,30000): | ||
65 | - x=ser.read() | ||
66 | - if (len(x)>0): | ||
67 | - raw_str+= "{:c}".format(x[0]) | ||
68 | - if (debug_level==2): | ||
69 | - print("=== Raw frame ===") | ||
70 | - print(raw_str) | ||
71 | - ser.close() | ||
72 | - | ||
73 | - # === decode | ||
74 | - valid=0b00 | ||
75 | - wind_dir_deg = 0 | ||
76 | - wind_dir_kt = 0 | ||
77 | - wind_dir_ms = 0 | ||
78 | - wind_tmp_degC = 0 | ||
79 | - msg_wind = "" | ||
80 | - msg_temp = "" | ||
81 | - raw_list = raw_str.split() | ||
82 | - if (debug_level==2): | ||
83 | - print("=== Raw list ===") | ||
84 | - print(raw_list) | ||
85 | - for message in raw_list: | ||
86 | - msg = str(message) | ||
87 | - # $IIMWV,135.0,R,000.0,N,A*3A | ||
88 | - key = "$IIMWV" | ||
89 | - k = msg.find(key) | ||
90 | - if ( (k==0) and (len(msg)>=27) ): | ||
91 | - msg_list = msg.split(","); | ||
92 | - if (debug_level==2): | ||
93 | - print("=== IIMWV ===") | ||
94 | - print(msg) | ||
95 | - print(msg_list) | ||
96 | - wind_dir_deg = float(msg_list[1]) | ||
97 | - wind_speed_kt = float(msg_list[3]) | ||
98 | - wind_speed_ms = wind_speed_kt*1.852/3.6 | ||
99 | - valid = valid | 0b01 | ||
100 | - msg_wind = msg | ||
101 | - # $WIXDR,C,021.0,C,,*51 | ||
102 | - key = "$WIXDR" | ||
103 | - k = msg.find(key) | ||
104 | - if ( (k==0) and (len(msg)>=21) ): | ||
105 | - msg_list = msg.split(","); | ||
106 | - if (debug_level==2): | ||
107 | - print("=== WIXDR ===") | ||
108 | - print(msg) | ||
109 | - print(msg_list) | ||
110 | - wind_tmp_degC = float(msg_list[2]) | ||
111 | - valid = valid | 0b10 | ||
112 | - msg_temp = msg | ||
113 | - # === return | ||
114 | - err = 0 | ||
115 | - if (power_mife==0): | ||
116 | - err += 1 | ||
117 | - if (serialerror==1): | ||
118 | - err += 2 | ||
119 | - if (valid==0): | ||
120 | - err += 4 | ||
121 | - | ||
122 | - return err, power_mife, wind_dir_deg, wind_speed_ms, wind_tmp_degC, power_mife_msg, msg_wind, msg_temp | ||
123 | - |
src/core/pyros_django/utils/plc/guitalens_observatory/driver_dht22.py deleted
@@ -1,202 +0,0 @@ | @@ -1,202 +0,0 @@ | ||
1 | -# -*- coding: utf-8 -*- | ||
2 | -from time import * | ||
3 | -import RPi.GPIO as io | ||
4 | - | ||
5 | -def get_data(pin_data_bcm=13, debug_level=0): | ||
6 | - if False: | ||
7 | - # --- method perso pure python | ||
8 | - err=0 | ||
9 | - k=0 | ||
10 | - sortie=False | ||
11 | - while (sortie==False): | ||
12 | - err_dht22, tmp, hum, seuil, data = get_data0(pin_data_bcm,debug_level) | ||
13 | - if ((err_dht22==0) or (k>20)): | ||
14 | - sortie=True | ||
15 | - else: | ||
16 | - sleep(0.1) | ||
17 | - k+=1 | ||
18 | - else: | ||
19 | - # --- method lib python+C | ||
20 | - import Adafruit_DHT | ||
21 | - sensorDHT = Adafruit_DHT.DHT22 | ||
22 | - hum, tmp = Adafruit_DHT.read_retry(sensorDHT, pin_data_bcm) | ||
23 | - err_dht22 = 0 | ||
24 | - seuil = 0 | ||
25 | - data = "" | ||
26 | - if (hum==None) or (tmp==None): | ||
27 | - err_dht22 = 1 | ||
28 | - hum = 0 | ||
29 | - tmp = 0 | ||
30 | - elif (hum>100): | ||
31 | - err_dht22 = 2 | ||
32 | - hum = 0 | ||
33 | - tmp = 0 | ||
34 | - return err_dht22, tmp, hum, seuil, data | ||
35 | - | ||
36 | -def get_data0(pin_data_bcm=13, debug_level=0): | ||
37 | - """Lecture d'une trame du capteur meteo DHT22. | ||
38 | -Retourne un tuple, dans l'ordre: Un code de validitรฉ, la tempรฉrature en ยฐC, le % d'humiditรฉ, le seuil de binarisation, les bits de la trame lue. Le code de validitรฉ =0 si la trame est valide, =1 si le checksum est mauvais, =2 si le nombre de bits lu n'est pas รฉgal ร 40. | ||
39 | -valide = 3 si la liste est vide | ||
40 | -Exemple: | ||
41 | - | ||
42 | -import driver_dht22 ; driver_dht22.get_data(13,2) | ||
43 | -""" | ||
44 | - listetrame = [] #trame รฉchantillonnรฉe | ||
45 | - data = [] #trame du capteur | ||
46 | - tableN = [] #liste des nombres de 1 | ||
47 | - | ||
48 | - io.setwarnings(False) | ||
49 | - io.setmode(io.BCM) | ||
50 | - | ||
51 | - # --- Pin GPIOxx for DHT data in mode OUT | ||
52 | - io.setup(pin_data_bcm,io.OUT) | ||
53 | - # --- Send HIGH->LOW(1ms)->HIGH to start an acquisition | ||
54 | - io.output(pin_data_bcm,io.HIGH) | ||
55 | - io.output(pin_data_bcm,io.LOW) | ||
56 | - sleep(0.001) | ||
57 | - io.output(pin_data_bcm,io.HIGH) | ||
58 | - | ||
59 | - # --- Pin GPIOxx for DHT data in mode IN | ||
60 | - io.setup(pin_data_bcm,io.IN) | ||
61 | - # --- Read continuously the GPIxx pin during few ms | ||
62 | - for k in range (0,2500): | ||
63 | - listetrame.append(io.input(pin_data_bcm)) #rรฉcupรฉration de la trame surรฉchantillonnรฉe | ||
64 | - if (debug_level==3): | ||
65 | - print("=== Raw data ===") | ||
66 | - print(listetrame) | ||
67 | - | ||
68 | - if (debug_level==2): | ||
69 | - print("=== Data -> 40 bits ===") | ||
70 | - cpt1=0 #compteur des 1 | ||
71 | - nb=1 #nombre du bit | ||
72 | - t = len(listetrame) | ||
73 | - for k in range(0,t-1) : #compte le nombre de 1 par bit | ||
74 | - a = listetrame[k] | ||
75 | - b = listetrame[k+1] | ||
76 | - if (b==1) : | ||
77 | - cpt1 = cpt1 + 1 | ||
78 | - if ((b-a) ==-1) : | ||
79 | - tableN.append(cpt1) #enregistrer le nombre de 1 dans tableN | ||
80 | - if (debug_level==2): | ||
81 | - print ("bit=",nb," len=",cpt1) | ||
82 | - if (nb%8==0): | ||
83 | - print() | ||
84 | - nb=nb+1 | ||
85 | - cpt1=0 | ||
86 | - | ||
87 | - try: | ||
88 | - | ||
89 | - seuil = (max(tableN)+min(tableN))/2 | ||
90 | - except ValueError : | ||
91 | - valide = 3 | ||
92 | - seuil = 0 | ||
93 | - return valide, 0, 0, 0 ,data | ||
94 | - if (debug_level==2): | ||
95 | - print("=== Threshold to binarize ===") | ||
96 | - print ("seuil=",seuil) | ||
97 | - | ||
98 | - # --- autocorrection of the first bit | ||
99 | - lent=len(tableN) | ||
100 | - #print("lent A=",lent) | ||
101 | - if (lent==41): | ||
102 | - tableN = tableN[1:lent:1] | ||
103 | - if (lent==39): | ||
104 | - tableN.insert(0,0) | ||
105 | - #print("tableN=",tableN) | ||
106 | - lent=len(tableN) | ||
107 | - #print("lent B=",lent) | ||
108 | - | ||
109 | - valide=0 | ||
110 | - tmp=0 | ||
111 | - hum=0 | ||
112 | - for elem in tableN: | ||
113 | - if elem > seuil: | ||
114 | - d=1 | ||
115 | - else: | ||
116 | - d=0 | ||
117 | - data.append(d) #on remplit data avec ses vraies valeurs binaires | ||
118 | - | ||
119 | - if lent != 40: | ||
120 | - valide=2 | ||
121 | - return valide, 0, 0, lent,data | ||
122 | - | ||
123 | - if (debug_level==2): | ||
124 | - print("=== 40 Bits -> 16_hum 16_temp 8_chksum ===") | ||
125 | - k=1 | ||
126 | - bi_hum="0b" | ||
127 | - bi_tmp="0b" | ||
128 | - bi="0b" | ||
129 | - sg_tmp=1 | ||
130 | - chk=0; #check somme | ||
131 | - for elem in tableN: | ||
132 | - if elem > seuil: | ||
133 | - d=1 | ||
134 | - else: | ||
135 | - d=0 | ||
136 | - if (k>=1 and k<=16): | ||
137 | - bi_hum=bi_hum+str(d) #on assemble le mot binaire de l'humiditรฉ | ||
138 | - if (k==16): | ||
139 | - hum=int(bi_hum,2)/10; #convertion du nombre binaire en dรฉcimal | ||
140 | - if (debug_level==2): | ||
141 | - print ("Binary humidity = ",bi_hum) | ||
142 | - print ("Decimal humidity = ",hum) | ||
143 | - if (k==17 and d==1): | ||
144 | - sg_tmp=-1 | ||
145 | - if (k>=18 and k<=32): | ||
146 | - bi_tmp=bi_tmp+str(d) #on assemble le mot binaire de la tempรฉrature | ||
147 | - # print ("le binaire de la temp vaut :",bi_tmp," (",k,")") | ||
148 | - if (k==32): | ||
149 | - tmp=sg_tmp*int(bi_tmp,2)/10; #convertion du nombre binaire en dรฉcimal | ||
150 | - if (debug_level==2): | ||
151 | - print ("Binary temperature = ",bi_tmp) | ||
152 | - print ("Decimal temperature = ",tmp) | ||
153 | - | ||
154 | - #checksum | ||
155 | - if (k>=1 and k<=8): | ||
156 | - bi=bi+str(d) #premier octet | ||
157 | - # print ("le binaire vaut :",bi," (",k,")") | ||
158 | - if (k==8): | ||
159 | - chk+=int(bi,2) #conversion du premier octet en dรฉcimal et addition du premier octet | ||
160 | - bi="0b"; | ||
161 | - if (k>=9 and k<=16): | ||
162 | - bi=bi+str(d) #second octet | ||
163 | - # print ("le binaire vaut :",bi," (",k,")") | ||
164 | - if (k==16): | ||
165 | - chk+=int(bi,2) #ajout du second octet | ||
166 | - bi="0b"; | ||
167 | - if (k>=17 and k<=24): | ||
168 | - bi=bi+str(d) | ||
169 | - # print ("le binaire vaut :",bi," (",k,")") | ||
170 | - if (k==24): | ||
171 | - chk+=int(bi,2) | ||
172 | - bi="0b"; | ||
173 | - if (k>=25 and k<=32): | ||
174 | - bi=bi+str(d) | ||
175 | - # print ("le binaire vaut :",bi," (",k,")") | ||
176 | - if (k==32): | ||
177 | - chk+=int(bi,2) | ||
178 | - bi="0b"; | ||
179 | - if (k>=33 and k<=40): | ||
180 | - bi=bi+str(d) | ||
181 | - # print ("le binaire vaut :",bi," (",k,")") | ||
182 | - if (k==40): | ||
183 | - if (debug_level==2): | ||
184 | - print ("=== Checksum ===") | ||
185 | - print ("Binary checksum data = ",bin(chk)) | ||
186 | - print ("Decimal checksum data = ",chk) | ||
187 | - chk=chk%256 #modulo 256 | ||
188 | - if (debug_level==2): | ||
189 | - print ("Decimal checksum data modulo = ",chk) | ||
190 | - chksum=int(bi,2) | ||
191 | - if (debug_level==2): | ||
192 | - print ("Binary checksum frame modulo = ",bi) | ||
193 | - print ("Decimal checksum frame modulo = ",chksum) | ||
194 | - if (chksum==chk): | ||
195 | - valide=0 | ||
196 | - else: | ||
197 | - valide=1 | ||
198 | - | ||
199 | - k+=1 | ||
200 | - | ||
201 | - return valide, tmp, hum, seuil, data | ||
202 | - |
src/core/pyros_django/utils/plc/guitalens_observatory/driver_mife.py deleted
@@ -1,35 +0,0 @@ | @@ -1,35 +0,0 @@ | ||
1 | -# -*- coding: utf-8 -*- | ||
2 | -import RPi.GPIO as io | ||
3 | -import time | ||
4 | - | ||
5 | -def do_led_green(pin_cmd_led_bcm=18, onoff=1): | ||
6 | - """ | ||
7 | - | ||
8 | -Exemple: | ||
9 | - | ||
10 | -import driver_mife ; driver_mife.do_led_green(18,1) | ||
11 | -""" | ||
12 | - | ||
13 | - io.setwarnings(False) | ||
14 | - io.setmode(io.BCM) #set up GPIO using BCM numbering | ||
15 | - io.setup(pin_cmd_led_bcm,io.OUT) # make pin an output (=arduino 2 open) | ||
16 | - | ||
17 | - io.output(pin_cmd_led_bcm,onoff) | ||
18 | - return onoff | ||
19 | - | ||
20 | -def do_led_red(pin_cmd_led_bcm=17, onoff=1): | ||
21 | - """ | ||
22 | - | ||
23 | -Exemple: | ||
24 | - | ||
25 | -import driver_mife ; driver_mife.do_led_red(17,1) | ||
26 | -""" | ||
27 | - | ||
28 | - io.setwarnings(False) | ||
29 | - io.setmode(io.BCM) #set up GPIO using BCM numbering | ||
30 | - io.setup(pin_cmd_led_bcm,io.OUT) # make pin an output (=arduino 3 open) | ||
31 | - | ||
32 | - io.output(pin_cmd_led_bcm,onoff) | ||
33 | - return onoff | ||
34 | - | ||
35 | - |
src/core/pyros_django/utils/plc/guitalens_observatory/driver_mlx.py deleted
@@ -1,56 +0,0 @@ | @@ -1,56 +0,0 @@ | ||
1 | -# -*-coding: utf-8 -*- | ||
2 | - | ||
3 | -#import smbus | ||
4 | -import time | ||
5 | -import math | ||
6 | -import subprocess | ||
7 | -#subprocess.check_output(['i2cget', 'y 1 0x5a 0x06']) | ||
8 | - | ||
9 | -def get_data(debug_level=0): | ||
10 | - """Lecture d'une trame du capteur MLX90614 | ||
11 | -Retourne un tuple, dans l'ordre: Un code de validitรฉ, la tempรฉrature du ciel en ยฐC, la tempรฉrature du boitier en ยฐC, octet brut temperature du ciel,octet brut temperature du boitier | ||
12 | -Exemple: | ||
13 | - | ||
14 | -import driver_mlx ; driver_mlx.get_data(2) | ||
15 | -""" | ||
16 | - add_i2c=0x5a | ||
17 | - #bus = smbus.SMBus(1) | ||
18 | - err=0 | ||
19 | - k=0 | ||
20 | - sortie=False | ||
21 | - while (sortie==False): | ||
22 | - err=0 | ||
23 | - try : | ||
24 | - #raw_data_ciel = bus.read_word_data(add_i2c,0x07) | ||
25 | - #raw_data_boit = bus.read_word_data(add_i2c,0x06) | ||
26 | - str_data_ciel = subprocess.check_output(['i2cget', '-y','1',str(add_i2c),'0x07','w']) | ||
27 | - str_data_boit = subprocess.check_output(['i2cget', '-y','1',str(add_i2c),'0x06','w']) | ||
28 | - raw_data_ciel = int(str_data_ciel[0:6],16) | ||
29 | - raw_data_boit = int(str_data_boit[0:6],16) | ||
30 | - #except IOError: | ||
31 | - except: | ||
32 | - err=1 | ||
33 | - raw_data_ciel=0 | ||
34 | - raw_data_boit=0 | ||
35 | - if ((err==0) or (k>5)): | ||
36 | - sortie=True | ||
37 | - else: | ||
38 | - time.sleep(0.1) | ||
39 | - k+=1 | ||
40 | - tmp_ciel = raw_data_ciel*0.02-273.15 | ||
41 | - tmp_boit = raw_data_boit*0.02-273.15 | ||
42 | - | ||
43 | - if (debug_level==2): | ||
44 | - print (" la valeur binaire de tempรฉrature ciel vaut : {}".format(raw_data_ciel)) | ||
45 | - print (" la valeur binaire de tempรฉrature boitier vaut : {}".format(raw_data_boit)) | ||
46 | - if (debug_level==1): | ||
47 | - print ("la tempรฉrature de l'objet vaut : {}".format(tmp_ciel)); | ||
48 | - print ("\n") | ||
49 | - print ("la tempรฉrature du boitier vaut : {}".format(tmp_boit)); | ||
50 | - if tmp_ciel < -16: | ||
51 | - print ("Le ciel est clair") | ||
52 | - else: | ||
53 | - print ("le ciel est nuageux") | ||
54 | - | ||
55 | - return err,tmp_ciel,tmp_boit,raw_data_ciel,raw_data_boit | ||
56 | - |
src/core/pyros_django/utils/plc/guitalens_observatory/driver_rg11.py deleted
@@ -1,67 +0,0 @@ | @@ -1,67 +0,0 @@ | ||
1 | -# -*- coding: utf-8 -*- | ||
2 | -import RPi.GPIO as io | ||
3 | - | ||
4 | -def get_data(pin_rain_bcm=19, pin_dry_bcm=20, pin_vin_bcm=25, debug_level=0): | ||
5 | - """Lecture d'une trame du capteur meteo RG11. | ||
6 | -Retourne un tuple, dans l'ordre: Un code de validitรฉ, etat (-1=unknown, 0=dry 1=rain), bit rain, bit dry. Le code de validitรฉ =0 si la trame est valide, =1 si Vin n'est pas detecte, =2 si les bits sont tous deux egaux a 0, =2 si les bits sont tous deux egaux ร 1. | ||
7 | - | ||
8 | -Exemple: | ||
9 | - | ||
10 | -import driver_rg11 ; driver_rg11.get_data(19,20,25,2) | ||
11 | -""" | ||
12 | - | ||
13 | - # === verify 12V power supply if it is possible | ||
14 | - power_mife = 1 | ||
15 | - if (pin_vin_bcm>0): | ||
16 | - io.setmode(io.BCM) #set up GPIO using BCM numbering | ||
17 | - io.setup(pin_vin_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 35->34 SWO_T60 = Vin) | ||
18 | - pin34 = io.input(pin_vin_bcm) | ||
19 | - power_mife = 1-pin34 | ||
20 | - if (debug_level==2): | ||
21 | - print("=== Voltage intput ===") | ||
22 | - disp ="pin34,35,gpio25,Vin="+str(pin34)+ " (0=12V 1=0V)" | ||
23 | - print(disp) | ||
24 | - err = 0 | ||
25 | - if ( power_mife==1 ): | ||
26 | - power_mife_msg = "12Volts" | ||
27 | - power_mife = 1 | ||
28 | - else: | ||
29 | - power_mife_msg = "0Volt" | ||
30 | - power_mife = 0 | ||
31 | - err = err +1 | ||
32 | - | ||
33 | - io.setwarnings(False) | ||
34 | - io.setmode(io.BCM) #set up GPIO using BCM numbering | ||
35 | - io.setup(pin_rain_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 46->36 rain) | ||
36 | - io.setup(pin_dry_bcm,io.IN, pull_up_down=io.PUD_DOWN) # make pin an input (=arduino 47->38 dry) | ||
37 | - | ||
38 | - pin36 = io.input(pin_rain_bcm) | ||
39 | - pin38 = io.input(pin_dry_bcm) | ||
40 | - if (debug_level==2): | ||
41 | - print("=== Bit states ===") | ||
42 | - disp ="pin36,46,gpio19,rain ="+str(pin36)+" pin38,47,gpio20,dry ="+str(pin38) | ||
43 | - print(disp) | ||
44 | - | ||
45 | - # === return | ||
46 | - err = 0 | ||
47 | - rain_state_msg = "Unknown" | ||
48 | - rain_state = 2 | ||
49 | - if (power_mife==1): | ||
50 | - if ( (pin36==0) and (pin38==0) ): | ||
51 | - err = err + 2 | ||
52 | - elif ( (pin36==1) and (pin38==1) ): | ||
53 | - err = err + 4 | ||
54 | - elif ( (pin36==0) and (pin38==1) ): | ||
55 | - rain_state_msg = "Rain" | ||
56 | - rain_state = 1 | ||
57 | - elif ( (pin36==1) and (pin38==0) ): | ||
58 | - rain_state_msg = "Dry" | ||
59 | - rain_state = 0 | ||
60 | - | ||
61 | - if (debug_level>=1): | ||
62 | - print("=== RG11 states ===") | ||
63 | - disp = " Vin ="+power_mife_msg + " RG11 ="+rain_state_msg | ||
64 | - print(disp) | ||
65 | - | ||
66 | - return err, power_mife, rain_state, rain_state, power_mife_msg, rain_state_msg, pin34, pin36, pin38 | ||
67 | - |
src/core/pyros_django/utils/plc/guitalens_observatory/maintenance_guide.odp deleted
No preview for this file type
src/core/pyros_django/utils/plc/guitalens_observatory/run_goc.py deleted
@@ -1,354 +0,0 @@ | @@ -1,354 +0,0 @@ | ||
1 | -# -*- coding: utf-8 -*- | ||
2 | -import time | ||
3 | -import socket | ||
4 | -import struct | ||
5 | -import sys | ||
6 | -import os | ||
7 | - | ||
8 | -# --- Interaction with Raspberry GPIO | ||
9 | -import fcntl | ||
10 | -import driver_rg11 | ||
11 | -import driver_cv7 | ||
12 | -import driver_dht22 | ||
13 | -import driver_mlx | ||
14 | -import driver_came | ||
15 | -import driver_mife | ||
16 | - | ||
17 | -# --- update the path of Python for util modules | ||
18 | -py_path = os.sys.path | ||
19 | -py_pwd = os.getcwd() | ||
20 | -py_pwd = os.getcwd() + "/../.." | ||
21 | -if (py_pwd not in py_path): | ||
22 | - (os.sys.path).append(py_pwd) | ||
23 | -import guitastro | ||
24 | -import report | ||
25 | - | ||
26 | -# === Some debug states | ||
27 | -roof_action = True | ||
28 | -delay_roof_sec = 20 | ||
29 | -oled_action = True | ||
30 | - | ||
31 | -# === Init OLED | ||
32 | -if (oled_action == True): | ||
33 | - import Adafruit_SSD1306 | ||
34 | - from PIL import Image | ||
35 | - from PIL import ImageDraw | ||
36 | - from PIL import ImageFont | ||
37 | - # Raspberry Pi pin configuration: | ||
38 | - RST = 24 | ||
39 | - # 128x64 display with hardware I2C: | ||
40 | - disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST) | ||
41 | - # Initialize library. | ||
42 | - disp.begin() | ||
43 | - # Clear display. | ||
44 | - disp.clear() | ||
45 | - disp.display() | ||
46 | - # Create blank image for drawing. | ||
47 | - # Make sure to create image with mode '1' for 1-bit color. | ||
48 | - width = disp.width | ||
49 | - height = disp.height | ||
50 | - panel1 = Image.new('1', (width, height)) | ||
51 | - panel2 = Image.new('1', (width, height)) | ||
52 | - #logo = Image.open("logo1.ppm").convert('1').resize((128,32),3) | ||
53 | - #crรฉation d'un objet font | ||
54 | - fontpath = "/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf" | ||
55 | - font1 = ImageFont.truetype(fontpath,10) | ||
56 | - # Get drawing object to draw on image. | ||
57 | - draw1 = ImageDraw.Draw(panel1) | ||
58 | - draw2 = ImageDraw.Draw(panel2) | ||
59 | - # Draw a black filled box to clear the image. | ||
60 | - draw1.rectangle((0,0,width,height), outline=0, fill=0) | ||
61 | - #disp.image(logo) | ||
62 | - #disp.display() | ||
63 | - | ||
64 | -# ======================================= | ||
65 | -def valid_yesno (err_int): | ||
66 | - if err_int==0: | ||
67 | - return "yes" | ||
68 | - else: | ||
69 | - return "no" | ||
70 | - | ||
71 | -# ======================================= | ||
72 | -def compute_error_code (err_int): | ||
73 | - if err_int==0: | ||
74 | - return "0" | ||
75 | - else: | ||
76 | - return "1" | ||
77 | - | ||
78 | -# ======================================= | ||
79 | -def get_ip_address(ifname): | ||
80 | - """Lecture de l'adresse IP du Raspberry. | ||
81 | -Exemple: | ||
82 | - | ||
83 | -get_ip_address('eth0') | ||
84 | -""" | ||
85 | - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
86 | - return socket.inet_ntoa(fcntl.ioctl( | ||
87 | - s.fileno(), | ||
88 | - 0x8915, | ||
89 | - struct.pack('256s', ifname[:15]) | ||
90 | - )[20:24]) | ||
91 | - | ||
92 | -# ======================================= | ||
93 | -def get_sunelev(): | ||
94 | - date = guitastro.Date("now") | ||
95 | - site = guitastro.Site("GPS 2 E 43 148") | ||
96 | - skyobj= {'planet':'Sun'} | ||
97 | - outputs = ['elev'] | ||
98 | - target = guitastro.Target() | ||
99 | - target.define(skyobj) | ||
100 | - output0s = ['ra','dec'] | ||
101 | - results = target.ephem(date,site,output0s) | ||
102 | - ra = results['RA'] | ||
103 | - dec = results['DEC'] | ||
104 | - skyobj= {'RA':ra , 'DEC':dec } | ||
105 | - target.define(skyobj) | ||
106 | - results = target.ephem(date,site,outputs) | ||
107 | - elev = results['ELEV'] | ||
108 | - return elev | ||
109 | - | ||
110 | -# === print the current Python version | ||
111 | -try: | ||
112 | - print (sys.version) | ||
113 | -except: | ||
114 | - pass | ||
115 | - | ||
116 | -# === print the IP address | ||
117 | -try: | ||
118 | - print("IP = ",get_ip_address('eth0')) | ||
119 | -except: | ||
120 | - pass | ||
121 | - | ||
122 | -# === Configuration of security | ||
123 | -delay_to_open_limit = 900 | ||
124 | -wind_speed_ms_limit = 5/3.6 | ||
125 | -tmp_cielcor_lim = -5 | ||
126 | - | ||
127 | -# === Main loop | ||
128 | -greenled_state = 0 | ||
129 | -t0 = time.time() | ||
130 | -t0closing = time.time() - delay_to_open_limit | ||
131 | -delay_to_open = 0 | ||
132 | -t0file = 0 | ||
133 | -t0wind = 0 | ||
134 | -while True: | ||
135 | - | ||
136 | - # === Blink the green led | ||
137 | - if greenled_state == 0: | ||
138 | - driver_mife.do_led_green(18,1) | ||
139 | - greenled_state = 1 | ||
140 | - else: | ||
141 | - driver_mife.do_led_green(18,0) | ||
142 | - greenled_state = 0 | ||
143 | - | ||
144 | - # === Clear the OLED displays | ||
145 | - try: | ||
146 | - draw1.rectangle((0,0,width,height), outline=0, fill=0) | ||
147 | - draw2.rectangle((0,0,width,height), outline=0, fill=0) | ||
148 | - except: | ||
149 | - pass | ||
150 | - | ||
151 | - # === Get Sun elevation | ||
152 | - sunelev = get_sunelev(); | ||
153 | - | ||
154 | - # === Init the error supercode | ||
155 | - err = 0 | ||
156 | - | ||
157 | - # === Get RG11 data | ||
158 | - err_rg11, power_mife_rg11, rain_state, rain_state, power_mife_msg, rain_state_msg, pin34, pin36, pin38 = driver_rg11.get_data(19,20,25,0) | ||
159 | - oled_rain = "RG11 : " | ||
160 | - if (err_rg11>0): | ||
161 | - print("RG11 err=",err_rg11) | ||
162 | - err+=1 | ||
163 | - oled_rain += "Err"+str(err_rg11) | ||
164 | - else: | ||
165 | - oled_rain += rain_state_msg | ||
166 | - | ||
167 | - # === Get CV7 data | ||
168 | - err_cv7, power_mife_cv7, wind_dir_deg, wind_speed_ms, wind_tmp_degC, power_mife_msg, msg_wind, msg_temp = driver_cv7.get_data("/dev/ttyS0", 25,0) | ||
169 | - oled_wind_speed = "Wind : " | ||
170 | - oled_wind_dir = "Wind dir : " | ||
171 | - if (err_cv7>0): | ||
172 | - print("CV7 err=",err_cv7) | ||
173 | - err+=2 | ||
174 | - oled_wind_speed += "Err"+str(err_cv7) | ||
175 | - oled_wind_dir += "Err"+str(err_cv7) | ||
176 | - else: | ||
177 | - oled_wind_speed += '{:.2f}'.format(wind_speed_ms)+" m/s" | ||
178 | - oled_wind_dir += '{:3.0f}'.format(wind_dir_deg)+ " deg" | ||
179 | - | ||
180 | - # === Get DHT22 data | ||
181 | - err_dht22, tmp, hum, seuil, data = driver_dht22.get_data(13,0) | ||
182 | - oled_tmp = "Temp : " | ||
183 | - oled_hum = "Humidity : " | ||
184 | - if (err_dht22>0): | ||
185 | - print("DHT22 err=",err_dht22) | ||
186 | - err+=4 | ||
187 | - oled_tmp += "Err"+str(err_dht22) | ||
188 | - oled_hum += "Err"+str(err_dht22) | ||
189 | - else: | ||
190 | - oled_tmp += "{:.1f}".format(tmp) + " degC" | ||
191 | - oled_hum += "{:.0f}".format(hum) + " %" | ||
192 | - | ||
193 | - # === Get MLX data | ||
194 | - err_mlx, tmp_ciel, tmp_boit, raw_data_ciel, raw_data_boit =driver_mlx.get_data(0) | ||
195 | - tmp_cielcor = tmp_ciel - tmp_boit * 0.7; | ||
196 | - oled_skytmp = "Sky temp : " | ||
197 | - if (err_mlx>0): | ||
198 | - print("mlx err =",err_mlx) | ||
199 | - err+=8 | ||
200 | - oled_skytmp += "Err"+str(err_mlx) | ||
201 | - else: | ||
202 | - oled_skytmp += "{:.2f}".format(tmp_ciel)+" degC" | ||
203 | - | ||
204 | - # === Get Came data | ||
205 | - err_came, power_came, mode_came, roof_state, power_came_msg, mode_came_msg, roof_state_msg, pin48, pin39, pin41,pin31 = driver_came.get_data(26,22,5,6,1) | ||
206 | - oled_came1 = "Roof mode : " | ||
207 | - oled_came2 = "Roof state : " | ||
208 | - if (err_came>0): | ||
209 | - oled_came1 += "Err"+str(err_mlx) | ||
210 | - oled_came2 += "Err"+str(err_mlx) | ||
211 | - else: | ||
212 | - oled_came1 += mode_came_msg | ||
213 | - oled_came2 += roof_state_msg | ||
214 | - | ||
215 | - # === Compute the meteo conditions | ||
216 | - meteo_conditions = 0 | ||
217 | - if (err_mlx==0): | ||
218 | - if (tmp_cielcor > tmp_cielcor_lim): | ||
219 | - meteo_conditions = meteo_conditions +1 | ||
220 | - if (err_rg11==0) and (rain_state==1): | ||
221 | - meteo_conditions = meteo_conditions +2 | ||
222 | - if (err_cv7==0) and (wind_speed_ms>wind_speed_ms_limit): | ||
223 | - meteo_conditions = meteo_conditions +4 | ||
224 | - if (err_rg11==1): | ||
225 | - # --- critical error | ||
226 | - meteo_conditions = meteo_conditions +8 | ||
227 | - | ||
228 | - # === Json status | ||
229 | - date = guitastro.Date("now") | ||
230 | - date_iso_utc = date.iso(); | ||
231 | - rep = report.Status_json() | ||
232 | - rep.new_status("PLC","20181014_0854") | ||
233 | - rep.append_entity("PLC_STATUS", "Raspberry", "20181014_0854", "Guitalens Observatory",date_iso_utc) | ||
234 | - # --- Json device Came | ||
235 | - rep.append_device("Came", "roof_controler", "S/N_A5EM", compute_error_code(err_came)) | ||
236 | - rep.append_value( "Error_code", "int",str(err_came),"","","0=OK 1=PowerPB 2=SwitchPB") | ||
237 | - rep.append_value( "Power_input", "int",str(power_came),"","","0=0Volt 1=24Volts") | ||
238 | - rep.append_value( "Mode_came", "int",str(mode_came),"","","0=Manual 1=Auto") | ||
239 | - rep.append_value( "Roof_state", "int",str(roof_state),"","","0=Closed 1=Opened 2=Intermediate") | ||
240 | - rep.append_value( "Meteo_conditions", "int",str(meteo_conditions),"","","0=OK +1=Clouds +2=Rain +4=Wind +8=CriticalError") | ||
241 | - rep.append_value( "Delay_to_open", "int","{:.0f}".format(delay_to_open),"s","","Current delay to open since the meteo became OK") | ||
242 | - rep.append_value( "Security_delay_to_open", "int","{:.0f}".format(delay_to_open_limit),"s","","Limit delay to open since the meteo becomes OK") | ||
243 | - rep.append_value( "SkyTemperatureCor_lim", "float","{:+.2f}".format(tmp_cielcor_lim),"degC","","Limit of the corrected temperature of the sky to close roof") | ||
244 | - rep.append_value( "Wind_speed_lim", "float","{:.2f}".format(wind_speed_ms_limit),"m/s","","Limit of wind speed to close the roof") | ||
245 | - rep.append_value( "Sun_elevation", "float","{:+.3f}".format(sunelev),"deg","","Local elevation of the Sun") | ||
246 | - # --- Json device CV7 | ||
247 | - rep.append_device("CV7", "weather_station", "S/N_09172419", compute_error_code(err_cv7)) | ||
248 | - rep.append_value( "Error_code", "int",str(err_cv7),"","","0=OK 1=SerialPB 2=FramePB") | ||
249 | - rep.append_value( "Power_input", "int",str(power_mife_cv7),"","","0=0Volt 1=12Volts (Power from MiFe board)") | ||
250 | - rep.append_value( "Wind_dir", "float","{:.2f}".format(wind_dir_deg),"degrees","Wind_direction","0=North 90=East") | ||
251 | - rep.append_value( "Wind_speed", "float","{:.2f}".format(wind_speed_ms),"m/s","Wind_speed","Wind speed from ultrasonic sensors") | ||
252 | - rep.append_value( "OutsideTemperature", "float","{:+.2f}".format(wind_tmp_degC),"degC","Temperature_outside","Temperature of the anemometer") | ||
253 | - # --- Json device DHT22 | ||
254 | - rep.append_device("DHT22", "weather_station", "MiFe_DHT1_1", compute_error_code(err_dht22)) | ||
255 | - rep.append_value( "Error_code", "int",str(err_dht22),"","","0=OK 1=CheksumPB 2=LengthPB 3=NodataPB") | ||
256 | - rep.append_value( "Temperature", "float","{:+.0f}".format(tmp),"degC","Temperature_outside","Temperature inside PLC box") | ||
257 | - rep.append_value( "Humidity", "float","{:.0f}".format(hum),"percent","Humidity_outside","Humidity inside PLC box") | ||
258 | - # --- device RG11 | ||
259 | - rep.append_device("RG11", "weather_station", "S/N_207588", compute_error_code(err_rg11)) | ||
260 | - rep.append_value( "Error_code", "int",str(err_rg11),"","","0=OK +1=PowerPB +2=NopowerPB +4=AllonePB") | ||
261 | - rep.append_value( "RainSate", "int",str(rain_state),"","Rain_boolean","0=Dry 1=Rain 2=Unknown") | ||
262 | - # --- device MLX90614 | ||
263 | - rep.append_device("MLX90614", "weather_station", "1", compute_error_code(err_mlx)) | ||
264 | - rep.append_value( "Error_code", "int",str(err_mlx),"","","0=OK 1=DataPB") | ||
265 | - rep.append_value( "SkyTemperature", "float","{:+5.2f}".format(tmp_ciel),"degC","","Temperature of the sky") | ||
266 | - rep.append_value( "CanTemperature", "float","{:+5.2f}".format(tmp_boit),"degC","","Temperature of the TO can") | ||
267 | - rep.append_value( "SkyTemperatureCor", "float","{:+5.2f}".format(tmp_cielcor),"degC","Temperature_sky","Corrected temperature of the sky") | ||
268 | - # --- save the Json status report | ||
269 | - rep.save_json("/var/www/html/meteo/plc_guitalens.json") | ||
270 | - | ||
271 | - # === String of results | ||
272 | - date_jd_utc = date.jd(); | ||
273 | - date_digits_utc = date.digits(0) | ||
274 | - msg_gene = "{:13.5f} {} {:+6.2f} {:2d} {:1d} ".format(date_jd_utc, date_digits_utc, sunelev,err,meteo_conditions) | ||
275 | - msg_came = "{:2d} {:1d} {:1d} {:1d} ".format(err_came, power_came, mode_came, roof_state) | ||
276 | - msg_mlx = "{:2d} {:+6.2f} {:+6.2f} {:+6.2f} ".format(err_mlx, tmp_ciel, tmp_boit, tmp_cielcor) | ||
277 | - msg_rg11 = "{:2d} {:1d} {:1d} ".format(err_rg11, power_mife_rg11, rain_state) | ||
278 | - msg_dht22 = "{:2d} {:+3.0f} {:3.0f} ".format(err_dht22, tmp, hum) | ||
279 | - msg_cv7 = "{:2d} {:1d} {:3.0f} {:6.2f} {:+3.0f} ".format(err_cv7, power_mife_cv7, wind_dir_deg, wind_speed_ms, wind_tmp_degC) | ||
280 | - msg = msg_gene + msg_came + msg_mlx + msg_rg11 + msg_dht22 + msg_cv7 | ||
281 | - print(msg) | ||
282 | - | ||
283 | - # === File for web site | ||
284 | - try: | ||
285 | - dt = time.time()-t0file; | ||
286 | - if (dt>30): | ||
287 | - dateymdhms= date.ymdhms() | ||
288 | - fic = "/var/www/html/meteo/meteo_{:04d}{:02d}{:02d}.txt".format(dateymdhms[0],dateymdhms[1],dateymdhms[2]) | ||
289 | - fichier = open(fic,"a") | ||
290 | - fichier.write(msg) | ||
291 | - fichier.write("\n") | ||
292 | - fichier.close() | ||
293 | - t0file = time.time() | ||
294 | - except: | ||
295 | - pass | ||
296 | - | ||
297 | - # === Display OLED | ||
298 | - try: | ||
299 | - dt = time.time()-t0; | ||
300 | - if (dt<6): | ||
301 | - draw1.text((0, 10),oled_came1, font=font1, fill=255) | ||
302 | - draw1.text((0, 20),oled_skytmp, font=font1, fill=255) | ||
303 | - draw1.text((0, 30),oled_tmp, font=font1, fill=255) | ||
304 | - draw1.text((0, 40),oled_hum, font=font1, fill=255) | ||
305 | - disp.image(panel1) | ||
306 | - elif (dt<12): | ||
307 | - draw2.text((0, 10),oled_came2, font=font1, fill=255) | ||
308 | - draw2.text((0, 20),oled_wind_speed, font=font1, fill=255) | ||
309 | - draw2.text((0, 30),oled_wind_dir, font=font1, fill=255) | ||
310 | - draw2.text((0, 40),oled_rain, font=font1, fill=255) | ||
311 | - disp.image(panel2) | ||
312 | - else: | ||
313 | - t0 = time.time() | ||
314 | - disp.display() | ||
315 | - except: | ||
316 | - pass | ||
317 | - | ||
318 | - # === Roof action according security rules | ||
319 | - delay_to_open = 0 | ||
320 | - if (mode_came_msg=="Auto") and (err_came==0): | ||
321 | - delay_to_open = time.time()-t0closing; | ||
322 | - if (sunelev>0): | ||
323 | - # --- Il fait jour | ||
324 | - if (roof_state_msg != 'Closed'): | ||
325 | - print("==> Il fait jour et le toit n'est pas ferme. On ferme.") | ||
326 | - if roof_action == True: | ||
327 | - driver_came.do_close_roof(23) | ||
328 | - time.sleep(delay_roof_sec) | ||
329 | - if (meteo_conditions>0): | ||
330 | - t0closing = time.time() | ||
331 | - else: | ||
332 | - # --- Il fait nuit mais pas beau | ||
333 | - if (meteo_conditions>0): | ||
334 | - # --- Il ne fait pas beau | ||
335 | - if (roof_state_msg != 'Closed'): | ||
336 | - print("==> Il fait nuit, il ne fait pas beau {} et le toit n'est pas ferme. On ferme.".format(meteo_conditions)) | ||
337 | - if roof_action == True: | ||
338 | - driver_came.do_close_roof(23) | ||
339 | - time.sleep(delay_roof_sec) | ||
340 | - t0closing = time.time() | ||
341 | - else: | ||
342 | - # --- Il fait nuit et il fait beau | ||
343 | - if (roof_state_msg != 'Opened'): | ||
344 | - if (delay_to_open>delay_to_open_limit): | ||
345 | - # --- Cela fait + de 600s que le toit avait ete prealablement ferme | ||
346 | - print("==> Il fait nuit, il fait beau {} depuis +{}s et le toit n'est pas ouvert. On ouvre.".format(meteo_conditions,delay_to_open_limit)) | ||
347 | - if roof_action == True: | ||
348 | - driver_came.do_open_roof(27) | ||
349 | - time.sleep(delay_roof_sec) | ||
350 | - else: | ||
351 | - print("==> Il fait nuit, il fait beau {} mais -{}s ({:.0f}) depuis la precedente fermeture.".format(meteo_conditions,delay_to_open_limit,delay_to_open)) | ||
352 | - | ||
353 | - # === Wait 1 seconds before the next read | ||
354 | - time.sleep(1) |
src/core/pyros_django/utils/report/COPYING deleted
@@ -1,18 +0,0 @@ | @@ -1,18 +0,0 @@ | ||
1 | -This file is part of the Report project | ||
2 | -Copyright (C) 2018-2018 The Report Core Team | ||
3 | - | ||
4 | -Initial author : Alain KLOTZ <alain.klotz@free.fr> | ||
5 | - | ||
6 | -This program is free software; you can redistribute it and/or modify | ||
7 | -it under the terms of the GNU General Public License as published by | ||
8 | -the Free Software Foundation; either version 2 of the License, or (at | ||
9 | -your option) any later version. | ||
10 | - | ||
11 | -This program is distributed in the hope that it will be useful, but | ||
12 | -WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | -General Public License for more details. | ||
15 | - | ||
16 | -You should have received a copy of the GNU General Public License | ||
17 | -along with this program; if not, write to the Free Software | ||
18 | -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
src/core/pyros_django/utils/report/PKG-INFO deleted
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -Metadata-Version: 1.0 | ||
2 | -Name: report | ||
3 | -Version: 0.1 | ||
4 | -Summary: Python for astronomy and robotic observatories | ||
5 | -Home-page: | ||
6 | -Author: Alain Klotz | ||
7 | -Author-email: alain.klotz@free.fr | ||
8 | -License: GNU General Public License | ||
9 | -Description: Report | ||
10 | - Python Pixel & Cassoulet package is a set of algorithms to drive | ||
11 | - robotic astronomical observatories. | ||
12 | -Platform: UNKNOWN | ||
13 | -Classifier: Development Status :: Beta | ||
14 | -Classifier: License :: GNU General Public License | ||
15 | -Classifier: Operating System :: OS Independent | ||
16 | -Classifier: Programming Language :: Python | ||
17 | -Classifier: Topic :: Scientific/Engineering :: Astronomy |
src/core/pyros_django/utils/report/README deleted
@@ -1,17 +0,0 @@ | @@ -1,17 +0,0 @@ | ||
1 | -report | ||
2 | -=========== | ||
3 | - | ||
4 | -A python module for driving a robotic observatory | ||
5 | -Web Page: none | ||
6 | -License: GNU General Public License | ||
7 | - | ||
8 | -Installation | ||
9 | ------------- | ||
10 | - | ||
11 | -If you have numpy (http://numpy.scipy.org/) installed, just do | ||
12 | - | ||
13 | -python setup.py install | ||
14 | - | ||
15 | -On some linux distributions, this may need to be | ||
16 | - | ||
17 | -sudo python setup.py install |
src/core/pyros_django/utils/report/__init__.py deleted
src/core/pyros_django/utils/report/doc/user_guide_module_report.odt deleted
No preview for this file type
src/core/pyros_django/utils/report/setup.py deleted
@@ -1,26 +0,0 @@ | @@ -1,26 +0,0 @@ | ||
1 | -#!/usr/bin/env python | ||
2 | -# -*- coding: utf-8 -*- | ||
3 | - | ||
4 | -from distutils.core import setup | ||
5 | - | ||
6 | -long_desc = u"""Report | ||
7 | -Python Pixel & Cassoulet package is a set of algorithms to drive | ||
8 | -robotic astronomical observatories.""" | ||
9 | - | ||
10 | -setup(name='report', | ||
11 | - version='0.1', | ||
12 | - description='Python for astronomy and robotic observatories', | ||
13 | - long_description = long_desc, | ||
14 | - author='Alain Klotz', | ||
15 | - author_email='alain.klotz@free.fr', | ||
16 | - url='http://', | ||
17 | - license='GNU General Public License', | ||
18 | - packages=['report',], | ||
19 | - classifiers=[ | ||
20 | - 'Development Status :: Beta', | ||
21 | - 'License :: GNU General Public License', | ||
22 | - 'Operating System :: OS Independent', | ||
23 | - 'Programming Language :: Python', | ||
24 | - 'Topic :: Scientific/Engineering :: Astronomy' | ||
25 | - ] | ||
26 | - ) |
src/core/pyros_django/utils/report/status_json.py deleted
@@ -1,798 +0,0 @@ | @@ -1,798 +0,0 @@ | ||
1 | -#import math | ||
2 | -import doctest | ||
3 | -import json | ||
4 | -import os | ||
5 | -import sys | ||
6 | - | ||
7 | -# --- update the path of Python | ||
8 | -py_path = os.sys.path | ||
9 | -py_pwd = os.getcwd() | ||
10 | -if (py_pwd not in py_path): | ||
11 | - (os.sys.path).append(py_pwd) | ||
12 | -py_pwd = os.getcwd() + "/.." | ||
13 | -if (py_pwd not in py_path): | ||
14 | - (os.sys.path).append(py_pwd) | ||
15 | -py_pwd = os.getcwd() + "/../.." | ||
16 | -if (py_pwd not in py_path): | ||
17 | - (os.sys.path).append(py_pwd) | ||
18 | - | ||
19 | - | ||
20 | -#import utils.celme as celme | ||
21 | -#sys.path.append('..') | ||
22 | -import vendor.guitastro.src.guitastro as guitastro | ||
23 | - | ||
24 | -# ======================================================== | ||
25 | -# ======================================================== | ||
26 | -# === Status_json | ||
27 | -# ======================================================== | ||
28 | -# ======================================================== | ||
29 | - | ||
30 | -class Status_json: | ||
31 | - """ Class to manage Json file reports into python variables and vice versa | ||
32 | - | ||
33 | -Example a a very wimple Json file report contents: | ||
34 | -{ | ||
35 | - "frame_model": "1.3", | ||
36 | - "producer_name": "PLC", | ||
37 | - "producer_version": "20180909", | ||
38 | - "entities": [ | ||
39 | - { | ||
40 | - "entity_name": "PLC_STATUS", | ||
41 | - "origin": "Raspberry", | ||
42 | - "version_firmware": "20180924A", | ||
43 | - "site": "MyObservatory", | ||
44 | - "date": "2019-01-10T20:20:20.738", | ||
45 | - "devices": [ | ||
46 | - { | ||
47 | - "device_name": "DHT22", | ||
48 | - "device_type": "meteo", | ||
49 | - "serial_number": "1", | ||
50 | - "error_code": "0", | ||
51 | - "device_values": [ | ||
52 | - { | ||
53 | - "name": "OutsideTemperature", | ||
54 | - "data_type": "float", | ||
55 | - "value": "22", | ||
56 | - "unit": "degC", | ||
57 | - "monitoring_name": "Temperature_outside", | ||
58 | - "comment": "Temperature", | ||
59 | - "date_data": "2019-01-10T20:20:20.738" | ||
60 | - } | ||
61 | - ] | ||
62 | - } | ||
63 | - ] | ||
64 | - } | ||
65 | - ] | ||
66 | -} | ||
67 | - | ||
68 | -A value is stored in a UFKI (Unique Four Key Identifier): | ||
69 | -UFKI = entity_name device_name serial_number name | ||
70 | - | ||
71 | -No support for hjson. See the following link to do that: | ||
72 | -https://github.com/hjson/hjson-py | ||
73 | - | ||
74 | - | ||
75 | - Usage: | ||
76 | - ------ | ||
77 | - | ||
78 | - First, instanciate an object from the class: | ||
79 | - report = report.Status_json() | ||
80 | - | ||
81 | - Informations: | ||
82 | - ------------- | ||
83 | - | ||
84 | - help(Status_json) | ||
85 | - Status_json().infos("doctest") | ||
86 | - Status_json().infos("doc_methods") | ||
87 | - """ | ||
88 | -# ======================================================== | ||
89 | -# === attributes | ||
90 | -# ======================================================== | ||
91 | - | ||
92 | - # --- multiplicators for units | ||
93 | - _status = [] | ||
94 | - _entity_name = "" | ||
95 | - _device_name = "" | ||
96 | - _serial_number = "" | ||
97 | - | ||
98 | -# ======================================================== | ||
99 | -# === internal methods | ||
100 | -# ======================================================== | ||
101 | - | ||
102 | - def _init(self,status=""): | ||
103 | - """ Initialize internal attributes. | ||
104 | - | ||
105 | - Inputs: | ||
106 | - ------- | ||
107 | - status is a list of dictionnaries according a predefined format. | ||
108 | - | ||
109 | - Usage: | ||
110 | - ------ | ||
111 | - report = report.Status_json() | ||
112 | - """ | ||
113 | - self._status = status | ||
114 | - self._entity_name = "" | ||
115 | - self._device_name = "" | ||
116 | - self._serial_number = "" | ||
117 | - | ||
118 | - def _is_number(self,s): | ||
119 | - """ Return True if the string is a number else return False. | ||
120 | - | ||
121 | - Usage: | ||
122 | - ------ | ||
123 | - >>> report = report.Status_json() | ||
124 | - >>> report._is_number("3e5") | ||
125 | - True | ||
126 | - >>> report._is_number("3a5") | ||
127 | - False | ||
128 | - """ | ||
129 | - try: | ||
130 | - float(s) | ||
131 | - return True | ||
132 | - except ValueError: | ||
133 | - pass | ||
134 | - try: | ||
135 | - import unicodedata | ||
136 | - unicodedata.numeric(s) | ||
137 | - return True | ||
138 | - except (TypeError, ValueError): | ||
139 | - pass | ||
140 | - return False | ||
141 | - | ||
142 | - #################################################################### | ||
143 | - # To read a Status | ||
144 | - #################################################################### | ||
145 | - | ||
146 | - def _get_indice_from_entities(self, entities, entity_name): | ||
147 | - indice = 0 | ||
148 | - found = -1 | ||
149 | - for entity in entities: | ||
150 | - #print("{} et {}".format(entity,entity_name)) | ||
151 | - if entity == entity_name: | ||
152 | - found = indice | ||
153 | - break | ||
154 | - indice += 1 | ||
155 | - return found | ||
156 | - | ||
157 | - def _get_indice_from_devices(self, devices, device_name, serial_number): | ||
158 | - indice = 0 | ||
159 | - found = -1 | ||
160 | - for device in devices: | ||
161 | - cur_device_name = device['device_name'] | ||
162 | - cur_serial_number = device['serial_number'] | ||
163 | - #print("{} et {}".format(device,device_name)) | ||
164 | - if (cur_device_name == device_name) and ( cur_serial_number == serial_number): | ||
165 | - found = indice | ||
166 | - break | ||
167 | - indice += 1 | ||
168 | - return found | ||
169 | - | ||
170 | - def _get_entity_names(self): | ||
171 | - #entities = self._status['statuses'][0]['entities'] | ||
172 | - entities = self._status['entities'] | ||
173 | - entity_names = [] | ||
174 | - for entity in entities: | ||
175 | - entity_names.append(entity['entity_name']) | ||
176 | - return entity_names | ||
177 | - | ||
178 | - def _get_device_nameserials(self, entity_name): | ||
179 | - entities = self._get_entity_names() | ||
180 | - indice = self._get_indice_from_entities(entities,entity_name) | ||
181 | - if indice == -1: | ||
182 | - return "" | ||
183 | - #devices = self._status['statuses'][0]['entities'][indice]['devices'] | ||
184 | - devices = self._status['entities'][indice]['devices'] | ||
185 | - device_names = [] | ||
186 | - for device in devices: | ||
187 | - devs = {'device_name':device['device_name'], 'serial_number':device['serial_number']} | ||
188 | - #print("devs={} ".format(devs)) | ||
189 | - device_names.append(devs) | ||
190 | - return device_names | ||
191 | - | ||
192 | - def _get_value_names(self, entity_name, device_name, serial_number): | ||
193 | - entities = self._get_entity_names() | ||
194 | - indicee = self._get_indice_from_entities(entities,entity_name) | ||
195 | - if indicee == -1: | ||
196 | - return "" | ||
197 | - #devices = self._status['statuses'][0]['entities'][indicee]['devices'] | ||
198 | - devices = self._status['entities'][indicee]['devices'] | ||
199 | - indiced = self._get_indice_from_devices(devices, device_name, serial_number) | ||
200 | - device = devices[indiced] | ||
201 | - #print("device={} ".format(device)) | ||
202 | - values = device['device_values'] | ||
203 | - value_names = [] | ||
204 | - for value in values: | ||
205 | - #print("value={} ".format(value)) | ||
206 | - value_names.append(value['name']) | ||
207 | - return value_names | ||
208 | - | ||
209 | - def _get_value_name_values(self, entity_name, device_name, serial_number, value_name): | ||
210 | - entities = self._get_entity_names() | ||
211 | - indicee = self._get_indice_from_entities(entities,entity_name) | ||
212 | - if indicee == -1: | ||
213 | - return "" | ||
214 | - #devices = self._status['statuses'][0]['entities'][indicee]['devices'] | ||
215 | - devices = self._status['entities'][indicee]['devices'] | ||
216 | - indiced = self._get_indice_from_devices(devices, device_name, serial_number) | ||
217 | - device = devices[indiced] | ||
218 | - #print("device={} ".format(device)) | ||
219 | - values = device['device_values'] | ||
220 | - for value in values: | ||
221 | - if value_name == value['name']: | ||
222 | - return value | ||
223 | - return "" | ||
224 | - | ||
225 | - def _set_value_name_values(self, entity_name, device_name, serial_number, value_name, dico): | ||
226 | - entities = self._get_entity_names() | ||
227 | - indicee = self._get_indice_from_entities(entities,entity_name) | ||
228 | - if indicee == -1: | ||
229 | - return "" | ||
230 | - #devices = self._status['statuses'][0]['entities'][indicee]['devices'] | ||
231 | - devices = self._status['entities'][indicee]['devices'] | ||
232 | - indiced = self._get_indice_from_devices(devices, device_name, serial_number) | ||
233 | - device = devices[indiced] | ||
234 | - #print("device={} ".format(device)) | ||
235 | - values = device['device_values'] | ||
236 | - indicev = 0 | ||
237 | - for value in values: | ||
238 | - if value_name == value['name']: | ||
239 | - #self._status['statuses'][0]['entities'][indicee]['devices'][indiced]['device_values'][indicev] = dico | ||
240 | - self._status['entities'][indicee]['devices'][indiced]['device_values'][indicev] = dico | ||
241 | - break | ||
242 | - indicev += 1 | ||
243 | - return "" | ||
244 | - | ||
245 | - #################################################################### | ||
246 | - # To create a Status | ||
247 | - #################################################################### | ||
248 | - | ||
249 | - def _status_new(self, producer_name, producer_version): | ||
250 | - status_header = {'frame_model':'1.3', 'producer_name':producer_name, 'producer_version':producer_version, 'entities':[]} | ||
251 | - #self._status = { 'statuses':[] } | ||
252 | - #self._status['statuses'].append(status_header) | ||
253 | - self._status = status_header | ||
254 | - | ||
255 | - def _status_new_entity(self, entity_name, theorigin, version_firmware, site, date=""): | ||
256 | - if date=="": | ||
257 | - date = (guitastro.Date("now")).iso() | ||
258 | - entity= {'entity_name':entity_name, 'origin':theorigin, 'version_firmware':version_firmware, 'site':site, 'date':date, 'devices':[]} | ||
259 | - #self._status['statuses'][0]['entities'].append(entity); | ||
260 | - self._status['entities'].append(entity); | ||
261 | - | ||
262 | - def _status_entity_new_device(self, entity_name, device_name, device_type, serial_number, error_code): | ||
263 | - entities = self._get_entity_names() | ||
264 | - indicee = self._get_indice_from_entities(entities,entity_name) | ||
265 | - if indicee == -1: | ||
266 | - return "" | ||
267 | - device = {'device_name':device_name, 'device_type':device_type, 'serial_number':serial_number, 'error_code':error_code, 'device_values':[]} | ||
268 | - #self._status['statuses'][0]['entities'][indicee]['devices'].append(device) | ||
269 | - self._status['entities'][indicee]['devices'].append(device) | ||
270 | - | ||
271 | - def _status_entity_device_new_value(self, entity_name, device_name, serial_number, name, data_type, value, unit="", monitoring_name="", comment="", date_data=""): | ||
272 | - entities = self._get_entity_names() | ||
273 | - indicee = self._get_indice_from_entities(entities,entity_name) | ||
274 | - if indicee == -1: | ||
275 | - return "" | ||
276 | - #devices = self._status['statuses'][0]['entities'][indicee]['devices'] | ||
277 | - devices = self._status['entities'][indicee]['devices'] | ||
278 | - indiced = self._get_indice_from_devices(devices, device_name, serial_number) | ||
279 | - if indiced == -1: | ||
280 | - return "" | ||
281 | - if date_data=="": | ||
282 | - date_data = (guitastro.Date("now")).iso() | ||
283 | - else: | ||
284 | - date_data = (guitastro.Date(date_data)).iso() | ||
285 | - dico = {'name':name, 'data_type':data_type, 'value':value, 'unit':unit, 'monitoring_name':monitoring_name, 'comment':comment, 'date_data':date_data} | ||
286 | - #self._status['statuses'][0]['entities'][indicee]['devices'][indiced]['device_values'].append(dico) | ||
287 | - self._status['entities'][indicee]['devices'][indiced]['device_values'].append(dico) | ||
288 | - | ||
289 | -# ======================================================== | ||
290 | -# === status_json methods | ||
291 | -# ======================================================== | ||
292 | - | ||
293 | - def new_status(self, producer_name, producer_version): | ||
294 | - """ Initialize a new status | ||
295 | - | ||
296 | - Inputs: | ||
297 | - ------- | ||
298 | - Dictionary keys of the creator. | ||
299 | - | ||
300 | - Usage: | ||
301 | - ------ | ||
302 | - >>> report = report.Status_json() | ||
303 | - >>> report.new_status("PLC","20180909") | ||
304 | - | ||
305 | - Related topics: | ||
306 | - --------------- | ||
307 | - Method append_entity | ||
308 | - """ | ||
309 | - self._init() | ||
310 | - self._status_new(producer_name, producer_version) | ||
311 | - | ||
312 | - def append_entity(self, entity_name, theorigin, version_firmware, site, date=""): | ||
313 | - """ Append a new entity to a creator | ||
314 | - | ||
315 | - Inputs: | ||
316 | - ------- | ||
317 | - Dictionary keys of the entity. | ||
318 | - | ||
319 | - Usage: | ||
320 | - ------ | ||
321 | - >>> report = report.Status_json() | ||
322 | - >>> report.new_status("PLC","20180909") | ||
323 | - >>> rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory") | ||
324 | - | ||
325 | - Related topics: | ||
326 | - --------------- | ||
327 | - Methods append_device, get_entities | ||
328 | - """ | ||
329 | - self._status_new_entity(entity_name, theorigin, version_firmware, site, date) | ||
330 | - self._entity_name = entity_name | ||
331 | - | ||
332 | - def append_device(self, device_name, device_type, serial_number, error_code): | ||
333 | - """ Append a new device to an entity | ||
334 | - | ||
335 | - Inputs: | ||
336 | - ------- | ||
337 | - Dictionary keys of the device. | ||
338 | - | ||
339 | - Usage: | ||
340 | - ------ | ||
341 | - >>> report = report.Status_json() | ||
342 | - >>> report.new_status("PLC","20180909") | ||
343 | - >>> rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory") | ||
344 | - >>> rep.append_device("DHT22", "meteo", "1", "0") | ||
345 | - | ||
346 | - Related topics: | ||
347 | - --------------- | ||
348 | - Methods append_value, get_devices | ||
349 | - """ | ||
350 | - entity_name = self._entity_name | ||
351 | - self._status_entity_new_device(entity_name, device_name, device_type, serial_number, error_code) | ||
352 | - self._device_name = device_name | ||
353 | - self._serial_number = serial_number | ||
354 | - | ||
355 | - def append_value(self, name, data_type, value, unit="", monitoring_name="", comment="", date_data=""): | ||
356 | - """ Append a new value to a device | ||
357 | - | ||
358 | - Inputs: | ||
359 | - ------- | ||
360 | - Dictionary keys of the device_value. | ||
361 | - | ||
362 | - Usage: | ||
363 | - ------ | ||
364 | - >>> report = report.Status_json() | ||
365 | - >>> report.new_status("PLC","20180909") | ||
366 | - >>> rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory") | ||
367 | - >>> rep.append_device("DHT22", "meteo", "1", "0") | ||
368 | - >>> rep.append_value( "OutsideTemperature", "float","22","degC","temperature","Temperature","") | ||
369 | - | ||
370 | - Related topics: | ||
371 | - --------------- | ||
372 | - Methods append_value, get_devices | ||
373 | - """ | ||
374 | - entity_name = self._entity_name | ||
375 | - device_name = self._device_name | ||
376 | - serial_number = self._serial_number | ||
377 | - self._status_entity_device_new_value(entity_name, device_name, serial_number, name, data_type, value, unit, monitoring_name, comment, date_data) | ||
378 | - | ||
379 | - def load_json(self, full_filename): | ||
380 | - """ Load a Json file as an object | ||
381 | - | ||
382 | - Inputs: | ||
383 | - ------- | ||
384 | - full_filename is the path + file name of the Json file | ||
385 | - | ||
386 | - Usage: | ||
387 | - ------ | ||
388 | - >>> report = report.Status_json() | ||
389 | - >>> report.load_json("") | ||
390 | - | ||
391 | - Related topics: | ||
392 | - --------------- | ||
393 | - The Json file does not have any comment | ||
394 | - """ | ||
395 | - if (full_filename != ""): | ||
396 | - with open(full_filename, "r") as read_file: | ||
397 | - self._status = json.load(read_file) | ||
398 | - | ||
399 | - def save_json(self, full_filename): | ||
400 | - """ Save a Json file from an object | ||
401 | - | ||
402 | - Inputs: | ||
403 | - ------- | ||
404 | - full_filename is the path + file name of the Json file | ||
405 | - | ||
406 | - Usage: | ||
407 | - ------ | ||
408 | - >>> report = report.Status_json() | ||
409 | - >>> report.create_a_simple_report_for_tests() | ||
410 | - >>> report.save_json("") | ||
411 | - | ||
412 | - Related topics: | ||
413 | - --------------- | ||
414 | - The Json file will not have any comment | ||
415 | - """ | ||
416 | - if (full_filename != "") and (self._status != ""): | ||
417 | - json_string = json.dumps(self._status, indent=2) | ||
418 | - with open(full_filename, "w") as write_file: | ||
419 | - write_file.write(json_string) | ||
420 | - | ||
421 | - def create_a_simple_report_for_tests(self): | ||
422 | - """ Create a simple report for tests | ||
423 | - | ||
424 | - Inputs: | ||
425 | - ------- | ||
426 | - None. | ||
427 | - | ||
428 | - Usage: | ||
429 | - ------ | ||
430 | - >>> report = report.Status_json() | ||
431 | - >>> report.create_a_simple_report_for_tests() | ||
432 | - | ||
433 | - Related topics: | ||
434 | - --------------- | ||
435 | - The Json file will not have any comment | ||
436 | - """ | ||
437 | - self.new_status("PLC","20180909") | ||
438 | - self.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory") | ||
439 | - self.append_device("DHT22", "meteo", "1", "0") | ||
440 | - self.append_value( "OutsideTemperature", "float","22","degC","temperature","Temperature") | ||
441 | - #full_filename = "test.json" | ||
442 | - #self.save_json(full_filename) | ||
443 | - | ||
444 | -# ======================================================== | ||
445 | -# === get/set methods | ||
446 | -# ======================================================== | ||
447 | - | ||
448 | - def get_error_message(self, error_code): | ||
449 | - """ Get the message of a given error code | ||
450 | - | ||
451 | - Inputs: | ||
452 | - ------- | ||
453 | - integer number corresponding to an error code. | ||
454 | - | ||
455 | - Outputs: | ||
456 | - ------- | ||
457 | - The string message of the error code. | ||
458 | - | ||
459 | - Usage: | ||
460 | - ------ | ||
461 | - >>> rep.get_error_message(102) | ||
462 | - >>> 'Disk full' | ||
463 | - | ||
464 | - Related topics: | ||
465 | - --------------- | ||
466 | - """ | ||
467 | - errs = [] | ||
468 | - errs.append( {'code':0, 'message':"No error", 'version':"1.0"} ) | ||
469 | - # errors | ||
470 | - errs.append( {'code':1 , 'message':"Unreferenced error", 'version':"1.2"} ) | ||
471 | - errs.append( {'code':2 , 'message':"System error", 'version':"1.2"} ) | ||
472 | - errs.append( {'code':3 , 'message':"Device temperature too high", 'version':"1.2"} ) | ||
473 | - errs.append( {'code':4 , 'message':"Device temperature too low", 'version':"1.2"} ) | ||
474 | - errs.append( {'code':101 , 'message':"Disk not found", 'version':"1.2"} ) | ||
475 | - errs.append( {'code':102 , 'message':"Disk full", 'version':"1.2"} ) | ||
476 | - errs.append( {'code':111 , 'message':"File not found", 'version':"1.2"} ) | ||
477 | - errs.append( {'code':112 , 'message':"File opening failure", 'version':"1.2"} ) | ||
478 | - errs.append( {'code':113 , 'message':"File reading error", 'version':"1.2"} ) | ||
479 | - errs.append( {'code':114 , 'message':"File writing error", 'version':"1.2"} ) | ||
480 | - errs.append( {'code':1001 , 'message':"Power supply off", 'version':"1.2"} ) | ||
481 | - errs.append( {'code':1002 , 'message':"Power supply over voltage", 'version':"1.2"} ) | ||
482 | - errs.append( {'code':2001 , 'message':"Data connection failed", 'version':"1.2"} ) | ||
483 | - errs.append( {'code':2002 , 'message':"Data checksum error", 'version':"1.2"} ) | ||
484 | - errs.append( {'code':2003 , 'message':"Data value out of range", 'version':"1.2"} ) | ||
485 | - errs.append( {'code':2004 , 'message':"No data", 'version':"1.2"} ) | ||
486 | - errs.append( {'code':2005 , 'message':"No response after timeout", 'version':"1.2"} ) | ||
487 | - errs.append( {'code':2006 , 'message':"Data raw frame error", 'version':"1.2"} ) | ||
488 | - # warnings | ||
489 | - errs.append( {'code':-3 , 'message':"Device temperature reaching high limit", 'version':"1.2"} ) | ||
490 | - errs.append( {'code':-4 , 'message':"Device temperature reaching low limit", 'version':"1.2"} ) | ||
491 | - errs.append( {'code':-102 , 'message':"Disk almost full", 'version':"1.2"} ) | ||
492 | - errs.append( {'code':-2003, 'message':"Data value not consistent", 'version':"1.2"} ) | ||
493 | - # find the message | ||
494 | - messages = [err['message'] for err in errs if err['code']==error_code] | ||
495 | - return messages[0] | ||
496 | - | ||
497 | - def get_monitoring_names(self, monitoring_name=""): | ||
498 | - """ Get the list of available monitoring names | ||
499 | - | ||
500 | - Inputs: | ||
501 | - ------- | ||
502 | - Optional: A particular monitoring name | ||
503 | - | ||
504 | - Outputs: | ||
505 | - ------- | ||
506 | - List of dictionaries of available monitoring names. | ||
507 | - If the optional particular monitoring name is specified as input then | ||
508 | - return only the dictionary of that monitoring name. | ||
509 | - | ||
510 | - Usage: | ||
511 | - ------ | ||
512 | - >>> rep.get_monitoring_names("Wind_speed") | ||
513 | - >>> [{'monitoring_name': 'Wind_speed', 'section': 'weather', 'description': '', 'version': '1.1'}] | ||
514 | - | ||
515 | - Related topics: | ||
516 | - --------------- | ||
517 | - """ | ||
518 | - monitors = [] | ||
519 | - # Weather | ||
520 | - monitors .append( {'monitoring_name':"Temperature_outside", 'section':"weather", 'description':"Ambiant temperature", 'version':"1.1"} ) | ||
521 | - monitors .append( {'monitoring_name':"Temperature_sky", 'section':"weather", 'description':"Cloud coverage", 'version':"1.1"} ) | ||
522 | - monitors .append( {'monitoring_name':"Humidity_outside", 'section':"weather", 'description':"Ambiant humidity", 'version':"1.1"} ) | ||
523 | - monitors .append( {'monitoring_name':"Pressure_outside", 'section':"weather", 'description':"Ambiant pressure (not corrected to sea level)", 'version':"1.1"} ) | ||
524 | - monitors .append( {'monitoring_name':"Wind_speed", 'section':"weather", 'description':"", 'version':"1.1"} ) | ||
525 | - monitors .append( {'monitoring_name':"Wind_direction", 'section':"weather", 'description':"0=N, 90=E", 'version':"1.1"} ) | ||
526 | - monitors .append( {'monitoring_name':"Rain_boolean", 'section':"weather", 'description':"0=No rain, 1=Rain", 'version':"1.1"} ) | ||
527 | - # Housing | ||
528 | - monitors .append( {'monitoring_name':"State_dome_shutter_east", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} ) | ||
529 | - monitors .append( {'monitoring_name':"State_dome_shutter_west", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} ) | ||
530 | - monitors .append( {'monitoring_name':"Direction_dome_shutter", 'section':"housing", 'description':'0=N, 90=E', 'version':"1.2"} ) | ||
531 | - monitors .append( {'monitoring_name':"State_roof", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate 3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} ) | ||
532 | - monitors .append( {'monitoring_name':"State_roof_north", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate 3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} ) | ||
533 | - monitors .append( {'monitoring_name':"State_roof_south", 'section':"housing", 'description':'0=Closed 1=Opened 2=Intermediate 3=Closing, 4=Opening, 5=Undefined', 'version':"1.2"} ) | ||
534 | - # Power supply | ||
535 | - monitors .append( {'monitoring_name':"Voltage_input", 'section':"powersupply", 'description':'', 'version':"1.2"} ) | ||
536 | - monitors .append( {'monitoring_name':"Voltage_output", 'section':"powersupply", 'description':'', 'version':"1.2"} ) | ||
537 | - # Instruments | ||
538 | - monitors .append( {'monitoring_name':"Temperature_mirror", 'section':"Instruments", 'description':'Mirrors temperatures (M1, M2, etc)', 'version':"1.2"} ) | ||
539 | - monitors .append( {'monitoring_name':"Position_filterwheel", 'section':"Instruments", 'description':'', 'version':"1.2"} ) | ||
540 | - monitors .append( {'monitoring_name':"Position_focuser", 'section':"Instruments", 'description':'Positions of focusers (M2, channel1, etc.)', 'version':"1.2"} ) | ||
541 | - monitors .append( {'monitoring_name':"Temperature_sensor", 'section':"Instruments", 'description':'', 'version':"1.2"} ) | ||
542 | - # Image quality | ||
543 | - monitors .append( {'monitoring_name':"PSF_FWHM", 'section':"Imagequality", 'description':'Image quality', 'version':"1.2"} ) | ||
544 | - monitors .append( {'monitoring_name':"ZeroMag", 'section':"Imagequality", 'description':'Transparency', 'version':"1.2"} ) | ||
545 | - monitors .append( {'monitoring_name':"SkyMag", 'section':"Imagequality", 'description':'Background brightness', 'version':"1.2"} ) | ||
546 | - if monitoring_name!="": | ||
547 | - # find the message | ||
548 | - print("Etape 1") | ||
549 | - dico = [monitor for monitor in monitors if monitor['monitoring_name']==monitoring_name] | ||
550 | - return dico | ||
551 | - return monitors | ||
552 | - | ||
553 | - def get_entities(self): | ||
554 | - """ Get the current entities | ||
555 | - | ||
556 | - Inputs: | ||
557 | - ------- | ||
558 | - None. | ||
559 | - | ||
560 | - Usage: | ||
561 | - ------ | ||
562 | - >>> report = report.Status_json() | ||
563 | - >>> print("{}",format(report.get_entities())) | ||
564 | - | ||
565 | - Related topics: | ||
566 | - --------------- | ||
567 | - """ | ||
568 | - entities = [] | ||
569 | - if self._status != "": | ||
570 | - entities = self._get_entity_names() | ||
571 | - return entities | ||
572 | - | ||
573 | - def get_devices(self, only_entity_name=""): | ||
574 | - """ Get the current devices | ||
575 | - | ||
576 | - Inputs: | ||
577 | - ------- | ||
578 | - None or a device name to check if exists. | ||
579 | - | ||
580 | - Usage: | ||
581 | - ------ | ||
582 | - >>> report = report.Status_json() | ||
583 | - >>> print("{}",format(report.get_devices())) | ||
584 | - | ||
585 | - Related topics: | ||
586 | - --------------- | ||
587 | - """ | ||
588 | - res = [] | ||
589 | - if self._status != "": | ||
590 | - entities = self._get_entity_names() | ||
591 | - for entity_name in entities: | ||
592 | - devices = [] | ||
593 | - if (only_entity_name==""): | ||
594 | - devices = self._get_device_nameserials(entity_name) | ||
595 | - else: | ||
596 | - if (only_entity_name==entity_name): | ||
597 | - devices = self._get_device_nameserials(entity_name) | ||
598 | - for device in devices: | ||
599 | - re = [entity_name, device['device_name'], device['serial_number']] | ||
600 | - res.append(re) | ||
601 | - return res | ||
602 | - | ||
603 | - def get_ufkis(self, only_device_name="", only_serial_number="", getvalue=False): | ||
604 | - """ Get the current values | ||
605 | - | ||
606 | - Inputs: | ||
607 | - ------- | ||
608 | - None or a device name + serial number + value to check if exists. | ||
609 | - | ||
610 | - Usage: | ||
611 | - ------ | ||
612 | - >>> report = report.Status_json() | ||
613 | - >>> print("{}",format(report.get_devices())) | ||
614 | - >>> print("{}",format(report.get_ufkis("","",True)) | ||
615 | - | ||
616 | - Related topics: | ||
617 | - --------------- | ||
618 | - """ | ||
619 | - res = [] | ||
620 | - if self._status != "": | ||
621 | - entities = self._get_entity_names() | ||
622 | - for entity_name in entities: | ||
623 | - devices = self._get_device_nameserials(entity_name) | ||
624 | - for device in devices: | ||
625 | - device_name = device['device_name'] | ||
626 | - serial_number = device['serial_number'] | ||
627 | - value_names = [] | ||
628 | - if (only_device_name=="") or (only_serial_number==""): | ||
629 | - value_names = self._get_value_names(entity_name, device_name, serial_number) | ||
630 | - else: | ||
631 | - if (only_device_name==device_name) or (only_serial_number==serial_number): | ||
632 | - value_names = self._get_value_names(entity_name, device_name, serial_number) | ||
633 | - for value_name in value_names: | ||
634 | - if getvalue==False: | ||
635 | - re = [entity_name, device_name, serial_number, value_name] | ||
636 | - else: | ||
637 | - val = self._get_value_name_values(entity_name, device_name, serial_number, value_name) | ||
638 | - re = [entity_name, device_name, serial_number, value_name, val] | ||
639 | - res.append(re) | ||
640 | - return res | ||
641 | - | ||
642 | - def get_sensors(self, only_device_name="", only_serial_number="", getvalue=False): | ||
643 | - """ Get the current values. Alias of get_ufkis. | ||
644 | - """ | ||
645 | - return self.get_ufkis(only_device_name, only_serial_number, getvalue); | ||
646 | - | ||
647 | - def get_values(self, only_device_name="", only_serial_number="", getvalue=False): | ||
648 | - """ Get the current values. Alias of get_ufkis. | ||
649 | - """ | ||
650 | - return self.get_ufkis(only_device_name, only_serial_number, getvalue); | ||
651 | - | ||
652 | - | ||
653 | -# ======================================================== | ||
654 | -# === debug methods | ||
655 | -# ======================================================== | ||
656 | - | ||
657 | - def infos(self, action) -> None: | ||
658 | - """ To get informations about this class | ||
659 | - | ||
660 | - :param action: A command to run a debug action (see examples). | ||
661 | - :type action: string | ||
662 | - | ||
663 | - :Example: | ||
664 | - | ||
665 | - Status_json().infos("doctest") | ||
666 | - Status_json().infos("doc_methods") | ||
667 | - Status_json().infos("internal_attributes") | ||
668 | - Status_json().infos("public_methods") | ||
669 | - """ | ||
670 | - if (action == "doc_methods"): | ||
671 | - publics = [x for x in dir(self) if x[0]!="_"] | ||
672 | - for public in publics: | ||
673 | - varname = "{}".format(public) | ||
674 | - if (callable(getattr(self,varname))==True): | ||
675 | - print("\n{:=^40}".format(" method "+varname+" ")) | ||
676 | - t = "Angle()."+varname+".__doc__" | ||
677 | - tt =eval(t) | ||
678 | - print(tt) | ||
679 | - if (action == "doctest"): | ||
680 | - if __name__ == "__main__": | ||
681 | - print("\n{:~^40}".format("doctest")) | ||
682 | - #doctest.testmod(verbose=True, extraglobs={'objangle': Angle()}) | ||
683 | - doctest.testmod(verbose=True) | ||
684 | - if (action == "internal_attributes"): | ||
685 | - internals = [x for x in dir(self) if x[0]=="_" and x[1]!="_"] | ||
686 | - for internal in internals: | ||
687 | - varname = "{}".format(internal) | ||
688 | - #if (hasattr(self,varname)==True): | ||
689 | - if (callable(getattr(self,varname))==False): | ||
690 | - print(varname + "=" + str(getattr(self,varname))) | ||
691 | - if (action == "public_methods"): | ||
692 | - publics = [x for x in dir(self) if x[0]!="_"] | ||
693 | - for public in publics: | ||
694 | - varname = "{}".format(public) | ||
695 | - if (callable(getattr(self,varname))==True): | ||
696 | - print(varname) | ||
697 | - | ||
698 | - | ||
699 | -# ======================================================== | ||
700 | -# === special methods | ||
701 | -# ======================================================== | ||
702 | - | ||
703 | - def __init__(self, status=""): | ||
704 | - """ Object initialization where angle is the input in any format. | ||
705 | - | ||
706 | - :param angle : An angle in any supported format (cf. help(Angle)) | ||
707 | - :type angle : string | ||
708 | - | ||
709 | - """ | ||
710 | - self._init(status) | ||
711 | - | ||
712 | -# ======================================================== | ||
713 | -# ======================================================== | ||
714 | -# ======================================================== | ||
715 | - | ||
716 | -# Examples of execution | ||
717 | - | ||
718 | -if __name__ == "__main__": | ||
719 | - | ||
720 | - # --- update the path of Python if necessary | ||
721 | - | ||
722 | - import report | ||
723 | - | ||
724 | - # =============================== | ||
725 | - # --- Write a very sipmle Json | ||
726 | - # =============================== | ||
727 | - print("Make a new report") | ||
728 | - rep = report.Status_json() | ||
729 | - rep.new_status("PLC","20180909") | ||
730 | - rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "MyObservatory") | ||
731 | - # --- one device with one value | ||
732 | - rep.append_device("DHT22", "meteo", "1", "0") | ||
733 | - rep.append_value( "OutsideTemperature", "float","22","degC","Temperature_outside","Temperature","now") | ||
734 | - # --- List the UFKIs | ||
735 | - ufkis = rep.get_ufkis("","",False) | ||
736 | - print(" List of all UFKIs:") | ||
737 | - for ufki in ufkis: | ||
738 | - print(" UFKI = {}".format(ufki)) | ||
739 | - # --- save the Json file | ||
740 | - rep.save_json("plc_verysimple.json") | ||
741 | - | ||
742 | - # =============================== | ||
743 | - # --- Write a more complex Json | ||
744 | - # =============================== | ||
745 | - print("Make a new report") | ||
746 | - rep = report.Status_json() | ||
747 | - rep.new_status("PLC","20180909") | ||
748 | - rep.append_entity("PLC_STATUS", "Raspberry", "20180924A", "Guitalens Observatory") | ||
749 | - # --- device Came | ||
750 | - rep.append_device("Came", "roof_controler", "124", "0") | ||
751 | - rep.append_value( "Error_code", "int","0","","","0=OK 1=PowerPB 2=SwitchPB","now") | ||
752 | - rep.append_value( "Power_input", "int","0","","","0=0Volt 1=24Volts","now") | ||
753 | - rep.append_value( "Mode_came", "int","0","","","0=Manual 1=Auto","now") | ||
754 | - rep.append_value( "Roof_state", "int","0","","","0=Closed 1=Opened 2=Intermediate","now") | ||
755 | - # --- device CV7 | ||
756 | - rep.append_device("CV7", "weather_station", "RET6789", "0") | ||
757 | - rep.append_value( "Error_code", "int","0","","","0=OK 1=SerialPB 2=FramePB","now") | ||
758 | - rep.append_value( "Power_input", "int","0","","","0=0Volt 1=12Volts (Power from MiFe board)","now") | ||
759 | - rep.append_value( "Wind_dir", "float","0","degrees","Wind_direction","0=North 90=East","now") | ||
760 | - rep.append_value( "Wind_speed", "float","0","m/s","Wind_spped","Wind speed from ultrasonic sensors","now") | ||
761 | - rep.append_value( "OutsideTemperature", "float","0","degC","Temperature_outside","Temperature of the anemometer","now") | ||
762 | - # --- device DHT22 | ||
763 | - rep.append_device("DHT22", "weather_station", "123", "0") | ||
764 | - rep.append_value( "Error_code", "int","0","","","0=OK 1=CheksumPB 2=LengthPB 3=NodataPB","now") | ||
765 | - rep.append_value( "Temperature", "float","21","degC","temperature","Temperature inside PLX box","now") | ||
766 | - rep.append_value( "Humidity", "float","77","percent","humidity","Humidity inside PLX box","now") | ||
767 | - # --- device RG11 | ||
768 | - rep.append_device("RG11", "weather_station", "TY67", "0") | ||
769 | - rep.append_value( "Error_code", "int","0","","","0=OK +1=PowerPB +2=NopowerPB +4=AllonePB","now") | ||
770 | - rep.append_value( "RainSate", "int","0","","rain","0=Dry 1=Rain 2=Unknown","now") | ||
771 | - # --- device MLX90614 | ||
772 | - rep.append_device("MLX90614", "weather_station", "1", "0") | ||
773 | - rep.append_value( "Error_code", "int","0","","","0=OK 1=DataPB","now") | ||
774 | - rep.append_value( "SkyTemperature", "float","-15.67","degC","Temperature_sky","Temperature of the sky","now") | ||
775 | - rep.append_value( "CanTemperature", "float","22.47","degC","","Temperature of the TO can","now") | ||
776 | - # --- List the UFKIs | ||
777 | - ufkis = rep.get_ufkis("","",False) | ||
778 | - print(" List of all UFKIs:") | ||
779 | - for ufki in ufkis: | ||
780 | - print(" UFKI = {}".format(ufki)) | ||
781 | - # --- save the Json file | ||
782 | - rep.save_json("plc_guitalens.json") | ||
783 | - | ||
784 | - # =============================== | ||
785 | - # --- Read an existing Json | ||
786 | - # =============================== | ||
787 | - rep = report.Status_json() | ||
788 | - path_filename = "plc_verysimple.json" | ||
789 | - print("Analysis of the file {}:".format(path_filename)) | ||
790 | - rep.load_json(path_filename) | ||
791 | - res = rep.get_entities() | ||
792 | - print(" entities = {}".format(res)) | ||
793 | - res = rep.get_devices() | ||
794 | - print(" devices = {}".format(res)) | ||
795 | - print(" List of all UFKIs:") | ||
796 | - ufkis = rep.get_ufkis("","",True) | ||
797 | - for ufki in ufkis: | ||
798 | - print(" UFKI = {}".format(ufki)) |