int ReloadGlobalConfig( void *module_config ) { global_config_t *conf = ( global_config_t * ) module_config; if ( strcmp( conf->fs_path, global_config.fs_path ) ) DisplayLog( LVL_MAJOR, "GlobalConfig", GLOBAL_CONFIG_BLOCK "::fs_path changed in config file, but cannot be modified dynamically" ); if ( strcmp( conf->fs_type, global_config.fs_type ) ) DisplayLog( LVL_MAJOR, "GlobalConfig", GLOBAL_CONFIG_BLOCK "::fs_type changed in config file, but cannot be modified dynamically" ); if ( strcmp( conf->lock_file, global_config.lock_file ) ) { DisplayLog( LVL_MAJOR, "GlobalConfig", GLOBAL_CONFIG_BLOCK "::lock_file updated: '%s'->'%s'", global_config.lock_file, conf->lock_file ); strcpy( global_config.fs_path, conf->lock_file ); } if ( global_config.stay_in_fs != conf->stay_in_fs ) { DisplayLog( LVL_EVENT, "GlobalConfig", GLOBAL_CONFIG_BLOCK "::stay_in_fs updated: %s->%s", bool2str( global_config.stay_in_fs ), bool2str( conf->stay_in_fs ) ); global_config.stay_in_fs = conf->stay_in_fs; } if ( global_config.check_mounted != conf->check_mounted ) { DisplayLog( LVL_EVENT, "GlobalConfig", GLOBAL_CONFIG_BLOCK "::check_mounted updated: %s->%s", bool2str( global_config.check_mounted ), bool2str( conf->check_mounted ) ); global_config.check_mounted = conf->check_mounted; } #if defined( _LUSTRE ) && defined( _MDS_STAT_SUPPORT ) if ( conf->direct_mds_stat != global_config.direct_mds_stat ) { DisplayLog( LVL_EVENT, "FS_Scan_Config", GLOBAL_CONFIG_BLOCK "::direct_mds_stat updated: %u->%u", global_config.direct_mds_stat, conf->direct_mds_stat ); global_config.direct_mds_stat = conf->direct_mds_stat; } #endif return 0; }
/***************************************************************** DATA TYPES */ void driz_param_dump(struct driz_param_t* p) { assert(p); printf("DRIZZLING PARAMETERS:\n" "kernel: %s\n" "pixel_fraction: %f\n" "exposure_time: %f\n" "weight_scale: %f\n" "fill_value: %f\n" "do_fill: %s\n" "in_units: %s\n" "out_units: %s\n" "scale: %f\n", kernel_enum2str(p->kernel), p->pixel_fraction, p->exposure_time, p->weight_scale, p->fill_value, bool2str(p->do_fill), unit_enum2str(p->in_units), unit_enum2str(p->out_units), p->scale ); }
std::ostream& operator<<(std::ostream& os, const Segment& s) { if (s.is_empty()) os << "[]"; else os << "[" << s.lower() << "," << s.upper() << "," << bool2str(s.lower_inclusive()) << "," << bool2str(s.upper_inclusive()) << "]"; return os; }
// **************************************************************************** // Function: operator<< // // Arguments: // os output stream to write to // c contract information to query. // // Programmer: Tom Fogal // Creation: May 3, 2009 // // Modifications: // // Dave Pugmire, Tue May 25 10:15:35 EDT 2010 // Add domain single domain replication to all processors. // // Hank Childs, Thu Aug 26 11:08:02 PDT 2010 // Print out extents calculation members // // **************************************************************************** ostream& operator<<(ostream &os, const avtContract& c) { os << "avtContract information:" << "\tpipeline index: " << c.pipelineIndex << "\n" << "\tstreaming possible: " << bool2str(c.canDoStreaming) << "\n" << "\tstreaming: " << bool2str(c.doingOnDemandStreaming) << "\n" << "\treplicateSingleDoms: " << bool2str(c.replicateSingleDomainOnAllProcessors) << "\n" << "\tload balancing: " << bool2str(c.useLoadBalancing) << "\n" << "\tcalculate mesh extents: " << bool2str(c.calculateMeshExtents) << "\n"; if (c.needExtentsForTheseVariables.size() == 0) { os << "\tcalculate extents for these variables: <none>\n"; } else { os << "\tcalculate extents for these variables:"; for (int i = 0 ; i < c.needExtentsForTheseVariables.size() ; i++) os << c.needExtentsForTheseVariables[i] << "; "; os << "\n"; } os << "\tmesh optimizations:" << "\n" << "\t\tcurvilinear: " << bool2str(c.haveCurvilinearMeshOptimizations) << "\n\t\trectilinear: " << bool2str(c.haveRectilinearMeshOptimizations) << "\n\tfilters: " << c.nFilters << std::endl; return os; }
const char * ULaserDevice::print(const char * preString, char * buff, int buffCnt) { snprintf(buff, buffCnt, "%s %s on %s open=%s w=%ddeg, " "res=%4.2fdeg, rate=%.1f/s scan=%lu\n", preString, getName(), devName, bool2str(isPortOpen()), modeAngleScan, angleResolution, getMsgRate(), getSerial()); return buff; }
/* * rpmemd_print_info -- print basic info and configuration */ static void rpmemd_print_info(struct rpmemd *rpmemd) { RPMEMD_LOG(NOTICE, "ssh connection: %s", _str(getenv("SSH_CONNECTION"))); RPMEMD_LOG(NOTICE, "user: %s", _str(getenv("USER"))); RPMEMD_LOG(NOTICE, "configuration"); RPMEMD_LOG(NOTICE, "\tpool set directory: '%s'", _str(rpmemd->config.poolset_dir)); RPMEMD_LOG(NOTICE, "\tpersist method: %s", rpmem_persist_method_to_str(rpmemd->persist_method)); RPMEMD_LOG(NOTICE, "\tnumber of threads: %lu", rpmemd->nthreads); RPMEMD_DBG("\tpersist APM: %s", bool2str(rpmemd->config.persist_apm)); RPMEMD_DBG("\tpersist GPSPM: %s", bool2str(rpmemd->config.persist_general)); RPMEMD_DBG("\tuse syslog: %s", bool2str(rpmemd->config.use_syslog)); RPMEMD_DBG("\tlog file: %s", _str(rpmemd->config.log_file)); RPMEMD_DBG("\tlog level: %s", rpmemd_log_level_to_str(rpmemd->config.log_level)); }
bool KvProxy::failover(uint32_t alias_index, bool is_del) { bool ret = false; string host_port; uint32_t index; uint32_t weight; if(is_del == true) { if(host_offline[alias_index] == true) { return true; } if(host_alias.find(alias_index) != host_alias.end()) { host_port = host_alias[alias_index].first + ":" + int2str(host_alias[alias_index].second); } else { return false; } if(hosts_default.find(alias_index) != hosts_default.end()) { ret = hash.delHost(alias_index); log_warn("%s offline in hosts, %s", host_port.c_str(), bool2str(ret).c_str()); } if(hosts_read.find(alias_index) != hosts_read.end()) { ret = hash_read.delHost(alias_index); log_warn("%s offline in hosts read, %s", host_port.c_str(), bool2str(ret).c_str()); } if(hosts_backup.find(alias_index) != hosts_backup.end()) { hash_backup.delHost(alias_index); log_warn("%s offline in hosts backup, %s", host_port.c_str(), bool2str(ret).c_str()); } host_offline[alias_index] = true; } else { if(host_offline[alias_index] == false) { return true; } if(host_alias.find(alias_index) != host_alias.end()) { host_port = host_alias[alias_index].first + ":" + int2str(host_alias[alias_index].second); } else { return false; } if(host_infos.find(alias_index) != host_infos.end()) { index = host_infos[alias_index].first; weight = host_infos[alias_index].second; } else { return false; } if(hosts_default.find(alias_index) != hosts_default.end()) { ret = hash.addHost(host_port, alias_index, index, weight); log_warn("%s online in hosts, %s", host_port.c_str(), bool2str(ret).c_str()); } if(hosts_read.find(alias_index) != hosts_read.end()) { ret = hash_read.addHost(host_port, alias_index, index, weight); log_warn("%s online in hosts read, %s", host_port.c_str(), bool2str(ret).c_str()); } if(hosts_backup.find(alias_index) != hosts_backup.end()) { ret = hash_backup.addHost(host_port, alias_index, index, weight); log_warn("%s online in hosts backup, %s", host_port.c_str(), bool2str(ret).c_str()); } host_offline[alias_index] = false; } return true; }
void UCamPar::print(const char * prestring) { printf("%s a3:%8.2e, a5:%8.2e, c:%7.2f, hx:%6.1f, hy:%6.1f", prestring, radialK1, radialK2, focalLength, headX, headY); printf(" - valid(%s), pixel size %f\n", bool2str(parValid), resFactor); if (parValid) { mP.print("mP"); mb.print("mb"); mCtoPRob.print("mCtoPRob"); mItoP.print("mItoP"); } }
bool UFunctionSeq::sendStatusMessage(UServerInMsg * msg, const char * tagName) { const int MRL = 1000; char reply[MRL]; bool result = true; USeqLine * lineActive; int lineNum; const int MCL = 200; char cmd[MCL] = "(none)"; // if (seq != NULL) { lineNum = seq->getActiveLine(); lineActive = seq->getLine(lineNum); if (lineActive != NULL) str2xml(cmd, MCL, lineActive->getCmdLine()); snprintf(reply, MRL, "<%s " "file=\"%s\" " "cmd=\"%s\" " "cmdLineNum=\"%d\" " "isIdle=\"%s\" " "simulated=\"%s\">\n", tagName, seq->getPlanName(), cmd, lineNum, bool2str(seq->isIdle()), bool2str(seq->isSimulated())); result = sendMsg(msg, reply); // send stop criteria status // -- not // send end tag snprintf(reply, MRL, "</%s>\n", tagName); result = sendMsg(msg, reply); } else sendWarning(msg, "Sequencer (seq) module lot loaded"); return result; }
int Reload_EntryProc_Config( void *module_config ) { entry_proc_config_t *conf = ( entry_proc_config_t * ) module_config; if ( conf->nb_thread != entry_proc_conf.nb_thread ) DisplayLog( LVL_MAJOR, "EntryProc_Config", ENTRYPROC_CONFIG_BLOCK "::nb_threads changed in config file, but cannot be modified dynamically" ); if ( conf->max_pending_operations != entry_proc_conf.max_pending_operations ) DisplayLog( LVL_MAJOR, "EntryProc_Config", ENTRYPROC_CONFIG_BLOCK "::max_pending_operations changed in config file, but cannot be modified dynamically" ); if ( conf->match_classes != entry_proc_conf.match_classes ) { DisplayLog( LVL_MAJOR, "EntryProc_Config", ENTRYPROC_CONFIG_BLOCK"::match_classes updated: '%s'->'%s'", bool2str(entry_proc_conf.match_classes), bool2str(conf->match_classes) ); entry_proc_conf.match_classes = conf->match_classes; } /* Check alert rules */ update_alerts( entry_proc_conf.alert_list, entry_proc_conf.alert_count, conf->alert_list, conf->alert_count, ENTRYPROC_CONFIG_BLOCK ); free_alert( conf->alert_list, conf->alert_count ); if ( entry_proc_conf.match_classes && !is_class_defined() ) { DisplayLog( LVL_EVENT, "EntryProc_Config" , "No class defined in policies, disabling class matching." ); entry_proc_conf.match_classes = FALSE; } return 0; }
void UProbPoly::print(const char * prestring, bool verbose) { int i; const int SL = 40; char s[SL]; printf("%s polygon with %d elements ", prestring, pointsCnt); poseOrgTime.print(" at"); if (verbose) { poseNow.print("Pose now"); poseNow.print("Pose org"); for (i = 0; i < pointsCnt; i++) { snprintf(s, SL, "#%3d obst %5s", i, bool2str(isObst[i])); points[i].print(s); } } }
const char * UPolyItem::codeXML(char * buf, const int bufCnt) { const int MEL = 100; char e[MEL]; USmlTag nTag; // if (bufCnt < (100 + 30 * pointsCnt)) printf("UPolyItem::codeXML: buffer too small just %d bytes left - skipping %s\n", bufCnt, name); else if (valid) { snprintf(e, MEL, "cooSys=\"%d\" relPoseUse=\"%s\" x=\"%.3f\" y=\"%.3f\" h=\"%.5f\" valid=\"true\"", cooSys, bool2str(relPoseUse), relPose.x, relPose.y, relPose.h); nTag.codePolygon(this, buf, bufCnt, name, e); } else { snprintf(buf, bufCnt, "<polygon name=\"%s\" valid=\"false\"/>\n", name); } return buf; }
bool UFuncPar::handleCommand(UServerInMsg * msg, void * extra) { const int MRL = 500; char reply[MRL]; // bool aLog, doLog, aDummy, aSilent = false; // bool aFake; // check for parameter 'help' if (msg->tag.getAttValue("help", NULL, 0)) { // create the reply in XML-like (html - like) format sendHelpStart("Par"); sendText("--- PAR is for roll and pitch calculations\n"); snprintf(reply, MRL, "log=true|false Opens or closes the logfile %s (open=%s)\n", logf.getLogFileName(), bool2str(logf.isOpen())); sendText(reply); sendText("eval evaluate parametric roll state\n"); sendText("update update parametric roll state with new sensor data\n"); //sendText("dummy update dummy data generator (output values for marg)\n"); sendText("fake=F fake some roll/pitch values F=roll frq\n"); sendText("sweep fake a frequenct sweep for the roll\n"); sendText("sweepStep fake a frequenct sweep step\n"); sendText("pitch=F with fake F=pitch frq\n"); sendText("silent do not make an info reply\n"); sendText("help This message\n"); sendHelpDone(); } else { // get any command attributes (when not a help request) bool doLog, aSilent, aSweep = false, aSweepStep = false, anEval = false; int aSweepSteps = 1; double rollFrq, pitchFrq=1.0/10.0; // 10Hz bool aLog = msg->tag.getAttBool("log", &doLog, true); bool aDummy = msg->tag.getAttBool("dummy", NULL); msg->tag.getAttBool("silent", &aSilent, true); bool aFake = msg->tag.getAttDouble("fake", &rollFrq, 1.0/20.0); msg->tag.getAttDouble("pitch", &pitchFrq, 1.0/10.0); msg->tag.getAttBool("sweep", &aSweep, true); aSweepStep = msg->tag.getAttInteger("sweepStep", &aSweepSteps, 1); msg->tag.getAttBool("eval", &anEval, true); bool anUpdate = msg->tag.getAttBool("update", NULL); // // implement command if (aLog) { // open or close the log aLog = logf.openLog(doLog); if (doLog) snprintf(reply, MRL, "Opened logfile %s (%s)", logf.getLogFileName(), bool2str(aLog)); else snprintf(reply, MRL, "closed logfile %s", logf.getLogFileName()); // send an information tag back to client sendInfo(reply); } else if (aDummy) { //dummy(); bool isOK = setGlobalVar("imu.aaa[1]", 33.0, true); printf("Set ima.aaa=33 %s\n", bool2str(isOK)); isOK = setGlobalVar("imu.bbb", 34.0, false); printf("Set ima.bbb=34 %s\n", bool2str(isOK)); isOK = getVarPool()->getGlobalVariable("imu.aaa")->setDouble(33.7, 1, true); printf("Set ima.aaa=33.7 %s\n", bool2str(isOK)); if (not aSilent) sendInfo("done"); } else if (aFake) { fakeImuValues(rollFrq, pitchFrq); // fake sweep } else if (aSweep) { double startFrq=0.001; //1.0; // oldest time double sampleRate=10.0; double endFrq = 0.3; // 0.0002; // newest time int samples=30000; UVariable * var = getVarPool()->getGlobalVariable("imu.rot"); fakeFrqSweep(var, 0.5, startFrq, endFrq, samples, sampleRate); // fake sweep } else if (anEval) { rollDetectBatch(); if (not aSilent) sendInfo("Done roll detect - not fully implemented yet"); } else if (anUpdate) { bool done = newImuData(); if (not aSilent) { if (done) sendInfo("updated sensor values"); else sendInfo("redundant info"); } } else if (not aSweepStep) sendWarning("No action see 'par help'"); if (aSweepStep) { UVariable * var = getVarPool()->getGlobalVariable("imu.rot"); double startFrq = 0.0003; // Hz double sampleRate = 3; // Hz double endFrq = sampleRate / 3.0; if (not setSweepMeasurement(var, -0.5, aSweepSteps, log(startFrq), log(endFrq), 20000, sampleRate)) { // last sample sweepStep = 0; sweepAngle = 0.0; } } } return true; }
bool UFunctionDisp::handleCommand(UServerInMsg * msg, void * extra) { // handle disp command char att[MAX_SML_NAME_LENGTH]; char att2[MAX_SML_NAME_LENGTH] = ""; const int VBL = 500; char val[VBL]; const int MRL = 600; char reply[MRL]; bool ask4help = false; bool result = false; bool replyOK = false; bool aLoad = false; const int MFL = 300; char aLoadName[MFL]; int theImgNum = 0; double v; UNavPaint * np; bool aPaint = false; // bool aCapture = false; // int aCaptureValue = 0; // if (disp == NULL) sendError(msg, "No display resource!!"); else { np = disp->getNavPaint(); while (msg->tag.getNextAttribute(att, val, VBL)) { // camera device if (strcasecmp(att, "help") == 0) ask4help = true; else if (strcasecmp(att, "load") == 0) { aLoad = true; strncpy(aLoadName, val, MFL); } else if (strcasecmp(att, "img") == 0) theImgNum = strtol(val, NULL, 0); else if (strcasecmp(att, "uvimg") == 0) { disp->setUVSource(strtol(val, NULL, 0)); aPaint = true; } else if (strcasecmp(att, "croma") == 0) { disp->setCROMASource(strtol(val, NULL, 0)); aPaint = true; } else if (strcasecmp(att, "intensMin") == 0) { disp->setIntensMin(strtol(val, NULL, 0)); aPaint = true; } else if (strcasecmp(att, "intensMax") == 0) { disp->setIntensMax(strtol(val, NULL, 0)); aPaint = true; } /* else if (strcasecmp(att, "testcap") == 0) { aCapture = true; if (strlen(val) > 0) aCaptureValue = strtol(val, NULL, 0); }*/ else if (disp != NULL) { aPaint = true; if (strcasecmp(att, "scale") == 0) disp->setScale(strtod(val, NULL)); // np->maxRange = maxd(1.0, strtod(val, NULL)); else if (strcasecmp(att, "pos") == 0) disp->setRobotPose(val); // np->robotPos = strtod(val, NULL); else if (strcasecmp(att, "bold") == 0) disp->paintBold(str2bool2(val, true)); else if (strcasecmp(att, "curves") == 0) np->paintCurves = str2bool2(val, true); else if (strcasecmp(att, "cam") == 0) np->paintCam = str2bool2(val, true); else if (strcasecmp(att, "gmk") == 0) np->paintGmk = str2bool2(val, true); else if (strcasecmp(att, "hereNow") == 0) np->setRefSystemsHere(); else if (strcasecmp(att, "autoHereNow") == 0) disp->setAutoHereNow(str2bool2(val, true)); else if (strcasecmp(att, "gridSys") == 0) np->paintPoseRef = strtol(val, NULL, 0); else if (strcasecmp(att, "grid") == 0) { v = strtod(val, NULL); np->paintGridOdo = (v > 0); if (v > 0) np->paintGridSize = v; } else if (strcasecmp(att, "rangeRings") == 0) disp->setRangeRingCnt(strtol(val, NULL, 10)); else if (strcasecmp(att, "pass") == 0) np->paintIntervalLines = str2bool2(val, true); else if (strcasecmp(att, "robot") == 0) disp->setRobot(val); else if (strcasecmp(att, "obst") == 0) np->paintObstCnt = strtol(val, NULL, 0); else if (strcasecmp(att, "poseHist") == 0) { np->paintPoseHistCnt = strtol(val, NULL, 0); } else if (strcasecmp(att, "poseHistVecCnt") == 0) np->paintPoseHistVecCnt = strtol(val, NULL, 0); else if (strcasecmp(att, "poseHistVecLng") == 0) np->paintPoseHistVecLng = strtol(val, NULL, 0); else if (strcasecmp(att, "path") == 0) np->paintPathLinesCnt = strtol(val, NULL, 0); else if (strcasecmp(att, "pathMid") == 0) np->paintPathMidPoses = str2bool2(val, true); else if (strcasecmp(att, "road") == 0) np->paintRoadHistCnt = strtol(val, NULL, 0); else if (strcasecmp(att, "roadAll") == 0) np->paintRoadAll = str2bool2(val, true); else if (strcasecmp(att, "scan") == 0) np->paintScanHistCnt = strtol(val, NULL, 0); else if (strcasecmp(att, "visPoly") == 0) np->paintVisPolyCnt = strtol(val, NULL, 0); else if (strcasecmp(att, "var") == 0) np->paintVar = str2bool2(val, true); else if (strcasecmp(att, "varAdd") == 0) { if (np->paintVarAdd(val, true)) np->paintVar = true; else strncpy(att2, att, MAX_SML_NAME_LENGTH); } else if (strcasecmp(att, "varDel") == 0) { if (not np->paintVarAdd(val, false)) strncpy(att2, att, MAX_SML_NAME_LENGTH); } else if (strcasecmp(att, "poly") == 0) np->paintPoly = str2bool2(val, true); else if (strcasecmp(att, "polyNameCnt") == 0) np->paintPolyNameCnt = strtol(val, NULL, 10); else if (strcasecmp(att, "polyHide") == 0) strncpy(np->paintPolyHide, val, np->maxStrLng); else if (strcasecmp(att, "polyShow") == 0) strncpy(np->paintPolyShow, val, np->maxStrLng); else if (strcasecmp(att, "odoPose") == 0) np->paintOdoPose = strtol(val, NULL, 0); else if (strcasecmp(att, "utmPose") == 0) np->paintUtmPose = strtol(val, NULL, 0); else if (strcasecmp(att, "mapPose") == 0) np->paintMapPose = strtol(val, NULL, 0); else if (strcasecmp(att, "do") == 0) disp->setNewDataNav(); else // not found - make a copy for reply strncpy(att2, att, MAX_SML_NAME_LENGTH); } } if (ask4help) { sendMsg(msg, "<help subject=\"disp\">\n"); sendText(msg, "----------- available disp options\n"); sendText(msg, "load=filename Load this image to imagepool image img=N (default N=0)"); sendText(msg, "img=N Use this image buffer number\n"); sendText(msg, "------ Image colour analysis options ----------\n"); sendText(msg, "uvimg=N Do UV analysis for this image number\n"); sendText(msg, "croma=N Do cromaticity analysis on this image number\n"); sendText(msg, "intensMin Minimum intensity to display colour\n"); sendText(msg, "intensMax Maximum intensity to display colour\n"); sendText(msg, "------ top-view (laser) image options ----------\n"); sendText(msg, "do update display\n"); snprintf(reply, MRL, "scale=height Scale image for image height in meter (is %gm)\n", np->maxRange); sendText(msg, reply); snprintf(reply, MRL, "pos=X[,Y] Place robot relative to bottom-center of image (is %gx, %gy)\n", np->robotPose.x, np->robotPose.y); sendText(msg, reply); sendText(msg, "bold[=false] Paint navigation image using bold lines (for presentations)\n"); snprintf(reply, MRL, "curves[=false] Paint laser line-fit variance curves (is %s)\n", bool2str(np->paintCurves)); sendText(msg, reply); snprintf(reply, MRL, "gridSys=0 | 1 | 2 Paint grid based on 0=odometry, 1=UTM, 2=Map coordinates (is %d)\n", np->paintPoseRef); sendText(msg, reply); snprintf(reply, MRL, "odoPose[=false] Show odometry pose at bottom of display (is %s)\n", bool2str(np->paintOdoPose)); sendText(msg, reply); snprintf(reply, MRL, "utmPose[=false] Show UTM (GPS) pose at bottom of display (is %s)\n", bool2str(np->paintUtmPose)); sendText(msg, reply); snprintf(reply, MRL, "mapPose[=false] Show map pose at bottom of display (is %s)\n", bool2str(np->paintMapPose)); sendText(msg, reply); sendText(msg, "hereNow Synchronoze all coordinate systems to here now\n"); snprintf(reply, MRL, "grid[=M] Paint coordinate grid every M meter (is %gm)\n", np->paintGridSize); sendText(msg, reply); snprintf(reply, MRL, "rangeRings[=M] Paint M range rings around laser scanner (is %dm)\n", np->rangeRingCnt); sendText(msg, reply); snprintf(reply, MRL, "pass[=false] Paint passable lines from laser scanner (is %s)\n", bool2str(np->paintIntervalLines)); sendText(msg, reply); snprintf(reply, MRL, "poly[=false] Paint poly items - planned mission lines etc. (is %s)\n", bool2str(np->paintPoly)); sendText(msg, reply); snprintf(reply, MRL, "polyNameCnt=N Paint polygon name, max N characters (last), N=%d\n", np->paintPolyNameCnt); sendText(msg, reply); snprintf(reply, MRL, "polyHide=\"name\" Hide selected poly items - accept wildchards (is '%s')\n", np->paintPolyHide); sendText(msg, reply); snprintf(reply, MRL, "polyShow=\"name\" Show among hidden poly items - accept wildchards (is '%s')\n", np->paintPolyShow); sendText(msg, reply); sendText(msg, "robot=[smr|mmr|hako|iRobot|guidebot] Paint robot outline as SMR, MMR...\n"); snprintf(reply, MRL, "obst=N Paint N obstacle groups (is %d)\n", np->paintObstCnt); sendText(msg, reply); snprintf(reply, MRL, "poseHist=N Paint N pose history positions for robot (is %d)\n", np->paintPoseHistCnt); sendText(msg, reply); snprintf(reply, MRL, "poseHistVecCnt=N Paint every N pose hist cnt a heading vector (is %d)\n", np->paintPoseHistVecCnt); sendText(msg, reply); snprintf(reply, MRL, "poseHistVecLng=N Paint pose hist heading vector N pixels long (is %d)\n", np->paintPoseHistVecLng); sendText(msg, reply); snprintf(reply, MRL, "path=[0 | 1 | N] Paint navigation path plan 0=no, 1=best, N=all (is %d)\n", np->paintPathLinesCnt); sendText(msg, reply); snprintf(reply, MRL, "pathMid[=false] Paint mid-poses used in path calculation (requires path > 0) is %s\n", bool2str(np->paintPathMidPoses)); sendText(msg, reply); snprintf(reply, MRL, "road[=N] Paint Road lines (if n > 0) and N road line updates (is %d)\n", np->paintRoadHistCnt); sendText(msg, reply); snprintf(reply, MRL, "roadAll Paint all available road lines (not just current best road) (is %s)\n", bool2str(np->paintRoadAll)); sendText(msg, reply); snprintf(reply, MRL, "scan=N Paint laserscan and history - up to N scans (is %d)\n", np->paintScanHistCnt); sendText(msg, reply); sendText(msg, "var[=false] Paint variables in struct list\n"); sendText(msg, "varAdd=struct Paint all variables in this struct\n"); sendText(msg, "varDel=struct Hide all variables in this struct\n"); snprintf(reply, MRL, "visPoly=N Paint N polygons from vision road detection (is %d)\n", np->paintVisPolyCnt); sendText(msg, reply); // sendText(msg, "testcap openCV test capture function\n"); sendText(msg, "help This help tekst\n"); sendText(msg, "--------\n"); sendText(msg, "See also POOLGET for image save or POOLLIST for available images\n"); sendMsg(msg, "</help>\n"); sendInfo(msg, "done"); } else if (disp != NULL) { if (aLoad) { result = disp->loadImgToPool(aLoadName, theImgNum); sendInfo(msg, "loaded"); replyOK = true; } if (strlen(att2) > 0) { snprintf(reply, MRL, "Unknown attribute %s", att2); sendWarning(msg, reply); replyOK = true; } else if (aPaint) { // an OK paint setting sendInfo(msg, "done"); replyOK = true; disp->setNewDataNav(); disp->setUvRedisplay(true); } /* else if (aCapture) { // an OK paint setting disp->capture(aCaptureValue); sendWarning(msg, "did a capture hmmm? may work"); replyOK = true; }*/ if (not replyOK) { snprintf(reply, MRL, "Unknown subject %s - try 'disp help'\n", msg->tag.getTagStart()); sendWarning(msg, reply); } } else sendWarning(msg, "No camera interface resource"); } return result; }
/** Update purge policy triggers */ static void update_triggers( trigger_item_t * trigger_list, unsigned int trigger_count ) { unsigned int i; int check_interval_chgd = FALSE; if ( trigger_count != resmon_config.trigger_count ) { /* skip trigger checking & update */ DisplayLog( LVL_MAJOR, RESMONCFG_TAG, "Trigger count changed in config file but cannot be modified dynamically: trigger update cancelled" ); return; } /* check trigger types */ for ( i = 0; i < trigger_count; i++ ) { if ( trigger_list[i].type != resmon_config.trigger_list[i].type ) { DisplayLog( LVL_MAJOR, RESMONCFG_TAG, "Trigger type changed (%d<>%d) in config file but cannot be modified dynamically: trigger update cancelled", trigger_list[i].type, resmon_config.trigger_list[i].type ); return; } else if ( ( trigger_list[i].type != TRIGGER_CUSTOM_CMD ) && ( trigger_list[i].type != TRIGGER_ALWAYS ) && ( trigger_list[i].hw_type != resmon_config.trigger_list[i].hw_type ) ) { DisplayLog( LVL_MAJOR, RESMONCFG_TAG, "High threshold type changed (%d<>%d) in config file but cannot be modified dynamically: trigger update cancelled", trigger_list[i].hw_type, resmon_config.trigger_list[i].hw_type ); return; } else if ( ( trigger_list[i].type != TRIGGER_CUSTOM_CMD ) && ( trigger_list[i].type != TRIGGER_ALWAYS ) && ( trigger_list[i].lw_type != resmon_config.trigger_list[i].lw_type ) ) { DisplayLog( LVL_MAJOR, RESMONCFG_TAG, "Low threshold type changed (%d<>%d) in config file but cannot be modified dynamically: trigger update cancelled", trigger_list[i].lw_type, resmon_config.trigger_list[i].lw_type ); return; } } /* triggers have the same type: update simple parameters: threshold levels and check interval */ for ( i = 0; i < trigger_count; i++ ) { if ( trigger_list[i].check_interval != resmon_config.trigger_list[i].check_interval ) { DisplayLog( LVL_EVENT, RESMONCFG_TAG, "check_interval updated for trigger #%u: %lu->%lu", i, resmon_config.trigger_list[i].check_interval, trigger_list[i].check_interval ); resmon_config.trigger_list[i].check_interval = trigger_list[i].check_interval; check_interval_chgd = TRUE; } if ( trigger_list[i].alert_hw != resmon_config.trigger_list[i].alert_hw ) { DisplayLog( LVL_EVENT, RESMONCFG_TAG, "alert_high updated for trigger #%u: %s->%s", i, bool2str(resmon_config.trigger_list[i].alert_hw), bool2str(trigger_list[i].alert_hw) ); resmon_config.trigger_list[i].alert_hw = trigger_list[i].alert_hw; } if ( trigger_list[i].alert_lw != resmon_config.trigger_list[i].alert_lw ) { DisplayLog( LVL_EVENT, RESMONCFG_TAG, "alert_low updated for trigger #%u: %s->%s", i, bool2str(resmon_config.trigger_list[i].alert_lw), bool2str(trigger_list[i].alert_lw) ); resmon_config.trigger_list[i].alert_lw = trigger_list[i].alert_lw; } /* no thresholds for custom cmd */ if ( trigger_list[i].type == TRIGGER_CUSTOM_CMD ) { if ( strcmp( trigger_list[i].list[0], resmon_config.trigger_list[i].list[0] ) ) { DisplayLog( LVL_MAJOR, RESMONCFG_TAG, "External command for trigger #%u changed in config file but cannot be modified dynamically", i ); } /* do nothing in all cases */ continue; } else if ( trigger_list[i].type == TRIGGER_ALWAYS ) /* no threshold for 'periodic' triggers */ continue; switch ( trigger_list[i].hw_type ) { case PCT_THRESHOLD: if ( trigger_list[i].hw_percent != resmon_config.trigger_list[i].hw_percent ) { DisplayLog( LVL_EVENT, RESMONCFG_TAG, "High threshold updated for trigger #%u: %.2f%%->%.2f%%", i, resmon_config.trigger_list[i].hw_percent, trigger_list[i].hw_percent ); resmon_config.trigger_list[i].hw_percent = trigger_list[i].hw_percent; } break; case VOL_THRESHOLD: if ( trigger_list[i].hw_volume != resmon_config.trigger_list[i].hw_volume ) { DisplayLog( LVL_EVENT, RESMONCFG_TAG, "High threshold updated for trigger #%u: %llu bytes->%llu bytes", i, resmon_config.trigger_list[i].hw_volume, trigger_list[i].hw_volume ); resmon_config.trigger_list[i].hw_volume = trigger_list[i].hw_volume; } break; case COUNT_THRESHOLD: if ( trigger_list[i].hw_count != resmon_config.trigger_list[i].hw_count ) { DisplayLog( LVL_EVENT, RESMONCFG_TAG, "High threshold updated for trigger #%u: %llu files->%llu files", i, resmon_config.trigger_list[i].hw_count, trigger_list[i].hw_count ); resmon_config.trigger_list[i].hw_count = trigger_list[i].hw_count; } break; } switch ( trigger_list[i].lw_type ) { case PCT_THRESHOLD: if ( trigger_list[i].lw_percent != resmon_config.trigger_list[i].lw_percent ) { DisplayLog( LVL_EVENT, RESMONCFG_TAG, "Low threshold updated for trigger #%u: %.2f%%->%.2f%%", i, resmon_config.trigger_list[i].lw_percent, trigger_list[i].lw_percent ); resmon_config.trigger_list[i].lw_percent = trigger_list[i].lw_percent; } break; case VOL_THRESHOLD: if ( trigger_list[i].lw_volume != resmon_config.trigger_list[i].lw_volume ) { DisplayLog( LVL_EVENT, RESMONCFG_TAG, "Low threshold updated for trigger #%u: %llu bytes->%llu bytes", i, resmon_config.trigger_list[i].lw_volume, trigger_list[i].lw_volume ); resmon_config.trigger_list[i].lw_volume = trigger_list[i].lw_volume; } break; case COUNT_THRESHOLD: if ( trigger_list[i].lw_count != resmon_config.trigger_list[i].lw_count ) { DisplayLog( LVL_EVENT, RESMONCFG_TAG, "Low threshold updated for trigger #%u: %llu files->%llu files", i, resmon_config.trigger_list[i].lw_count, trigger_list[i].lw_count ); resmon_config.trigger_list[i].lw_count = trigger_list[i].lw_count; } break; } } /* update global interval check (GCD of all check intervals) if one of them changed */ if ( check_interval_chgd ) ResMon_UpdateCheckInterval( ); /* triggers have been updated */ return; }
static int lmgr_cfg_read(config_file_t config, void *module_config, char *msg_out) { int rc; bool bval; lmgr_config_t *conf = (lmgr_config_t *) module_config; char **options = NULL; unsigned int nb_options = 0; char tmpstr[1024]; config_item_t lmgr_block; config_item_t db_block; static const char *lmgr_allowed[] = { "commit_behavior", "connect_retry_interval_min", "connect_retry_interval_max", "accounting", MYSQL_CONFIG_BLOCK, SQLITE_CONFIG_BLOCK, "user_acct", "group_acct", /* deprecated => accounting */ NULL }; const cfg_param_t cfg_params[] = { {"connect_retry_interval_min", PT_DURATION, PFLG_POSITIVE | PFLG_NOT_NULL, &conf->connect_retry_min, 0}, {"connect_retry_interval_max", PT_DURATION, PFLG_POSITIVE | PFLG_NOT_NULL, &conf->connect_retry_max, 0}, {"accounting", PT_BOOL, 0, &conf->acct, 0}, END_OF_PARAMS }; #ifdef _MYSQL static const char *db_allowed[] = { "server", "db", "user", "password", "password_file", "port", "socket", "engine", "tokudb_compression", NULL }; const cfg_param_t db_params[] = { {"server", PT_STRING, PFLG_NO_WILDCARDS, conf->db_config.server, sizeof(conf->db_config.server)} , {"db", PT_STRING, PFLG_MANDATORY | PFLG_NO_WILDCARDS, conf->db_config.db, sizeof(conf->db_config.db)} , {"user", PT_STRING, PFLG_NO_WILDCARDS, conf->db_config.user, sizeof(conf->db_config.user)} , {"port", PT_INT, PFLG_POSITIVE | PFLG_NOT_NULL, (int *)&conf->db_config.port, 0}, {"socket", PT_STRING, PFLG_NO_WILDCARDS | PFLG_ABSOLUTE_PATH, conf->db_config.socket, sizeof(conf->db_config.socket)} , {"engine", PT_STRING, PFLG_NO_WILDCARDS | PFLG_NOT_EMPTY, conf->db_config.engine, sizeof(conf->db_config.engine)} , {"tokudb_compression", PT_STRING, PFLG_NO_WILDCARDS, conf->db_config.tokudb_compression, sizeof(conf->db_config.tokudb_compression)} , END_OF_PARAMS }; #elif defined(_SQLITE) static const char *db_allowed[] = { "db_file", "retry_delay_microsec", NULL }; const cfg_param_t db_params[] = { {"db_file", PT_STRING, PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS, conf->db_config.filepath, sizeof(conf->db_config.filepath)} , {"retry_delay_microsec", PT_INT, PFLG_POSITIVE | PFLG_NOT_NULL, (int *)&conf->db_config.retry_delay_microsec, 0}, END_OF_PARAMS }; #endif /* get ListManager block */ rc = get_cfg_block(config, LMGR_CONFIG_BLOCK, &lmgr_block, msg_out); if (rc) return rc; /* retrieve std parameters */ rc = read_scalar_params(lmgr_block, LMGR_CONFIG_BLOCK, cfg_params, msg_out); if (rc) return rc; /* commit_behavior */ rc = GetStringParam(lmgr_block, LMGR_CONFIG_BLOCK, "commit_behavior", PFLG_NO_WILDCARDS, tmpstr, sizeof(tmpstr), &options, &nb_options, msg_out); if ((rc != 0) && (rc != ENOENT)) return rc; else if (rc != ENOENT) { if (!strcasecmp(tmpstr, "autocommit")) conf->commit_behavior = 0; else if (!strcasecmp(tmpstr, "transaction")) conf->commit_behavior = 1; else if (!strcasecmp(tmpstr, "periodic")) { if ((nb_options != 1) || !options || !options[0]) { strcpy(msg_out, "A single argument is expected for periodic commit behavior. Eg: commit_behavior = periodic(1000)"); return EINVAL; } conf->commit_behavior = atoi(options[0]); if (conf->commit_behavior == 0) { strcpy(msg_out, "The argument for \"" LMGR_CONFIG_BLOCK "::commit_behavior = periodic\" must be a positive integer. Eg: commit_behavior = periodic(1000)"); return EINVAL; } } else { sprintf(msg_out, "Invalid commit behavior '%s' (expected: autocommit, " "transaction, periodic(<count>))", tmpstr); return EINVAL; } } /* manage deprecated parameters */ rc = GetBoolParam(lmgr_block, LMGR_CONFIG_BLOCK, "user_acct", 0, &bval, NULL, NULL, msg_out); if (rc == 0) { DisplayLog(LVL_CRIT, TAG, "WARNING: parameter %s::%s' is deprecated. Specify 'accounting = yes/no' instead.", LMGR_CONFIG_BLOCK, "user_acct"); DisplayLog(LVL_MAJOR, TAG, "Setting 'accounting = %s' for compatibility.", bool2str(bval)); conf->acct = bval; } rc = GetBoolParam(lmgr_block, LMGR_CONFIG_BLOCK, "group_acct", 0, &bval, NULL, NULL, msg_out); if (rc == 0) { DisplayLog(LVL_CRIT, TAG, "WARNING: parameter %s::%s' is deprecated. Specify 'accounting = yes/no' instead.", LMGR_CONFIG_BLOCK, "group_acct"); DisplayLog(LVL_MAJOR, TAG, "Setting 'accounting = %s' for compatibility.", bool2str(bval)); conf->acct = bval; } CheckUnknownParameters(lmgr_block, LMGR_CONFIG_BLOCK, lmgr_allowed); /* Database parameters */ #ifdef _MYSQL /* get MySQL block */ rc = get_cfg_block(config, LMGR_CONFIG_BLOCK "::" MYSQL_CONFIG_BLOCK, &db_block, msg_out); if (rc) return rc; /* DB std params */ rc = read_scalar_params(db_block, MYSQL_CONFIG_BLOCK, db_params, msg_out); if (rc) return rc; /* DB params with specific type */ rc = GetStringParam(db_block, MYSQL_CONFIG_BLOCK, "password", 0, conf->db_config.password, 256, NULL, NULL, msg_out); if ((rc != 0) && (rc != ENOENT)) return rc; else if (rc == ENOENT) { FILE *passfile; char errstr[1024]; rc = GetStringParam(db_block, MYSQL_CONFIG_BLOCK, "password_file", PFLG_ABSOLUTE_PATH | PFLG_NO_WILDCARDS, tmpstr, sizeof(tmpstr), NULL, NULL, msg_out); if ((rc != 0) && (rc != ENOENT)) return rc; else if (rc == ENOENT) { strcpy(msg_out, MYSQL_CONFIG_BLOCK "::password or " MYSQL_CONFIG_BLOCK "::password_file must be provided"); return ENOENT; } /* read password file and @TODO check its rights */ passfile = fopen(tmpstr, "r"); if (!passfile) { rc = errno; sprintf(msg_out, "Error opening password file %s : %s", tmpstr, strerror(errno)); return rc; } rc = fscanf(passfile, "%1023s", tmpstr); if (ferror(passfile) || rc < 1) { rc = errno; if (strerror_r(rc, errstr, sizeof(errstr))) { snprintf(errstr, sizeof(errstr), "%d", rc); } sprintf(msg_out, "Error reading password file %s : %s", tmpstr, errstr); return rc; } fclose(passfile); rh_strncpy(conf->db_config.password, tmpstr, 256); } CheckUnknownParameters(db_block, MYSQL_CONFIG_BLOCK, db_allowed); #elif defined(_SQLITE) /* get SQLite block */ rc = get_cfg_block(config, LMGR_CONFIG_BLOCK "::" SQLITE_CONFIG_BLOCK, &db_block, msg_out); if (rc) return rc; rc = read_scalar_params(db_block, SQLITE_CONFIG_BLOCK, db_params, msg_out); if (rc) return rc; CheckUnknownParameters(db_block, SQLITE_CONFIG_BLOCK, db_allowed); #endif return 0; }
int FSScan_ReloadConfig( void *module_config ) { fs_scan_config_t *conf = ( fs_scan_config_t * ) module_config; /* Parameters that can be modified dynamically */ if ( conf->min_scan_interval != fs_scan_config.min_scan_interval ) { DisplayLog( LVL_EVENT, "FS_Scan_Config", FSSCAN_CONFIG_BLOCK "::min_scan_interval updated: %u->%u", fs_scan_config.min_scan_interval, conf->min_scan_interval ); fs_scan_config.min_scan_interval = conf->min_scan_interval; } if ( conf->max_scan_interval != fs_scan_config.max_scan_interval ) { DisplayLog( LVL_EVENT, "FS_Scan_Config", FSSCAN_CONFIG_BLOCK "::max_scan_interval updated: %u->%u", fs_scan_config.max_scan_interval, conf->max_scan_interval ); fs_scan_config.max_scan_interval = conf->max_scan_interval; } if ( conf->scan_retry_delay != fs_scan_config.scan_retry_delay ) { DisplayLog( LVL_EVENT, "FS_Scan_Config", FSSCAN_CONFIG_BLOCK "::scan_retry_delay updated: %u->%u", fs_scan_config.scan_retry_delay, conf->scan_retry_delay ); fs_scan_config.scan_retry_delay = conf->scan_retry_delay; } if ( conf->scan_op_timeout != fs_scan_config.scan_op_timeout ) { DisplayLog( LVL_EVENT, "FS_Scan_Config", FSSCAN_CONFIG_BLOCK "::scan_op_timeout updated: %u->%u", fs_scan_config.scan_op_timeout, conf->scan_op_timeout ); fs_scan_config.scan_op_timeout = conf->scan_op_timeout; } if ( conf->exit_on_timeout != fs_scan_config.exit_on_timeout ) { DisplayLog( LVL_EVENT, "FS_Scan_Config", FSSCAN_CONFIG_BLOCK "::exit_on_timeout updated: %s->%s", bool2str(fs_scan_config.exit_on_timeout), bool2str(conf->exit_on_timeout) ); fs_scan_config.exit_on_timeout = conf->exit_on_timeout; } if ( conf->spooler_check_interval != fs_scan_config.spooler_check_interval ) { DisplayLog( LVL_EVENT, "FS_Scan_Config", FSSCAN_CONFIG_BLOCK "::spooler_check_interval updated: %u->%u", fs_scan_config.spooler_check_interval, conf->spooler_check_interval ); fs_scan_config.spooler_check_interval = conf->spooler_check_interval; } if ( strcmp( conf->completion_command, fs_scan_config.completion_command ) ) { DisplayLog( LVL_EVENT, "FS_Scan_Config", FSSCAN_CONFIG_BLOCK "::completion_command updated: '%s'->'%s'", fs_scan_config.completion_command, conf->completion_command ); strcpy( fs_scan_config.completion_command, conf->completion_command); } /* Parameters that canNOT be modified dynamically */ if ( conf->nb_threads_scan != fs_scan_config.nb_threads_scan ) DisplayLog( LVL_MAJOR, "FS_Scan_Config", FSSCAN_CONFIG_BLOCK "::nb_threads_scan changed in config file, but cannot be modified dynamically" ); if ( conf->nb_prealloc_tasks != fs_scan_config.nb_prealloc_tasks ) DisplayLog( LVL_MAJOR, "FS_Scan_Config", FSSCAN_CONFIG_BLOCK "::nb_prealloc_tasks changed in config file, but cannot be modified dynamically" ); /* compare ignore list */ update_ignore( fs_scan_config.ignore_list, fs_scan_config.ignore_count, conf->ignore_list, conf->ignore_count, FSSCAN_CONFIG_BLOCK ); /* free conf structure */ free_ignore( conf->ignore_list, conf->ignore_count ); return 0; }
const char * UFunctionSeq::print(const char * preString, char * buff, int buffCnt) { snprintf(buff, buffCnt, "%s Sequencer loop resource (empty %s)\n", preString, bool2str(seq == NULL)); return buff; }
int ReloadLogConfig( void *module_config ) { log_config_t *conf = ( log_config_t * ) module_config; if ( conf->debug_level != log_config.debug_level ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::debug_level modified: '%d'->'%d'", log_config.debug_level, conf->debug_level ); log_config.debug_level = conf->debug_level; } /* log files can be changed dynamically : this will just be considered as if it was renamed */ if ( strcmp( conf->log_file, log_config.log_file ) ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::log_file modified: '%s'->'%s'", log_config.log_file, conf->log_file ); /* lock file name to avoid reading inconsistent filenames */ pthread_mutex_lock( &mutex_reopen ); strcpy( log_config.log_file, conf->log_file ); pthread_mutex_unlock( &mutex_reopen ); } if ( strcmp( conf->report_file, log_config.report_file ) ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::report_file modified: '%s'->'%s'", log_config.report_file, conf->report_file ); /* lock file name to avoid reading inconsistent filenames */ pthread_mutex_lock( &mutex_reopen ); strcpy( log_config.report_file, conf->report_file ); pthread_mutex_unlock( &mutex_reopen ); } if ( strcmp( conf->alert_file, log_config.alert_file ) ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_file modified: '%s'->'%s'", log_config.alert_file, conf->alert_file ); /* lock file name to avoid reading inconsistent filenames */ pthread_mutex_lock( &mutex_reopen ); strcpy( log_config.alert_file, conf->alert_file ); pthread_mutex_unlock( &mutex_reopen ); } if ( strcmp( conf->alert_mail, log_config.alert_mail ) ) DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_mail changed in config file, but cannot be modified dynamically" ); if ( conf->stats_interval != log_config.stats_interval ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::stats_interval modified: " "'%"PRI_TT"'->'%"PRI_TT"'", log_config.stats_interval, conf->stats_interval ); log_config.stats_interval = conf->stats_interval; } if ( conf->batch_alert_max != log_config.batch_alert_max ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::batch_alert_max modified: '%u'->'%u'", log_config.batch_alert_max, conf->batch_alert_max ); /* flush batched alerts first */ P( alert_mutex ); if ( alert_batching ) /* don't release mutex */ FlushAlerts(FALSE); log_config.batch_alert_max = conf->batch_alert_max; V( alert_mutex ); } if ( conf->alert_show_attrs != log_config.alert_show_attrs ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_show_attrs modified: '%s'->'%s'", bool2str(log_config.alert_show_attrs), bool2str(conf->alert_show_attrs) ); log_config.alert_show_attrs = conf->alert_show_attrs; } return 0; }
static void test_CarlaUtils() { // ---------------------------------------------------------------------------------------------------------------- // misc functions { bool2str(false); bool2str(true); pass(); char strBuf[2]; nullStrBuf(strBuf); char* const strBuf2(strBuf+1); nullStrBuf(strBuf2); } // ---------------------------------------------------------------------------------------------------------------- // string print functions { carla_debug("DEBUG"); carla_stdout("STDOUT %s", bool2str(true)); carla_stderr("STDERR %s", bool2str(false)); carla_stderr2("STDERR2 " P_UINT64, 0xffffffff); // 4294967295 } // ---------------------------------------------------------------------------------------------------------------- // carla_*sleep { carla_sleep(1); carla_msleep(1); } // ---------------------------------------------------------------------------------------------------------------- // carla_setenv { carla_setenv("THIS", "THAT"); assert(std::strcmp(std::getenv("THIS"), "THAT") == 0); carla_unsetenv("THIS"); assert(std::getenv("THIS") == nullptr); } // ---------------------------------------------------------------------------------------------------------------- // carla_strdup { // with variables const char* const str1(carla_strdup("stringN")); const char* const strF(carla_strdup_free(strdup("stringF"))); const char* const str2(carla_strdup_safe("stringS")); delete[] str1; delete[] str2; delete[] strF; // without variables delete[] carla_strdup("string_normal"); delete[] carla_strdup_free(strdup("string_free")); delete[] carla_strdup_safe("string_safe"); } { // common use case in Carla code struct TestStruct { const char* strNull; const char* strNormal; const char* strFree; const char* strSafe; TestStruct() : strNull(nullptr), strNormal(carla_strdup("strNormal")), strFree(carla_strdup_free(strdup("strFree"))), strSafe(carla_strdup_safe("strSafe")) {} ~TestStruct() noexcept { if (strNull != nullptr) { delete[] strNull; strNull = nullptr; } if (strNormal != nullptr) { delete[] strNormal; strNormal = nullptr; } if (strFree != nullptr) { delete[] strFree; strFree = nullptr; } if (strSafe != nullptr) { delete[] strSafe; strSafe = nullptr; } } CARLA_DECLARE_NON_COPY_STRUCT(TestStruct) }; TestStruct a, b, c; } // ---------------------------------------------------------------------------------------------------------------- // memory functions { int a1[] = { 4, 3, 2, 1 }; int a2[] = { 4, 3, 2, 1 }; int b1[] = { 1, 2, 3, 4 }; int b2[] = { 1, 2, 3, 4 }; carla_add(a1, b1, 4); assert(a1[0] == 5); assert(a1[1] == 5); assert(a1[2] == 5); assert(a1[3] == 5); carla_add(b1, a2, 4); assert(b1[0] == 5); assert(b1[1] == 5); assert(b1[2] == 5); assert(b1[3] == 5); assert(a1[0] == b1[0]); assert(a1[1] == b1[1]); assert(a1[2] == b1[2]); assert(a1[3] == b1[3]); carla_copy(a1, b2, 4); assert(a1[0] != b1[0]); assert(a1[1] != b1[1]); assert(a1[2] != b1[2]); assert(a1[3] != b1[3]); assert(a1[0] == b2[0]); assert(a1[1] == b2[1]); assert(a1[2] == b2[2]); assert(a1[3] == b2[3]); carla_copy(a1, b1, 4); assert(a1[0] == b1[0]); assert(a1[1] == b1[1]); assert(a1[2] == b1[2]); assert(a1[3] == b1[3]); carla_copy(a1, b2, 2); assert(a1[0] != b1[0]); assert(a1[1] != b1[1]); assert(a1[2] == b1[2]); assert(a1[3] == b1[3]); carla_copy(a1+2, b2+2, 2); assert(a1[0] != b1[0]); assert(a1[1] != b1[1]); assert(a1[2] != b1[2]); assert(a1[3] != b1[3]); carla_copy(a1, b1, 2); assert(a1[0] == b1[0]); assert(a1[1] == b1[1]); assert(a1[2] != b1[2]); assert(a1[3] != b1[3]); carla_copy(a1+2, b1+2, 2); assert(a1[0] == b1[0]); assert(a1[1] == b1[1]); assert(a1[2] == b1[2]); assert(a1[3] == b1[3]); carla_fill(a1, 0, 4); assert(a1[0] == 0); assert(a1[1] == 0); assert(a1[2] == 0); assert(a1[3] == 0); carla_fill(a1, -11, 4); assert(a1[0] == -11); assert(a1[1] == -11); assert(a1[2] == -11); assert(a1[3] == -11); carla_fill(a1, 1791, 2); assert(a1[0] == 1791); assert(a1[1] == 1791); assert(a1[2] == -11); assert(a1[3] == -11); carla_fill(a1+2, 1791, 2); assert(a1[0] == 1791); assert(a1[1] == 1791); assert(a1[2] == 1791); assert(a1[3] == 1791); int16_t d = 1527, e = 0; carla_add(&d, &d, 1); assert(d == 1527*2); carla_add(&d, &d, 1); assert(d == 1527*4); carla_add(&d, &e, 1); assert(d == 1527*4); assert(e == 0); carla_add(&e, &d, 1); assert(d == e); carla_add(&e, &d, 1); assert(e == d*2); d = -e; carla_add(&d, &e, 1); assert(d == 0); } { bool x; const bool f = false, t = true; carla_copy(&x, &t, 1); assert(x); carla_copy(&x, &f, 1); assert(! x); carla_fill(&x, true, 1); assert(x); carla_fill(&x, false, 1); assert(! x); } { uint8_t a[] = { 3, 2, 1, 0 }; carla_zeroBytes(a, 1); assert(a[0] == 0); assert(a[1] == 2); assert(a[2] == 1); assert(a[3] == 0); carla_zeroBytes(a+1, 2); assert(a[0] == 0); assert(a[1] == 0); assert(a[2] == 0); assert(a[3] == 0); } { char a[501]; for (int i=500; --i>=0;) a[i] = 'a'; carla_zeroChars(a, 501); for (int i=501; --i>=0;) assert(a[i] == '\0'); for (int i=500; --i>=0;) a[i] = 'a'; assert(std::strlen(a) == 500); carla_fill(a+200, '\0', 1); assert(std::strlen(a) == 200); } { void* a[33]; carla_zeroPointers(a, 33); for (int i=33; --i>=0;) assert(a[i] == nullptr); } { struct Thing { char c; int i; int64_t h; bool operator==(const Thing& t) const noexcept { return (t.c == c && t.i == i && t.h == h); } bool operator!=(const Thing& t) const noexcept { return !operator==(t); } }; Thing a, b, c; a.c = 0; a.i = 0; a.h = 0; b.c = 64; b.i = 64; b.h = 64; c = a; carla_copyStruct(a, b); assert(a == b); carla_zeroStruct(a); assert(a == c); carla_copyStruct(c, b); assert(a != c); // make it non-zero a.c = 1; Thing d[3]; carla_zeroStructs(d, 3); assert(d[0] != a); assert(d[1] != b); assert(d[2] != c); carla_copyStructs(d, &a, 1); assert(d[0] == a); assert(d[1] != b); assert(d[2] != c); carla_copyStructs(&c, d+2, 1); assert(d[0] == a); assert(d[1] != b); assert(d[2] == c); } }
/** * \pre This should be called with the factory lock taken. * * param[in] num_local Number of local forwarders discovered, -1 if not counted * param[in] timeout True if a timeout occurred */ static qeo_retcode_t fwd_server_state_machine_eval_ul(qeo_factory_t *factory, int num_local, bool timeout, bool public_ip_available) { qeo_retcode_t rc = QEO_OK; qeo_log_i("old state %s : local fwd count = %d, timeout = %s, public ip available = %s", server_state_to_str(factory->fwd.u.server.state), num_local, bool2str(timeout), bool2str(public_ip_available)); switch (factory->fwd.u.server.state) { case FWD_STATE_INIT: { /* done with initialization */ int timeout = qeocore_parameter_get_number("FWD_WAIT_LOCAL_FWD"); rc = ddsrc_to_qeorc(DDS_Timer_start(factory->fwd.timer, timeout, (uintptr_t)factory, fwd_server_timeout)); if (QEO_OK != rc) { qeo_log_e("failed to start forwarder timer"); break; } rc = qeocore_reader_enable(factory->fwd.reader); if (QEO_OK != rc) { qeo_log_e("failed to enable forwarder reader"); break; } factory->fwd.u.server.state = FWD_STATE_WAIT_LOCAL; break; } case FWD_STATE_WAIT_LOCAL: /* done waiting for local forwarder */ if (timeout) { /* no local forwarders found, try start forwarding ourselves */ factory->fwd.u.server.state = FWD_STATE_STARTING; unlock(&factory->mutex); factory->listener.on_fwdfactory_get_public_locator(factory); lock(&factory->mutex); } else if (num_local > 0) { /* local forwarder(s) available stop timer */ DDS_Timer_stop(factory->fwd.timer); factory->fwd.u.server.state = FWD_STATE_DISABLED; } break; case FWD_STATE_STARTING: /* done waiting for publicly available locator */ if (num_local > 0) { factory->fwd.u.server.state = FWD_STATE_DISABLED; } else if (public_ip_available) { if (QEO_OK == fwd_server_start_forwarding(factory)) { factory->fwd.u.server.state = FWD_STATE_ENABLED; } else { /* failed to start */ factory->fwd.u.server.state = FWD_STATE_DISABLED; } } break; case FWD_STATE_ENABLED: if (public_ip_available) { if (QEO_OK == fwd_server_start_forwarding(factory)) { factory->fwd.u.server.state = FWD_STATE_ENABLED; } else { /* failed to start */ factory->fwd.u.server.state = FWD_STATE_DISABLED; } } break; case FWD_STATE_DISABLED: if (0 == num_local) { /* no local forwarders anymore, try start forwarding ourselves */ factory->fwd.u.server.state = FWD_STATE_STARTING; unlock(&factory->mutex); factory->listener.on_fwdfactory_get_public_locator(factory); lock(&factory->mutex); } break; } qeo_log_i("new state %s", server_state_to_str(factory->fwd.u.server.state)); return rc; }
std::string Vertical::toString() { return " udef = ["+bool2str(udef)+" z = "+Fm2(z)+"]"; }
void scr_PutBoolean (const char *key, bool value) { check_map_init (); scr_PutString (key, bool2str(value)); }
static int log_cfg_reload(log_config_t *conf) { if (conf->debug_level != log_config.debug_level) { if (!log_config.force_debug_level) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::debug_level modified: '%d'->'%d'", log_config.debug_level, conf->debug_level); log_config.debug_level = conf->debug_level; } else { DisplayLog(LVL_EVENT, "LogConfig", "Log level is forced by command " "line. Not taking configuration parameter " RBH_LOG_CONFIG_BLOCK "::debug_level into account."); } } /* log files can be changed dynamically: this will just be considered as if * it was renamed */ if (strcmp(conf->log_file, log_config.log_file)) { if (!log_config.force_log_file) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::log_file modified: '%s'->'%s'", log_config.log_file, conf->log_file); /* lock file name to avoid reading inconsistent filenames */ pthread_rwlock_wrlock(&log.f_lock); strcpy(log_config.log_file, conf->log_file); pthread_rwlock_wrlock(&log.f_lock); } else { DisplayLog(LVL_EVENT, "LogConfig", "Log file is forced by command " "line. Not taking configuration parameter " RBH_LOG_CONFIG_BLOCK "::log_file into account."); } } if (strcmp(conf->report_file, log_config.report_file)) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::report_file modified: '%s'->'%s'", log_config.report_file, conf->report_file); /* lock file name to avoid reading inconsistent filenames */ pthread_rwlock_wrlock(&report.f_lock); strcpy(log_config.report_file, conf->report_file); pthread_rwlock_unlock(&report.f_lock); } if (strcmp(conf->alert_file, log_config.alert_file)) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_file modified: '%s'->'%s'", log_config.alert_file, conf->alert_file); /* lock file name to avoid reading inconsistent filenames */ pthread_rwlock_wrlock(&alert.f_lock); strcpy(log_config.alert_file, conf->alert_file); pthread_rwlock_unlock(&alert.f_lock); } if (strcmp(conf->alert_mail, log_config.alert_mail)) DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_mail changed in config file, but cannot be modified dynamically"); #ifdef HAVE_CHANGELOGS if (strcmp(conf->changelogs_file, log_config.changelogs_file)) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::changelogs_file modified: '%s'->'%s'", log_config.changelogs_file, conf->changelogs_file); /* lock file name to avoid reading inconsistent filenames */ pthread_rwlock_wrlock(&chglogs.f_lock); strcpy(log_config.changelogs_file, conf->changelogs_file); pthread_rwlock_unlock(&chglogs.f_lock); } #endif if (conf->stats_interval != log_config.stats_interval) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::stats_interval modified: " "'%" PRI_TT "'->'%" PRI_TT "'", log_config.stats_interval, conf->stats_interval); log_config.stats_interval = conf->stats_interval; } if (conf->batch_alert_max != log_config.batch_alert_max) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::batch_alert_max modified: '%u'->'%u'", log_config.batch_alert_max, conf->batch_alert_max); /* flush batched alerts first */ P(alert_mutex); if (alert_batching) /* don't release mutex */ FlushAlerts(false); log_config.batch_alert_max = conf->batch_alert_max; V(alert_mutex); } if (conf->log_process != log_config.log_process) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::log_procname modified: '%s'->'%s'", bool2str(log_config.log_process), bool2str(conf->log_process)); log_config.log_process = conf->log_process; } if (conf->log_host != log_config.log_host) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::log_hostname modified: '%s'->'%s'", bool2str(log_config.log_host), bool2str(conf->log_host)); log_config.log_host = conf->log_host; } rbh_adjust_log_level_external(); return 0; }
/** reload parameters for a single policy */ static int polrun_reload(const char *blkname, policy_run_config_t *cfg_tgt, policy_run_config_t *cfg_new, bool *recompute_interval) { /* parameters that can't be modified dynamically */ if (cfg_tgt->nb_threads != cfg_new->nb_threads) no_param_updt_msg(blkname, "nb_threads"); if (cfg_tgt->queue_size != cfg_new->queue_size) no_param_updt_msg(blkname, "queue_size"); // FIXME can change action functions, but not cmd string // if (strcmp(cfg_new->default_action, cfg_tgt->default_action)) // no_param_updt_msg(blkname, "default_action"); // TODO parse action and action_params // and set params_attr_mask accordingly. if (cfg_tgt->lru_sort_attr != cfg_new->lru_sort_attr) no_param_updt_msg(blkname, "lru_sort_attr"); /* dynamic parameters */ if (cfg_tgt->max_action_nbr != cfg_new->max_action_nbr) { PARAM_UPDT_MSG(blkname, "max_action_count", "%u", cfg_tgt->max_action_nbr, cfg_new->max_action_nbr); cfg_tgt->max_action_nbr = cfg_new->max_action_nbr; } if (cfg_tgt->max_action_vol != cfg_new->max_action_vol) { PARAM_UPDT_MSG(blkname, "max_action_volume", "%llu", cfg_tgt->max_action_vol, cfg_new->max_action_vol); cfg_tgt->max_action_vol = cfg_new->max_action_vol; } if (cfg_tgt->suspend_error_pct != cfg_new->suspend_error_pct) { PARAM_UPDT_MSG(blkname, "suspend_error_pct", "%.2f%%", cfg_tgt->suspend_error_pct, cfg_new->suspend_error_pct); cfg_tgt->suspend_error_pct = cfg_new->suspend_error_pct; } if (cfg_tgt->suspend_error_min != cfg_new->suspend_error_min) { PARAM_UPDT_MSG(blkname, "suspend_error_min", "%u", cfg_tgt->suspend_error_min, cfg_new->suspend_error_min); cfg_tgt->suspend_error_min = cfg_new->suspend_error_min; } if (cfg_tgt->report_interval != cfg_new->report_interval) { PARAM_UPDT_MSG(blkname, "report_interval", "%lu", cfg_tgt->report_interval, cfg_new->report_interval); cfg_tgt->report_interval = cfg_new->report_interval; } if (cfg_tgt->action_timeout != cfg_new->action_timeout) { PARAM_UPDT_MSG(blkname, "action_timeout", "%lu", cfg_tgt->action_timeout, cfg_new->action_timeout); cfg_tgt->action_timeout = cfg_new->action_timeout; } if (cfg_tgt->check_action_status_delay != cfg_new->check_action_status_delay) { PARAM_UPDT_MSG(blkname, "check_actions_interval", "%lu", cfg_tgt->check_action_status_delay, cfg_new->check_action_status_delay); cfg_tgt->check_action_status_delay = cfg_new->check_action_status_delay; } if (cfg_tgt->db_request_limit != cfg_new->db_request_limit) { PARAM_UPDT_MSG(blkname, "db_result_size_max", "%u", cfg_tgt->db_request_limit, cfg_new->db_request_limit); cfg_tgt->db_request_limit = cfg_new->db_request_limit; } if (cfg_tgt->pre_maintenance_window != cfg_new->pre_maintenance_window) { PARAM_UPDT_MSG(blkname, "pre_maintenance_window", "%lu", cfg_tgt->pre_maintenance_window, cfg_new->pre_maintenance_window); cfg_tgt->pre_maintenance_window = cfg_new->pre_maintenance_window; } if (cfg_tgt->maint_min_apply_delay != cfg_new->maint_min_apply_delay) { PARAM_UPDT_MSG(blkname, "maint_min_apply_delay", "%lu", cfg_tgt->maint_min_apply_delay, cfg_new->maint_min_apply_delay); cfg_tgt->maint_min_apply_delay = cfg_new->maint_min_apply_delay; } if (cfg_tgt->check_action_status_on_startup != cfg_new->check_action_status_on_startup) { PARAM_UPDT_MSG(blkname, "check_actions_on_startup", "%s", bool2str(cfg_tgt->check_action_status_on_startup), bool2str(cfg_new->check_action_status_on_startup)); cfg_tgt->check_action_status_on_startup = cfg_new->check_action_status_on_startup; } if (cfg_tgt->recheck_ignored_entries != cfg_new->recheck_ignored_entries) { PARAM_UPDT_MSG(blkname, "recheck_ignored_entries", "%s", bool2str(cfg_tgt->recheck_ignored_entries), bool2str(cfg_new->recheck_ignored_entries)); cfg_tgt->recheck_ignored_entries = cfg_new->recheck_ignored_entries; } if (cfg_tgt->report_actions != cfg_new->report_actions) { PARAM_UPDT_MSG(blkname, "report_actions", "%s", bool2str(cfg_tgt->report_actions), bool2str(cfg_new->report_actions)); cfg_tgt->report_actions = cfg_new->report_actions; } update_triggers(cfg_tgt->trigger_list, cfg_tgt->trigger_count, cfg_new->trigger_list, cfg_new->trigger_count, recompute_interval); return 0; }
bool UFuncPar::newImuData() { UVarPool * vp = getVarPool(); const char * varSrc = varImuSource->getValues(); UVariable * rotHist = vp->getGlobalVariable(varSrc); bool isOK = rotHist != NULL; bool initialize = rollRaw == NULL; const int oversamplingRate = 40; const int firCnt = 51; int bufSize = firCnt * 2 + 1; // bandpass filter assuming sample rate is 40 times natural roll frq. // center frequency is 1/20 = 0.05 // MATLAB: >> filter51 = fir1(51, [0.045 0.06]) const double fir51[] = { -0.003218328227846, -0.004057818065448, -0.005242771040626, -0.006854855724642, -0.008903243900917, -0.011317902752974, -0.013950493386618, -0.016583013848246, -0.018943644085201, -0.020728605105972, -0.021628290934674, -0.021355518618346, -0.019673505879184, -0.016421150568180, -0.011533356575684, -0.005054515489408, 0.002856216387663, 0.011928552849292, 0.021793609182402, 0.032004583207385, 0.042064159327846, 0.051456638607989, 0.059682385435555, 0.066291962326425, 0.070917318410768, 0.073297605871962, 0.073297605871962, 0.070917318410768, 0.066291962326425, 0.059682385435555, 0.051456638607989, 0.042064159327846, 0.032004583207385, 0.021793609182402, 0.011928552849292, 0.002856216387663, -0.005054515489408, -0.011533356575684, -0.016421150568180, -0.019673505879184, -0.021355518618346, -0.021628290934674, -0.020728605105972, -0.018943644085201, -0.016583013848246, -0.013950493386618, -0.011317902752974, -0.008903243900917, -0.006854855724642, -0.005242771040626, -0.004057818065448, -0.003218328227846}; // current sample time for this filter and roll resonance double dt = varp.rollT->getDouble() / double(oversamplingRate * 2); UTime t1; // if (isOK) { t1 = rotHist->getUpdTime(); isOK = (t1 - tLastSample) > dt; } if (isOK and not initialize) { // set update time if ((t1 - tLastSample) > 10.0) // uninitialized - or reconnected initialize = true; else // just update tLastSample += dt; // save value } if (initialize) { rollRaw = (double *) realloc(rollRaw, bufSize * sizeof(double)); pitchRaw = (double *) realloc(pitchRaw, bufSize * sizeof(double)); rollRawCnt = 0; tLastSample = t1; isOK = rollRaw != NULL and pitchRaw != NULL; printf("(re) initialized raw data buffer (%d elements) before filter (OK=%s)\n", bufSize, bool2str(isOK)); } if (isOK) { if (rollRawCnt < bufSize) rollRawCnt++; memmove(&rollRaw[1], rollRaw, sizeof(double) * (rollRawCnt - 1)); memmove(&pitchRaw[1], pitchRaw, sizeof(double) * (rollRawCnt - 1)); rollRaw[0] = rotHist->getDouble(0); pitchRaw[0] = rotHist->getDouble(1); rawUpdTime = t1; isOK = rollRawCnt == bufSize; if (not isOK) printf("filling filter buffer, now %d/%d\n", rollRawCnt, bufSize); } if (isOK) { int filterBuffer = varp.filteredBufferTime->getDouble() / (dt * 2.0); if (rollFilt == NULL or rollFiltMaxCnt < rollFiltMaxCnt) { rollFilt = (double *) realloc(rollFilt, filterBuffer * sizeof(double)); pitchFilt = (double *) realloc(pitchFilt, filterBuffer * sizeof(double)); rollFiltMaxCnt = filterBuffer; rollFiltIdx = -1; // newest data rollFiltCnt = 0; // number of available elements printf("PAR: initialized filter buffer (to %d elements, spanning %.1f seconds)\n", filterBuffer, varp.filteredBufferTime->getDouble()); } rollFiltIdx = (rollFiltIdx + 1) % filterBuffer; if (rollFiltCnt < filterBuffer) rollFiltCnt++; /* rollFiltCnt = filter(&rollFilt[firCnt], rollRaw, imuSampleCnt, fir51, firCnt, 2); pitchFiltCnt = filter(&pitchFilt[firCnt], pitchRaw, imuSampleCnt, fir51, firCnt, 1);*/ // filter roll with every other sample rollFilt[rollFiltIdx] = fold(rollRaw, fir51, firCnt, 2); // filter pitch with every sample - twice the center frequency pitchFilt[rollFiltIdx] = fold(&pitchRaw[firCnt/2], fir51, firCnt, 1); // save update time of newly filtered value - filtUpdTime = t1 - (firCnt * dt); // debug printf("filter %d: roll:%g to %g, pitch %g to %g at time %.3f\n", rollFiltIdx, rollRaw[firCnt], rollFilt[rollFiltIdx], pitchRaw[firCnt], pitchFilt[rollFiltIdx], filtUpdTime.GetDecSec()); // debug end } return isOK; }
const char * UPolyItem::print(const char * preStr, char * buff, const int buffCnt) { char * p1 = buff; int n = 0; // snprintf(p1, buffCnt - n, "%s %s has %d points, closed=%s, color=%s\n", preStr, name, pointsCnt, bool2str(isPolygon()), color); // return buff; }
void UFuncPar::rollDetectBatch() { // filter camculated with this oversample rate (filter frequency compared to sample frequency) const int oversamplingRate = 40; // need double amount of samples to filter around pitch frequency int sn = round(varp.scRollPeriods->getDouble() * oversamplingRate) * 2; // pointer to variable with raw data UVariable * rotHist; bool isOK; // obtained samples int rollRawCnt, pitchRawCnt; // obtained samples when filtered int rollFiltCnt, pitchFiltCnt; UTime t, t0, toTime; // estimated values double rollMuHat, rollSigmaHat, pitchMuHat, pitchSigmaHat; // update rate double updr = -1.0; // bandpass filter assuming sample rate is 40 times natural roll frq. // center frequency is 1/20 = 0.05 // MATLAB filter51 = fir1(51, [0.045 0.06]) const int firCnt = 51; const double fir51[] = { -0.003218328227846, -0.004057818065448, -0.005242771040626, -0.006854855724642, -0.008903243900917, -0.011317902752974, -0.013950493386618, -0.016583013848246, -0.018943644085201, -0.020728605105972, -0.021628290934674, -0.021355518618346, -0.019673505879184, -0.016421150568180, -0.011533356575684, -0.005054515489408, 0.002856216387663, 0.011928552849292, 0.021793609182402, 0.032004583207385, 0.042064159327846, 0.051456638607989, 0.059682385435555, 0.066291962326425, 0.070917318410768, 0.073297605871962, 0.073297605871962, 0.070917318410768, 0.066291962326425, 0.059682385435555, 0.051456638607989, 0.042064159327846, 0.032004583207385, 0.021793609182402, 0.011928552849292, 0.002856216387663, -0.005054515489408, -0.011533356575684, -0.016421150568180, -0.019673505879184, -0.021355518618346, -0.021628290934674, -0.020728605105972, -0.018943644085201, -0.016583013848246, -0.013950493386618, -0.011317902752974, -0.008903243900917, -0.006854855724642, -0.005242771040626, -0.004057818065448, -0.003218328227846 }; // if (sn > imuSampleMaxCnt) { // need for more space in sample buffer // rollRaw = (double *) realloc(rollRaw, sn * sizeof(double)); rollFilt = (double *) realloc(rollFilt, sn * sizeof(double)); // pitchRaw = (double *) realloc(pitchRaw, sn * sizeof(double)); pitchFilt = (double *) realloc(pitchFilt, sn * sizeof(double)); yawRaw = (double *) realloc(yawRaw, sn * sizeof(double)); timeRaw = (double *) realloc(timeRaw, sn * sizeof(double)); w2gDrive = (double *) realloc(w2gDrive, sn * sizeof(double)); imuSampleMaxCnt = sn; printf("Allocated space for %d samples\n", sn); } t.now(); isOK = sn <= imuSampleMaxCnt; if (isOK) { UVarPool * vp = getVarPool(); const char * varSrc = varImuSource->getValues(); rotHist = vp->getGlobalVariable(varSrc); isOK = rotHist != NULL; if (isOK) isOK = rotHist->hasHist() and rotHist->getHistoryRows() > oversamplingRate * 4; printf("PAR: imu.rot has %d samples, need %d (OK = %s)\n", rotHist->getHistoryRows(), oversamplingRate * 4, bool2str(isOK)); } if (isOK) { // get sample rate for data vector updr = rotHist->hist->getSampleRate(50); // get step size of data for pitch (highest sample rate) int step = maxi(1, round(updr * varp.rollT->getDouble() / double(oversamplingRate * 2))); // / varp.updFrq->getDouble()); // actual sample time for roll and pitch double dtR = 0.1, dtP = 0.1; // printf("PAR: uses every %d step from imu.rot history buffer\n", step); // t0 = rotHist->getUpdTime(); if (not t0.valid) t0.now(); toTime = t0 - varp.scRollPeriods->getDouble() * varp.rollT->getDouble(); // debug // do not limit using sample time toTime.SetTime(0, 0); // debug end rollRawCnt = rotHist->hist->getVectorToTime(rollRaw, sn, 0, toTime, step, &dtR); pitchRawCnt = rotHist->hist->getVectorToTime(pitchRaw, sn, 1, toTime, step, &dtP); // imuSampleCnt = mini(rollRawCnt, pitchRawCnt); // debug // debug save of values // get also yaw info - used for debug only (loaded with sweep frequency // NB! index 0 is the newest rotHist->hist->getVectorToTime(yawRaw, sn, 2, toTime, step, NULL); rotHist->hist->getVectorToTime(timeRaw, sn, -2, toTime, step, NULL); // debug print printf("IMU sensor raw data %g Hz update rate\n", updr); printf(" - pitch: uses every %d measurement, got dtP=%gsec (sfP=%gHz optimal %gHz)\n", step, dtP, 1.0/dtP, 2.0*oversamplingRate/varp.rollT->getDouble()); printf(" - roll: uses every %d measurement, got dtR=%gsec (sfR=%gHz optimal %gHz)\n", step * 2, dtR * 2, 0.5/dtR, oversamplingRate/varp.rollT->getDouble()); printf(" - rollcnt=%d, pitchcnt=%d/%d, time span max = %g sec\n", rollRawCnt, pitchRawCnt, sn, timeRaw[0] - timeRaw[pitchRawCnt-1]); // debug end // do we have enough samples to try an estimate isOK = imuSampleCnt > oversamplingRate * 2; if (not isOK) printf(" - sample count too low, needs %d got %d\n", oversamplingRate * 2, imuSampleCnt); } // debug //printf("ParRollDetect took %g msec to get roll and pitch data\n", t.getTimePassed()*1000.0); // debug end if (isOK) { // filter roll by half frequency memset(rollFilt, 0, sizeof(double)*imuSampleCnt); // firCnt should be enough memset(pitchFilt, 0, sizeof(double)*imuSampleCnt); rollFiltCnt = filter(&rollFilt[firCnt], rollRaw, imuSampleCnt, fir51, firCnt, 2); pitchFiltCnt = filter(&pitchFilt[firCnt], pitchRaw, imuSampleCnt, fir51, firCnt, 1); // } // debug //printf("ParRollDetect took %g msec including filter\n", t.getTimePassed() * 1000.0); // debug end if (isOK) { // variance estimate of filtered values FILE * toLog; toLog = fopen("medianRoll.txt", "w"); rollMuHat = median(&rollFilt[firCnt], rollFiltCnt, 2, toLog); fclose(toLog); toLog = fopen("medianPitch.txt", "w"); pitchMuHat = median(&pitchFilt[firCnt], pitchFiltCnt, 2, toLog); fclose(toLog); // rollSigmaHat = sqr(medianAbsMean(&rollFilt[firCnt], rollFiltCnt, rollMuHat, 2)/0.6745); pitchSigmaHat = sqr(medianAbsMean(&pitchFilt[firCnt], pitchFiltCnt, pitchMuHat, 1)/0.6745); printf("PAR mean_roll_hat=%.5f, mean_pitch_hat=%.5f, roll_sigma_hat=%.5f, pitch_sigma_hat=%.5f\n", rollMuHat, pitchMuHat, rollSigmaHat, pitchSigmaHat); } // scaled signal combined of filtered pitch squared roll. if (isOK) { // roll rollFiltCnt is the number of usable samples in the analysis sample set. double driveScale = 1.0/(1.0 + sqrt(rollSigmaHat * pitchSigmaHat)); printf("PAR: drive scale=%.5f\n", driveScale); for (int i = 0; i < rollFiltCnt; i++) { // roll has the lowest sample rate, so use i<<1 for pitch index w2gDrive[i] = sqr(rollFilt[i] - rollMuHat) * (pitchFilt[i] - pitchMuHat) * driveScale; } // debug save of values if (isOK) // and rollRawCnt > sn - 10) { double * pData[7]; pData[0] = timeRaw; pData[1] = rollRaw; pData[2] = pitchRaw; pData[3] = rollFilt; pData[4] = pitchFilt; pData[5] = yawRaw; pData[6] = w2gDrive; toFile("rollPitchFilt.txt",pData, 7, rollFiltCnt); } } if (isOK) { // find shape of Weibull distribution double w2gShape; double w2gScale, sm = 0.0; // w2gShape = findW2gScale(w2gDrive, rollFiltCnt); for (int i = 0; i < rollFiltCnt; i++) sm += pow(w2gDrive[i], w2gShape); w2gScale = pow(sm/double(rollFiltCnt), 1.0/w2gShape); // vars.w2gShape->setDouble(w2gShape); vars.w2gScale->setDouble(w2gScale); } // debug //printf("ParRollDetect took %g msec including median\n", t.getTimePassed() * 1000.0); // debug end update6hMax(varp.horizon6h->getDouble() * 60.0); // debug //printf("ParRollDetect took %g msec including 6h update\n", t.getTimePassed() * 1000.0); vars.calcTime->setDouble(t.getTimePassed() * 1000.0); // debug end }
bool UHokuyo::receiveData() { bool gotData = false; int n, i = 0; char * dend = NULL; UTime t; bool gotRngData = false; const int MSL = 500; char s[MSL]; // if (modeSimulated) { //gotData = receiveSimulatedData(&length); Wait(0.1); } else { if (dataCnt > 0) { // test for old data if (dataTime.getTimePassed() > 1.0) { printf("Discarded '%s'\n", dataBuf); for (n = 0; n < dataCnt; n++) printf("%02x,", dataBuf[n]); printf("\n"); printf("Discarded %d bytes of old data\n", dataCnt); statBadCnt++; dataCnt = 0; } } lock(); if (isPortOpen()) { // set timeout to ~30 ms n = receiveFromDevice(&dataBuf[dataCnt], MAX_DATA_LNG - dataCnt - 1, 0.015); if (/*repeatGetScan and*/ (n > 0)) { // request more data requestMoreData(); } //if (n > 0) // printf("(%d bytes)", n); } else n = 0; unlock(); if (n > 0) { dataCnt += n; dataBuf[dataCnt] = '\0'; dend = strstr(dataBuf, "\n\n"); // debug /* if (verbose and (datalog != NULL)) { // log the received part of the buffer dataBuf[n] = '\0'; fprintf(datalog, "%4d (n=%3d) got:'%s'\n", dataCnt, n, dataBuf); }*/ // debug end gotData = (dend != NULL); } } // while (gotData) { // message length badSeries++; n = dend - dataBuf; // debug if (n > dataCnt) { printf("UHokuyo::receiveData message end found after buffer end? n=%d dataCnt=%d\n", n, dataCnt); } if (verbose) { snprintf(s, MSL, "In %d 'gotData' dataCnt=%d n=%d %c%c%c%c%c%c%c%c%c... after %g sec\n", i, dataCnt, n, dataBuf[0], dataBuf[1], dataBuf[2],dataBuf[3], dataBuf[4], dataBuf[5], dataBuf[6], dataBuf[7], dataBuf[8], dataTime.getTimePassed()); laslog.toLog("urg:", s); } //printf("msg:%s", dataBuf); i++; // debug end switch (dataBuf[0]) { case 'V': dend[1] = '\0'; if (dataBuf[1] == '\n') { // some garbage may also start with a V if (versionInfoCnt < 5 or verbose) printf("Got version (%d) info ((grp %d) %d chars):'%s'\n", versionInfoCnt, i, dataCnt, dataBuf); decodeName(dataBuf); versionInfoCnt++; if (verbose) laslog.toLog(" - V:", &dataBuf[4]); } break; case 'G': if (dataBuf[10] != '0') { // must be '0 to be valid scandata // printf("Bad data set laser may be off (bdSeries=%d) - send an on-command (\\nL1\\n)\n", badSeries); sendToDevice("\nL1\n", 4); break; } badSeries = 0; if (lasData == NULL) lasData = new ULaserData(); if (lasData != NULL) { // save data into decoded buffer lasData->lock(); lasData->setDeviceNum(deviceNum); gotRngData = decodeData(dataBuf, n, lasData); lasData->setMaxValidRange(maxValidRange); //if (repeatGetScan and not gotRngData) //{ // error message - request new data // // send request for more data right away // lock(); // //sendToDevice("00038401\n", 9); // //sendToDevice("00076801\n", 9); // unlock(); //} if (gotRngData) statGoodCnt++; lasData->setMirror(mirrorData); lasData->unlock(); // if (gotRngData) // do pending push commands. // No need to set data as locked, as // a client scanGet may use data at the same time as a scanpush, // as none of these will modify the 'lasData' structure. gotNewScan(lasData); if (verbose) { // debug logging snprintf(s, MSL, "UHokuyo::receiveData: scan=%6s %drngs In %2d msgCnt=%4d/%4d : %c%c%c%c%c%c%c%c%c %c %c%c... after %g sec\n", bool2str(gotRngData), lasData->getRangeCnt(), i, n, dataCnt, dataBuf[0], dataBuf[1], dataBuf[2],dataBuf[3], dataBuf[4], dataBuf[5], dataBuf[6], dataBuf[7], dataBuf[8], dataBuf[10], dataBuf[12], dataBuf[13], dataTime.getTimePassed()); laslog.toLog(" - G:", s); // to screen also printf("%s", s); } dataTime.Now(); } break; default: // got error // discard to first newline /* char * nl = strchr(dataBuf, '\n'); if (nl < dend and nl > dataBuf) { // newline found, // set new data end (dend) to one earlier, as if it was // a real "\n\n" command termination. // this is to avoid a situation where OK scans // are part of an error-respond. dend = --nl; }*/ // close string and restart dend[1] = '\0'; // debug if (verbose) { snprintf(s, MSL, "UHokuyo::receiveData: garbage msg %4d of %4d chars in buffer:'%c%c%c...'\n", n, dataCnt, dataBuf[0], dataBuf[1], dataBuf[2]); laslog.toLog(" - ", s); } //printf("UHokuyo::receiveData: ignored garbage (%d chars):'%s'\n", dataCnt, dataBuf); //rp = true; //repeatGetScan; // no other than G???... should be // received in repeat mode, well // sometimes a LFLF is in the error message //repeatGetScan = false; /*closePort(); printf("Got unknown garbage:--------Closing port\n"); Wait(0.2); if (rp) { // repeat is enabled - request dummy data printf("-------------restarting in repeat mode\n"); getNewestData(NULL, 0, false); //repeatGetScan = true; }*/ statBadCnt++; break; } // discard the used (or unknown) data n = dataCnt - (dend - dataBuf) - 2; memmove(dataBuf, dend + 2, n); // reduce available data count dataCnt = n; dataBuf[dataCnt] = '\0'; // test for more data in buffer gotData = dataCnt > 3; if (gotData) { // is it a full message dend = strstr(dataBuf, "\n\n"); gotData = (dend != NULL); //printf("****Got more messages in one read (OK, but indicate latency)\n"); } } return gotRngData; }
static void update_triggers(trigger_item_t *trigger_tgt, unsigned int count_tgt, trigger_item_t *trigger_new, unsigned int count_new, bool *check_interval_chgd) { unsigned int i; *check_interval_chgd = false; if (count_new != count_tgt) { /* skip trigger checking & update */ no_trig_updt_msg("Trigger count"); return; } /* check trigger types */ for (i = 0; i < count_new; i++) { if (trigger_new[i].trigger_type != trigger_tgt[i].trigger_type || trigger_new[i].target_type != trigger_tgt[i].target_type) { no_trig_updt_msg("Trigger type"); return; } else if ((trigger_new[i].trigger_type != TRIG_ALWAYS) && (trigger_new[i].hw_type != trigger_tgt[i].hw_type)) { no_trig_updt_msg("High threshold type"); return; } else if ((trigger_new[i].trigger_type != TRIG_ALWAYS) && (trigger_new[i].lw_type != trigger_tgt[i].lw_type)) { no_trig_updt_msg("Low threshold type"); return; } } /* triggers have the same type: update simple parameters: * max_action_count, max_action_volume, check_interval, alert_high, * alert_low, post_trigger_wait */ for (i = 0; i < count_new; i++) { char tname[256]; snprintf(tname, sizeof(tname), "#%u (%s): ", i, trigger2str(&trigger_tgt[i])); if (trigger_new[i].check_interval != trigger_tgt[i].check_interval) { DisplayLog(LVL_EVENT, TAG, "check_interval updated for trigger %s: %lu->%lu", tname, trigger_tgt[i].check_interval, trigger_new[i].check_interval); trigger_tgt[i].check_interval = trigger_new[i].check_interval; *check_interval_chgd = true; } if (trigger_new[i].max_action_nbr != trigger_tgt[i].max_action_nbr) { DisplayLog(LVL_EVENT, TAG, "max_action_count updated for trigger %s: %u entries ->%u entries", tname, trigger_tgt[i].max_action_nbr, trigger_new[i].max_action_nbr); trigger_tgt[i].max_action_nbr = trigger_new[i].max_action_nbr; } if (trigger_new[i].max_action_vol != trigger_tgt[i].max_action_vol) { DisplayLog(LVL_EVENT, TAG, "max_action_volume updated for trigger %s: %llu bytes->%llu bytes", tname, trigger_tgt[i].max_action_vol, trigger_new[i].max_action_vol); trigger_tgt[i].max_action_vol = trigger_new[i].max_action_vol; } if (trigger_new[i].post_trigger_wait != trigger_tgt[i].post_trigger_wait) { DisplayLog(LVL_EVENT, TAG, "post_trigger_wait updated for trigger %s: %lu->%lu", tname, trigger_tgt[i].post_trigger_wait, trigger_new[i].post_trigger_wait); trigger_tgt[i].post_trigger_wait = trigger_new[i].post_trigger_wait; } if (trigger_new[i].alert_hw != trigger_tgt[i].alert_hw) { DisplayLog(LVL_EVENT, TAG, "alert_high updated for trigger %s: %s->%s", tname, bool2str(trigger_tgt[i].alert_hw), bool2str(trigger_new[i].alert_hw)); trigger_tgt[i].alert_hw = trigger_new[i].alert_hw; } if (trigger_new[i].alert_lw != trigger_tgt[i].alert_lw) { DisplayLog(LVL_EVENT, TAG, "alert_low updated for trigger %s: %s->%s", tname, bool2str(trigger_tgt[i].alert_lw), bool2str(trigger_new[i].alert_lw)); trigger_tgt[i].alert_lw = trigger_new[i].alert_lw; } if (trigger_new[i].trigger_type == TRIG_ALWAYS) /* no threshold for 'periodic' triggers */ continue; switch (trigger_new[i].hw_type) { case PCT_THRESHOLD: if (trigger_new[i].hw_percent != trigger_tgt[i].hw_percent) { DisplayLog(LVL_EVENT, TAG, "High threshold updated for trigger %s: " "%.2f%%->%.2f%%", tname, trigger_tgt[i].hw_percent, trigger_new[i].hw_percent); trigger_tgt[i].hw_percent = trigger_new[i].hw_percent; } break; case VOL_THRESHOLD: if (trigger_new[i].hw_volume != trigger_tgt[i].hw_volume) { DisplayLog(LVL_EVENT, TAG, "High threshold updated for trigger %s: %llu bytes->%llu bytes", tname, trigger_tgt[i].hw_volume, trigger_new[i].hw_volume); trigger_tgt[i].hw_volume = trigger_new[i].hw_volume; } break; case COUNT_THRESHOLD: if (trigger_new[i].hw_count != trigger_tgt[i].hw_count) { DisplayLog(LVL_EVENT, TAG, "High threshold updated for trigger %s: %llu entries ->%llu entries", tname, trigger_tgt[i].hw_count, trigger_new[i].hw_count); trigger_tgt[i].hw_count = trigger_new[i].hw_count; } break; } switch (trigger_new[i].lw_type) { case PCT_THRESHOLD: if (trigger_new[i].lw_percent != trigger_tgt[i].lw_percent) { DisplayLog(LVL_EVENT, TAG, "Low threshold updated for trigger %s: %.2f%%->%.2f%%", tname, trigger_tgt[i].lw_percent, trigger_new[i].lw_percent); trigger_tgt[i].lw_percent = trigger_new[i].lw_percent; } break; case VOL_THRESHOLD: if (trigger_new[i].lw_volume != trigger_tgt[i].lw_volume) { DisplayLog(LVL_EVENT, TAG, "Low threshold updated for trigger %s: %llu bytes->%llu bytes", tname, trigger_tgt[i].lw_volume, trigger_new[i].lw_volume); trigger_tgt[i].lw_volume = trigger_new[i].lw_volume; } break; case COUNT_THRESHOLD: if (trigger_new[i].lw_count != trigger_tgt[i].lw_count) { DisplayLog(LVL_EVENT, TAG, "Low threshold updated for trigger %s: %llu entries->%llu entries", tname, trigger_tgt[i].lw_count, trigger_new[i].lw_count); trigger_tgt[i].lw_count = trigger_new[i].lw_count; } break; } } /* update global interval check (GCD of all check intervals) if one of * them changed */ // TODO move to caller // if (check_interval_chgd) // ResMon_UpdateCheckInterval(); /* triggers have been updated */ return; }