コード例 #1
0
ファイル: peislogger.c プロジェクト: Gardee/WearAmI
int main(int argc,char **args)
{	
	char configfilename[MAXLENGTH];
	char logfilename[MAXLENGTH];
	FILE* logfile;
	int skipHeader = 0;
	char tuplename[MAXLENGTH];
	int isRunning;
	int element_ready;
	PeisTuple* mytuple;	
	int i;
	int ID, len;
	char* value;
	time_t now;
    struct tm ts;
  	char date[MAXLENGTH];
	float kernel_time;
  
	// handlers
  	PeisSubscriberHandle subHandler[MAXKEYS];
	PeisCallbackHandle callHandler[MAXKEYS];
	  	
	// init isRunning
	isRunning = 1;
	// init the semaphore
	pthread_mutex_init(&tuple_processing, NULL);
	// init the tuple list
	initializeList(&tuples);
	
	// initial check for arguments
  	memcpy(configfilename, CONFIGFILE, strlen(CONFIGFILE)+1);
  	memcpy(logfilename, LOGFILE, strlen(CONFIGFILE)+1);

	for ( i = 0; i < argc; i++ )
    {
		if (strcmp(args[i],"--help") == 0) { printUsage(stderr,argc,args); }
		if (strcmp(args[i],"--conf") == 0) { memcpy(configfilename, args[i+1], strlen(args[i+1])+1); }
		if (strcmp(args[i],"--log") == 0)  { memcpy(logfilename, args[i+1], strlen(args[i+1])+1); }
		if (strcmp(args[i],"--skip") == 0) { skipHeader = 1; }
	}

  	// instantiate & initialize the PEIS component
	peiskmt_initialize(&argc, args);

	// prepare the header of the log file
  	// time: "ddd yyyy-mm-dd hh:mm:ss zzz"
 	time(&now);
  	ts = *localtime(&now);
  	strftime(date, sizeof(date), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
  	kernel_time = peiskmt_gettimef();

  	// Printing the header for the log file
  	if (skipHeader == 0)
	{
        if( !(logfile = fopen(logfilename, "w") ) )
        {
            printf("Error opening the log file %s \n", logfilename);
            isRunning = 0;
        }
        ID = peiskmt_peisid();
        PeisTuple* kernelTuple = peiskmt_getTuple(ID,"kernel.version",PEISK_KEEP_OLD|PEISK_NON_BLOCKING);
        fprintf(logfile, "; Kernel version %s\n", kernelTuple->data);
        fprintf(logfile, "; peislogger version 1.0\n");
        fprintf(logfile, "; starting at %f kernel time, %s\n", kernel_time, date);
        fprintf(logfile, "%f\n", kernel_time);
        fprintf(logfile, "; structure of recorded data:\n");
        fprintf(logfile, "; kernel_ts,write_ts,user_ts,expire_ts,owner,creator,keyDepth,keys,datalenght,data\n");
        fclose(logfile);
	}

  	// Reading the keys of the tuples to subscribe
  	if (!readConfiguration(configfilename))
    {
		printf("Problem reading from configuration file %s \n", configfilename);
		isRunning = 0;
	}
	
  	// Subscribe to all the keys specified in the configuration file and attach a callback
  	for( i = 0 ; i < keyscounter ; i++)
    {
        printf("Subscribing to tuple: \"%s\" ", keys[i]);
        printf("...");
        subHandler[i] = peiskmt_subscribe(-1, keys[i]);
        callHandler[i] = peiskmt_registerTupleCallback(-1, keys[i], NULL, (void*)eventCallback);
        printf("DONE \n");
  	}
 	
  	while( isRunning && peiskmt_isRunning() )
    { 
        // get the tuple to write
  		// not very elegant, but this way I can use the semaphores
		pthread_mutex_lock(&tuple_processing);
  		element_ready = isNotEmpty(&tuples);
		pthread_mutex_unlock(&tuple_processing);

		if(element_ready)
        {
			pthread_mutex_lock(&tuple_processing);
			mytuple = getAndDeleteFirstElement(&tuples);
			pthread_mutex_unlock(&tuple_processing);
			
			peiskmt_printTuple(mytuple);
			printf("\n");
            if ( !(logfile = fopen(logfilename, "a") ) )
            {
				printf("Error appending to logfile file %s \n", logfilename);
				exit(0);
			}
            peiskmt_getTupleName(mytuple, tuplename, sizeof(tuplename));
            fprintf(logfile, "%f %d.%d %d.%d %d.%d %d %d %d %d %d %s %d %s\n", 
			peiskmt_gettimef(), mytuple->ts_write[0], mytuple->ts_write[1], 
			mytuple->ts_user[0], mytuple->ts_user[1], mytuple->ts_expire[0], mytuple->ts_expire[1],
			mytuple->owner, mytuple->creator, mytuple->alloclen, mytuple->isNew, mytuple->keyDepth, 
			tuplename, strlen(mytuple->data)+1, (char*)mytuple->data);
    		fclose(logfile);
		}		
	    usleep(10000);
  	}

	// unsubscribe
	for( i = 0 ; i < keyscounter ; i++)
    {
        peiskmt_unsubscribe(subHandler[i]);
		peiskmt_unregisterTupleCallback(callHandler[i]);
	}

	// free the memory of both the queue and the variables
	peiskmt_freeTuple(mytuple);
	emptyQueue(&tuples);
	pthread_mutex_destroy(&tuple_processing);
  	
	peiskmt_shutdown();
}
コード例 #2
0
ファイル: plotterMaps.cpp プロジェクト: CeF3TB/H4_2015
int main( int argc, char* argv[] ) {

  DrawTools::setStyle();

  std::string tag = "V00";
  std::string config = "SiPM2015Config";
  
  if( argc>1 ) {
    std::string tag_str(argv[1]);
    tag = tag_str;
    if( argc>2 ) {
      std::string config_str(argv[2]);
      config=config_str;
    }
  } else {
    std::cout << "Usage:" << std::endl;
    std::cout << "./plotterMaps ([tag]) ([config])" << std::endl;
    exit(12345);
  }

  std::cout<<config<<std::endl;
  
  theConfiguration_=readConfiguration(config);

  std::string constDirName = "plots_maps_";
  constDirName+=theConfiguration_.setup;
  if(theConfiguration_.addTagFileName){
    constDirName+="_";
    constDirName+=theConfiguration_.tagFileName;
  }
  system(Form("mkdir -p %s", constDirName.c_str()));

  
  TString dir(constDirName);



  std::vector<int> runs;
  std::vector<float> energies;
  for (int i=0;i<theConfiguration_.runs.size()+1;++i){//+1 for all the run together
    if(i<theConfiguration_.runs.size()){
      runs.push_back(theConfiguration_.runs[i]);
      energies.push_back(theConfiguration_.energies[i]);
    }

    TString filename= "plots_timing_"+theConfiguration_.setup+"/timingStudiesSiPM_"+tag+"_";

    if(i<theConfiguration_.runs.size()){
      filename+=runs[i];
    }else{
      filename+="total";
    }
    filename+=".root";

    TFile* file = TFile::Open(filename.Data());
    
    TH2F* timing_map_total=(TH2F*)file->Get("timing_map_channel");
    TH2F* amplitude_map_total=(TH2F*)file->Get("amplitude_map_channel");
    TH2F* amplitude_map_fibre2=(TH2F*)file->Get("amplitude_map_fibre2");

    TH2F* timing_map_sel_channel=(TH2F*)file->Get("timing_map_sel_channel");
    TH2F* amplitude_map_sel_channel=(TH2F*)file->Get("amplitude_map_sel_channel");

    TH2F* timing_map_sel_fibre=(TH2F*)file->Get("timing_map_sel_fibre");
    TH2F* amplitude_map_sel_fibre=(TH2F*)file->Get("amplitude_map_sel_fibre");

    TH1F* maxAmpl_sel_fibre=(TH1F*)file->Get("maxAmpl_sel_fibre");
    TH1F* maxAmpl_sel_channel=(TH1F*)file->Get("maxAmpl_sel_channel");


    TString runString;
    if(i<theConfiguration_.runs.size()){
      runString+=runs[i];
    }else{
      runString+="total";

      //for total we do normalized plots
      float max= amplitude_map_total->GetMaximum();
      amplitude_map_total->Scale(1./max);
      amplitude_map_total->SetAxisRange(0,1,"Z");
      
      max= amplitude_map_fibre2->GetMaximum();
      amplitude_map_fibre2->Scale(1./max);
      amplitude_map_fibre2->SetAxisRange(0,1,"Z");
      
      max= amplitude_map_sel_channel->GetMaximum();
      amplitude_map_sel_channel->Scale(1./max);
      amplitude_map_sel_channel->SetAxisRange(0,1,"Z");
     
      max= amplitude_map_sel_fibre->GetMaximum();
      amplitude_map_sel_fibre->Scale(1./max);
      amplitude_map_sel_fibre->SetAxisRange(0,1,"Z");

      //timing should be scaled for number of files after hadd      
      timing_map_total->Scale(1./runs.size());
      timing_map_total->SetAxisRange(-0.1,0.9,"Z");

      timing_map_sel_channel->Scale(1./runs.size());
      timing_map_sel_channel->SetAxisRange(-0.1,0.9,"Z");

      timing_map_sel_fibre->Scale(1./runs.size());
      timing_map_sel_fibre->SetAxisRange(-0.1,0.6,"Z");

    }


    gStyle->SetPadRightMargin(0.17);//for the palette
    TCanvas c1;
    amplitude_map_total->Draw("colz");
    c1.SaveAs(dir+"/amplitude_map_"+runString+".pdf");
    c1.SaveAs(dir+"/amplitude_map_"+runString+".png");

    c1.Clear();
    amplitude_map_fibre2->Draw("colz");
    c1.SaveAs(dir+"/amplitude_map_fibre2_"+runString+".pdf");
    c1.SaveAs(dir+"/amplitude_map_fibre2_"+runString+".png");


    c1.Clear();
    timing_map_total->Draw("colz");
    c1.SaveAs(dir+"/timing_map_"+runString+".pdf");
    c1.SaveAs(dir+"/timing_map_"+runString+".png");

    c1.Clear();
    amplitude_map_sel_channel->Draw("colz");
    c1.SaveAs(dir+"/amplitude_map_sel_channel"+runString+".pdf");
    c1.SaveAs(dir+"/amplitude_map_sel_channel"+runString+".png");

    c1.Clear();
    timing_map_sel_channel->Draw("colz");
    c1.SaveAs(dir+"/timing_map_sel_channel"+runString+".pdf");
    c1.SaveAs(dir+"/timing_map_sel_channel"+runString+".png");

    c1.Clear();
    amplitude_map_sel_fibre->Draw("colz");
    c1.SaveAs(dir+"/amplitude_map_sel_fibre"+runString+".pdf");
    c1.SaveAs(dir+"/amplitude_map_sel_fibre"+runString+".png");

    c1.Clear();
    timing_map_sel_fibre->Draw("colz");
    c1.SaveAs(dir+"/timing_map_sel_fibre"+runString+".pdf");
    c1.SaveAs(dir+"/timing_map_sel_fibre"+runString+".png");

    gStyle->SetPadRightMargin(0.10);
    TCanvas c2;
    maxAmpl_sel_channel->GetXaxis()->SetRangeUser(0,800.);
    maxAmpl_sel_channel->SetLineWidth(2);
    maxAmpl_sel_fibre->SetLineWidth(2);
    maxAmpl_sel_channel->DrawNormalized();
    maxAmpl_sel_fibre->DrawNormalized("same");



    if(i<theConfiguration_.runs.size()){
      std::string energy(Form("%.0f",energies[i]));
      TPaveText* pave = DrawTools::getLabelTop_expOnXaxis(energy+" GeV Electron Beam");
      pave->Draw("same");
    }else{
      std::string energy(Form("%.0f",energies[i]));
      TPaveText* pave = DrawTools::getLabelTop_expOnXaxis("Electron Beam");
      pave->Draw("same");
    }

    c2.SaveAs(dir+"/maxAmpl_comparison_"+runString+".pdf");
    c2.SaveAs(dir+"/maxAmpl_comparison_"+runString+".png");

  }

}
コード例 #3
0
bool loadSLConfigXML(slParams *sl_params, slCalib *sl_calib,
    const char *configFile = CONFIG_FILE,
    const char *outputDir = NULL)
{
  // Read structured lighting parameters from configuration file.
  FILE* pFile = fopen(configFile, "r");
  if(pFile != NULL){
    fclose(pFile);
    fprintf(stderr, "Reading configuration file...\n");
    readConfiguration(configFile, sl_params);
  }
  else{
    return false;
  }

  // Allocate storage for calibration parameters.
  int cam_nelems                  = sl_params->cam_w*sl_params->cam_h;
  int proj_nelems                 = sl_params->proj_w*sl_params->proj_h;
  sl_calib->cam_intrinsic_calib   = false;
  sl_calib->proj_intrinsic_calib  = false;
  sl_calib->procam_extrinsic_calib= false;
  sl_calib->cam_intrinsic         = cvCreateMat(3,3,CV_32FC1);
  sl_calib->cam_distortion        = cvCreateMat(5,1,CV_32FC1);
  sl_calib->cam_extrinsic         = cvCreateMat(2, 3, CV_32FC1);
  sl_calib->proj_intrinsic        = cvCreateMat(3, 3, CV_32FC1);
  sl_calib->proj_distortion       = cvCreateMat(5, 1, CV_32FC1);
  sl_calib->proj_extrinsic        = cvCreateMat(2, 3, CV_32FC1);
  sl_calib->cam_center            = cvCreateMat(3, 1, CV_32FC1);
  sl_calib->proj_center           = cvCreateMat(3, 1, CV_32FC1);
  sl_calib->cam_rays              = cvCreateMat(3, cam_nelems, CV_32FC1);
  sl_calib->proj_rays             = cvCreateMat(3, proj_nelems, CV_32FC1);
  sl_calib->proj_column_planes    = cvCreateMat(sl_params->proj_w, 4, CV_32FC1);
  sl_calib->proj_row_planes       = cvCreateMat(sl_params->proj_h, 4, CV_32FC1);

  if(outputDir) strcpy(sl_params->outdir, outputDir);
  
  // Load intrinsic camera calibration parameters (if found).
  char str1[1024], str2[1024];
  sprintf(str1, "%s/calib/cam/cam_intrinsic.xml",  sl_params->outdir);
  sprintf(str2, "%s/calib/cam/cam_distortion.xml", sl_params->outdir);
  if( ((CvMat*)cvLoad(str1) != 0) && ((CvMat*)cvLoad(str2) != 0) ){
    sl_calib->cam_intrinsic  = (CvMat*)cvLoad(str1);
    sl_calib->cam_distortion = (CvMat*)cvLoad(str2);
    sl_calib->cam_intrinsic_calib = true;
    fprintf(stderr, "Loaded previous intrinsic camera calibration.\n");
  }
  else {
    fprintf(stderr, "WARNING: previous intrinsic calibration NOT loaded.\n");
  }

  // Load intrinsic projector calibration parameters (if found);
  sprintf(str1, "%s/calib/proj/proj_intrinsic.xml",  sl_params->outdir);
  sprintf(str2, "%s/calib/proj/proj_distortion.xml", sl_params->outdir);
  if( ((CvMat*)cvLoad(str1) != 0) && ((CvMat*)cvLoad(str2) != 0) ){
    sl_calib->proj_intrinsic  = (CvMat*)cvLoad(str1);
    sl_calib->proj_distortion = (CvMat*)cvLoad(str2);
    sl_calib->proj_intrinsic_calib = true;
    fprintf(stderr, "Loaded previous intrinsic projector calibration.\n");
  }
  else {
    fprintf(stderr, "WARNING: previous intrinsic projector calibration NOT loaded.\n");
  }
  
  // Load extrinsic projector-camera parameters (if found).
  sprintf(str1, "%s/calib/proj/cam_extrinsic.xml",  sl_params->outdir);
  sprintf(str2, "%s/calib/proj/proj_extrinsic.xml", sl_params->outdir);
  if( (sl_calib->cam_intrinsic_calib && sl_calib->proj_intrinsic_calib) &&
    ( ((CvMat*)cvLoad(str1) != 0) && ((CvMat*)cvLoad(str2) != 0) ) ){
    sl_calib->cam_extrinsic  = (CvMat*)cvLoad(str1);
    sl_calib->proj_extrinsic = (CvMat*)cvLoad(str2);
    sl_calib->procam_extrinsic_calib = true;
    evaluateProCamGeometry(sl_params, sl_calib);
    fprintf(stderr, "Loaded previous extrinsic projector-camera calibration.\n");
  }
  else {
    fprintf(stderr, "WARNING: previous extrinsic projector-camera calibration NOT loaded.\n");
  }
  
  // Initialize background model.
  sl_calib->background_depth_map = cvCreateMat(
      sl_params->cam_h, sl_params->cam_w, CV_32FC1);
  sl_calib->background_image     = cvCreateImage(
                                    cvSize(sl_params->cam_w, sl_params->cam_h),
                                    IPL_DEPTH_8U, 3);
  sl_calib->background_mask      = cvCreateImage(
                                    cvSize(sl_params->cam_w, sl_params->cam_h),
                                    IPL_DEPTH_8U, 1);
  cvSet(sl_calib->background_depth_map, cvScalar(FLT_MAX));
  cvZero(sl_calib->background_image);
  cvSet(sl_calib->background_mask, cvScalar(255));
  
  return true;
}
コード例 #4
0
int P4d::performWebifRequests()
{
   tableJobs->clear();

   for (int f = selectPendingJobs->find(); f; f = selectPendingJobs->fetch())
   {
      int start = time(0);
      int addr = tableJobs->getIntValue("ADDRESS");
      const char* command = tableJobs->getStrValue("COMMAND");
      const char* data = tableJobs->getStrValue("DATA");
      int jobId = tableJobs->getIntValue("ID");

      tableJobs->find();
      tableJobs->setValue("DONEAT", time(0));
      tableJobs->setValue("STATE", "D");

      tell(eloAlways, "Processing WEBIF job %d '%s:0x%04x/%s'",
           jobId, command, addr, data);

      if (strcasecmp(command, "test-mail") == 0)
      {
         char* subject = strdup(data);
         char* body = 0;

         if ((body = strchr(subject, ':')))
         {
            *body = 0; body++;

            tell(eloDetail, "Test mail requested with: '%s/%s'", subject, body);

            if (isEmpty(mailScript))
               tableJobs->setValue("RESULT", "fail:missing mailscript");
            else if (!fileExists(mailScript))
               tableJobs->setValue("RESULT", "fail:mail-script not found");
            else if (isEmpty(stateMailTo))
               tableJobs->setValue("RESULT", "fail:missing-receiver");
            else if (sendMail(stateMailTo, subject, body, "text/plain") != success)
               tableJobs->setValue("RESULT", "fail:mail-sended");
            else
               tableJobs->setValue("RESULT", "success:mail-sended");
         }
      }

      else if (strcasecmp(command, "check-login") == 0)
      {
         char* webUser = 0;
         char* webPass = 0;
         md5Buf defaultPwd;

         createMd5("p4-3200", defaultPwd);

         getConfigItem("user", webUser, "p4");
         getConfigItem("passwd", webPass, defaultPwd);

         char* user = strdup(data);
         char* pwd = 0;

         if ((pwd = strchr(user, ':')))
         {
            *pwd = 0; pwd++;

            tell(eloDetail, "%s/%s", pwd, webPass);

            if (strcmp(webUser, user) == 0 && strcmp(pwd, webPass) == 0)
               tableJobs->setValue("RESULT", "success:login-confirmed");
            else
               tableJobs->setValue("RESULT", "fail:login-denied");
         }

         free(webPass);
         free(webUser);
         free(user);
      }

      else if (strcasecmp(command, "update-schemacfg") == 0)
      {
         updateSchemaConfTable();
         tableJobs->setValue("RESULT", "success:done");
      }

      else if (strcasecmp(command, "write-config") == 0)
      {
         char* name = strdup(data);
         char* value = 0;

         if ((value = strchr(name, ':')))
         {
            *value = 0; value++;

            setConfigItem(name, value);

            tableJobs->setValue("RESULT", "success:stored");
         }

         free(name);

         // read the config from table to apply changes

         readConfiguration();
      }

      else if (strcasecmp(command, "read-config") == 0)
      {
         char* name = strdup(data);
         char* buf = 0;
         char* value = 0;
         char* def = 0;

         if ((def = strchr(name, ':')))
         {
            *def = 0;
            def++;
         }

         getConfigItem(name, value, def ? def : "");

         asprintf(&buf, "success:%s", value);
         tableJobs->setValue("RESULT", buf);

         free(name);
         free(buf);
         free(value);
      }

      else if (strcasecmp(command, "getp") == 0)
      {
         tableMenu->clear();
         tableMenu->setValue("ID", addr);

         if (tableMenu->find())
         {
            int type = tableMenu->getIntValue("TYPE");
            unsigned int paddr = tableMenu->getIntValue("ADDRESS");

            ConfigParameter p(paddr);

            if (request->getParameter(&p) == success)
            {
               char* buf = 0;
               cRetBuf value = ConfigParameter::toNice(p.value, type);

               // special for time min/max/default

               if (type == mstParZeit)
                  ;  // #TODO

               asprintf(&buf, "success#%s#%s#%d#%d#%d#%d", *value, type == 0x0a ? "Uhr" : p.unit,
                        p.def, p.min, p.max, p.digits);
               tableJobs->setValue("RESULT", buf);

               free(buf);
            }
         }
      }

      else if (strcasecmp(command, "setp") == 0)
      {
         int status;

         tableMenu->clear();
         tableMenu->setValue("ID", addr);

         if (tableMenu->find())
         {
            int type = tableMenu->getIntValue("TYPE");
            int paddr = tableMenu->getIntValue("ADDRESS");

            ConfigParameter p(paddr);

            // Set Value

            if (ConfigParameter::toValue(data, type, p.value) == success)
            {
               tell(eloAlways, "Storing value '%s/%d' for parameter at address 0x%x", data, p.value, paddr);

               if ((status = request->setParameter(&p)) == success)
               {
                  char* buf = 0;
                  cRetBuf value = ConfigParameter::toNice(p.value, type);

                  // store job result

                  asprintf(&buf, "success#%s#%s#%d#%d#%d#%d", *value, p.unit,
                           p.def, p.min, p.max, p.digits);
                  tableJobs->setValue("RESULT", buf);
                  free(buf);

                  // update menu table

                  tableMenu->setValue("VALUE", value);
                  tableMenu->setValue("UNIT", p.unit);
                  tableMenu->update();
               }
               else
               {
                  tell(eloAlways, "Set of parameter failed, error %d", status);

                  if (status == P4Request::wrnNonUpdate)
                     tableJobs->setValue("RESULT", "fail#no update");
                  else if (status == P4Request::wrnOutOfRange)
                     tableJobs->setValue("RESULT", "fail#out of range");
                  else
                     tableJobs->setValue("RESULT", "fail#communication error");
               }
            }
            else
            {
               tell(eloAlways, "Set of parameter failed, wrong format");
               tableJobs->setValue("RESULT", "fail#format error");
            }
         }
         else
         {
            tell(eloAlways, "Set of parameter failed, id 0x%x not found", addr);
            tableJobs->setValue("RESULT", "fail#id not found");
         }
      }

      else if (strcasecmp(command, "gettrp") == 0)
      {
         // first update the time range data
         //  s3200 support no single request of a time range parameter

         // don't update since it takes to long (assume table is up to date)
         // updateTimeRangeData();

         // now read it from the table

         tableTimeRanges->clear();
         tableTimeRanges->setValue("ADDRESS", addr);

         if (tableTimeRanges->find())
         {
            char* buf = 0;
            char fName[10+TB];
            char tName[10+TB];
            int n = atoi(data);

            sprintf(fName, "FROM%d", n);
            sprintf(tName, "TO%d", n);

            asprintf(&buf, "success#%s#%s#%s",
                     tableTimeRanges->getStrValue(fName),
                     tableTimeRanges->getStrValue(tName),
                     "Zeitraum");
            tableJobs->setValue("RESULT", buf);

            free(buf);
         }
      }

      else if (strcasecmp(command, "settrp") == 0)
      {
         int status = success;
         Fs::TimeRanges t(addr);
         char fName[10+TB];
         char tName[10+TB];
         int rangeNo;
         char valueFrom[100+TB];
         char valueTo[100+TB];

         // parse rangeNo and value from data

         if (sscanf(data, "%d#%[^#]#%[^#]", &rangeNo, valueFrom, valueTo) != 3)
         {
            tell(eloAlways, "Parsing of '%s' failed", data);
            status = fail;
         }

         rangeNo--;

         // get actual values from table

         tableTimeRanges->clear();
         tableTimeRanges->setValue("ADDRESS", addr);

         if (status == success && tableTimeRanges->find())
         {
            for (int n = 0; n < 4; n++)
            {
               sprintf(fName, "FROM%d", n+1);
               sprintf(tName, "TO%d", n+1);

               status += t.setTimeRange(n, tableTimeRanges->getStrValue(fName), tableTimeRanges->getStrValue(tName));
            }

            // override the 'rangeNo' with new value

            status += t.setTimeRange(rangeNo, valueFrom, valueTo);

            if (status == success)
            {
               tell(eloAlways, "Storing '%s' for time range '%d' of parameter 0x%x", t.getTimeRange(rangeNo), rangeNo+1, t.address);

               if ((status = request->setTimeRanges(&t)) == success)
               {
                  char* buf = 0;

                  // store job result

                  asprintf(&buf, "success#%s#%s#%s", t.getTimeRangeFrom(rangeNo), t.getTimeRangeTo(rangeNo), "Zeitbereich");
                  tableJobs->setValue("RESULT", buf);
                  free(buf);

                  // update time range table

                  sprintf(fName, "FROM%d", rangeNo+1);
                  sprintf(tName, "TO%d", rangeNo+1);
                  tableTimeRanges->setValue(fName, t.getTimeRangeFrom(rangeNo));
                  tableTimeRanges->setValue(tName, t.getTimeRangeTo(rangeNo));
                  tableTimeRanges->update();
               }
               else
               {
                  tell(eloAlways, "Set of time range parameter failed, error %d", status);

                  if (status == P4Request::wrnNonUpdate)
                     tableJobs->setValue("RESULT", "fail#no update");
                  else if (status == P4Request::wrnOutOfRange)
                     tableJobs->setValue("RESULT", "fail#out of range");
                  else
                     tableJobs->setValue("RESULT", "fail#communication error");
               }
            }
            else
            {
               tell(eloAlways, "Set of time range parameter failed, wrong format");
               tableJobs->setValue("RESULT", "fail#format error");
            }
         }
         else
         {
            tell(eloAlways, "Set of time range parameter failed, addr 0x%x for '%s' not found", addr, data);
            tableJobs->setValue("RESULT", "fail#id not found");
         }
      }

      else if (strcasecmp(command, "getv") == 0)
      {
         Value v(addr);

         tableValueFacts->clear();
         tableValueFacts->setValue("TYPE", "VA");
         tableValueFacts->setValue("ADDRESS", addr);

         if (tableValueFacts->find())
         {
            double factor = tableValueFacts->getIntValue("FACTOR");
            const char* unit = tableValueFacts->getStrValue("UNIT");

            if (request->getValue(&v) == success)
            {
               char* buf = 0;

               asprintf(&buf, "success:%.2f%s", v.value / factor, unit);
               tableJobs->setValue("RESULT", buf);
               free(buf);
            }
         }
      }

      else if (strcasecmp(command, "initmenu") == 0)
      {
         initMenu();
         tableJobs->setValue("RESULT", "success:done");
      }

      else if (strcasecmp(command, "updatehm") == 0)
      {
         if (hmSyncSysVars() == success)
            tableJobs->setValue("RESULT", "success:done");
         else
            tableJobs->setValue("RESULT", "fail:error");
      }

      else if (strcasecmp(command, "p4d-state") == 0)
      {
         struct tm tim = {0};

         double averages[3];
         char dt[10];
         char d[100];
         char* buf;

         memset(averages, 0, sizeof(averages));
         localtime_r(&nextAt, &tim);
         strftime(dt, 10, "%H:%M:%S", &tim);
         toElapsed(time(0)-startedAt, d);

         getloadavg(averages, 3);

         asprintf(&buf, "success:%s#%s#%s#%3.2f %3.2f %3.2f",
                  dt, VERSION, d, averages[0], averages[1], averages[2]);

         tableJobs->setValue("RESULT", buf);
         free(buf);
      }

      else if (strcasecmp(command, "s3200-state") == 0)
      {
         struct tm tim = {0};
         char date[100];
         char* buf = 0;

         localtime_r(&currentState.time, &tim);
         strftime(date, 100, "%A, %d. %b. %G %H:%M:%S", &tim);

         asprintf(&buf, "success:%s#%d#%s#%s", date,
                  currentState.state, currentState.stateinfo,
                  currentState.modeinfo);

         tableJobs->setValue("RESULT", buf);
         free(buf);
      }

      else if (strcasecmp(command, "initvaluefacts") == 0)
      {
         updateValueFacts();
         tableJobs->setValue("RESULT", "success:done");
      }

      else if (strcasecmp(command, "updatemenu") == 0)
      {
         tableMenu->clear();

         for (int f = selectAllMenuItems->find(); f; f = selectAllMenuItems->fetch())
         {
            int type = tableMenu->getIntValue("TYPE");
            int paddr = tableMenu->getIntValue("ADDRESS");

            if (type == 0x07 || type == 0x08 || type == 0x0a ||
                type == 0x40 || type == 0x39 || type == 0x32)
            {
               Fs::ConfigParameter p(paddr);

               if (request->getParameter(&p) == success)
               {
                  cRetBuf value = ConfigParameter::toNice(p.value, type);

                  if (tableMenu->find())
                  {
                     tableMenu->setValue("VALUE", value);
                     tableMenu->setValue("UNIT", p.unit);
                     tableMenu->update();
                  }
               }
            }

            else if (type == mstFirmware)
            {
               Fs::Status s;

               if (request->getStatus(&s) == success)
               {
                  if (tableMenu->find())
                  {
                     tableMenu->setValue("VALUE", s.version);
                     tableMenu->setValue("UNIT", "");
                     tableMenu->update();
                  }
               }
            }

            else if (type == mstDigOut || type == mstDigIn || type == mstAnlOut)
            {
               int status;
               Fs::IoValue v(paddr);

               if (type == mstDigOut)
                  status = request->getDigitalOut(&v);
               else if (type == mstDigIn)
                  status = request->getDigitalIn(&v);
               else
                  status = request->getAnalogOut(&v);

               if (status == success)
               {
                  char* buf = 0;

                  if (type == mstAnlOut)
                  {
                     if (v.mode == 0xff)
                        asprintf(&buf, "%d (A)", v.state);
                     else
                        asprintf(&buf, "%d (%d)", v.state, v.mode);
                  }
                  else
                     asprintf(&buf, "%s (%c)", v.state ? "on" : "off", v.mode);

                  if (tableMenu->find())
                  {
                     tableMenu->setValue("VALUE", buf);
                     tableMenu->setValue("UNIT", "");
                     tableMenu->update();
                  }

                  free(buf);
               }
            }

            else if (type == mstMesswert || type == mstMesswert1)
            {
               int status;
               Fs::Value v(paddr);

               tableValueFacts->clear();
               tableValueFacts->setValue("TYPE", "VA");
               tableValueFacts->setValue("ADDRESS", paddr);

               if (tableValueFacts->find())
               {
                  double factor = tableValueFacts->getIntValue("FACTOR");
                  const char* unit = tableValueFacts->getStrValue("UNIT");

                  status = request->getValue(&v);

                  if (status == success)
                  {
                     char* buf = 0;
                     asprintf(&buf, "%.2f", v.value / factor);

                     if (tableMenu->find())
                     {
                        tableMenu->setValue("VALUE", buf);

                        if (strcmp(unit, "°") == 0)
                           tableMenu->setValue("UNIT", "°C");
                        else
                           tableMenu->setValue("UNIT", unit);

                        tableMenu->update();
                     }

                     free(buf);
                  }
               }
            }
         }

         selectAllMenuItems->freeResult();

         updateTimeRangeData();

         tableJobs->setValue("RESULT", "success:done");
      }

      else
      {
         tell(eloAlways, "Warning: Ignoring unknown job '%s'", command);
         tableJobs->setValue("RESULT", "fail:unknown command");
      }

      tableJobs->store();

      tell(eloAlways, "Processing WEBIF job %d done with '%s' after %ld seconds",
           jobId, tableJobs->getStrValue("RESULT"),
           time(0) - start);
   }

   selectPendingJobs->freeResult();

   return success;
}