Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pseudo_monitor_point.cc

00001 /**********************************************************************/
00002 /*  Class PseudoMonitorPoint:-     */
00003 /*                                           */
00004 /*                                                                    */
00005 /*                                          Simon Hoyle               */
00006 /*                      October 2005              */
00007 /**********************************************************************/
00008 
00009 
00010 #include <iostream>
00011 #ifdef SOLARIS
00012 #include <stdio.h>
00013 #endif
00014 #include <cstring>
00015 #include <ctype.h>
00016 #include <assert.h>
00017 
00018 #include "comms_device.h"
00019 #include "control_point.h"
00020 #include "pseudo_monitor_point.h"
00021 
00022 using namespace std;
00023 
00024 bool PseudoMonitorPoint::debugAll = false;
00025 
00026 
00027 PseudoMonitorPoint::PseudoMonitorPoint(const char* name, const float* var) : 
00028                                        MonitorPoint(name, NULL), fvar(var) 
00029 { 
00030     dbp.dsCat = Dataset::ANALOG;
00031     ivar = NULL;
00032     cp = NULL;   
00033 }
00034 
00035 PseudoMonitorPoint::PseudoMonitorPoint(const char* name, const int* var) : 
00036                                        MonitorPoint(name, NULL), ivar(var) 
00037 { 
00038     dbp.dsCat = Dataset::BIT32;
00039     fvar = NULL;
00040     cp = NULL;
00041 }
00042 
00043 PseudoMonitorPoint::PseudoMonitorPoint(const char* name, ControlPoint* cp) : 
00044                                        MonitorPoint(name, NULL), cp(cp) 
00045 { 
00046     dbp.dsCat = Dataset::BIT32;
00047     fvar = NULL;
00048     ivar = NULL;
00049 }
00050 
00051 void PseudoMonitorPoint::init(char* format, int interval, bool enabled, char* desc)
00052 {
00053     strcpy(dbp.op, "-\0");
00054     dbp.scale = 1.0;
00055     dbp.offset = 0.0;
00056     strncpy(dbp.format, format, 7);
00057     dbp.interval = interval;
00058     dbp.enabled = enabled;
00059     strncpy(dbp.desc, desc, 59);
00060     commDevType = NONE;
00061     if (debugAll || debug)
00062     {
00063         cout << "PseudoMonitorPoint:" << dbp.name
00064         << ":init: " << "dbParams=" << endl;
00065         printDbParams();
00066         cout << endl;
00067     }
00068 }
00069 
00070 void PseudoMonitorPoint::add(int num, const char* val)
00071 {
00072     vals[num] = val;
00073 }
00074 
00075 const char* PseudoMonitorPoint::read()
00076 { 
00077     sprintf(timestamp, "%s", CommsDevice::getUT());
00078     if (dbp.dsCat == Dataset::ANALOG)
00079     {
00080         fval = *fvar * dbp.scale + dbp.offset; 
00081         if (lineariser != NULL)    
00082             fval = (*lineariser)(fval);
00083         sprintf(valStr, dbp.format, fval);
00084     }
00085     else if (cp != NULL)
00086     {
00087         sprintf(valStr, dbp.format, cp->getVal());
00088     }
00089     else
00090     {
00091         ival = *ivar;
00092         if ((it = vals.find(ival)) != vals.end())
00093             sprintf(valStr, "%s", static_cast<const char*>(it->second));
00094         else
00095             sprintf(valStr, dbp.format, ival);
00096     }
00097     sprintf(response, "%s\t%s\t%s", dbp.name, valStr, timestamp);
00098     return response;
00099 }
00100 
00101 const char* PseudoMonitorPoint::read(const char* id)
00102 {
00103     if (!hasID(id)) 
00104     {
00105         sprintf(response, "<ERR>\t%s is not %s", dbp.name, id);
00106         return response;
00107     }
00108     sprintf(timestamp, "%s", CommsDevice::getUT());
00109     if (dbp.dsCat == Dataset::ANALOG)
00110     {
00111         fval = *fvar * dbp.scale + dbp.offset; 
00112         if (lineariser != NULL)    
00113             fval = (*lineariser)(fval);
00114         sprintf(valStr, dbp.format, fval);
00115     }
00116     else if (cp != NULL)
00117     {
00118         sprintf(valStr, dbp.format, cp->getVal());
00119     }
00120     else
00121     {
00122         ival = *ivar;
00123         if ((it = vals.find(ival)) != vals.end())
00124             sprintf(valStr, "%s", static_cast<const char*>(it->second));
00125         else
00126             sprintf(valStr, dbp.format, ival);
00127     }  
00128     sprintf(response, "<OK>\t%s\t%s\t%s", dbp.name, valStr, timestamp);
00129     return response;   
00130 }
00131 
00132 int PseudoMonitorPoint::read(int* val)
00133 {
00134     assert(dbp.dsCat != Dataset::ANALOG);
00135     if (cp != NULL)
00136         *val = cp->getVal();
00137     else
00138         *val = ival = *ivar;
00139     return 0;       
00140 }
00141 
00142 int PseudoMonitorPoint::read(float* val)
00143 {
00144     assert(dbp.dsCat == Dataset::ANALOG);
00145     fval = *fvar * dbp.scale + dbp.offset; 
00146     if (lineariser != NULL)    
00147         fval = (*lineariser)(fval);
00148     *val = fval;
00149     return 0;
00150 }
00151 

Generated on Mon Apr 30 13:32:38 2007 for Parkes M & C - PKMC C++ library API by  doxygen 1.4.4