Commit 9f3db1a322c9b0b565a58ad6af63e2693274236f

Authored by Quentin Durand
1 parent 40ee3b96
Exists in dev

plc_mode in progress + debug simulator

pyros.py
... ... @@ -142,6 +142,8 @@ class AManager(Utils):
142 142  
143 143 def signal_handler(self, signal, frame):
144 144 self.printFullTerm(Colors.WARNING, "Ctrl-c catched")
  145 + self.replacePatternInFile("CELERY_TEST = True", "CELERY_TEST = False", "pyros/settings.py")
  146 + self.replacePatternInFile("SIMULATOR = True", "SIMULATOR = False", "pyros/settings.py")
145 147 for p in self.subproc:
146 148 proc, name = p
147 149 self.printColor(Colors.BLUE, "Killing process " + str(name))
... ... @@ -766,9 +768,10 @@ class Pyros(AManager):
766 768 return 0
767 769  
768 770 def kill_simulation(self):
769   - # self.changeDirectory("src")
  771 + self.changeDirectory("src")
770 772 self.replacePatternInFile("CELERY_TEST = True", "CELERY_TEST = False", "pyros/settings.py")
771 773 self.replacePatternInFile("SIMULATOR = True", "SIMULATOR = False", "pyros/settings.py")
  774 + self.changeDirectory("..")
772 775 if (self.system == "Windows"):
773 776 self.execProcessAsync("taskkill /f /im python.exe")
774 777 #self.execProcessAsync("del /f testdb.sqlite3") obsolete
... ... @@ -778,6 +781,7 @@ class Pyros(AManager):
778 781  
779 782 # Kill web server (processes using TCP port 8000) :
780 783 #self.execProcessAsync("fuser -k 8000/tcp")
  784 +
781 785 self.kill_server()
782 786  
783 787 # (if not using celery) Kill all agents :
... ...
simulators/plc/plcSimulator.py
... ... @@ -73,7 +73,9 @@ class PLCSimulator(DeviceSim, StatusManager):
73 73 {"name": "current", "value": 0.234, "unit": "Ampere", "comment": ""}
74 74 ]
75 75 }
76   - ]
  76 + ],
  77 + "mode": "AUTO",
  78 + "is_safe": True
