/* * detector.c * * Created on: Jun 24, 2013 * Author: nerses@jlab.org */ #include #include #include #include using namespace std; #include #include "detector.hh" #include #include #include #include // for hostname_to_ip #include #include #include #include string prefix; extern "C" { #include "HVCAENx527.h" /* * Get ip from domain name */ int hostname_to_ip(char *hostname , char *ip) { struct addrinfo hints, *servinfo, *p; struct sockaddr_in *h; int rv; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; // use AF_INET6 to force IPv6 hints.ai_socktype = SOCK_STREAM; if ( (rv = getaddrinfo( hostname , "http" , &hints , &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } // loop through all the results and connect to the first we can for(p = servinfo; p != NULL; p = p->ai_next) { h = (struct sockaddr_in *) p->ai_addr; strcpy(ip , inet_ntoa( h->sin_addr ) ); } freeaddrinfo(servinfo); // all done with this structure return 0; } /* ------------------------------------------------------------ */ /* Information needed by iocsh */ static const iocshArg detUsePrefixArg0 = {"Prefix", iocshArgString}; static const iocshArg *detUsePrefixArgs[] = { &detUsePrefixArg0, }; static const iocshFuncDef detUsePrefixFuncDef = {"detUsePrefix", 1, detUsePrefixArgs}; /* Wrapper called by iocsh, selects the argument types that function needs */ static void detUsePrefixCallFunc(const iocshArgBuf *args) { if (args[0].sval == NULL) { prefix = ""; } else { prefix = args[0].sval; } } /* Registration routine, runs at startup */ static void detUsePrefixRegister(void) { iocshRegister(&detUsePrefixFuncDef, detUsePrefixCallFunc); } /* ------------------------------------------------------------ */ void detConfigureCrate(const char *det, const char* uri){ db->addDetector(det, uri); map > cr = db->getCrates(det); for (std::map >::iterator it=cr.begin(); it != cr.end(); ++it) { string n = (string)(*it).first; string tmp = prefix; tmp += n; char* name = (char*)tmp.c_str(); map prop = (*it).second; // for (std::map::iterator it2=prop.begin(); it2 != prop.end(); ++it2) { char* host = (char*)prop["HOST"].c_str(); string type = prop["TYPE"]; cout<<__FILE__<<"::"<<__FUNCTION__<<"::"<<__LINE__ <<" name = "< > channels = db->getChannels(); // cout<<"channels.size() = "< dets = db->getDetectors(); for (map >::iterator it = channels.begin(); it != channels.end(); ++it) { string pars; // parameters to be sent dbLoadRecords() string DETch; // DETch from map (basic part of PV name, w/out prefix and suffix) string type; // type = {hv, lv bias} // fill the pars map items = it->second; for (map::iterator items_it = items.begin(); items_it != items.end(); ++items_it) { PDEBUG(2) cout<<__FILE__<<":"<<__FUNCTION__<<":"<<__LINE__ <<" items_it->first = "<first <<" items_it->second = "<second<0) pars += ","; // The first entry doesn't need "," pars += items_it->first; pars += "="; pars += items_it->second; if (items_it->first.compare("DETch") == 0) DETch = items_it->second; if (items_it->first.compare("TYPE") == 0) type = items_it->second; } // insert the prefix int idx; idx = pars.find("PSNAME="); pars.insert(idx+7, prefix); idx = pars.find("DETch="); pars.insert(idx+6, prefix); // NOTE: idx is DETch= place it is going to be used PDEBUG(2) cout<<__FILE__<<":"<<__FUNCTION__<<":"<<__LINE__<<" pars(+prefix) = "<0) chpattern += prefix; chpattern += dets.at(iv); chpattern += ":"; if(chname.find(chpattern)!=std::string::npos) isDetInTheList = true; // cout<<__FILE__<<":"<<__FUNCTION__<<":"<<__LINE__<<" chname = "<first = "<first<<" DETch = "< DETch + COMMUNITY == "guru" + HOST == hostname + PORT <==> PSNAME + SCAN == "2 second" - ADDR <==> SLOT - MBB == {"ZR", "ON", ... , "FF"} mpv_8008l.db with arguments PORT=lv55,HOST=halldmpod1,COMMUNITY=guru,SCAN=2 second,CH=100 ehs_f_205pf.db with arguments PORT=lv55,HOST=halldmpod1,COMMUNITY=guru,SCAN=2 second,CH=700 DETch=hv:CDC:A:1,BOARD=A1550P,CHANNUM=0,PSNAME=hv35,SLOT=1 */ string board; int slot; int ch; int idx1, idx2; idx1 = pars.find("BOARD=")+6; idx2 = pars.find(",", idx1); if (idx2<0) idx2=pars.size(); // cout<<"BOARD idx1,2 = "< lv idx1,2 = "< lv idx1,2 = "<