-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated context manager to read SETO topo areas
- Loading branch information
1 parent
67073c4
commit c10f842
Showing
7 changed files
with
263 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
gridappsd-field-bus-lib/gridappsd/field_interface/context_managers/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import List | ||
|
||
from gridappsd.field_interface.context_managers.context_manager_agents import (SubstationAreaContextManager, | ||
FeederAreaContextManager, | ||
SwitchAreaContextManager, | ||
SecondaryAreaContextManager) | ||
|
||
|
||
__all__: List[str] = ["SubstationAreaContextManager","FeederAreaContextManager","SwitchAreaContextManager","SecondaryAreaContextManager"] |
93 changes: 93 additions & 0 deletions
93
...-field-bus-lib/gridappsd/field_interface/context_managers/centralized_context_managers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import argparse | ||
import logging | ||
import json | ||
import os | ||
import time | ||
from typing import Dict | ||
|
||
|
||
from cimgraph.data_profile import CIM_PROFILE | ||
from gridappsd import GridAPPSD | ||
import gridappsd.topics as t | ||
import gridappsd.field_interface.agents.agents as agents_mod | ||
from gridappsd.field_interface.context_managers.utils import REQUEST_FIELD, get_MessageBusDefinition | ||
from gridappsd.field_interface.context_managers.context_manager_agents import FeederAreaContextManager, SwitchAreaContextManager, SecondaryAreaContextManager | ||
|
||
cim_profile = CIM_PROFILE.RC4_2021.value | ||
agents_mod.set_cim_profile(cim_profile=cim_profile, iec61970_301=7) | ||
cim = agents_mod.cim | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
logging.getLogger('goss').setLevel(logging.ERROR) | ||
logging.getLogger('stomp.py').setLevel(logging.ERROR) | ||
|
||
_log = logging.getLogger(__name__) | ||
|
||
def _main(): | ||
|
||
time.sleep(10) | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--simulation_id", | ||
help="Simulation id to use for communicating with simulated devices on the message bus. \ | ||
If simulation_id is not provided then Context Manager assumes to run on deployed field with real devices.", | ||
required=False) | ||
opts = parser.parse_args() | ||
simulation_id = opts.simulation_id | ||
|
||
agent_config = { | ||
"app_id": | ||
"context_manager", | ||
"description": | ||
"This agent provides topological context information like neighboring agents and devices to other distributed agents" | ||
} | ||
|
||
gapps = GridAPPSD() | ||
response = gapps.get_response(t.PLATFORM_STATUS, {"isField": True}) | ||
field_model_mrid = response['fieldModelMrid'] | ||
|
||
is_field_initialized = False | ||
|
||
while not is_field_initialized: | ||
response = gapps.get_response(REQUEST_FIELD, {"request_type": "is_initilized"}) | ||
print(response) | ||
is_field_initialized = response['data']['initialized'] | ||
time.sleep(1) | ||
|
||
system_message_bus_def = get_MessageBusDefinition(field_model_mrid) | ||
feeder_message_bus_def = get_MessageBusDefinition(field_model_mrid) | ||
|
||
#TODO: create access control for agents for different layers | ||
feeder_agent = FeederAreaContextManager(system_message_bus_def, | ||
feeder_message_bus_def, | ||
agent_config, | ||
simulation_id=simulation_id) | ||
|
||
for switch_area in feeder_agent.agent_area_dict['switch_areas']: | ||
switch_area_message_bus_def = get_MessageBusDefinition(str(switch_area['message_bus_id'])) | ||
print("Creating switch area agent " + str(switch_area['message_bus_id'])) | ||
switch_area_agent = SwitchAreaContextManager(feeder_message_bus_def, | ||
switch_area_message_bus_def, | ||
agent_config, | ||
simulation_id=simulation_id) | ||
|
||
# create secondary area distributed agents | ||
for secondary_area in switch_area['secondary_areas']: | ||
secondary_area_message_bus_def = get_MessageBusDefinition( | ||
str(secondary_area['message_bus_id'])) | ||
print("Creating secondary area agent " + str(secondary_area['message_bus_id'])) | ||
secondary_area_agent = SecondaryAreaContextManager(switch_area_message_bus_def, | ||
secondary_area_message_bus_def, | ||
agent_config, | ||
simulation_id=simulation_id) | ||
|
||
while True: | ||
try: | ||
time.sleep(0.1) | ||
except KeyboardInterrupt: | ||
print("Exiting sample") | ||
break | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
gridappsd-field-bus-lib/gridappsd/field_interface/context_managers/substation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import argparse | ||
import json | ||
import logging | ||
import time | ||
|
||
from cimgraph.data_profile import CIM_PROFILE | ||
|
||
import gridappsd.field_interface.agents.agents as agents_mod | ||
from gridappsd.field_interface.interfaces import MessageBusDefinition | ||
from gridappsd.field_interface.context_managers.context_manager_agents import SubstationAreaContextManager | ||
|
||
|
||
cim_profile = CIM_PROFILE.RC4_2021.value | ||
agents_mod.set_cim_profile(cim_profile=cim_profile, iec61970_301=7) | ||
cim = agents_mod.cim | ||
|
||
logging.basicConfig(level=logging.DEBUG) | ||
logging.getLogger('goss').setLevel(logging.ERROR) | ||
logging.getLogger('stomp.py').setLevel(logging.ERROR) | ||
|
||
_log = logging.getLogger(__name__) | ||
|
||
def _main(): | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--simulation_id", | ||
help="Simulation id to use for communicating with simulated devices on the message bus. \ | ||
If simulation_id is not provided then Context Manager assumes to run on deployed field with real devices.", | ||
required=False) | ||
parser.add_argument( | ||
"--system_message_bus", | ||
help="Yaml file to connect with upstream system(OT) message bus.", | ||
required=True) | ||
|
||
parser.add_argument( | ||
"--substation_message_bus", | ||
help="Yaml file to connect with downstream substation area message bus.", | ||
required=True) | ||
|
||
parser.add_argument( | ||
"--substation_dict", | ||
help="JSON file containing substation topology dictionary. If this file is not provided then disctionary is requested by Field Bus Manager using upstream message bus.", | ||
required=False) | ||
|
||
opts = parser.parse_args() | ||
simulation_id = opts.simulation_id | ||
|
||
agent_config = { | ||
"app_id": | ||
"context_manager", | ||
"description": | ||
"This agent provides topological context information like neighboring agents and devices to other distributed agents" | ||
} | ||
|
||
|
||
system_message_bus_def = MessageBusDefinition.load(opts.system_message_bus) | ||
substation_message_bus_def = MessageBusDefinition.load(opts.substation_message_bus) | ||
|
||
with open(opts.substation_dict,encoding="utf-8") as f: | ||
substation_dict = json.load(f) | ||
|
||
substation_agent = SubstationAreaContextManager(system_message_bus_def, | ||
substation_message_bus_def, | ||
agent_config, | ||
substation_dict = substation_dict, | ||
simulation_id=simulation_id) | ||
|
||
while True: | ||
try: | ||
time.sleep(0.1) | ||
except KeyboardInterrupt: | ||
print("Exiting sample") | ||
break | ||
|
||
|
||
if __name__ == "__main__": | ||
_main() |
Oops, something went wrong.