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)
def pmuThread(pmuID, pmu_ip, port, buffer_size, setTS): pmu = Pmu(pmu_id=int(pmuID), port=int(port), ip=pmu_ip, buffer_size=int(buffer_size), set_timestamp=setTS) # pmu.logger.setLevel("DEBUG") pmu.set_configuration( cybergridCfg ) # This will load PMU configuration specified in IEEE C37.118.2 -Annex D (Table D.2) pmu.set_header() phaseAng1 = 0 phaseAng2 = 2.09439 phaseAng3 = -2.09439 pmu.run() # PMU starts listening for incoming connections while True: try: if pmu.clients: # Check if there is any connected PDCs sleep(1 / pmu.cfg2.get_data_rate()) cybergrid_data_sample.set_phasors([(120.0, phaseAng1), (120.0, phaseAng2), (120.0, phaseAng3)]) # pmu.send_data(phasors=[(120.0, 3.14), # (120.0, 3.14), # (120.0, 3.14)], # analog=[9.91], # 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()
60, # Nominal frequency 1, # Configuration change count 240) # Rate of phasor data transmission) hf = HeaderFrame( 7, # PMU_ID "Hello I'm nanoPMU!") # Header Message df = DataFrame( 7, # PMU_ID ("ok", True, "timestamp", False, False, False, 0, "<10", 0), # STAT WORD - Check DataFrame set_stat() [(14635, 0), (-7318, -12676), (-7318, 12675), (1092, 0)], # PHASORS (3 - v, 1 - i) 2500, # Frequency deviation from nominal in mHz 0, # Rate of Change of Frequency [100, 1000, 10000], # Analog Values [0x3c12], # Digital status word cfg) # Data Stream Configuration pmu.set_configuration(cfg) pmu.set_header(hf) pmu.run() while True: if pmu.clients: pmu.send(df) pmu.join()
from synchrophasor.pmu import Pmu """ tinyPMU will listen on ip:port for incoming connections. When tinyPMU receives command to start sending measurements - fixed (sample) measurement will be sent. """ if __name__ == "__main__": pmu = Pmu(ip="127.0.0.1", port=1410) pmu.logger.setLevel("DEBUG") pmu.set_configuration( ) # This will load default PMU configuration specified in IEEE C37.118.2 - Annex D (Table D.2) pmu.set_header( ) # This will load default header message "Hello I'm tinyPMU!" pmu.run() # PMU starts listening for incoming connections while True: if pmu.clients: # Check if there is any connected PDCs pmu.send( pmu.ieee_data_sample ) # Sending sample data frame specified in IEEE C37.118.2 - Annex D (Table D.1) pmu.join()
1, # Configuration change count 240) # Rate of phasor data transmission) hf = HeaderFrame(7, # PMU_ID "This is the test program") # Header Message pmu.set_configuration(cfg) pmu.set_header(hf) pmu.run() sock = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP sock.bind((SIMULINK_UDP_IP, SIMULINK_UDP_PORT)) while True: data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes parsData = struct.unpack('45d', data) df = DataFrame(int(parsData[0]), # PMU_ID ('ok', True, 'timestamp', False, False, False, 0, '<10', 0), # STAT WORD - Check DataFrame set_stat() [(parsData[3], parsData[4]), (parsData[5], parsData[6]), (parsData[7], parsData[8]), (parsData[9], 0),(parsData[11], 0), (parsData[13], 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0),(0, parsData[28]), (0,parsData[30]), (0,parsData[32]), (0, 0), (0, 0), (0, 0), (0, 0), (0, 0),(0, 0)], # PHASORS (3 - v, 1 - i) int(parsData[2]), # Frequency deviation from nominal in mHz 0, # Rate of Change of Frequency [100, 1000, 10000], # Analog Values [0x3c12], # Digital status word 0x0006) # Data Format pmu.send(df) # pmu.join()
""" tinyPMU will listen on ip:port for incoming connections. When tinyPMU receives command to start sending measurements - fixed (sample) measurement will be sent. """ from synchrophasor.pmu import Pmu from multiprocessing import Process import socket import sys if __name__ == "__main__": pmu = Pmu(ip="127.0.0.3", port=1410) pmu.logger.setLevel("DEBUG") pmu.set_configuration() # This will load default PMU configuration specified in IEEE C37.118.2 - Annex D (Table D.2) pmu.set_header() # This will load default header message "Hello I'm tinyPMU!" pmu.run() # PMU starts listening for incoming connections while True: if pmu.clients: # Check if there is any connected PDCs pmu.send(pmu.ieee_data_sample) # Sending sample data frame specified in IEEE C37.118.2 - Annex D (Table D.1) pmu.join()