00001
00009 #include <stdlib.h>
00010 #include <stdio.h>
00011 #include <errno.h>
00012 #include <math.h>
00013
00014 #include "sectionalizer.h"
00015
00016
00017 CLASS* sectionalizer::oclass = NULL;
00018 CLASS* sectionalizer::pclass = NULL;
00019
00020 sectionalizer::sectionalizer(MODULE *mod) : switch_object(mod)
00021 {
00022
00023 if (oclass==NULL)
00024 {
00025
00026 pclass = link_object::oclass;
00027
00028
00029 oclass = gl_register_class(mod,"sectionalizer",sizeof(sectionalizer),PC_PRETOPDOWN|PC_BOTTOMUP|PC_POSTTOPDOWN|PC_UNSAFE_OVERRIDE_OMIT|PC_AUTOLOCK);
00030 if(oclass == NULL)
00031 GL_THROW("unable to register object class implemented by %s",__FILE__);
00032
00033
00034 if(gl_publish_variable(oclass,
00035 PT_INHERIT, "switch",
00036 NULL) < 1) GL_THROW("unable to publish properties in %s",__FILE__);
00037
00038 if (gl_publish_function(oclass,"change_sectionalizer_state",(FUNCTIONADDR)change_sectionalizer_state)==NULL)
00039 GL_THROW("Unable to publish sectionalizer state change function");
00040 if (gl_publish_function(oclass,"sectionalizer_reliability_operation",(FUNCTIONADDR)sectionalizer_reliability_operation)==NULL)
00041 GL_THROW("Unable to publish sectionalizer reliability operation function");
00042 if (gl_publish_function(oclass, "change_sectionalizer_faults", (FUNCTIONADDR)sectionalizer_fault_updates)==NULL)
00043 GL_THROW("Unable to publish sectionalizer fault correction function");
00044
00045
00046 if (gl_publish_function(oclass, "interupdate_pwr_object", (FUNCTIONADDR)interupdate_switch)==NULL)
00047 GL_THROW("Unable to publish sectionalizer deltamode function");
00048
00049
00050 if (gl_publish_function(oclass, "update_power_pwr_object", (FUNCTIONADDR)updatepowercalc_link)==NULL)
00051 GL_THROW("Unable to publish sectionalizer external power calculation function");
00052 if (gl_publish_function(oclass, "check_limits_pwr_object", (FUNCTIONADDR)calculate_overlimit_link)==NULL)
00053 GL_THROW("Unable to publish sectionalizer external power limit calculation function");
00054 }
00055 }
00056
00057 int sectionalizer::isa(char *classname)
00058 {
00059 return strcmp(classname,"sectionalizer")==0 || switch_object::isa(classname);
00060 }
00061
00062
00063 int sectionalizer::create()
00064 {
00065 int result = switch_object::create();
00066
00067 prev_full_status = 0x00;
00068 switch_banked_mode = BANKED_SW;
00069 phase_A_state = CLOSED;
00070 phase_B_state = CLOSED;
00071 phase_C_state = CLOSED;
00072
00073 return result;
00074 }
00075
00076
00077 int sectionalizer::init(OBJECT *parent)
00078 {
00079
00080 return switch_object::init(parent);
00081 }
00082
00084
00086
00087 EXPORT int isa_sectionalizer(OBJECT *obj, char *classname)
00088 {
00089 return OBJECTDATA(obj,sectionalizer)->isa(classname);
00090 }
00091
00092 EXPORT int create_sectionalizer(OBJECT **obj, OBJECT *parent)
00093 {
00094 try
00095 {
00096 *obj = gl_create_object(sectionalizer::oclass);
00097 if (*obj!=NULL)
00098 {
00099 sectionalizer *my = OBJECTDATA(*obj,sectionalizer);
00100 gl_set_parent(*obj,parent);
00101 return my->create();
00102 }
00103 else
00104 return 0;
00105 }
00106 CREATE_CATCHALL(sectionalizer);
00107 }
00108
00109 EXPORT int init_sectionalizer(OBJECT *obj)
00110 {
00111 try {
00112 sectionalizer *my = OBJECTDATA(obj,sectionalizer);
00113 return my->init(obj->parent);
00114 }
00115 INIT_CATCHALL(sectionalizer);
00116 }
00117
00118 EXPORT TIMESTAMP sync_sectionalizer(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass)
00119 {
00120 try {
00121 sectionalizer *pObj = OBJECTDATA(obj,sectionalizer);
00122 TIMESTAMP t1 = TS_NEVER;
00123 switch (pass) {
00124 case PC_PRETOPDOWN:
00125 return pObj->presync(t0);
00126 case PC_BOTTOMUP:
00127 return pObj->sync(t0);
00128 case PC_POSTTOPDOWN:
00129 t1 = pObj->postsync(t0);
00130 obj->clock = t0;
00131 return t1;
00132 default:
00133 throw "invalid pass request";
00134 }
00135 }
00136 SYNC_CATCHALL(sectionalizer);
00137 }
00138
00139
00140 EXPORT double change_sectionalizer_state(OBJECT *thisobj, unsigned char phase_change, bool state)
00141 {
00142 double count_values, recloser_count;
00143 char desA, desB, desC;
00144 switch_object *swtchobj;
00145 sectionalizer *sectionobj;
00146 FUNCTIONADDR funadd = NULL;
00147 bool perform_operation;
00148
00149
00150 count_values = 0.0;
00151
00152 if ((state == false) && (restoration_checks_active == false))
00153 {
00154
00155 sectionobj = OBJECTDATA(thisobj,sectionalizer);
00156
00157
00158 if (fault_check_object == NULL)
00159 {
00160 GL_THROW("Reliability call made without fault_check object present!");
00161
00162
00163
00164
00165
00166 }
00167
00168
00169 funadd = (FUNCTIONADDR)(gl_get_function(fault_check_object,"handle_sectionalizer"));
00170
00171
00172 if (funadd==NULL)
00173 {
00174 GL_THROW("Failed to find sectionalizer checking method on object %s",fault_check_object->name);
00175
00176
00177
00178
00179
00180 }
00181
00182
00183 recloser_count = ((double (*)(OBJECT *, int))(*funadd))(fault_check_object,sectionobj->NR_branch_reference);
00184
00185 if (recloser_count == 0.0)
00186 {
00187 GL_THROW("Failed to handle sectionalizer check on %s",thisobj->name);
00188
00189
00190
00191
00192
00193 }
00194
00195
00196 if (recloser_count < 0)
00197 {
00198 count_values = recloser_count;
00199 perform_operation = false;
00200 }
00201 else
00202 {
00203 perform_operation = true;
00204 count_values = recloser_count;
00205 }
00206 }
00207 else
00208 {
00209 perform_operation = true;
00210 count_values = 1.0;
00211 }
00212
00213 if (perform_operation==true)
00214 {
00215
00216 swtchobj = OBJECTDATA(thisobj,switch_object);
00217
00218 if ((swtchobj->switch_banked_mode == switch_object::BANKED_SW) || (meshed_fault_checking_enabled == true))
00219 {
00220 swtchobj->set_switch(state);
00221 }
00222 else
00223 {
00224
00225 if ((phase_change & 0x04) == 0x04)
00226 {
00227 if (state==true)
00228 desA=1;
00229 else
00230 desA=0;
00231 }
00232 else
00233 desA=2;
00234
00235
00236 if ((phase_change & 0x02) == 0x02)
00237 {
00238 if (state==true)
00239 desB=1;
00240 else
00241 desB=0;
00242 }
00243 else
00244 desB=2;
00245
00246
00247 if ((phase_change & 0x01) == 0x01)
00248 {
00249 if (state==true)
00250 desC=1;
00251 else
00252 desC=0;
00253 }
00254 else
00255 desC=2;
00256
00257
00258 swtchobj->set_switch_full(desA,desB,desC);
00259 }
00260 }
00261
00262 return count_values;
00263 }
00264
00265
00266 EXPORT int sectionalizer_reliability_operation(OBJECT *thisobj, unsigned char desired_phases)
00267 {
00268
00269 switch_object *swtchobj = OBJECTDATA(thisobj,switch_object);
00270
00271 swtchobj->set_switch_full_reliability(desired_phases);
00272
00273 return 1;
00274 }
00275
00276 EXPORT int sectionalizer_fault_updates(OBJECT *thisobj, unsigned char restoration_phases)
00277 {
00278
00279 switch_object *thisswitch = OBJECTDATA(thisobj,switch_object);
00280
00281
00282 thisswitch->set_switch_faulted_phases(restoration_phases);
00283
00284 return 1;
00285 }