32 PwrMon::PwrMon( std::string name,
const std::string &conffile)
throw (AOException) :
AOApp(name, conffile)
49 _logger->log(Logger::LOG_LEV_ERROR,
"Could not create status board.");
54 strncpy(bsb->appname, MyFullName().c_str(), 25);
63 Config_File *cfg = &ConfigDictionary();
64 std::string pwrctrl_name, pwrconf_name, pwr_full_name;
65 Config_File * pwr_conf;
69 pwrctrl_name = (std::string)(*cfg)[
"pwrCtrlName"];
71 catch (Config_File_Exception &e)
73 Logger::get()->log( Logger::LOG_LEV_FATAL, e.what().c_str());
77 pwr_full_name = pwrctrl_name +
".L";
79 pwrconf_name = Utils::getConffile(pwrctrl_name);
81 pwr_conf =
new Config_File(pwrconf_name);
83 std::vector<std::string> item_codes(8);
84 std::vector<std::string> item_names(8);
88 for(
int i=0; i< 8; i++)
91 snprintf( item_code, 32,
"item%d.code", i);
92 snprintf( item_name, 32,
"item%d.name", i);
96 item_codes[i] = (std::string)(*pwr_conf)[item_code];
98 catch (Config_File_Exception &e)
100 snprintf( item_code, 32,
"OUTLET%d", i+1);
101 item_codes[i] = item_code;
106 item_names[i] = (std::string)(*pwr_conf)[item_name];
108 catch (Config_File_Exception &e)
110 snprintf( item_name, 32,
"OUTLET%d", i+1);
111 item_names[i] = item_name;
118 var_outlet1_cur = RTDBvar( pwr_full_name, item_codes[0], CUR_VAR, INT_VARIABLE, 1,1);
119 var_outlet1_req = RTDBvar( pwr_full_name, item_codes[0], REQ_VAR, INT_VARIABLE, 1,1);
120 var_outlet1_name = RTDBvar( pwr_full_name, item_codes[0]+
".NAME" , NO_DIR, CHAR_VARIABLE, item_names[0].size());
121 Notify(var_outlet1_cur, outlet1CurChanged);
123 var_outlet2_cur = RTDBvar( pwr_full_name, item_codes[1], CUR_VAR, INT_VARIABLE, 1,1);
124 var_outlet2_req = RTDBvar( pwr_full_name, item_codes[1], REQ_VAR, INT_VARIABLE, 1,1);
125 var_outlet2_name = RTDBvar( pwr_full_name, item_codes[1]+
".NAME" , NO_DIR, CHAR_VARIABLE, item_names[1].size());
126 Notify(var_outlet2_cur, outlet2CurChanged);
128 var_outlet3_cur = RTDBvar( pwr_full_name, item_codes[2], CUR_VAR, INT_VARIABLE, 1,1);
129 var_outlet3_req = RTDBvar( pwr_full_name, item_codes[2], REQ_VAR, INT_VARIABLE, 1,1);
130 var_outlet3_name = RTDBvar( pwr_full_name, item_codes[2]+
".NAME" , NO_DIR, CHAR_VARIABLE, item_names[2].size());
131 Notify(var_outlet3_cur, outlet3CurChanged);
133 var_outlet4_cur = RTDBvar( pwr_full_name, item_codes[3], CUR_VAR, INT_VARIABLE, 1,1);
134 var_outlet4_req = RTDBvar( pwr_full_name, item_codes[3], REQ_VAR, INT_VARIABLE, 1,1);
135 var_outlet4_name = RTDBvar( pwr_full_name, item_codes[3]+
".NAME" , NO_DIR, CHAR_VARIABLE, item_names[3].size());
136 Notify(var_outlet4_cur, outlet4CurChanged);
138 var_outlet5_cur = RTDBvar( pwr_full_name, item_codes[4], CUR_VAR, INT_VARIABLE, 1,1);
139 var_outlet5_req = RTDBvar( pwr_full_name, item_codes[4], REQ_VAR, INT_VARIABLE, 1,1);
140 var_outlet5_name = RTDBvar( pwr_full_name, item_codes[4]+
".NAME" , NO_DIR, CHAR_VARIABLE, item_names[4].size());
141 Notify(var_outlet5_cur, outlet5CurChanged);
143 var_outlet6_cur = RTDBvar( pwr_full_name, item_codes[5], CUR_VAR, INT_VARIABLE, 1,1);
144 var_outlet6_req = RTDBvar( pwr_full_name, item_codes[5], REQ_VAR, INT_VARIABLE, 1,1);
145 var_outlet6_name = RTDBvar( pwr_full_name, item_codes[5]+
".NAME" , NO_DIR, CHAR_VARIABLE, item_names[5].size());
146 Notify(var_outlet6_cur, outlet6CurChanged);
148 var_outlet7_cur = RTDBvar( pwr_full_name, item_codes[6], CUR_VAR, INT_VARIABLE, 1,1);
149 var_outlet7_req = RTDBvar( pwr_full_name, item_codes[6], REQ_VAR, INT_VARIABLE, 1,1);
150 var_outlet7_name = RTDBvar( pwr_full_name, item_codes[6]+
".NAME" , NO_DIR, CHAR_VARIABLE, item_names[6].size());
151 Notify(var_outlet7_cur, outlet7CurChanged);
153 var_outlet8_cur = RTDBvar( pwr_full_name, item_codes[7], CUR_VAR, INT_VARIABLE, 1,1);
154 var_outlet8_req = RTDBvar( pwr_full_name, item_codes[7], REQ_VAR, INT_VARIABLE, 1,1);
155 var_outlet8_name = RTDBvar( pwr_full_name, item_codes[7]+
".NAME" , NO_DIR, CHAR_VARIABLE, item_names[7].size());
156 Notify(var_outlet8_cur, outlet8CurChanged);
159 catch (AOVarException &e)
161 Logger::get()->log(Logger::LOG_LEV_FATAL,
"%s:%s: %s", __FILE__, __LINE__, e.what().c_str());
162 throw AOException(
"Error creating RTDB variables");
166 int PwrMon::outlet1CurChanged(
void *pt, Variable *msgb)
170 pm->var_outlet1_cur.Update();
177 int PwrMon::outlet2CurChanged(
void *pt, Variable *msgb)
181 pm->var_outlet2_cur.Update();
183 pm->update_statusboard();
188 int PwrMon::outlet3CurChanged(
void *pt, Variable *msgb)
192 pm->var_outlet3_cur.Update();
194 pm->update_statusboard();
199 int PwrMon::outlet4CurChanged(
void *pt, Variable *msgb)
203 pm->var_outlet4_cur.Update();
205 pm->update_statusboard();
210 int PwrMon::outlet5CurChanged(
void *pt, Variable *msgb)
214 pm->var_outlet5_cur.Update();
216 pm->update_statusboard();
222 int PwrMon::outlet6CurChanged(
void *pt, Variable *msgb)
226 pm->var_outlet6_cur.Update();
228 pm->update_statusboard();
233 int PwrMon::outlet7CurChanged(
void *pt, Variable *msgb)
237 pm->var_outlet7_cur.Update();
239 pm->update_statusboard();
244 int PwrMon::outlet8CurChanged(
void *pt, Variable *msgb)
248 pm->var_outlet8_cur.Update();
250 pm->update_statusboard();
260 _logger->log( Logger::LOG_LEV_INFO,
"Running...");
269 catch (AOException &e)
271 _logger->log( Logger::LOG_LEV_ERROR,
"Caught exception (at %s:%d): %s", __FILE__, __LINE__, e.what().c_str());
277 int PwrMon::init_statusboard()
284 tmpstr = var_outlet1_name.Get();
285 strncpy(psb->outlet1_name, tmpstr.c_str(), 50);
287 tmpstr = var_outlet2_name.Get();
288 strncpy(psb->outlet2_name, tmpstr.c_str(), 50);
290 tmpstr = var_outlet3_name.Get();
291 strncpy(psb->outlet3_name, tmpstr.c_str(), 50);
293 tmpstr = var_outlet4_name.Get();
294 strncpy(psb->outlet4_name, tmpstr.c_str(), 50);
296 tmpstr = var_outlet5_name.Get();
297 strncpy(psb->outlet5_name, tmpstr.c_str(), 50);
299 tmpstr = var_outlet6_name.Get();
300 strncpy(psb->outlet6_name, tmpstr.c_str(), 50);
302 tmpstr = var_outlet7_name.Get();
303 strncpy(psb->outlet7_name, tmpstr.c_str(), 50);
305 tmpstr = var_outlet8_name.Get();
306 strncpy(psb->outlet8_name, tmpstr.c_str(), 50);
329 var_outlet1_cur.Get(&psb->outlet1_state);
330 var_outlet2_cur.Get(&psb->outlet2_state);
331 var_outlet3_cur.Get(&psb->outlet3_state);
332 var_outlet4_cur.Get(&psb->outlet4_state);
333 var_outlet5_cur.Get(&psb->outlet5_state);
334 var_outlet6_cur.Get(&psb->outlet6_state);
335 var_outlet7_cur.Get(&psb->outlet7_state);
336 var_outlet8_cur.Get(&psb->outlet8_state);
339 std::cout << psb->outlet1_name <<
" " << psb->outlet1_state <<
"\n";
340 std::cout << psb->outlet2_name <<
" " << psb->outlet2_state <<
"\n";
341 std::cout << psb->outlet3_name <<
" " << psb->outlet3_state <<
"\n";
342 std::cout << psb->outlet4_name <<
" " << psb->outlet4_state <<
"\n";
343 std::cout << psb->outlet5_name <<
" " << psb->outlet5_state <<
"\n";
344 std::cout << psb->outlet6_name <<
" " << psb->outlet6_state <<
"\n";
345 std::cout << psb->outlet7_name <<
" " << psb->outlet7_state <<
"\n";
346 std::cout << psb->outlet8_name <<
" " << psb->outlet8_state <<
"\n";
A class to monitor the VisAOPwrCtrl via the RTDB.
void SetupVars()
Virtual function to setup variables in RTDB.
Declarations for the VisAOPwrMon class.
void * statusboard_shmemptr
The pointer to the shared memory block for the statusboard.
virtual int update_statusboard()
Update the status board.
void setupVisAOApp()
Basic setup of the class, called by both constructors.
key_t statusboard_shmemkey
The key used to lookup the shared memory.
PwrMon(std::string name, const std::string &conffile)
Standard adopt style config file constructor.
int TimeToDie
Global set by SIGTERM.
double pause_time
Time to pause during application main loop.
int create_statusboard(size_t sz)
Creates and attaches to the statusboard shared memory.
virtual int update_statusboard()
Update the status board.
The namespace of VisAO software.