from andes_addon.dime import Dime dimec = Dime('ISLANDING', 'tcp://192.168.1.200:5000') dimec.start() event = {'id': [143, 146, 135], 'name': ['Line', 'Line', 'Line'], 'time': [-1, -1, -1], 'duration': [0, 0, 0], 'action': [0, 0, 0] } dimec.send_var('sim', 'Event', event) dimec.exit()
class MiniPDC(object): """A MiniPDC connecting to multiple PMUs and a DiME server """ def __init__(self, name, dime_address, ip_list, port_list=None, loglevel=logging.INFO): self._name = name self._dime_address = dime_address self._loglevel = loglevel self.dimec = Dime(name, dime_address) self.ip_list = ip_list self.port_list = port_list # not being used now # check if the lengths of `ip_list` and `port_list` match self.pdc = {} self.header = {} self.config = {} self.last_var = None # state flags self.andes_online = False # self.pdc_started = False @property def npmu(self): return len(self.ip_list) def initialize(self): """ Reset or initialize, it is the same thing Returns ------- """ pass def sync_and_handle(self): """ Sync from DiME and handle the received data """ self.last_var = self.dimec.sync() val = None if self.last_var not in (None, False): val = self.dimec.workspace[self.last_var] else: return if self.last_var == 'DONE' and int(val) == 1: self.andes_online = False self.initialize() pass return self.last_var def start_dime(self): logger.info('Connecting to DiME at {}'.format(self._dime_address)) self.dimec.start() try: self.dimec.exit() except: pass self.dimec.start() logger.info('DiME connected') 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') def get_header_config(self): for idx, item in self.pdc.items(): # each item is a PDC item.run() # Connect to PMU self.header[idx] = item.get_header() self.config[idx] = item.get_config() for idx, item in self.pdc.items(): # each item is a PDC item.start() # Request to start sending measurements self.pdc_started = True logger.info('PMU Header and ConfigFrame received') def collect_data(self): pass def process_data(self): pass def run(self): pass