def check_bilateraltbl_attributes(): # request "Bilateral_Table_ID", "TASE2_Version", and "Supported_Features" # check with client local values # if values don't match issue a conclude request to server # loop until conflict is resolved global conn global vcc mmsError = iec61850.toMmsErrorP() bltid_ok = False t2ver_ok = False success = False try: bltid_mms = iec61850.MmsConnection_readVariable( conn.MmsConnection, mmsError, vcc.domain, "Bilateral_Table_ID") if (iec61850.MmsValue_toString(bltid_mms) == vcc.bilateraltable.bilateral_table_id): bltid_ok = True else: iec61850.MmsConnection_conclude(conn.MmsConnection, mmsError) except: pass try: tase2version_mms = iec61850.MmsConnection_readVariable( conn.MmsConnection, mmsError, None, "TASE2_Version") tase2version_val_major = iec61850.MmsValue_toUint32( iec61850.MmsValue_getElement(tase2version_mms, 0)) tase2version_val_minor = iec61850.MmsValue_toUint32( iec61850.MmsValue_getElement(tase2version_mms, 1)) tase2version_str = str(tase2version_val_major) + "-" + str( tase2version_val_minor) if (tase2version_str == vcc.bilateraltable.tase2_version): t2ver_ok = True else: iec61850.MmsConnection_conclude(conn.MmsConnection, mmsError) except: pass try: supp_feat_mms = iec61850.MmsConnection_readVariable( conn.MmsConnection, mmsError, None, "Supported_Features") feat_bitstring_size = iec61850.MmsValue_getBitStringSize(supp_feat_mms) lst1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] lst2 = [] for i in range(feat_bitstring_size): lst2.append(iec61850.MmsValue_getBitStringBit(supp_feat_mms, i)) Supported_Features = [a * b for a, b in zip(lst1, lst2)] filter(lambda a: a != 0, Supported_Features) vcc.associations[0].supported_features = ".".join( str(Supported_Features)) except: pass success = bltid_ok and t2ver_ok return success
def main(): local_tselector = iec61850.TSelector() local_tselector.size = 2 local_tselector.value = [0, 1] local_sselector = iec61850.SSelector() local_sselector.size = 2 local_sselector.value = [0, 1] local_pselector = iec61850.PSelector() local_pselector.size = 4 local_pselector.value = [0, 0, 0, 1] remote_tselector = iec61850.TSelector() remote_tselector.size = 2 remote_tselector.value = [0, 1] remote_sselector = iec61850.SSelector() remote_sselector.size = 2 remote_sselector.value = [0, 1] remote_pselector = iec61850.PSelector() remote_pselector.size = 4 remote_pselector.value = [0, 0, 0, 1] mms_connection = iec61850.MmsConnection_createWisop( "1.2.32.2", 1, local_tselector, local_sselector, local_pselector, "1.2.3", 21, remote_tselector, remote_sselector, remote_pselector) mmsError = iec61850.toMmsErrorP() conn = iec61850.MmsConnection_connect(mms_connection, mmsError, remote_server, remote_port) if (conn): print("Connection established!\n") vars = iec61850.LinkedList_create() name = iec61850.MmsVariableAccessSpecification_create( domain, "Transfer_Set_Name") tst = iec61850.MmsVariableAccessSpecification_create( domain, "Transfer_Set_Time_Stamp") dsc = iec61850.MmsVariableAccessSpecification_create( domain, "DSConditions_Detected") iec61850.LinkedList_add(vars, name) iec61850.LinkedList_add(vars, tst) iec61850.LinkedList_add(vars, dsc) iec61850.MmsConnection_defineNamedVariableList(mms_connection, mmsError, domain, ds_name, vars) for item in itemId: value = iec61850.MmsConnection_readVariable( mms_connection, mmsError, domain, item) val_part1 = iec61850.MmsValue_toDouble( iec61850.MmsValue_getElement(value, 0)) val_part2 = iec61850.MmsValue_getElement(value, 1) bitstring_size = iec61850.MmsValue_getBitStringSize(val_part2) print(item) print("value: %s" % val_part1) print("bitstring_size: %s" % bitstring_size) for i in range(bitstring_size): print("bitstring_value: %s" % iec61850.MmsValue_getBitStringBit(val_part2, i)) else: print("Connection failed!\n")
def start_iccp(dataconf_file): global conn global vcc mmsError = iec61850.toMmsErrorP() success = False chk_blt_tbl_ok = False del_datasets_ok = False read_dataconf_ok = False create_ts_ok = False create_ds_ok = False add_ds_ts_ok = False # check bilateral tables attributes try: chk_blt_tbl_ok = check_bilateraltbl_attributes() except: print("Error in checking bilateral tables attributes") pass # delete existing datasets try: if (len(vcc.datasets) != 0): for dataset in vcc.datasets: del_datasets_ok = dataset.delete_dataset( vcc.domain, dataset.name) else: del_datasets_ok = True except: print("Error in deleting datasets") pass # create datasets from input file try: dataconf = readDataConf(dataconf_file, conn.MmsConnection, mmsError) read_dataconf_ok = (len(dataconf) != 0) except: pass try: for ds_item in dataconf: vars = iec61850.LinkedList_create() #name = iec61850.MmsVariableAccessSpecification_create(vcc.domain, "Transfer_Set_Name") #tst = iec61850.MmsVariableAccessSpecification_create(vcc.domain, "Transfer_Set_Time_Stamp") #dsc = iec61850.MmsVariableAccessSpecification_create(vcc.domain, "DSConditions_Detected") #iec61850.LinkedList_add(vars, name) #iec61850.LinkedList_add(vars, tst) #iec61850.LinkedList_add(vars, dsc) var_s_lst = [] for dv_item in ds_item.datavalues: var = iec61850.MmsVariableAccessSpecification_create( vcc.domain, dv_item.name.encode("utf-8")) iec61850.LinkedList_add(vars, var) # fixes a bug with the var pointing to the last item of the dv_item list var_s_lst.append(iec61850.getMmsVASItemId(var)) iec61850.MmsConnection_defineNamedVariableList( conn.MmsConnection, mmsError, vcc.domain, ds_item.name.encode("utf-8"), vars) create_ds_ok = True except: print("Error in creating datasets from input file") pass # create transfersets ds_ts_lst = [] try: for ds_item in dataconf: ds_ts = DSTransferSet(conn.MmsConnection, mmsError) next_ts = iec61850.MmsConnection_readVariable( conn.MmsConnection, mmsError, vcc.domain, "Next_DSTransfer_Set") next_ts_value = iec61850.MmsValue_toString( iec61850.MmsValue_getElement(next_ts, 2)) #next_ts = ds_ts.get_next_transferset_value(vcc.domain) ds_ts.set_name(next_ts_value) ds_ts.set_dataset_name(ds_item.name) ds_ts.set_dataset_type(ds_item.ds_type) ds_ts.set_association_id(vcc.associations[0].association_id) ds_ts.set_status = "ENABLED" ds_ts_lst.append(ds_ts) create_ts_ok = (len(ds_ts_lst) != 0) except: print("Error in creating transfersets") pass # add report information handler handler = iec61850.informationReportHandler_create() iec61850.MmsConnection_setInformationReportHandler(conn.MmsConnection, handler, conn.MmsConnection) # add datasets to transfersets for ds_ts_item in ds_ts_lst: try: if (ds_ts_item.dataset_type == "analog"): print("analog dataset detected") add_ds_ts_ok = write_dataset( conn.MmsConnection, vcc.domain, ds_ts_item.dataset_name.encode("utf-8"), ds_ts_item.name, analog_buf, integrity_time, REPORT_INTERVAL_TIMEOUT | REPORT_OBJECT_CHANGES | REPORT_BUFFERED) elif (ds_ts_item.dataset_type == "digital"): print("digital dataset detected") add_ds_ts_ok = write_dataset( conn.MmsConnection, vcc.domain, ds_ts_item.dataset_name.encode("utf-8"), ds_ts_item.name, digital_buf, integrity_time, REPORT_INTERVAL_TIMEOUT | REPORT_OBJECT_CHANGES) elif (ds_ts_item.dataset_type == "events"): print("events dataset detected") add_ds_ts_ok = write_dataset( conn.MmsConnection, vcc.domain, ds_ts_item.dataset_name.encode("utf-8"), ds_ts_item.name, events_buf, integrity_time, REPORT_OBJECT_CHANGES) else: add_ds_ts_ok = False except: print("Error in adding datasets to transfersets") pass success = chk_blt_tbl_ok and del_datasets_ok and read_dataconf_ok and create_ds_ok and create_ts_ok and add_ds_ts_ok return success
remote_sselector = iec61850.SSelector() remote_sselector.size = 2 remote_sselector.value = [0, 1] remote_pselector = iec61850.PSelector() remote_pselector.size = 4 remote_pselector.value = [0, 0, 0, 1] mms_connection = iec61850.MmsConnection_createWisop( "1.2.32.2", 1, local_tselector, local_sselector, local_pselector, "1.2.3", 21, remote_tselector, remote_sselector, remote_pselector) remote_server = "10.132.0.110" remote_port = 102 mmsError = iec61850.toMmsErrorP() result = iec61850.MmsConnection_connect(mms_connection, mmsError, remote_server, remote_port) biltid = iec61850.MmsConnection_readVariable(mms_connection, mmsError, "TestDomain", "Bilateral_Table_ID") bltid_value = iec61850.MmsValue_toString(biltid) print("Bilateral_Table_ID: " + str(bltid_value)) tase2version = iec61850.MmsConnection_readVariable(mms_connection, mmsError, None, "TASE2_Version") tase2version_val_major = iec61850.MmsValue_toUint32( iec61850.MmsValue_getElement(tase2version, 0)) tase2version_val_minor = iec61850.MmsValue_toUint32( iec61850.MmsValue_getElement(tase2version, 1)) print("TASE2_Version: " + str(tase2version_val_major) + "-" + str(tase2version_val_minor)) feat = iec61850.MmsConnection_readVariable(mms_connection, mmsError, None, "Supported_Features") feat_bitstring_size = iec61850.MmsValue_getBitStringSize(feat) lst1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
def main(): local_tselector = iec61850.TSelector() local_tselector.size = 2 local_tselector.value = [0, 1] local_sselector = iec61850.SSelector() local_sselector.size = 2 local_sselector.value = [0, 1] local_pselector = iec61850.PSelector() local_pselector.size = 4 local_pselector.value = [0, 0, 0, 1] remote_tselector = iec61850.TSelector() remote_tselector.size = 2 remote_tselector.value = [0, 1] remote_sselector = iec61850.SSelector() remote_sselector.size = 2 remote_sselector.value = [0, 1] remote_pselector = iec61850.PSelector() remote_pselector.size = 4 remote_pselector.value = [0, 0, 0, 1] mms_connection = iec61850.MmsConnection_createWisop( "1.2.32.2", 1, local_tselector, local_sselector, local_pselector, "1.2.3", 21, remote_tselector, remote_sselector, remote_pselector) mmsError = iec61850.toMmsErrorP() result = iec61850.MmsConnection_connect(mms_connection, mmsError, remote_server, remote_port) iec61850.MmsConnection_deleteNamedVariableList(mms_connection, mmsError, domain, ds_name) handler = iec61850.informationReportHandler_create() iec61850.MmsConnection_setInformationReportHandler(mms_connection, handler, mms_connection) vars = iec61850.LinkedList_create() #name = iec61850.MmsVariableAccessSpecification_create(domain, "Transfer_Set_Name") #tst = iec61850.MmsVariableAccessSpecification_create(domain, "Transfer_Set_Time_Stamp") #dsc = iec61850.MmsVariableAccessSpecification_create(domain, "DSConditions_Detected") #iec61850.LinkedList_add(vars, name) #iec61850.LinkedList_add(vars, tst) #iec61850.LinkedList_add(vars, dsc) var = iec61850.MmsVariableAccessSpecification_create(domain, "tm1") iec61850.LinkedList_add(vars, var) iec61850.MmsConnection_defineNamedVariableList(mms_connection, mmsError, domain, ds_name, vars) next_ts = iec61850.MmsConnection_readVariable(mms_connection, mmsError, domain, "Next_DSTransfer_Set") ts_name = iec61850.MmsValue_toString( iec61850.MmsValue_getElement(next_ts, 2)) try: iec61850.write_dataset( mms_connection, domain, ds_name, ts_name, buffer_time, integrity_time, REPORT_INTERVAL_TIMEOUT | REPORT_OBJECT_CHANGES | REPORT_BUFFERED) print("Writing dataset successful") except: print("Error writing dataset") pass