예제 #1
0
파일: db.cpp 프로젝트: kiransj/todo
bool SqlDB::change_state(const char *pr_number, PrState new_state)
{
    PrInfo pr;
    PrState old_state;
    bool flag = false;
    char query_state_change[512];   
    snprintf(query_state_change, 512, "UPDATE TODOLIST SET PR_STATE=%d WHERE PR_NUMBER='%s';", new_state, pr_number);        
    if(status == false)
    {
        snprintf(last_error_msg, 1024, "First open the database before any query");
        return false;
    }
    
    if(get_pr(pr_number, &pr) == false)
    {
        snprintf(last_error_msg, 1024, "Pr '%s' does not exists", pr_number);
        return false;
    }

    old_state = pr.pr_state;
    if(old_state == new_state)
    {
        snprintf(last_error_msg, 1024, "new and old state are the same");
        return false;   
    }       

    flag = execute_stmt(query_state_change);
    if(flag == true)
    {
        char msg[1024];
        snprintf(msg, 1024, "change state from %s to %s", PrState_string[old_state], PrState_string[new_state]);
        flag = add_update(pr_number, msg);
    }
    return flag;
}
예제 #2
0
파일: db.cpp 프로젝트: kiransj/todo
bool SqlDB::add_new_pr(const PrInfo pr)
{
    bool flag = false;
    char query_insert_newpr[1024];
    snprintf(query_insert_newpr, 1024,  "INSERT INTO ToDoList (PR_NUMBER, PR_HEADER, PR_DATE, PR_STATE)"
                                     "VALUES('%s', '%s', %lu, %u);",
                                     pr.pr_number,
                                     pr.pr_header,
                                     pr.pr_date,
                                     pr.pr_state);
    if(status == false)
    {
        snprintf(last_error_msg, 1024, "First open the database before any query");
        return flag;    
    }
    else
    {
        int rc;
        sqlite3_stmt *statement;     
        rc = sqlite3_prepare_v2(database, query_insert_newpr, -1, &statement, 0);
        if(rc == SQLITE_OK)
        {
            int rc = sqlite3_step(statement);
            if(rc == SQLITE_DONE)
            {
                status = true;
                flag = true;
            }
            else if(rc == SQLITE_CONSTRAINT)
            {
                if(get_pr(pr.pr_number, NULL) == true)
                    snprintf(last_error_msg, 1024, "Pr %s already exists", pr.pr_number);
                else
                    snprintf(last_error_msg, 1024, "SQLITE_CONSTRAINT error");
            }
            else
            {
                snprintf(last_error_msg, 1024, "query '%s' failed", query_insert_newpr);
            }
            sqlite3_finalize(statement);
        }
        else
        {
            printf("Error in stat  %d\n", rc);
        }
    }
    return flag;
}
예제 #3
0
파일: proc.c 프로젝트: KHATEEBNSIT/AP
int load_prop (char type, char *file_name, prop_data properties[])
{
	FILE *fid;
	char line[1024];//jwchang
	int prop_count = 0;

	if ((fid = fopen (file_name, "r")) == NULL)  
	{
		printf(" fopen == NULL\n");
		return 0;
	}
	while (!feof (fid))
	{
		fgets(line, 255, fid);
		if(feof(fid)) break;
		if (strchr(line, '\n'))  *(strchr(line, '\n')) = '\0';
		if (get_pr (type, line, (prop_data *) & properties[prop_count]))
		{
			prop_count++;
		}
	}
	fclose (fid);
	return prop_count;
}
예제 #4
0
int pt_dispatch_proc_to_job(
lnk_link_t *job_list,
int time_stamp,
time_t last_time
) {
   char procnam[128];
   int fd = -1;
#if defined(LINUX)
   char buffer[BIGLINE];
   lListElem *pr = NULL;
   SGE_STRUCT_STAT fst;
   unsigned long utime, stime, vsize, pid;
   int pos_pid = lGetPosInDescr(PRO_Type, PRO_pid);
   int pos_utime = lGetPosInDescr(PRO_Type, PRO_utime);
   int pos_stime = lGetPosInDescr(PRO_Type, PRO_stime);
   int pos_vsize = lGetPosInDescr(PRO_Type, PRO_vsize);
   int pos_groups = lGetPosInDescr(PRO_Type, PRO_groups);
   int pos_rel = lGetPosInDescr(PRO_Type, PRO_rel);
   int pos_run = lGetPosInDescr(PRO_Type, PRO_run);
   int pos_io = lGetPosInDescr(PRO_Type, PRO_io);
   int pos_group = lGetPosInDescr(GR_Type, GR_group);
#else
   prstatus_t pr;
   prpsinfo_t pri;
#endif

#if defined(SOLARIS) || defined(ALPHA)   
   prcred_t proc_cred;
#endif

   int ret;
   u_long32 max_groups;
   gid_t *list;
   int groups=0;
   int pid_tmp;

   proc_elem_t *proc_elem = NULL;
   job_elem_t *job_elem = NULL;
   lnk_link_t *curr;
   double old_time = 0;
   uint64 old_vmem = 0;

   DENTER(TOP_LAYER, "pt_dispatch_proc_to_job");

   max_groups = sge_sysconf(SGE_SYSCONF_NGROUPS_MAX);
   if (max_groups <= 0) {
      ERROR((SGE_EVENT, SFNMAX, MSG_SGE_NGROUPS_MAXOSRECONFIGURATIONNECESSARY));
      DEXIT;
      return 1;  
   }   

   list = (gid_t*) malloc(max_groups*sizeof(gid_t));
   if (list == NULL) {
      ERROR((SGE_EVENT, SFNMAX, MSG_SGE_PTDISPATCHPROCTOJOBMALLOCFAILED));
      DEXIT;
      return 1;
   }

   /* find next valid entry in procfs */ 
   while ((dent = readdir(cwd))) {
      char *pidname;

      if (!dent->d_name)
         continue;
      if (!dent->d_name[0])
         continue;

      if (!strcmp(dent->d_name, "..") || !strcmp(dent->d_name, "."))
         continue;

      if (dent->d_name[0] == '.')
          pidname = &dent->d_name[1];
      else
          pidname = dent->d_name;

      if (atoi(pidname) == 0)
         continue;

#if defined(LINUX)
      /* check only processes which belongs to a GE job */
      if ((pr = get_pr(atoi(pidname))) != NULL) {
         /* set process as still running */
         lSetPosBool(pr, pos_run, true);
         if (lGetPosBool(pr, pos_rel) != true) {
            continue;
         }
      }
      sprintf(procnam, PROC_DIR "/%s/stat", dent->d_name);

      if (SGE_STAT(procnam, &fst)) {
         if (errno != ENOENT) {
#ifdef MONITOR_PDC
            INFO((SGE_EVENT, "could not stat %s: %s\n", procnam, strerror(errno)));
#endif
            touch_time_stamp(dent->d_name, time_stamp, job_list);
         }
         continue;
      }
      /* TODO (SH): This does not work with Linux 2.6. I'm looking for a workaround.
       * If the stat file was not changed since our last parsing there is no need to do it again
       */
      /*if (pr == NULL || fst.st_mtime > last_time) {*/
      {
#else
         sprintf(procnam, "%s/%s", PROC_DIR, dent->d_name);
#endif
         if ((fd = open(procnam, O_RDONLY, 0)) == -1) {
            if (errno != ENOENT) {
#ifdef MONITOR_PDC
               if (errno == EACCES)
                  INFO((SGE_EVENT, "(uid:"gid_t_fmt" euid:"gid_t_fmt") could not open %s: %s\n",
                           getuid(), geteuid(), procnam, strerror(errno)));
               else
                  INFO((SGE_EVENT, "could not open %s: %s\n", procnam, strerror(errno)));
#endif
                  touch_time_stamp(dent->d_name, time_stamp, job_list);
            }
            continue;
         }

         /** 
          ** get a list of supplementary group ids to decide
          ** whether this process will be needed;
          ** read also prstatus
          **/

#  if defined(LINUX)

         /* 
          * Read the line and append a 0-Byte 
          */
         if ((ret = read(fd, buffer, BIGLINE-1))<=0) {
            close(fd);
            if (ret == -1 && errno != ENOENT) {
#ifdef MONITOR_PDC
               INFO((SGE_EVENT, "could not read %s: %s\n", procnam, strerror(errno)));
#endif
               touch_time_stamp(dent->d_name, time_stamp, job_list);
            }
            continue;
         }
         buffer[BIGLINE-1] = '\0';

         /* 
          * get prstatus
          */
         ret = sscanf(buffer, "%lu %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu %*d %*d %*d %*d %*d %*d %*u %lu",
                      &pid,
                      &utime,
                      &stime,
                      &vsize);

         if (ret != 4) {
            close(fd);
            continue;
         }

         if (pr == NULL) {
            pr = lCreateElem(PRO_Type);
            lSetPosUlong(pr, pos_pid, pid);
            lSetPosBool(pr, pos_rel, false);
            append_pr(pr);
         }
         
         lSetPosUlong(pr, pos_utime, utime);
         lSetPosUlong(pr, pos_stime, stime);
         lSetPosUlong(pr, pos_vsize, vsize);
         
         close(fd);
      }
      /* mark this proc as running */
      lSetPosBool(pr, pos_run, true);

      /* 
       * get number of groups; 
       * get list of supplementary groups 
       */
      {
         char procnam[256];
         lList *groupTable = lGetPosList(pr, pos_groups);

         sprintf(procnam, PROC_DIR "/%s/status", dent->d_name);
         if (SGE_STAT(procnam, &fst) != 0) {
            if (errno != ENOENT) {
#ifdef MONITOR_PDC
               INFO((SGE_EVENT, "could not stat %s: %s\n", procnam, strerror(errno)));
#endif
               touch_time_stamp(dent->d_name, time_stamp, job_list);
            }
            continue;
         }

         groups = 0;
         if (fst.st_mtime < last_time && groupTable != NULL) {
            lListElem *group;

            for_each(group, groupTable) {
               list[groups] = lGetPosUlong(group, pos_group);
               groups++;
            }
         } else {
예제 #5
0
void main()
{
    TRISC.f1=0;    //rw
    TRISC.f3=0; //warning output
    TRISD.f5=0;  //acknowledge ip
    TRISC.f0=0; //rs
    TRISC.f2=0; //en
    TRISB=0x01; //PORTB as output port for LCD
    Lcd_Custom_Config(&PORTB,7,6,5,4,&PORTC,0,1,2); //PORTD configured for LCD
    TRISD.f4=1;   // for emergency stop
    INTCON.f7=1; //enabling global interrupt
    INTCON.f6=1; //enabling peripheral interrupt
    INTCON.f4=1;  //enabling int0 interrupt

    INTCON2.f6=0; //interrupt on falling edge
    PIR2.f1=0; //when 1, timer 3 overflow interrupt has occured
    PIE2.f1=1;//enabling timer 3 overflow interrupt
    TMR3H=0x00; //loading timer 3 registers with 0 initial value
    TMR3L=0x00; // timer 3 counts until FFFF or 65536
    T3CON=0xB0;//16 bit readable; prescaled by 8; input clock source=Fosc/4

  //timer3 to be used for display timing

    PIE1=0x01; // enable timer 1 interrupt
    PIR1.f0=0; //timer 1 interrupt flag=0(no interrupt has occured)
    TMR0L=0X00;//timer 0 as counter to count pulses with initial value=0
    TMR0H=0X00;
    TMR1H=0X15; //for 1 ms delay
    TMR1L=0XA0;
    T0CON=0b00111000; //stop,16bit,ext clk,H to L,bypass prescalar
    T1CON=0X00;// dont start timer1 yet

  //timer0 & 1 engaged in rpm measurement

    TRISA=0xFF; //all pins set as inputs
    TRISE.f0=1;


    T0CON.f7=1; //start counting pulses
    T1CON.f0=1; //start timer for 1ms
    T3CON.f0=1;//start timer3 for display
  comeback:  while(1)
    {
      estop=0;
      if(PORTD.f4==0)
      {
        delay_ms(2000);
        if(PORTD.f4==0)
        {
        estop=1;
        shutdown=1;
        break;
        }
      }


      for(i=0;i<7;i++)
      {
      if(fault_code[i]==0)

      fault_count++;
      if(fault_code[i]==2)
      {
      shutdown=1;
       break;
       }
      }
      if(fault_count<7)
       fault=1;   // fault is either a warning or shutdown
       else
       fault=0;
       fault_count=0;


       if(shutdown==1)
       break;
       if(fault==1)  // now the possible fault is a warning
       {
       shutdown=0;
       if(ack_flag==1)
       {
        ack_flag=0;
        ack=1;
       }

        if(ack==0)  //fault not yet acknowledged
       {
       PORTC.f3=1;  // give warning output
       disp_del=10;
       }
       else if(ack==1)
       {
       disp_del=24;
      // PORTC.f3=0;
       }
       }
       else if(fault==0)
       {
       shutdown=0;
       disp_del=24;
       ack=0;
       PORTC.f3=0;        // warning output
      }
      if(flag==1)       // flag is for specified delay
     {
      flag=0;
      if((fault==0) || ((fault==1)&&(ack==1)))
      disp();
      else if((fault==1) && (ack==0))
      disp_fault();

      }
     //1. battery voltage

       ADCON1=0b11000000;//right justified; conversion time=16Tosc and
                                 //all pins of PORTA as analog inputs
       ADCON0=0b01000001;//channel 0; ADC enabled
       delay_us(20);
       ADCON0.f2=1;// start conversion
       while(ADCON0.f2);
       bat_temp=(256*ADRESH)+ADRESL;


       if(bat_temp>0)
       {
       if(bat_temp>614)
       bat_thresh=716; //21V
       else
       bat_thresh=307; // 9V
       if(bat_temp<bat_thresh)
       fault_code[0]=1;
       else
       fault_code[0]=0;
        }


       ADRESL=0x00; // clearing ADRES resgisters
       ADRESH=0x00;

      //2. coolant temperature

       ADCON1=0b11000000;//right justified; conversion time=16Tosc and
                      //all pins of PORTA as analog inputs
       ADCON0=0b01001001;//channel 1; ADC enabled
       delay_us(20);
       ADCON0.f2=1;// start conversion
       while( ADCON0.f2);

       ct_temp=(256*ADRESH)+ADRESL;
       ct=get_temp1(ct_temp);
       ct=ct*250;  //to deg F
       if(ct>=3200)
       {
       ct=ct-3200;
       ct_neg=0;

       }
       else
       {
        ct=3200-ct;
        ct_neg=1;

      }

        //to deg C
       ct=(ct/9)*5;


       if (ct>ct_thresh1)
       {
       fault_code[1]=1;
        if(ct>ct_thresh2)
        fault_code[1]=2; }
       else
       fault_code[1]=0;

        if(ct<ct_thresh_l)
        {
        //if(PORTC.f1!=1)
        PORTC.f1=1;
        }     //low coolant temp  warning;
        else if(ct>ct_thresh_l)
        PORTC.f1=0;


       ADRESL=0x00; // clearing ADRES resgisters
       ADRESH=0x00;

      //3. lubricant oil pressure

       ADCON1=0b11000000;//right justified; conversion time=16Tosc and
                      //all pins of PORTA as analog inputs
       ADCON0=0b01010001;//channel 2; ADC enabled
       delay_us(20);
       ADCON0.f2=1;// start conversion
       while( ADCON0.f2);
       lop_temp=(256*ADRESH)+ADRESL;
       lop=get_pr(lop_temp);

       if(lop_temp<184 || lop_temp>286)
       {
        fault_code[2]=1;
        if(lop_temp<184)
        lop_case=0;
        else if(lop_temp>286)
        lop_case=1;
        if(lop_temp<163 || lop_temp>307)


        fault_code[2]=2;
        }
        else
        {
        lop_case=2;
       fault_code[2]=0;
       }

       ADRESL=0x00; // clearing ADRES resgisters
       ADRESH=0x00;

      //4. exhaust gas temperature

       ADCON1=0b11000000;//right justified; conversion time=16Tosc and
                      //all pins of PORTA as analog inputs
       ADCON0=0b01011001;//channel 3; ADC enabled
       delay_us(20);
       ADCON0.f2=1;// start conversion
       while( ADCON0.f2);
       egt_temp=(256*ADRESH)+ADRESL;
       egt=get_temp2(egt_temp);
      if(egt>egt_thresh1)
      {
      fault_code[3]=1;
      if(egt>egt_thresh2)
      fault_code[3]=2;
      }
       else
       fault_code[3]=0;



       ADRESL=0x00; // clearing ADRES resgisters
       ADRESH=0x00;

      //5. rpm



      //6. compressor outlet temperature

       ADCON1=0b11000000;//right justified; conversion time=16Tosc and
                      //all pins of PORTA as analog inputs
       ADCON0=0b01100001;//channel 5; ADC enabled
       delay_us(20);
       ADCON0.f2=1;// start conversion
       while( ADCON0.f2);
       cot_temp=(256*ADRESH)+ADRESL;
       cot=get_temp1(cot_temp);
       cot=cot*250;  //to deg F
       if(cot>=3200)
        {
       cot=cot-3200; //to deg C

       cot=(cot/9)*5;

     if(cot>cot_thresh1)
     {
       fault_code[5]=1;
       if(cot>cot_thresh2)
       fault_code[5]=2;
       }
       else
       fault_code[5]=0;
       }

       ADRESL=0x00; // clearing ADRES resgisters
       ADRESH=0x00;

      //7. intake manifold temperature

       ADCON1=0b11000000;//right justified; conversion time=16Tosc and
                      //all pins of PORTA as analog inputs
       ADCON0=0b01101001;//channel 5; ADC enabled
       delay_us(20);
       ADCON0.f2=1;// start conversion
       while( ADCON0.f2);
       imt_temp=(256*ADRESH)+ADRESL;
       imt=get_temp1(imt_temp);
       imt=imt*250;  //to deg F
       if(imt>=3200)
        {
       imt=imt-3200; //to deg C

       imt=(imt/9)*5;
       if(imt>imt_thresh1)
       {
       fault_code[6]=1;
       if(imt>imt_thresh2)
       fault_code[6]=2;
       }
       else
       fault_code[6]=0;
        }


       ADRESL=0x00; // clearing ADRES resgisters
       ADRESH=0x00;
  }
  if(shutdown==0)
  {
  goto comeback;
  }
  else if(shutdown==1)
  {
  PORTC.f3=0;
  Lcd_Custom_Cmd(LCD_CLEAR);
  Lcd_Custom_Cmd(LCD_CURSOR_OFF);
  Lcd_Custom_Chr(1,2,' ');
  for(i=0;i<7;i++)
  Lcd_Custom_Chr_cp(fault_code[i]+48);
  Lcd_Custom_Out_Cp("Shutdown due to:");
  Lcd_Custom_Chr(3,4,' ');
  if(estop==1)
  Lcd_Custom_Out_Cp("Emergency Stop");
  for(i=0;i<7;i++)
  if(fault_code[i]==2)
  {
  switch(i)
  {
  case 1:
  Lcd_Custom_Out_Cp("high coolant temp");
  break;

  case 2:
  if(lop_case==0)
  Lcd_Custom_Out_Cp("low L O P");
  else
  Lcd_Custom_Out_Cp("high L O P");
  break;

  case 3:
  Lcd_Custom_Out_Cp("high E G T");
  break;
  case 4:
  Lcd_Custom_Out_Cp("Overspeed");
  break;

  case 5:
  Lcd_Custom_Out_Cp("high C O Temp");
  break;

  case 6:
  Lcd_Custom_Out_Cp("high I M Temp");
  break;
  }

}

  TRISB=0x00;     // drive fuel shut off relay
  PORTD.f5=1;
}

}