Commit f47ec7270dec86233086b8c61b30bd40b98700e8

Authored by Quentin Durand
1 parent af407ee1
Exists in dev

hotfix monitoring

simulators/plc/plcSimulator.py
... ... @@ -169,7 +169,6 @@ class PLCSimulator(DeviceSim, StatusManager):
169 169  
170 170 def loop(self):
171 171 i = 0
172   -
173 172 if (self.EVENT_GENERATOR and self.ended==0):
174 173 self.plcPrint("No entry for PLC found in config file : " + self.config_file)
175 174 return False
... ...
src/devices/Device.py
... ... @@ -103,8 +103,9 @@ class DeviceController():
103 103 try:
104 104 readable, writable, exceptional = select.select([self.sock], [], [self.sock], 0)
105 105 if not (readable or exceptional):
106   - ret = self.sock.recv(size).decode()
107   - raise (Exception("KO: " + ret))
  106 + #ret = self.sock.recv(size).decode()
  107 + raise (Exception("KO: socket error"))
  108 +
108 109 ret = self.sock.recv(size).decode()
109 110 if (not ret):
110 111 if (settings.DEBUG):
... ...
src/devices/PLC.py
... ... @@ -21,8 +21,10 @@ class PLCController(DeviceController):
21 21 def sendCommandWithAnswer(self, dict_list):
22 22 # Send commmand TO plc
23 23 status = self.sendCommand(dict_list)
  24 +
24 25 #EP added
25   - if not status: return "NOT_SET1"
  26 + if not status:
  27 + return "NOT_SET1"
26 28 # Read result FROM plc
27 29 return (self.blockAndReadBytes(4096))
28 30  
... ... @@ -30,8 +32,8 @@ class PLCController(DeviceController):
30 32 return self.sendCommandWithAnswer([{"name":"LIST"}])
31 33  
32 34 def getStatus(self):
33   - return self.sendCommandWithAnswer([{"name":"STATUS"}])
34   -
  35 + s = self.sendCommandWithAnswer([{"name":"STATUS"}])
  36 + return s
35 37 '''
36 38 Value is a string ("on" or "off"), current is a decimal value ("0.231")
37 39 '''
... ...
src/monitoring/tasks.py
... ... @@ -160,6 +160,7 @@ class Monitoring(Task):
160 160 def extractFromDict(self, status):
161 161 synthesis = {}
162 162 devices = status["device"]
  163 + #print(devices)
163 164 #is_safe_str = status["is_safe"]
164 165 #mode = status["mode"]
165 166 for device in devices:
... ... @@ -170,7 +171,8 @@ class Monitoring(Task):
170 171  
171 172 # TODO ATTENTION SI DEUX DEVICES ONT LE MEME NOM
172 173 def saveContent(self, content):
173   - devices = content["device"]
  174 + devices = content[0]["device"]
  175 +
174 176 for device in devices:
175 177 status = PlcDeviceStatus()
176 178 try:
... ... @@ -192,15 +194,16 @@ class Monitoring(Task):
192 194 def parseStatus(self, status_plc):
193 195 try:
194 196 status = {}
195   - dict = json.loads(status_plc)[0]
196   - if dict["name"] == "STATUS":
  197 + dict = json.loads(status_plc)
  198 + if dict[0]["name"] == "STATUS":
197 199 if self.isStatusValid():
198   - status = self.extractFromDict(dict)
  200 + status = self.extractFromDict(dict[0])
199 201 self.saveContent(dict)
200 202 else:
201 203 # TODO HANDLE ERROR HERE
202 204 pass
203 205 except Exception as e:
  206 +
204 207 if DEBUG_FILE and settings.DEBUG:
205 208 log.info(str(e))
206 209 self.status_plc = {}
... ... @@ -254,15 +257,18 @@ class Monitoring(Task):
254 257 # Reset timer total duration
255 258 self.timers["timer_status"] = self.timer_status
256 259 status_plc = self.plcController.getStatus()
257   -
  260 + #print("status ->" + status_plc)
  261 +
258 262 # Error while READING status ?
259 263 if (self.plcController.isError(status_plc)):
  264 +
260 265 if (settings.DEBUG and DEBUG_FILE):
261 266 log.info("Invalid PLC status returned (while reading) : " + str(status_plc))
262 267 # EP Non car 1 = true
263 268 #return (1)
  269 +
264 270 return False
265   -
  271 +
266 272 # (EP) if parseStatus() = THERE WAS AN ERROR !!!
267 273 # Error while PARSING status ?
268 274 if self.parseStatus(status_plc):
... ... @@ -271,7 +277,6 @@ class Monitoring(Task):
271 277 # EP Non car 1 = true
272 278 #return (1)
273 279 return False
274   -
275 280 print("Status received from PLC (read and parsed ok):")
276 281 print(status_plc)
277 282 #return self.saveStatus()
... ... @@ -284,7 +289,7 @@ class Monitoring(Task):
284 289 Main loop
285 290 '''
286 291 def loop(self):
287   - i=0
  292 + i = 0
288 293 while (self.state != "SHUTDOWN"):
289 294 print("-")
290 295 print("-")
... ...