diff --git a/ems_config b/building_data_management/__init__.py similarity index 100% rename from ems_config rename to building_data_management/__init__.py diff --git a/building_data_management/bdms_main.py b/building_data_management/bdms_main.py new file mode 100644 index 0000000..7171377 --- /dev/null +++ b/building_data_management/bdms_main.py @@ -0,0 +1,15 @@ +from Queue import Queue +from threading import Thread +from ems_config import * +import json + + +class BuildingDataManagementSystem(): + + def __init__(self): + """ + Initialize ClusteringManagementSystem object. + Read messages from the BMS interface bubble messages through a Queue + + """ + pass diff --git a/cms/__init__.py b/cms/__init__.py deleted file mode 100644 index ad56d4f..0000000 --- a/cms/__init__.py +++ /dev/null @@ -1,10 +0,0 @@ - -class ClusteringManagementSystem: - """ - Description and how to use it - """ - - def __init__(self): - """ - Initialize ClusteringManagementSystem object. - """ diff --git a/cms/cms_main.py b/cms/cms_main.py deleted file mode 100644 index edc1793..0000000 --- a/cms/cms_main.py +++ /dev/null @@ -1,24 +0,0 @@ -from queue import Queue -from threading import Thread - - -class ClusteringManagementSystem(Thread): - - def __init__(self, in_q): - """ - Initialize BMSInterface object. - Launch a thread to listen to BMS bubble messages through a websocket - Initialize the dictionary to link sensors and loads - Filter the incoming messages - """ - Thread.__init__(self) - self.in_stream = in_q - - def run(self): - """ - To be executed during thread process - """ - while True: - msg = self.in_stream.get(True) - print("CMS received: {0}".format(msg)) - diff --git a/ems_config.py b/ems_config.py new file mode 100644 index 0000000..8bb9f97 --- /dev/null +++ b/ems_config.py @@ -0,0 +1,22 @@ +__author__ = 'Olivier Van Cutsem' + +# EMS connection with outside world +EMS_MODE_VE_SIMULATION = "VE_SIMULATION" # VE_SIMULATION: simulation through the vEngine +EMS_MODE = EMS_MODE_VE_SIMULATION + +# OPEN BMS CONNECTION: API +OPENBMS_IP = '128.178.19.163' #128.178.19.240 +OPENBMS_PORT = '80' + +# OPEN BMS CONNECTION: RT server +RT_SERVER_IP = OPENBMS_IP +RT_SERVER_PORT = '8000' + +WEBSOCKET_ZMQ_MSG_TYPE = "ZMQ_MSG" #for messages arriving through the zmq loop +WEBSOCKET_WEB_MSG_TYPE = "WEB_MSG" #for messages arriving through the websockets loop + +# ZMQ_PORT +ZMQ_BMS_IP = '128.178.19.69' +ZMQ_PORT_REP = '51400' +ZMQ_PORT_PUB = '51450' +SOCKET_SETTLE_TIME = 1 diff --git a/emscore/__init__.py b/emscore/__init__.py new file mode 100644 index 0000000..139597f --- /dev/null +++ b/emscore/__init__.py @@ -0,0 +1,2 @@ + + diff --git a/emscore/ems_main.py b/emscore/ems_main.py new file mode 100644 index 0000000..190b279 --- /dev/null +++ b/emscore/ems_main.py @@ -0,0 +1,83 @@ +from Queue import Queue +from threading import Thread +from ems_config import * +import json + +class ClusteringManagementSystem(Thread): + + def __init__(self, in_q): + """ + Initialize ClusteringManagementSystem object. + Read messages from the BMS interface bubble messages through a Queue + + """ + Thread.__init__(self) + self.in_stream = in_q + self.entity_tree = {'LOADS': {}, 'GEN': {}, 'BAT': {}} + + def run(self): + """ + To be executed during thread process + """ + while True: + msg = self.in_stream.get(True) + print("CMS received: {0}".format(msg)) + #self.decode_incoming_msg(msg) + + def decode_incoming_msg(self, in_msg): + """ + Interpret a new message coming from the BMS interface + """ + json_msg = json.load(in_msg) + + if not('MSG_TYPE' in json_msg and 'ID' in json_msg): + return + + # Identify the type of incoming message + if json_msg['MSG_TYPE'] == INIT_ENTITY_INTERFACE_MSG: + # Check first whether the new entity isn't indeed in the list + if json_msg['ID'] in self.entity_tree['LOADS'] or json_msg['ID'] in self.entity_tree['GEN'] or json_msg['ID'] in self.entity_tree['BAT']: + pass + + self.add_new_entity(json_msg['ID'], json_msg['PAYLOAD']) + + elif json_msg['MSG_TYPE'] == NEW_VALUE_INTERFACE_MSG: + pass + else: + pass + + def add_new_entity(self, id, raw_info): + """ + :param id: entity ID in the BMS + :param raw_info: param field stored in the BMS + :return: / + """ + + #TODO find the type of load and add it to the appropriate tree branch + + def update_entity(self, id, new_val): + """ + :param id: + :param new_val: + :return: + """ + + #TODO: general structure of the tree !!! + + entity_type = '' + + if id in self.entity_tree[LOAD_ENTITY_TYPE]: + entity_type = LOAD_ENTITY_TYPE + elif id in self.entity_tree[BAT_ENTITY_TYPE]: + entity_type = BAT_ENTITY_TYPE + elif id in self.entity_tree[GEN_ENTITY_TYPE]: + entity_type = GEN_ENTITY_TYPE + + entity_info = self.entity_tree[entity_type][id] + + + + + + +