00001
00012 #include <stdlib.h>
00013 #include <stdio.h>
00014 #include <errno.h>
00015 #include <math.h>
00016
00017 #include "recloser.h"
00018
00019 CLASS* recloser::oclass = NULL;
00020 CLASS* recloser::pclass = NULL;
00021
00022 recloser::recloser(MODULE *mod) : switch_object(mod)
00023 {
00024 if(oclass == NULL)
00025 {
00026 pclass = link_object::oclass;
00027
00028 oclass = gl_register_class(mod,"recloser",sizeof(recloser),PC_PRETOPDOWN|PC_BOTTOMUP|PC_POSTTOPDOWN|PC_UNSAFE_OVERRIDE_OMIT|PC_AUTOLOCK);
00029 if(oclass == NULL)
00030 GL_THROW("unable to register object class implemented by %s",__FILE__);
00031
00032 if(gl_publish_variable(oclass,
00033 PT_INHERIT, "switch",
00034 PT_double, "retry_time[s]", PADDR(retry_time), PT_DESCRIPTION, "the amount of time in seconds to wait before the recloser attempts to close",
00035 PT_double, "max_number_of_tries", PADDR(ntries), PT_DESCRIPTION, "the number of times the recloser will try to close before permanently opening",
00036 PT_double, "number_of_tries", PADDR(curr_tries), PT_DESCRIPTION, "Current number of tries recloser has attempted",
00037 NULL) < 1) GL_THROW("unable to publish properties in %s",__FILE__);
00038
00039 if (gl_publish_function(oclass,"change_recloser_state",(FUNCTIONADDR)change_recloser_state)==NULL)
00040 GL_THROW("Unable to publish recloser state change function");
00041 if (gl_publish_function(oclass,"recloser_reliability_operation",(FUNCTIONADDR)recloser_reliability_operation)==NULL)
00042 GL_THROW("Unable to publish recloser reliability operation function");
00043 if (gl_publish_function(oclass, "change_recloser_faults", (FUNCTIONADDR)recloser_fault_updates)==NULL)
00044 GL_THROW("Unable to publish recloser fault correction function");
00045
00046
00047 if (gl_publish_function(oclass, "interupdate_pwr_object", (FUNCTIONADDR)interupdate_switch)==NULL)
00048 GL_THROW("Unable to publish recloser deltamode function");
00049
00050
00051 if (gl_publish_function(oclass, "update_power_pwr_object", (FUNCTIONADDR)updatepowercalc_link)==NULL)
00052 GL_THROW("Unable to publish recloser external power calculation function");
00053 if (gl_publish_function(oclass, "check_limits_pwr_object", (FUNCTIONADDR)calculate_overlimit_link)==NULL)
00054 GL_THROW("Unable to publish recloser external power limit calculation function");
00055 }
00056 }
00057
00058 int recloser::isa(char *classname)
00059 {
00060 return strcmp(classname,"recloser")==0 || switch_object::isa(classname);
00061 }
00062
00063 int recloser::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 prev_SW_time = 0;
00074 retry_time = 0;
00075 ntries = 0;
00076 curr_tries = 0.0;
00077 prev_rec_time = 0;
00078 return result;
00079 }
00080
00081 int recloser::init(OBJECT *parent)
00082 {
00083 int result = switch_object::init(parent);
00084
00085 TIMESTAMP next_ret;
00086 next_ret = gl_globalclock;
00087
00088 if(ntries<0)
00089 {
00090 gl_warning("The number of recloser tries is less than 0 resetting to zero");
00091 ntries = 0;
00092 }
00093
00094 if(retry_time < 0)
00095 {
00096 gl_warning("retry time is < 0 resetting to zero");
00097 retry_time = 0;
00098 }
00099
00100 if(ntries == 0)
00101 ntries = 3;
00102 if(retry_time == 0)
00103 {
00104 retry_time = 1;
00105 return_time = 1;
00106 } else {
00107 return_time = (TIMESTAMP)floor(retry_time + 0.5);
00108 }
00109 return result;
00110 }
00111
00112
00113 TIMESTAMP recloser::sync(TIMESTAMP t0)
00114 {
00115
00116 if (prev_rec_time != t0)
00117 {
00118 prev_rec_time = t0;
00119 curr_tries = 0.0;
00120 }
00121
00122 return switch_object::sync(t0);
00123 }
00124
00126
00128
00136 EXPORT int create_recloser(OBJECT **obj, OBJECT *parent)
00137 {
00138 try
00139 {
00140 *obj = gl_create_object(recloser::oclass);
00141 if (*obj!=NULL)
00142 {
00143 recloser *my = OBJECTDATA(*obj,recloser);
00144 gl_set_parent(*obj,parent);
00145 return my->create();
00146 }
00147 else
00148 return 0;
00149 }
00150 CREATE_CATCHALL(recloser);
00151 }
00152
00159 EXPORT int init_recloser(OBJECT *obj)
00160 {
00161 try {
00162 recloser *my = OBJECTDATA(obj,recloser);
00163 return my->init(obj->parent);
00164 }
00165 INIT_CATCHALL(recloser);
00166 }
00167
00168
00169 EXPORT TIMESTAMP sync_recloser(OBJECT *obj, TIMESTAMP t0, PASSCONFIG pass)
00170 {
00171 try {
00172 recloser *pObj = OBJECTDATA(obj,recloser);
00173 TIMESTAMP t1 = TS_NEVER;
00174 switch (pass) {
00175 case PC_PRETOPDOWN:
00176 return pObj->presync(t0);
00177 case PC_BOTTOMUP:
00178 return pObj->sync(t0);
00179 case PC_POSTTOPDOWN:
00180 t1 = pObj->postsync(t0);
00181 obj->clock = t0;
00182 return t1;
00183 default:
00184 throw "invalid pass request";
00185 }
00186 }
00187 SYNC_CATCHALL(recloser);
00188 }
00189
00190 EXPORT int isa_recloser(OBJECT *obj, char *classname)
00191 {
00192 return OBJECTDATA(obj,recloser)->isa(classname);
00193 }
00194
00195
00196 EXPORT double change_recloser_state(OBJECT *thisobj, unsigned char phase_change, bool state)
00197 {
00198 double count_values;
00199 char desA, desB, desC;
00200 recloser *reclobj;
00201 switch_object *swtchobj;
00202 FUNCTIONADDR funadd = NULL;
00203
00204
00205 count_values = 0.0;
00206
00207
00208 reclobj = OBJECTDATA(thisobj,recloser);
00209
00210
00211 if (state == false)
00212 count_values = reclobj->ntries;
00213 else
00214 count_values = 1.0;
00215
00216
00217 swtchobj = OBJECTDATA(thisobj,switch_object);
00218
00219 if ((swtchobj->switch_banked_mode == switch_object::BANKED_SW) || (meshed_fault_checking_enabled == true))
00220 {
00221 swtchobj->set_switch(state);
00222 }
00223 else
00224 {
00225
00226 if ((phase_change & 0x04) == 0x04)
00227 {
00228 if (state==true)
00229 desA=1;
00230 else
00231 desA=0;
00232 }
00233 else
00234 desA=2;
00235
00236
00237 if ((phase_change & 0x02) == 0x02)
00238 {
00239 if (state==true)
00240 desB=1;
00241 else
00242 desB=0;
00243 }
00244 else
00245 desB=2;
00246
00247
00248 if ((phase_change & 0x01) == 0x01)
00249 {
00250 if (state==true)
00251 desC=1;
00252 else
00253 desC=0;
00254 }
00255 else
00256 desC=2;
00257
00258
00259 swtchobj->set_switch_full(desA,desB,desC);
00260 }
00261
00262 return count_values;
00263 }
00264
00265
00266 EXPORT int recloser_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 recloser_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 }