77 79 }
78 80  
79 81 list = {"name": "LIST", "from": "Beckhoff", "version_firmware": "20170809", "site": "OSM-Mexico",
... ...
src/common/models.py
... ... @@ -52,7 +52,7 @@ class Device(models.Model):
52 52 return (str(self.name))
53 53  
54 54 class PlcDeviceStatus(models.Model):
55   - device = models.ForeignKey('PlcDevice', on_delete=models.CASCADE, related_name='status')
  55 + device = models.ForeignKey('PlcDevice', on_delete=models.CASCADE, related_name='current_status')
56 56  
57 57 outside_temp = models.DecimalField(max_digits=15, decimal_places=8, blank=True, null=True)
58 58 outside_temp_unit = models.CharField(max_length=45, blank=True, null=True)
... ... @@ -149,12 +149,14 @@ class PlcDeviceStatus(models.Model):
149 149 else:
150 150 raise KeyError("Key " + str(key) + " unrecognized")
151 151  
152   -class PlcDevice(models.Model):
153   - device = models.ForeignKey('Plc', on_delete=models.CASCADE, related_name='plc_devices')
  152 +class PlcDevice(Device):
  153 + #device = models.ForeignKey('Plc', on_delete=models.CASCADE, related_name='plc_devices')
154 154 name = models.CharField(max_length=45, blank=True, null=True)
155 155 desc = models.TextField(blank=True, null=True)
156 156 created = models.DateTimeField(blank=True, null=True, auto_now_add=True)
157 157 updated = models.DateTimeField(blank=True, null=True, auto_now=True)
  158 + is_safe = models.BooleanField(default=True)
  159 + plc_mode = models.CharField(max_length=4, null=True)
158 160  
159 161 class Meta:
160 162 managed = True
... ... @@ -164,12 +166,12 @@ class PlcDevice(models.Model):
164 166 return str(self.name)
165 167  
166 168  
167   -class Plc(Device):
168   - last_update_status = models.DateTimeField(blank=True, null=True)
169   -
170   - class Meta:
171   - managed = True
172   - db_table = 'plc'
  169 +#class Plc(Device):
  170 + # last_update_status = models.DateTimeField(blank=True, null=True)
  171 +# i
  172 + # class Meta:
  173 + # managed = True
  174 + # db_table = 'plc'
173 175  
174 176  
175 177 class Detector(Device):
... ...
src/dashboard/templates/dashboard/system_logs.html
... ... @@ -26,7 +26,7 @@
26 26 <div class="fixed" style="color: #00CC00;">
27 27 <ul>
28 28 {% for log in alert_logs %}
29   - <li>{{log.created}} : {{log.message}}</li> {% endfor %}
  29 + <li>{{ogl.created}} : {{log.message}}</li> {% endfor %}
30 30 </ul>
31 31  
32 32 </div>
... ...
src/dashboard/views.py
... ... @@ -50,7 +50,7 @@ def retrieve_env_navbar(request):
50 50 weather_status = WeatherWatch.objects.latest('updated')
51 51 weather = serializers.serialize('json', [weather_status])
52 52 weather = json.loads(weather)
53   - weather[0]['sunelev'] = randint(-30, 30)
  53 + weather[0]['sunelev'] = randint(-30, 30) #remplacer par l'appel au code d'Alain quand il sera dispo
54 54 return HttpResponse(json.dumps(weather), content_type="application/json")
55 55 except WeatherWatch.DoesNotExist:
56 56 raise Http404("No WeatherWatch matches the given query.")
... ...
src/misc/fixtures/initial_fixture.json
... ... @@ -63,16 +63,17 @@
63 63 }
64 64 },
65 65 {
66   - "model": "common.plc",
  66 + "model": "common.plcdevice",
67 67 "pk": 1,
68 68 "fields": {
69   - "last_update_status": null,
70   - "name": "Plc",
71   - "desc": "",
72   - "created": "2016-05-13 11:50:14",
73   - "updated": "2016-05-13 11:50:14",
74   - "is_online": false,
75   - "maintenance_date": null
  69 + "is_safe": true,
  70 + "status": null,
  71 + "name": "Plc",
  72 + "desc": "",
  73 + "created": "2018-06-18 14:32:00",
  74 + "updated": "2018-06-18 14:32:00",
  75 + "is_online": false,
  76 + "maintenance_date": null
76 77 }
77 78 },
78 79 {
... ...
src/misc/templates/base.html
... ... @@ -112,6 +112,7 @@ a {
112 112 <li><a href="#">Images</a></li>
113 113 </ul>
114 114 <ul class="nav navbar-nav navbar-right navbar-user">
  115 + <li id="plc_state"></li>
115 116 <li><a id="hour">Sun elevation :</a></li>
116 117 <li><a id="day_night" href="{% url "weather" %}"><img id="day_night_img"></a></li>
117 118 <li><a id="wind" href="{% url "weather" %}"><img id="wind_img"></a></li>
... ...
src/misc/templates/base_unlogged.html
... ... @@ -99,7 +99,7 @@ a {
99 99 <li><a href="{% url "current_schedule" %}">Schedule</a></li>
100 100 </ul>
101 101 <ul class="nav navbar-nav navbar-right navbar-user">
102   - <li><a id="hour">lol</a></li>
  102 + <li><a id="hour"></a></li>
103 103 <li><a id="day_night" href="{% url "weather" %}"><img id="day_night_img"></a></li>
104 104 <li><a id="wind" href="{% url "weather" %}"><img id="wind_img"></a></li>
105 105 <li><a id="weather" href="{% url "weather" %}"><img id="weather_img"></a></li>
... ... @@ -113,7 +113,7 @@ a {
113 113 <script>
114 114 var TOO_STRONG_WIND = 60; //Totally arbitrary values, just for demonstration
115 115 var MAX_CLOUD_VALUE = 1;
116   - var REFRESH_ICONS_FREQUENCE_MILLISECONDS = 60000;
  116 + var REFRESH_ICONS_FREQUENCE_MILLISECONDS = 1000;
117 117 var MAX_RAIN_RATE = 10;
118 118  
119 119 $( document ).ready(function() {
... ...
src/monitoring/tasks.py
... ... @@ -174,8 +174,8 @@ class Monitoring(Task):
174 174 try:
175 175 database_device = PlcDevice.objects.get(name=device["name"])
176 176 except Exception as e:
177   - plc = Plc.objects.first()
178   - database_device = PlcDevice.objects.create(device=plc, name=device["name"])
  177 + # plc = Plc.objects.first()
  178 + database_device = PlcDevice.objects.create(name=device["name"])
179 179 status.device = database_device
180 180 for value in device["values"]:
181 181 status.setValue(value["name"], value["value"], value["unit"])
... ...
src/pyros/settings.py
... ... @@ -124,12 +124,12 @@ LOGIN_URL = &quot;/&quot;
124 124 ''' DO NOT TOUCH THESE VARIABLES
125 125 "$ pyros.py simulator_development" will automatically set them to "True"
126 126 '''
127   -# FOR SIMULATOR (TODO: remove because not used)
128   -SIMULATOR = True
  127 +# FOR SIMULATOR (htopTODO: remove because not used)
  128 +SIMULATOR = False
129 129 # FOR SIMULATOR (and TESTS)
130   -CELERY_TEST = True
  130 +CELERY_TEST = False
131 131  
132   -# CELERY_TEST = True ==> DEFAULT (NORMAL) RUN MODE, use pyros (normal) database
  132 +# CELERY_TEST = False ==> DEFAULT (NORMAL) RUN MODE, use pyros (normal) database
133 133 if not CELERY_TEST:
134 134 if not MYSQL:
135 135 DATABASES = {
... ... @@ -148,7 +148,7 @@ if not CELERY_TEST:
148 148 }
149 149 }
150 150  
151   -# CELERY_TEST = True ==> 'TEST' RUN MODE, use pyros_test database
  151 +# CELERY_TEST = False ==> 'TEST' RUN MODE, use pyros_test database
152 152 else:
153 153 DATABASES = {
154 154 'default': {
... ...