Commit c830a3bcc157200157546e8c0e00a1c717ad9921
1 parent
6973f7df
Exists in
dev
PLC ACK + plc timeout
Showing
10 changed files
with
60 additions
and
17 deletions
Show diff stats
src/common/models.py
... | ... | @@ -840,10 +840,11 @@ class Config(models.Model): |
840 | 840 | camera_ip_address = models.CharField(max_length=45, default="127.0.0.1") |
841 | 841 | plc_ip_address = models.CharField(max_length=45, default="127.0.0.1") |
842 | 842 | global_mode = models.BooleanField(default='True') |
843 | - ack = models.BooleanField(default='True') | |
843 | + ack = models.BooleanField(default='False') | |
844 | 844 | bypass = models.BooleanField(default='True') |
845 | 845 | scheduler_state = models.CharField(max_length=1, choices=SCHEDULER_STATE, default=0) |
846 | 846 | force_passive_mode = models.BooleanField(default='False') |
847 | + plc_timeout_seconds = models.PositiveIntegerField(default=60) | |
847 | 848 | |
848 | 849 | class Meta: |
849 | 850 | managed = True | ... | ... |
src/dashboard/templates/dashboard/observation_status_env.html
... | ... | @@ -28,12 +28,16 @@ figure figcaption { |
28 | 28 | text-align: center; |
29 | 29 | color: darkblue; |
30 | 30 | } |
31 | + | |
32 | + #no_plc | |
33 | + { | |
34 | + color: red; | |
35 | + } | |
31 | 36 | </style> |
32 | - <h1 id="time"> Current site time : {{ t.hour }}h {{ t.minute }}min {{ t.second }}s</h1> | |
37 | +<h1 id="time"> Current site time : {{ t.hour }}h {{ t.minute }}min {{ t.second }}s</h1> | |
33 | 38 | <div id="weather"> |
34 | 39 | |
35 | 40 | <div class="element" id="day_night"> |
36 | - | |
37 | 41 | {% if isDay %} |
38 | 42 | <figure> |
39 | 43 | <img src="{% static "media/rising_sun.png" %}" alt="" width="150" height="150"> |
... | ... | @@ -50,7 +54,12 @@ figure figcaption { |
50 | 54 | </div> |
51 | 55 | |
52 | 56 | <div class="element" id="sky_state"> |
53 | - {% if weather_status.rain > 10 %} | |
57 | + {% if timeout > plc_timeout %} | |
58 | + <figure> | |
59 | + <img src="{% static "media/rain_no_plc.png" %}" alt="" width="150" height="150"> | |
60 | + <figcaption>Raining</figcaption> | |
61 | + </figure> | |
62 | + {% elif weather_status.rain > 10 %} | |
54 | 63 | <figure> |
55 | 64 | <img src="{% static "media/rain.svg" %}" alt="" width="150" height="150"> |
56 | 65 | <figcaption>Raining</figcaption> |
... | ... | @@ -71,8 +80,12 @@ figure figcaption { |
71 | 80 | </div> |
72 | 81 | |
73 | 82 | <div class="element" id="wind"> |
74 | - | |
75 | - {% if weather_status.wind >= 60 %} | |
83 | + {% if timeout > plc_timeout %} | |
84 | + <figure> | |
85 | + <img src="{% static "media/wind_no_plc.png" %}" alt="" width="150" height="150"> | |
86 | + <figcaption>Raining</figcaption> | |
87 | + </figure> | |
88 | + {% elif weather_status.wind >= 60 %} | |
76 | 89 | <figure> |
77 | 90 | <img src="{% static "media/wind.png" %}" alt="" width="150" height="150"> |
78 | 91 | <figcaption>The Wind is too strong : {{ weather_status.wind }}km/h</figcaption> |
... | ... | @@ -83,7 +96,9 @@ figure figcaption { |
83 | 96 | <figcaption>The Wind is acceptable : {{ weather_status.wind }}km/h</figcaption> |
84 | 97 | </figure> |
85 | 98 | {% endif %} |
86 | - | |
87 | - | |
88 | 99 | </div> |
100 | + {% if timeout > plc_timeout %} | |
101 | + <h2 id="no_plc">No plc online : last weather info received {{ timeout_affichage }} !</h2> | |
102 | + {% endif %} | |
103 | + | |
89 | 104 | </div> |
90 | 105 | \ No newline at end of file | ... | ... |
src/dashboard/views.py
... | ... | @@ -19,6 +19,7 @@ from random import randint |
19 | 19 | from devices.Telescope import TelescopeController |
20 | 20 | from devices.TelescopeRemoteControl import TelescopeRemoteControl |
21 | 21 | from django.core.mail import send_mail |
22 | +import time | |
22 | 23 | |
23 | 24 | log = l.setupLogger("dashboard", "dashboard") |
24 | 25 | |
... | ... | @@ -32,8 +33,15 @@ def index(request): |
32 | 33 | # return render(request, 'dashboard/observation_status.html') |
33 | 34 | |
34 | 35 | def retrieve_env(request): |
36 | + ''' | |
37 | + TODO: integrate Alain's code do determine day/night with sunelev and switch to utc time when the plc will use it | |
38 | + ''' | |
39 | + | |
35 | 40 | try: |
36 | 41 | weather_status = WeatherWatch.objects.latest('updated') |
42 | + plc_timeout = Config.objects.get(pk=1).plc_timeout_seconds | |
43 | + timeout = (datetime.datetime.now() - weather_status.updated).total_seconds() | |
44 | + timeout_affichage = datetime.datetime.now() - datetime.timedelta(seconds=timeout) | |
37 | 45 | t = datetime.datetime.now() + datetime.timedelta(hours=-7) #temporary method to demonstrate the day/night display |
38 | 46 | isDay = False |
39 | 47 | if t.hour > 5 and t.hour < 20: |
... | ... | @@ -48,11 +56,13 @@ def retrieve_env_navbar(request): |
48 | 56 | weather_status = WeatherWatch.objects.latest('updated') |
49 | 57 | plc_mode = PlcDeviceStatus.objects.latest('created').plc_mode |
50 | 58 | is_safe = PlcDeviceStatus.objects.latest('created').is_safe |
59 | + ack = Config.objects.get(id=1).ack | |
51 | 60 | weather = serializers.serialize('json', [weather_status]) |
52 | 61 | weather = json.loads(weather) |
53 | 62 | weather[0]['sunelev'] = randint(-30, 30) #remplacer par l'appel au code d'Alain quand il sera dispo |
54 | 63 | weather[0]["plc_mode"] = plc_mode |
55 | 64 | weather[0]["is_safe"] = is_safe |
65 | + weather[0]["ACK"] = ack | |
56 | 66 | return HttpResponse(json.dumps(weather), content_type="application/json") |
57 | 67 | except WeatherWatch.DoesNotExist: |
58 | 68 | raise Http404("No WeatherWatch matches the given query.") | ... | ... |
src/misc/fixtures/initial_fixture.json
7.92 KB
31.6 KB
7.76 KB
31.4 KB
21.9 KB
src/misc/templates/base.html
... | ... | @@ -3,7 +3,6 @@ |
3 | 3 | <head> |
4 | 4 | |
5 | 5 | {% load staticfiles %} |
6 | - | |
7 | 6 | <meta charset="utf-8"> |
8 | 7 | <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
9 | 8 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
... | ... | @@ -78,7 +77,7 @@ a { |
78 | 77 | |
79 | 78 | #plc_state |
80 | 79 | { |
81 | - color: white; | |
80 | + color: black; | |
82 | 81 | font-size: 18px; |
83 | 82 | } |
84 | 83 | |
... | ... | @@ -139,8 +138,9 @@ a { |
139 | 138 | <li><a class="nav-brand" id="hour">Sun elevation :</a></li> |
140 | 139 | <li><a class="nav-brand" id="day_night" href="{% url "weather" %}"><img id="day_night_img"></a></li> |
141 | 140 | <li><a class="nav-brand" id="wind" href="{% url "weather" %}"><img id="wind_img"></a></li> |
142 | - <li><a class="nav-brand" id="globalmode" style="color: black;"> {% global_mode request %} </a> | |
143 | 141 | <li><a class="nav-brand" id="weather" href="{% url "weather" %}"><img id="weather_img"></a></li> |
142 | + <li><a class="nav-brand" id="globalmode" style="color: black;"> {% global_mode request %} </a> | |
143 | + | |
144 | 144 | <li> |
145 | 145 | <a class="nav-brand" href="{% url "profile" %}" style="color: black;"><i id="profile" class="fas fa-cog "></i></a> |
146 | 146 | </li> |
... | ... | @@ -155,6 +155,8 @@ a { |
155 | 155 | var REFRESH_ICONS_FREQUENCE_MILLISECONDS = 1000; |
156 | 156 | var MAX_RAIN_RATE = 10; |
157 | 157 | |
158 | + var check_change = true; | |
159 | + | |
158 | 160 | $( document ).ready(function() { |
159 | 161 | //get_hour(); |
160 | 162 | //setInterval(function() {get_hour();}, 900); |
... | ... | @@ -173,13 +175,28 @@ a { |
173 | 175 | color = "#6b69f3"; |
174 | 176 | $("#topbar").css("background-color", color); |
175 | 177 | } |
176 | - function info_plc(is_safe, mode) | |
178 | + function info_plc(is_safe, mode, ack) | |
177 | 179 | { |
180 | + | |
181 | + | |
178 | 182 | var safe = "UNSAFE"; |
179 | 183 | if (is_safe) |
180 | 184 | safe = "SAFE"; |
181 | 185 | |
182 | - $("#plc_state").text("PLC: " + mode + " " + safe); | |
186 | + if (ack) { | |
187 | + ack = "STAFF ACK: OK"; | |
188 | + if (!check_change) | |
189 | + window.location.reload(true); | |
190 | + check_change = true; | |
191 | + } | |
192 | + else | |
193 | + { | |
194 | + ack = "STAFF ACK: KO"; | |
195 | + $("#plc_state").css("background-color", "red"); | |
196 | + check_change = false; | |
197 | + } | |
198 | + | |
199 | + $("#plc_state").text("PLC: " + mode + " " + safe + " " + ack); | |
183 | 200 | } |
184 | 201 | |
185 | 202 | ajax_request(); |
... | ... | @@ -232,8 +249,7 @@ a { |
232 | 249 | |
233 | 250 | set_elev(weather_status[0]['sunelev']); |
234 | 251 | change_color(parseInt(weather_status[0]['sunelev'])); |
235 | - console.log(weather_status); | |
236 | - info_plc(weather_status[0]["is_safe"], weather_status[0]["plc_mode"]); | |
252 | + info_plc(weather_status[0]["is_safe"], weather_status[0]["plc_mode"], weather_status[0]["ACK"] ); | |
237 | 253 | } |
238 | 254 | }, 'json') |
239 | 255 | .fail(function () { | ... | ... |