def __init__(self, source_ip, source_port, listen_ip, listen_port, pdc_id=1, method="tcp", buffer_size=2048): self.pdc = Pdc(pdc_id, source_ip, source_port, buffer_size, method) self.pmu = Pmu(ip=listen_ip, port=listen_port, method=method, buffer_size=buffer_size, set_timestamp=False) self.source_cfg1 = None self.source_cfg2 = None self.source_cfg3 = None self.source_header = None
def __init__(self, source_ip, source_port, listen_ip, listen_port, pdc_id=1, method='tcp', buffer_size=2048): self.pdc = Pdc(pdc_id, source_ip, source_port, buffer_size, method) self.pmu = Pmu(ip=listen_ip, port=listen_port, method=method, buffer_size=buffer_size) self.source_cfg1 = None self.source_cfg2 = None self.source_cfg3 = None self.source_header = None
def init_pdc(self): for idx, item in enumerate(self.ip_list): pmu_idx = int(item.split('.')[3]) self.pdc[idx] = Pdc(pdc_id=pmu_idx, pmu_ip=self.ip_list[idx], pmu_port=1410) self.pdc[idx].logger.setLevel("INFO") logger.info('PDC initialized')
class StreamSplitter(object): def __init__(self, source_ip, source_port, listen_ip, listen_port, pdc_id=1, method="tcp", buffer_size=2048): self.pdc = Pdc(pdc_id, source_ip, source_port, buffer_size, method) self.pmu = Pmu(ip=listen_ip, port=listen_port, method=method, buffer_size=buffer_size, set_timestamp=False) self.source_cfg1 = None self.source_cfg2 = None self.source_cfg3 = None self.source_header = None def run(self): self.pdc.run() self.source_header = self.pdc.get_header() self.source_cfg2 = self.pdc.get_config() self.pdc.start() self.pmu.run() self.pmu.set_header(self.source_header) self.pmu.set_configuration(self.source_cfg2) while True: message = self.pdc.get() if self.pmu.clients and message: self.pmu.send(message) if isinstance(message, HeaderFrame): self.pmu.set_header(message) elif isinstance(message, ConfigFrame2): self.pmu.set_configuration(message)
class StreamSplitter(object): def __init__(self, source_ip, source_port, listen_ip, listen_port, pdc_id=1, method="tcp", buffer_size=2048): self.pdc = Pdc(pdc_id, source_ip, source_port, buffer_size, method) self.pmu = Pmu(ip=listen_ip, port=listen_port, method=method, buffer_size=buffer_size, set_timestamp=False) self.source_cfg1 = None self.source_cfg2 = None self.source_cfg3 = None self.source_header = None def run(self): self.pdc.run() self.source_header = self.pdc.get_header() self.source_cfg2 = self.pdc.get_config() self.pdc.start() self.pmu.run() self.pmu.set_header(self.source_header) self.pmu.set_configuration(self.source_cfg2) while True: message = self.pdc.get() if self.pmu.clients and message: self.pmu.send(message) if isinstance(message, HeaderFrame): self.pmu.set_header(message) elif isinstance(message, ConfigFrame2): self.pmu.set_configuration(message)
arguments = argument_parser.parse_args() # Receive ideal number of measurements in 60s. measurements2receive = 60 * arguments.data_rate timestamp = datetime.now().strftime("%Y%m%d_%H-%M-%S") errors = 0 print( "Running PDC(s) on {:d} separate thread(s) waiting for {:d} measurements with expected" " data rate of {:d} measurements per second.\n".format( arguments.jobs, measurements2receive, arguments.data_rate)) sleep(2) pdc = Pdc(pdc_id=arguments.id, pmu_ip=arguments.ip, pmu_port=arguments.port, buffer_size=arguments.buffer, method=arguments.method) pdc.logger.setLevel(arguments.log_level) pdc.run() # Connect to PMU header = pdc.get_header() # Get header message from PMU config = pdc.get_config() # Get configuration from PMU # Create result folder if not os.path.exists("results/" + str(arguments.data_rate)): os.makedirs("results/" + str(arguments.data_rate)) log = "./results/{:d}/result_j{:d}_id_{:d}_{:s}.log".format( arguments.data_rate, arguments.jobs, arguments.id, timestamp)
# digital=[0x0001]) pmu.send( cybergrid_data_sample ) # Sending sample data frame specified in IEEE C37.118.2 - Annex D (Table D.1) phaseAng1 = phaseIncrem(phaseAng1) phaseAng2 = phaseIncrem(phaseAng2) phaseAng3 = phaseIncrem(phaseAng3) except EnvironmentError as e: print(e) sys.exit() pmu.join() if exec_type == "PDC": pdc = Pdc(pdc_id=int(pmuID), pmu_ip=pmu_ip, pmu_port=int(port)) pdc.logger.setLevel("DEBUG") pdc.run() # Connect to PMU try: header = pdc.get_header() # Get header message from PMU config = pdc.get_config() # Get configuration from PMU except BrokenPipeError as e: pdc.quit() sys.exit() pdc.start() # Request to start sending measurements while True: data = pdc.get() # Keep receiving data
for x in range(5): ip = str(IPv4Address('127.0.1.10') + x) idd = 2 + x print(ip) #127.0.1.10", port=1420 #pdc(x) = Pdc(pdc_id=7, pmu_ip=ip, pmu_port=4712) #pdc1 = Pdc(pdc_id=7, pmu_ip="127.0.0.4", pmu_port=4712) # pdc.logger.setLevel("DEBUG") # pdc1.logger.setLevel("DEBUG") n = os.fork() if n == 0: print("Child process : ", os.getpid()) pdc = Pdc(pdc_id=idd, pmu_ip=ip, pmu_port=1420) pdc.logger.setLevel("DEBUG") pdc.run() header = pdc.get_header() config = pdc.get_config() pdc.start() while True: data = pdc.get() if type(data) == DataFrame: print(data.get_measurements()) if not data: pdc.quit() break else:
from multiprocessing import Process, Pipe, Queue iplist = [] iplist.append('127.0.0.1') iplist.append('127.0.0.2') iplist.append('127.0.0.3') iplist.append('127.0.0.4') iplist.append('127.0.0.5') iplist.append('127.0.0.6') iplist.append('127.0.0.7') iplist.append('127.0.0.8') pmunumber = 8 if __name__ == "__main__": pdc1 = Pdc(pdc_id=7, pmu_ip=iplist[0], pmu_port=1410) pdc2 = Pdc(pdc_id=7, pmu_ip=iplist[1], pmu_port=1410) pdc3 = Pdc(pdc_id=7, pmu_ip=iplist[2], pmu_port=1410) # pdc4 = Pdc(pdc_id=7, pmu_ip=iplist[3], pmu_port=1410) pdc1.logger.setLevel("DEBUG") pdc2.logger.setLevel("DEBUG") pdc3.logger.setLevel("DEBUG") # pdc4.logger.setLevel("DEBUG") pdc1.run() # Connect to PMU pdc2.run() # Connect to PMU pdc3.run() # Connect to PMU # pdc4.run() # Connect to PMU header = pdc1.get_header() # Get header message from PMU
from synchrophasor.pdc import Pdc """ tinyPDC will connect to pmu_ip:pmu_port and send request for header message, configuration and eventually to start sending measurements. ONLY FOR TCP """ pdc = Pdc(pdc_id=7, pmu_ip='127.0.0.1', pmu_port=4712) pdc.run() # Connect to PMU header = pdc.get_header() # Get header message from PMU config = pdc.get_config() # Get configuration from PMU pdc.start() # Request to start sending measurements while True: data = pdc.get() # Keep receiving data if not data: pdc.quit() # Close connection break
def pdcThread(pmuID, pmu_ip, port, buffSize): pdc = Pdc(pdc_id=int(pmuID), pmu_ip=pmu_ip, pmu_port=int(port), buffer_size=buffSize) # pdc.logger.setLevel("DEBUG") pdc.run() # Connect to PMU dt_buffer = list() try: header = pdc.get_header() # Get header message from PMU config = pdc.get_config() # Get configuration from PMU except BrokenPipeError as e: pdc.quit() sys.exit() pdc.start() # Request to start sending measurements while True: data = pdc.get() # Keep receiving data if data is None: data = pdc.get() # Try again receiving data if type(data) == DataFrame: outData = data.get_measurements() yield outData if not data: pdc.quit() # Close connection break
from synchrophasor.pdc import Pdc from synchrophasor.frame import DataFrame """ tinyPDC will connect to pmu_ip:pmu_port and send request for header message, configuration and eventually to start sending measurements. """ if __name__ == "__main__": pdc = Pdc(pdc_id=1, pmu_ip="192.168.137.79", pmu_port=4712) pdc.logger.setLevel("DEBUG") pdc.run() # Connect to PMU # header = pdc.get_header() # Get header message from PMU config = pdc.get_config() # Get configuration from PMU pdc.start() # Request to start sending measurements while True: data = pdc.get() # Keep receiving data if type(data) == DataFrame: print(data.get_measurements()) if not data: pdc.quit() # Close connection