def add_card(self,net_msg): c_dir = net_msg.params[0] b_dir = net_msg.params[1] type = net_msg.params[2] ret_msg = NetMsg() channels = self.rt_core.channels ch_key = "Bus_%d" % b_dir if not type in Bus.supported_card_types: ret_msg.error_code = -1 ret_msg.error_msg = 'El tipo de targeta %s no existe ' % type return ret_msg if not ch_key in channels: try : ch = Bus(b_dir,True) except ChannelException, e: e.log(self.logger_instance) ret_msg.error_code = -1 ret_msg.error_msg = 'Error: el canal %d no pudo ser creado' % b_dir return ret_msg self.rt_core.add_channel(ch,False) ch.start()
def test(self): real_time_core = RealTimeCore.get_instance() # Modo simulacion channel_0 = Bus(0,False) # channel_1 = Bus(1,True) channel_0.add_card(Digital(channel_0.channel_id,2)) # channel_0.add_card(2,'Digital') # channel_0.add_card(6,'Digital') # channel_0.add_card(16,'Digital') # channel_0.add_card(33,'Analogic') # channel_0.add_card(40,'Analogic') # channel_0.add_card(56,'Analogic') # channel_0.add_card(120,'Analogic') # channel_1.add_card(0,'Digital') # channel_1.add_card(2,'Digital') # channel_1.add_card(6,'Digital') # channel_1.add_card(16,'Digital') # channel_1.add_card(33,'Analogic') # channel_1.add_card(40,'Analogic') # channel_1.add_card(56,'Analogic') # channel_1.add_card(120,'Analogic') channel_0.test_cards_speeds() # channel_1.test_cards_speeds() try : real_time_core.add_channel(channel_0,True) except DomoticaException, e: e.log()
def test_save(): d = Domotica() # Modo simulacion channel_0 = Bus(0,False) channel_0.add_card(Digital(channel_0.channel_id,2)) channel_0.test_cards_speeds() try : d.RTCore.add_channel(channel_0,True) except DomoticaException, e: e.log() boolean = BooleanEvent(None,'Bus_0_I_02_01') boolean_2 = BooleanEvent(None,'Bus_0_O_02_01',reverse=True) comp = CompositeEvent(None,'%d and %d',[boolean,boolean_2],None,False) comp.name = 'Se detecto movimiento' comp.pause_delta = timedelta(seconds=5) comp.paused_mode = True #prendo este led action = SetterAction(None,['Bus_0_O_02_01'],SetterAction.MODE_SET) action.name = 'Prender luces' d.RTCore.map_event(comp,action) boolean = BooleanEvent(None,'Bus_0_I_02_01',reverse=True) timer = TimerEvent(None,None,timedelta(seconds=5),None) timer.name = 'Timer de 15 segundos sin movimiento' reset_condition = Template('not $%s' % boolean.get_event_id()) comp = CompositeEvent(None,'%d and %d',[boolean,timer],True,reset_condition) comp.name = 'Hace 15 segundos que no hay movimiento' out_ports = ['Bus_0_O_02_01'] action = SetterAction(None,out_ports,SetterAction.MODE_CLEAR) action.name = 'Apagar luces' d.RTCore.map_event(comp,action) d.RTCore.start_executer() time.sleep(2) d.RTCore.start_listener() raw_input("Presiones una tecla para termiar el programa") #real_time_core.stop_channel(channel_0.channel_id) d.RTCore.shutdown() try: d.conf.save_configuration(d.RTCore) except ConfiguratorException, e: e.log(self.logger_instance)
def test_dump(self): real_time_core = RealTimeCore.get_instance() channel_0 = Bus(0,False) channel_1 = Bus(1,True) channel_0.add_card(Digital(channel_0.channel_id,2)) channel_0.add_card(Digital(channel_0.channel_id,4)) channel_0.add_card(Digital(channel_0.channel_id,6)) channel_1.add_card(Digital(channel_1.channel_id,2)) channel_1.add_card(Digital(channel_1.channel_id,2)) channel_1.add_card(Digital(channel_1.channel_id,6)) real_time_core.add_channel(channel_0,False) real_time_core.add_channel(channel_1,False) # ------------------------------------------------- boolean = BooleanEvent('Bus_0_I_02_00') boolean_2 = BooleanEvent('Bus_0_O_02_00',reverse=True) comp = CompositeEvent('%d and %d',[boolean,boolean_2],False) comp.name = 'Se detecto movimiento' comp.pause_delta = timedelta(seconds=5) comp.paused_mode = True #prendo este led action = SetterAction(['Bus_0_O_02_00'],SetterAction.MODE_SET) action.name = 'Prender luces' real_time_core.map_event(comp,action) # ------------------------------------------------- boolean = BooleanEvent('Bus_0_I_02_01') boolean_2 = BooleanEvent('Bus_0_O_02_01',reverse=True) comp = CompositeEvent('%d and %d',[boolean,boolean_2],False) comp.name = 'Se detecto movimiento' comp.pause_delta = timedelta(seconds=5) comp.paused_mode = True #prendo este led action = SetterAction(['Bus_0_O_02_01'],SetterAction.MODE_SET) action.name = 'Prender luces' real_time_core.map_event(comp,action) # ------------------------------------------------- real_time_core.start_listener() real_time_core.start_executer() time.sleep(10) real_time_core.shutdown() print yaml.dump_all([real_time_core],explicit_start=True)
def search_connected_cards(self,net_msg): channel_number = net_msg.params[0] channel_id = "Bus_%s" % channel_number ret_msg = NetMsg() ret_msg.response = '' ret_msg.error_code = 0 paused = False # print self.rt_core.channels if channel_id in self.rt_core.channels: # print "el channel esta" channel = self.rt_core.channels[channel_id] if not channel.paused : channel.pause() # print "pauso el channel" paused = True ret_msg.response = Bus.search_connected_cards(channel_number) # print "retorno \n%s"% ret_msg.response if paused : channel.resume() return ret_msg
#!/usr/bin/python from channel.bus import Bus from channel.digital import Digital import yaml b = Bus(0,False) b.add_card(Digital(b.channel_id,0)) b.add_card(Digital(b.channel_id,2)) b1 = Bus(1,True) b1.add_card(Digital(b1.channel_id,0)) b1.add_card(Digital(b1.channel_id,0)) b1.add_card(Digital(b1.channel_id,0)) b1.add_card(Digital(b1.channel_id,0)) #print yaml.dump([b,b1]) print "--------------" yaml.dump(yaml.load(yaml.dump([b,b1])))