Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ ENV/

# pytest cache
.pytest_cache
/gridappsd-python.code-workspace
9 changes: 7 additions & 2 deletions gridappsd-field-bus-lib/gridappsd_field_bus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
from gridappsd_field_bus.field_interface.interfaces import FieldMessageBus
from gridappsd_field_bus.field_interface.interfaces import MessageBusDefinition
from gridappsd_field_bus.field_interface.interfaces import (
MessageBusDefinitions,
MessageBusDefinition,
FieldMessageBus,
FieldProtocol,
DeviceFieldInterface
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def get_message_bus_definition(area_id: str) -> MessageBusDefinition:
bus = MessageBusDefinition(id=area_id,
is_ot_bus=True,
connection_type="GRIDAPPSD_TYPE_GRIDAPPSD",
conneciton_args=connection_args)
connection_args=connection_args)

return bus
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

REQUEST_FIELD = ".".join((topics.PROCESS_PREFIX, "request.field"))

class FieldListener():
class FieldListener:

def __init__(self, ot_connection: GridAPPSD, proxy_connection: stomp.Connection):
self.ot_connection = ot_connection
Expand Down Expand Up @@ -37,7 +37,7 @@ def on_message(self, headers, message):
except Exception as e:
print(f"Error processing message: {e}")

class FieldProxyForwarder():
class FieldProxyForwarder:
"""
FieldProxyForwarder acts as a bridge between field bus and OT bus
when direct connection is not possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def __init__(self, definition: MessageBusDefinition):
super(GridAPPSDMessageBus, self).__init__(definition)
self._id = definition.id

self._user = definition.conneciton_args["GRIDAPPSD_USER"]
self._password = definition.conneciton_args["GRIDAPPSD_PASSWORD"]
self._address = definition.conneciton_args["GRIDAPPSD_ADDRESS"]
self._user = definition.connection_args["GRIDAPPSD_USER"]
self._password = definition.connection_args["GRIDAPPSD_PASSWORD"]
self._address = definition.connection_args["GRIDAPPSD_ADDRESS"]

self.gridappsd_obj = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
from os import PathLike
from pathlib import Path
from typing import Dict, List, Optional, Union
from typing import Dict, List, Optional, Union, Any

import yaml

Expand All @@ -31,6 +31,7 @@ class ConnectionType(Enum):
# CONNECTION_TYPE_WS = "WS"
# CONNECTION_TYPE_HTTP = "HTTP"
# CONNECTION_TYPE_TCP = "TCP"
CONNECTION_TYPE = "STOMP"
CONNECTION_TYPE_GRIDAPPSD = "CONNECTION_TYPE_GRIDAPPSD"


Expand Down Expand Up @@ -79,38 +80,40 @@ class MessageBusDefinition:
"""
connection_args allows dynamic key/value paired strings to be added to allow connections.
"""
conneciton_args: Dict[str, str]
connection_args: Dict[str, str | int]

"""
Determines whether or not this message bus has the role of ot bus.
"""
is_ot_bus: bool = False

@staticmethod
def load(config_file) -> MessageBusDefinition:
"""

"""
config = yaml.load(open(config_file), Loader=yaml.FullLoader)['connections']

def __validate_loader__(json_obj: dict[str, Any]) -> bool:
required = ["id", "connection_type", "connection_args"]
for k in required:
if k not in config:
if k not in json_obj:
raise ValueError(f"Missing keys for connection {k}")

definition = MessageBusDefinition(config[required[0]], config[required[1]],
config[required[2]])
for k in config:
if k == "connection_args":
definition.conneciton_args = dict()
for k1, v1 in config[k].items():
definition.conneciton_args[k1] = v1
else:
setattr(definition, k, config[k])
return True

@staticmethod
def load_from_json(json_obj: dict[str, str | dict]) -> MessageBusDefinition:
MessageBusDefinition.__validate_loader__(json_obj)

mb_def = MessageBusDefinition(**json_obj)
if not hasattr(mb_def, "is_ot_bus"):
setattr(mb_def, "is_ot_bus", False)

if not hasattr(definition, "is_ot_bus"):
setattr(definition, "is_ot_bus", False)
return mb_def

@staticmethod
def load(config_file) -> MessageBusDefinition:
"""
Load a single message bus definition from a YAML file.
"""
config = yaml.load(open(config_file), Loader=yaml.FullLoader)['connections']

return definition
return MessageBusDefinition.load_from_json(config)


class FieldMessageBus:
Expand Down
28 changes: 28 additions & 0 deletions gridappsd-field-bus-lib/gridappsd_field_bus/forwarder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import time

import click
import yaml
import os

from gridappsd_field_bus import MessageBusDefinition
from gridappsd_field_bus.field_interface.field_proxy_forwarder import FieldProxyForwarder


@click.command()
@click.option('--username', required=True, help='Username for the connection.')
@click.option('--password', required=True, help='Password for the connection.')
@click.option('--connection_url', required=True, help='Connection URL.')
def start_forwarder(username, password, connection_url):
"""Start the field proxy forwarder with either a YAML configuration or cmd-line arguments."""

# Use command-line arguments
click.echo(f"Using command line arguments: {username}, {password}, {connection_url}")

proxy_forwarder = FieldProxyForwarder(username, password, connection_url)

time.sleep(0.1)



if __name__ == '__main__':
start_forwarder()
11 changes: 7 additions & 4 deletions gridappsd-field-bus-lib/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ packages = [
{ include = 'gridappsd_field_bus'}
]

[tool.poetry.scripts]
# Add things in the form
# myscript = 'my_package:main'
context_manager = 'gridappsd.field_interface.context_manager:_main'

[tool.poetry.dependencies]
python = ">=3.10,<4.0"
gridappsd-python = { path="../gridappsd-python-lib", develop = true}
cim-graph = ">=0.1.1a0"
click = "^8.1.8"

[tool.poetry.scripts]
# Add things in the form
# myscript = 'my_package:main'
start-field-bus-forwarder = 'gridappsd_field_bus.forwarder:start_forwarder'
context_manager = 'gridappsd_field_bus.field_interface.context_managers.centralized_context_managers:_main'

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.4"
Expand Down
Loading
Loading