@@ -120,6 +120,11 @@ def _create_model(self):
120120 dict [Neosoco .OUTPUT_1 ] = self ._output_1_device = self ._add_device (Neosoco .OUTPUT_1 , "Output1" , DeviceType .EFFECTOR , DataType .INTEGER , 1 , 0 , 255 , 0 )
121121 dict [Neosoco .OUTPUT_2 ] = self ._output_2_device = self ._add_device (Neosoco .OUTPUT_2 , "Output2" , DeviceType .EFFECTOR , DataType .INTEGER , 1 , 0 , 255 , 0 )
122122 dict [Neosoco .OUTPUT_3 ] = self ._output_3_device = self ._add_device (Neosoco .OUTPUT_3 , "Output3" , DeviceType .EFFECTOR , DataType .INTEGER , 1 , 0 , 255 , 0 )
123+ dict [Neosoco .INPUT_1 ] = self ._input_1_device = self ._add_device (Neosoco .INPUT_1 , "Input1" , DeviceType .SENSOR , DataType .INTEGER , 1 , 0 , 255 , 0 )
124+ dict [Neosoco .INPUT_2 ] = self ._input_2_device = self ._add_device (Neosoco .INPUT_2 , "Input2" , DeviceType .SENSOR , DataType .INTEGER , 1 , 0 , 255 , 0 )
125+ dict [Neosoco .INPUT_3 ] = self ._input_3_device = self ._add_device (Neosoco .INPUT_3 , "Input3" , DeviceType .SENSOR , DataType .INTEGER , 1 , 0 , 255 , 0 )
126+ dict [Neosoco .REMOCTL ] = self ._remoctl_device = self ._add_device (Neosoco .REMOCTL , "RemoteCtl" , DeviceType .SENSOR , DataType .INTEGER , 1 , 0 , 255 , 0 )
127+ dict [Neosoco .BATTERY ] = self ._battery_device = self ._add_device (Neosoco .BATTERY , "Battery" , DeviceType .SENSOR , DataType .INTEGER , 1 , 0 , 255 , 0 )
123128
124129 def find_device_by_id (self , device_id ):
125130 return self ._device_dict .get (device_id )
@@ -250,150 +255,23 @@ def _encode_motoring_packet(self, address):
250255 return result
251256
252257 def _decode_sensory_packet (self , packet ):
253- packet = str (packet )
254- if self ._model_code == 0x0E :
255- value = int (packet [0 :1 ], 16 )
256- if value != 1 : return False
257- value = int (packet [6 :8 ], 16 )
258- self ._left_proximity_device ._put (value )
259- value = int (packet [8 :10 ], 16 )
260- self ._right_proximity_device ._put (value )
261- value2 = int (packet [38 :40 ], 16 )
262- if (value2 & 0x01 ) == 0 :
263- self ._light = int (packet [10 :14 ], 16 )
264- else :
265- value = int (packet [10 :12 ], 16 )
266- if value > 0x7f : value -= 0x100
267- self ._temperature = Util .round (value / 2.0 + 23 )
268- self ._light_device ._put (self ._light )
269- self ._temperature_device ._put (self ._temperature )
270- value = int (packet [14 :16 ], 16 )
271- self ._left_floor_device ._put (value )
272- value = int (packet [16 :18 ], 16 )
273- self ._right_floor_device ._put (value )
274- acc_x = int (packet [18 :22 ], 16 )
275- if acc_x > 0x7fff : acc_x -= 0x10000
276- self ._acceleration_device ._put_at (0 , acc_x )
277- acc_y = int (packet [22 :26 ], 16 )
278- if acc_y > 0x7fff : acc_y -= 0x10000
279- self ._acceleration_device ._put_at (1 , acc_y )
280- acc_z = int (packet [26 :30 ], 16 )
281- if acc_z > 0x7fff : acc_z -= 0x10000
282- self ._acceleration_device ._put_at (2 , acc_z )
283- if acc_z < 8192 and acc_x > 8192 and acc_y > - 4096 and acc_y < 4096 : value = 1
284- elif acc_z < 8192 and acc_x < - 8192 and acc_y > - 4096 and acc_y < 4096 : value = - 1
285- elif acc_z < 8192 and acc_y > 8192 and acc_x > - 4096 and acc_x < 4096 : value = 2
286- elif acc_z < 8192 and acc_y < - 8192 and acc_x > - 4096 and acc_x < 4096 : value = - 2
287- elif acc_z > 12288 and acc_x > - 8192 and acc_x < 8192 and acc_y > - 8192 and acc_y < 8192 : value = 3
288- elif acc_z < - 12288 and acc_x > - 4096 and acc_x < 4096 and acc_y > - 4096 and acc_y < 4096 : value = - 3
289- else : value = 0
290- if value != self ._event_tilt :
291- self ._tilt_device ._put (value , self ._event_tilt != - 4 )
292- self ._event_tilt = value
293- value = int (packet [30 :32 ], 16 )
294- self ._input_a_device ._put (value )
295- value = int (packet [32 :34 ], 16 )
296- self ._input_b_device ._put (value )
297- value = int (packet [36 :38 ], 16 )
298- value -= 0x100
299- self ._signal_strength_device ._put (value )
300- value = (value2 >> 6 ) & 0x03
301- if (value & 0x02 ) != 0 :
302- if self ._line_tracer_event == 1 :
303- if value == 0x02 :
304- self ._line_tracer_count += 1
305- if self ._line_tracer_count > 5 : self ._line_tracer_event = 2
306- else :
307- self ._line_tracer_event = 2
308- if self ._line_tracer_event == 2 :
309- if value != self ._line_tracer_state or self ._line_tracer_count > 5 :
310- self ._line_tracer_state = value
311- self ._line_tracer_state_device ._put (value << 5 )
312- if value == 0x02 :
313- self ._line_tracer_event = 0
314- self ._line_tracer_count = 0
315- value = (value2 >> 1 ) & 0x03
316- if value == 0 : value = 2
317- elif value >= 2 : value = 0
318- if value != self ._event_battery_state :
319- self ._battery_state_device ._put (value , self ._event_battery_state != - 1 )
320- self ._event_battery_state = value
321- else :
322- value = int (packet [4 :5 ], 16 )
323- if value != 1 : return False
324- value = int (packet [6 :8 ], 16 )
325- value -= 0x100
326- self ._signal_strength_device ._put (value )
327- value = int (packet [8 :10 ], 16 )
328- self ._left_proximity_device ._put (value )
329- value = int (packet [10 :12 ], 16 )
330- self ._right_proximity_device ._put (value )
331- value = int (packet [12 :14 ], 16 )
332- self ._left_floor_device ._put (value )
333- value = int (packet [14 :16 ], 16 )
334- self ._right_floor_device ._put (value )
335- acc_x = int (packet [16 :20 ], 16 )
336- if acc_x > 0x7fff : acc_x -= 0x10000
337- self ._acceleration_device ._put_at (0 , acc_x )
338- acc_y = int (packet [20 :24 ], 16 )
339- if acc_y > 0x7fff : acc_y -= 0x10000
340- self ._acceleration_device ._put_at (1 , acc_y )
341- acc_z = int (packet [24 :28 ], 16 )
342- if acc_z > 0x7fff : acc_z -= 0x10000
343- self ._acceleration_device ._put_at (2 , acc_z )
344- if acc_z < 8192 and acc_x > 8192 and acc_y > - 4096 and acc_y < 4096 : value = 1
345- elif acc_z < 8192 and acc_x < - 8192 and acc_y > - 4096 and acc_y < 4096 : value = - 1
346- elif acc_z < 8192 and acc_y > 8192 and acc_x > - 4096 and acc_x < 4096 : value = 2
347- elif acc_z < 8192 and acc_y < - 8192 and acc_x > - 4096 and acc_x < 4096 : value = - 2
348- elif acc_z > 12288 and acc_x > - 8192 and acc_x < 8192 and acc_y > - 8192 and acc_y < 8192 : value = 3
349- elif acc_z < - 12288 and acc_x > - 4096 and acc_x < 4096 and acc_y > - 4096 and acc_y < 4096 : value = - 3
350- else : value = 0
351- if value != self ._event_tilt :
352- self ._tilt_device ._put (value , self ._event_tilt != - 4 )
353- self ._event_tilt = value
354- value = int (packet [28 :30 ], 16 )
355- if value == 0 :
356- self ._light = int (packet [30 :34 ], 16 )
357- else :
358- value = int (packet [30 :32 ], 16 )
359- if value > 0x7f : value -= 0x100
360- self ._temperature = Util .round (value / 2.0 + 24 )
361- value = (int (packet [32 :34 ], 16 ) + 200 ) / 100.0
362- if value < 3.6 : value = 0
363- elif value <= 3.7 : value = 1
364- else : value = 2
365- if value != self ._event_battery_state :
366- self ._battery_state_device ._put (value , self ._event_battery_state != - 1 )
367- self ._event_battery_state = value
368- self ._light_device ._put (self ._light )
369- self ._temperature_device ._put (self ._temperature )
370- value = int (packet [34 :36 ], 16 )
371- self ._input_a_device ._put (value )
372- value = int (packet [36 :38 ], 16 )
373- self ._input_b_device ._put (value )
374- value = int (packet [38 :40 ], 16 )
375- if (value & 0x40 ) != 0 :
376- if self ._line_tracer_event == 1 :
377- if value != 0x40 :
378- self ._line_tracer_event = 2
379- if self ._line_tracer_event == 2 :
380- if value != self ._line_tracer_state :
381- self ._line_tracer_state = value
382- self ._line_tracer_state_device ._put (value )
383- if value == 0x40 :
384- self ._line_tracer_event = 0
258+ self ._input_1_device ._put (packet [2 ])
259+ self ._input_2_device ._put (packet [3 ])
260+ self ._input_3_device ._put (packet [4 ])
261+ self ._remoctl_device ._put (packet [5 ])
262+ self ._battery_device ._put (packet [6 ])
385263 return True
386264
387265 def _receive (self , connector ):
388266 if connector :
389267 packet = connector .read ()
390268 if packet :
391- # if self._decode_sensory_packet(packet): # Temporary blocking
269+ if self ._decode_sensory_packet (packet ):
392270 if self ._ready == False :
393271 self ._ready = True
394272 Runner .register_checked ()
395273 self ._notify_sensory_device_data_changed ()
396- return True
274+ return True
397275 return False
398276
399277 def _send (self , connector ):
0 commit comments