def cb_initialize_plugin(self): self.block1 = DBlock('Progress') signal = DSignal('percent') self.block1.add_signal(signal) self.block2 = DBlock('Trigger') signal = DSignal('trigger') self.block2.add_signal(signal) self.block3 = DBlock('ResetTrigger') signal = DSignal('reset') self.block3.add_signal(signal) self.block4 = DBlock('ParaToSig') signal = DSignal('parameter') self.block4.add_signal(signal) blockList = [self.block1, self.block2, self.block3, self.block4] self.pl_send_new_block_list(blockList) self.para3 = DParameter('Choose', default=0, Regex='\d+') para_l = [self.para3] self.pl_send_new_parameter_list(para_l) self.pl_set_event_trigger_mode(True) self.initialized = True return True
def test_attach_signal(self): dblock = DBlock('SinMit_f1') ds_1 = DSignal(CORE_TIME_SIGNAL) ds_2 = DSignal('f1_1') dblock.add_signal(ds_1) dblock.add_signal(ds_2) subscription = DSubscription(dblock) self.assertTrue(subscription.add_signal(ds_1)) self.assertIn(ds_1, subscription.get_signals()) self.assertFalse(subscription.add_signal(ds_1))
def cb_initialize_plugin(self): self.t = 0 self.amax = Fourier_Rect_MOD.amax self.amplitude = 1 self.max_approx = Fourier_Rect_MOD.max_approx self.freq = 1 self.vec = numpy.ones(self.amax * (self.max_approx + 1)) print(['Fourier: process id: ', os.getpid()]) self.HOST = "130.149.155.73" self.PORT = 9999 # SOCK_DGRAM is the socket type to use for UDP sockets self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock.setblocking(0) self.block1 = DBlock('Rectangle') for i in range(1, self.max_approx): self.block1.add_signal(DSignal('rect' + str(i))) self.pl_send_new_block_list([self.block1]) self.pl_set_event_trigger_mode(True) self.goOn = True self.thread = threading.Thread(target=self.thread_execute, args=(self.HOST, self.PORT)) self.thread.start() return True
def config_loader_subs(self, pl_to_start, subs_to_make, parameters_to_change, signals_to_change): """ Function for callback when timer finished to apply subscriptions and parameter changed of config. :param pl_to_start: list of plugins to start :type pl_to_start: list :param subs_to_make: list of subscriptions to make :type subs_to_make: list :param parameters_to_change: parameter changes to apply :type parameters_to_change: list :param signals_to_change: signal name changes to apply :type signals_to_change: list :return: """ for sub in subs_to_make: self.do_subscribe_uname(sub[0], sub[1], sub[2], sub[3], sub[4]) for para in parameters_to_change: self.do_set_parameter_uname(para[0], para[1], para[2]) for sig in signals_to_change: plugin_uname = sig[0] dblock_name = sig[1] dsignal_uname = sig[2] dsignal_dname = sig[3] self.do_edit_plugin_uname( plugin_uname, DBlock(dblock_name), {'edit': DSignal(dsignal_uname, dsignal_dname)})
def cb_initialize_plugin(self): self.config = self.pl_get_current_config_ref() self.t = 0 self.amax = Fourier_Rect.amax self.amplitude = 1 self.max_approx = Fourier_Rect.max_approx self.freq = 1 self.vec = numpy.ones(self.amax * (self.max_approx + 1)) print(['Fourier: process id: ', os.getpid()]) self.HOST = self.config['host']['value'] self.PORT = int(self.config['port']['value']) # SOCK_DGRAM is the socket type to use for UDP sockets self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock.setblocking(0) self.block1 = DBlock('Rectangle') for i in range(1, self.max_approx): self.block1.add_signal(DSignal('rect' + str(i))) self.pl_send_new_block_list([self.block1]) return True
def debug_papi(self): config = self.get_cb_plugin_configuration() config['yRange'] = { 'value': '[0.0 50.0]', 'regex': '(\d+\.\d+)', 'advanced': '1', 'display_text': 'y: range' } config['buffersize'] = { 'value': '1000', 'regex': '(\d+\.\d+)', 'advanced': '1', 'display_text': 'y: range' } config['downsampling_rate'] = { 'value': '10', 'regex': '(\d+\.\d+)', 'advanced': '1', 'display_text': 'y: range' } self.config = config self.__id__ = 0 self.cb_initialize_plugin(config) signal_1 = DSignal('signal_1') signal_2 = DSignal('signal_2') signal_3 = DSignal('signal_3') signal_4 = DSignal('signal_4') signal_5 = DSignal('signal_5') self.add_plot_item(signal_1, 1) self.add_plot_item(signal_2, 2) self.add_plot_item(signal_3, 3) self.add_plot_item(signal_4, 4) self.add_plot_item(signal_5, 5) self.update_pens() self.update_legend() pass
def test_remove_signal(self): dblock = DBlock('SinMit_f1') ds_1 = DSignal(CORE_TIME_SIGNAL) dblock.add_signal(ds_1) subscription = DSubscription(dblock) subscription.add_signal(ds_1) self.assertTrue(subscription.rm_signal(ds_1)) self.assertNotIn(ds_1, subscription.get_signals()) self.assertTrue(subscription.add_signal(ds_1))
def __init__(self, name): """ A block is described by name, which has to be unique within the context of the plugin owning this block. :param name: name of the block :return: """ super(DObject, self).__init__() self.subscribers = {} self.dplugin_id = None self.name = name self.signals = [] self.add_signal(DSignal(CORE_TIME_SIGNAL))
def cb_initialize_plugin(self): self.t = 0 #print(['ADD: process id: ',os.getpid()] ) self.approx_max = 300 self.fac = 1 self.amax = 20 self.approx = self.approx_max * self.fac self.block1 = DBlock('AddOut1') signal = DSignal('Sum') self.block1.add_signal(signal) self.pl_send_new_block_list([self.block1]) return True
def update_block_list(self, ORTDSources): #self.block_id = self.block_id +1 #newBlock = DBlock('SourceGroup'+str(self.block_id)) #self.blocks['SourceGroup'+str(self.block_id)] = newBlock if 'SourceGroup0' in self.blocks: self.pl_send_delete_block('SourceGroup0') newBlock = DBlock('SourceGroup0') self.blocks['SourceGroup0'] = newBlock self.Sources = ORTDSources keys = list(self.Sources.keys()) for key in keys: Source = self.Sources[key] sig_name = Source['SourceName'] newBlock.add_signal(DSignal(sig_name)) self.pl_send_new_block_list([newBlock])
def cb_initialize_plugin(self): # -------------------------------- # Step 0: Read documentation: http://tub-control.github.io/PaPI/ # -------------------------------- # -------------------------------- # Step 1: Read configuration items (startup cfg) # OPTIONAL # -------------------------------- # Please read the Documentation of pl_get_config_element() to understand what is happening here. # e.g. a configuration item named 'offset' is read. offset = self.pl_get_config_element('offset') offset = float(offset) if offset is not None else 0 # -------------------------------- # Step 2:Define blocks for output signals and define signals of blocks! # OPTIONAL # -------------------------------- # Here: block called CPU_LOAD with 2 signals for Core1 and Core2 blockLoad = DBlock('CPU_LOAD') sig_core1 = DSignal('Load_C1') sig_core2 = DSignal('Load_C2') blockLoad.add_signal(sig_core1) blockLoad.add_signal(sig_core2) self.pl_send_new_block_list([blockLoad]) # -------------------------------- # Step 3: Define parameter that are offered to PaPI # OPTIONAL # Sub-Step 1: Create Parameter Object # Sub-Step 2: Send list of Parameter Objects created to PaPI # -------------------------------- # use self. to remember the parameter object in this class/context for own usage! # e.g. parameter named parameterName1 is created! # Refer to the Doc of DParameter to read about advanced usages! self.parameter1 = DParameter('parameterName1') self.parameter2 = DParameter('parameterName2') self.pl_send_new_parameter_list([self.parameter1, self.parameter1]) # -------------------------------- # Step 4: Set the plugin trigger mode # OPTIONAL # In most cases for IOP you will leave it default, for DPP you will set it to true # Default will mean, that PaPI will decide on it. # -------------------------------- self.pl_set_event_trigger_mode('default') # -------------------------------- # Step 5: Developer and Plugin specific configuration # OPTIONAL # -------------------------------- # -------------------------------- # Step 6: Return Value # OBLIGATORY # Return True if the everything is alright! # False will lead to PaPI not starting this Plugin! # -------------------------------- return True
def cb_initialize_plugin(self): print('ORTD', self.__id__, ':process id', os.getpid()) self.config = self.pl_get_current_config_ref() # open UDP self.HOST = self.config['address']['value'] self.SOURCE_PORT = int(self.config['source_port']['value']) self.OUT_PORT = int(self.config['out_port']['value']) self.LOCALBIND_HOST = '' # config['source_address']['value'] #CK self.sendOnReceivePort = True if self.config['SendOnReceivePort'][ 'value'] == '1' else False self.UseSocketIO = True if self.config['UseSocketIO'][ 'value'] == '1' else False if self.UseSocketIO: self.SocketIOPort = int(self.config['socketio_port']['value']) #self.sendOnReceivePort = True # NOTE: remove this #self.UseSocketIO = True # NOTE: remove this print("SendOnReceivePort = ", self.sendOnReceivePort) print("UseSocketIO = ", self.UseSocketIO) self.PAPI_SIMULINK_BLOCK = False self.separate = int(self.config['SeparateSignals']['value']) self.onlyInitialConfig = self.config['OnlyInitialConfig'][ 'value'] == '1' self.hasInitialConfig = False if (not self.sendOnReceivePort): # SOCK_DGRAM is the socket type to use for UDP sockets self.sock_parameter = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock_parameter.setblocking(1) self.ControlBlock = DBlock('ControllerSignals') self.ControlBlock.add_signal(DSignal('ControlSignalReset')) self.ControlBlock.add_signal(DSignal('ControlSignalCreate')) self.ControlBlock.add_signal(DSignal('ControlSignalSub')) self.ControlBlock.add_signal(DSignal('ControllerSignalParameter')) self.ControlBlock.add_signal(DSignal('ControllerSignalClose')) self.ControlBlock.add_signal(DSignal('ActiveTab')) self.pl_send_new_block_list([self.ControlBlock]) self.t = 0 self.pl_set_event_trigger_mode(True) self.sock_recv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) if (not self.sendOnReceivePort): self.sock_recv.bind((self.LOCALBIND_HOST, self.SOURCE_PORT)) # CK print("UDP_Plugin-plugin listening on: ", self.LOCALBIND_HOST, ":", self.SOURCE_PORT) #CK else: print("---- Using client UDP mode (not binding to a port) ----") self.sock_recv.settimeout(1) self.thread_goOn = True self.lock = threading.Lock() self.thread = threading.Thread(target=self.thread_execute) self.thread.start() if self.UseSocketIO: print("Using socket.io connection on port", self.SocketIOPort) self.thread_socket_goOn = True self.thread_socketio = threading.Thread( target=self.thread_socketio_execute) self.blocks = {} self.Sources = {} self.parameters = {} self.signal_values = {} self.block_id = 0 self.config_complete = False self.config_buffer = {} self.timer = Timer(3, self.callback_timeout_timer) self.timer_active = False self.ConsoleBlock = DBlock('ConsoleSignals') self.ConsoleBlock.add_signal(DSignal('MainSignal')) self.pl_send_new_block_list([self.ConsoleBlock]) self.consoleIn = DParameter('consoleIn', default='') self.pl_send_new_parameter_list([self.consoleIn]) if self.UseSocketIO: self.thread_socketio.start() return True
def cb_initialize_plugin(self): config = self.pl_get_current_config_ref() self.t = 0 self.amax = int(config['amax']['value']) self.f = float(config['f']['value']) self.block1 = DBlock('SinMit_f1') signal = DSignal('f1_1') signal.dname = 'f1_f1DNAME' self.block1.add_signal(signal) self.block2 = DBlock('SinMit_f2') signal = DSignal('f2_1') self.block2.add_signal(signal) self.block3 = DBlock('SinMit_f3') signal = DSignal('f3_1') self.block3.add_signal(signal) signal = DSignal('f3_2') self.block3.add_signal(signal) signal = DSignal('f3_scalar') self.block3.add_signal(signal) #self.block4 = self.create_new_block('Sin4', [CORE_TIME_SIGNAL,'f3_1','f3_2', 'Scalar'], [ 'numpy_vec', 'numpy_vec', 'numpy_vec', 'int'], 100 ) blockList = [self.block1, self.block2, self.block3] self.pl_send_new_block_list(blockList) self.para3 = DParameter('Frequenz Block SinMit_f3', default= 0.3, Regex='[0-9]+.[0-9]+') para_l = [self.para3] self.pl_send_new_parameter_list(para_l) print('Sinus started working') return True