IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8192


Ignore:
Timestamp:
Aug 5, 2006, 1:39:43 PM (20 years ago)
Author:
eugene
Message:

fixed up the trange concepts, fixed bugs in queuedrop/queuepop

Location:
trunk/Ohana/src/opihi
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.data/queuedrop.c

    r8177 r8192  
    33int queuedrop (int argc, char **argv) {
    44 
    5   int N, Key;
     5  int N;
     6  char *Key;
    67  char *var;
    78  char *line;
     
    910  Queue *queue;
    1011
    11   Key = -1;
     12  Key = NULL;
    1213  if ((N = get_argument (argc, argv, "-key"))) {
    1314    remove_argument (N, &argc, argv);
    14     Key = atoi (argv[N]);
     15    Key = strcreate (argv[N]);
    1516    remove_argument (N, &argc, argv);
    1617    Value = strcreate (argv[N]);
    1718    remove_argument (N, &argc, argv);
    1819  }
    19 
    2020
    2121  if ((argc != 2) || (Key == -1)) {
  • trunk/Ohana/src/opihi/cmd.data/queuepop.c

    r8190 r8192  
    2525    remove_argument (N, &argc, argv);
    2626  }
    27 
    2827
    2928  if (argc != 2) {
  • trunk/Ohana/src/opihi/include/convert.h

    r4810 r8192  
    1515int           day_to_sec            PROTO((char *string, time_t *second));
    1616int           hms_to_sec            PROTO((char *string, time_t *second));
     17char         *sec_to_hms            PROTO((time_t second));
     18char         *sec_to_day            PROTO((time_t second));
    1719
    1820char         *meade_deg_to_str      PROTO((double deg));
  • trunk/Ohana/src/opihi/include/pantasks.h

    r8191 r8192  
    5151  time_t stop;
    5252  char type;
    53   char keep;
     53  char include;
    5454  int Nmax;
    5555  int Nrun;
  • trunk/Ohana/src/opihi/lib.data/convert.c

    r4810 r8192  
    116116}
    117117
     118/***** convert seconds to HH:MM:SS ****/
     119char *sec_to_hms (time_t second) {
     120 
     121  struct tm *gmt;
     122  char *line;
     123
     124  ALLOCATE (line, char, 64);
     125  gmt   = gmtime (&second);
     126  sprintf (line, "%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     127  return (line);
     128}
     129
     130/***** convert seconds to Day@HH:MM:SS ****/
     131char *sec_to_day (time_t second) {
     132 
     133  struct tm *gmt;
     134  char *line;
     135
     136  ALLOCATE (line, char, 64);
     137  gmt   = gmtime (&second);
     138  switch (gmt[0].tm_wday) {
     139    case 0:
     140      sprintf (line, "Sun@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     141      break;
     142    case 1:
     143      sprintf (line, "Mon@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     144      break;
     145    case 2:
     146      sprintf (line, "Tue@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     147      break;
     148    case 3:
     149      sprintf (line, "Wed@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     150      break;
     151    case 4:
     152      sprintf (line, "Thu@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     153      break;
     154    case 5:
     155      sprintf (line, "Fri@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     156      break;
     157    case 6:
     158      sprintf (line, "Sat@%02d:%02d:%02d", gmt[0].tm_hour, gmt[0].tm_min, gmt[0].tm_sec);
     159      break;
     160  }
     161  return (line);
     162}
     163
    118164int hh_hm (double hh, int *hr, double *mn) {
    119165
  • trunk/Ohana/src/opihi/pantasks/CheckTimeRanges.c

    r8191 r8192  
    11# include "pantasks.h"
     2
     3/* the tested time is saved by CheckTimeRanges for a following BumpTimeRanges
     4   otherwise we could have an inconsistency between valid ranges and Nrun */
     5static time_t daytime, weektime, abstime;
    26
    37/* test if we meet all time range qualifications */
    48int CheckTimeRanges (TimeRange *ranges, int Nranges) {
    59
    6   int i, intime, valid;
    7   time_t daytime, weektime, abstime, testtime;
     10  int i, intime, Ninclude, include, exclude, valid;
     11  time_t testtime;
    812  struct timeval now;
    913  struct tm Now;
     
    1620  abstime  = now.tv_sec;
    1721
    18   valid = TRUE;
    19   for (i = 0; (i < Nranges) && valid; i++) {
     22  Ninclude = 0;
     23  include = FALSE;
     24  exclude = FALSE;
     25 
     26  for (i = 0; i < Nranges; i++) {
     27    if (ranges[i].include) Ninclude ++;
     28
    2029    switch (ranges[i].type) {
    2130      /* set the testtime */
     
    3544
    3645    /* check for more than max runs in time range */
    37     if (ranges[i].keep && intime && ranges[i].Nmax) {
     46    if (ranges[i].include && intime && ranges[i].Nmax) {
    3847      if (ranges[i].Nrun >= ranges[i].Nmax) return (FALSE);
    3948    }
    4049    /* reset Nrun if we are outside of intime */
    41     if (ranges[i].keep && !intime && ranges[i].Nmax && ranges[i].Nrun) {
     50    if (ranges[i].include && !intime && ranges[i].Nmax && ranges[i].Nrun) {
    4251      ranges[i].Nrun = 0;
    4352    }
    4453
    4554    /* is this a valid time? */
    46     valid = ranges[i].keep ? intime : !intime;
     55    if ( ranges[i].include &&  intime) include = TRUE;
     56    if (!ranges[i].include && !intime) exclude = TRUE;
    4757  }
     58
     59  if (Ninclude == 0) include = TRUE;
     60  valid = include && !exclude;
     61
    4862  return (valid);
    4963
     
    5367int BumpTimeRanges (TimeRange *ranges, int Nranges) {
    5468
    55   int i;
     69  int i, intime;
     70  time_t testtime;
    5671
     72  /* only increment the counter for ranges which are valid */
    5773  for (i = 0; i < Nranges; i++) {
    58     if (ranges[i].keep && ranges[i].Nmax) {
    59       ranges[i].Nrun ++;
     74    if (!ranges[i].Nmax) continue;
     75    if (!ranges[i].include) continue;
     76
     77    switch (ranges[i].type) {
     78      /* set the testtime */
     79      case RANGE_ABS:
     80        testtime = abstime;
     81        break;
     82      case RANGE_DAY:
     83        testtime = daytime;
     84        break;
     85      case RANGE_WEEK:
     86        testtime = weektime;
     87        break;
     88      default:
     89        abort ();
    6090    }
     91    intime = (testtime >= ranges[i].start) && (testtime <= ranges[i].stop);
     92
     93    /* reset Nrun if we are outside of intime */
     94    if (intime) ranges[i].Nrun ++;
    6195  }
    6296  return (TRUE);
  • trunk/Ohana/src/opihi/pantasks/TaskOps.c

    r8129 r8192  
    5252void ListTasks (int verbose) {
    5353
    54   int i, valid;
     54  int i, j, valid;
     55  char *start, *stop;
    5556
    5657  gprint (GP_LOG, "\n");
     
    7879      gprint (GP_LOG, "    spawn period: %f, polling period: %f, timeout period: %f\n",
    7980               tasks[i][0].exec_period, tasks[i][0].poll_period, tasks[i][0].timeout_period);
     81      for (j = 0; j < tasks[i][0].Nranges; j++) {
     82        switch (tasks[i][0].ranges[j].type) {
     83          case RANGE_ABS:
     84            start = sec_to_date (tasks[i][0].ranges[j].start);
     85            stop  = sec_to_date (tasks[i][0].ranges[j].stop);
     86            break;
     87          case RANGE_DAY:
     88            start = sec_to_hms (tasks[i][0].ranges[j].start);
     89            stop  = sec_to_hms (tasks[i][0].ranges[j].stop);
     90            break;
     91          case RANGE_WEEK:
     92            start = sec_to_day (tasks[i][0].ranges[j].start);
     93            stop  = sec_to_day (tasks[i][0].ranges[j].stop);
     94            break;
     95          default:
     96            abort ();
     97        }
     98        if (tasks[i][0].ranges[j].include) {
     99          gprint (GP_LOG, "     active : %s - %s", start, stop);
     100          if (tasks[i][0].ranges[j].Nmax) gprint (GP_LOG, " (%d of %d)", tasks[i][0].ranges[j].Nrun, tasks[i][0].ranges[j].Nmax);
     101          gprint (GP_LOG, "\n");
     102        } else {
     103          gprint (GP_LOG, "     avoid  : %s - %s\n", start, stop);
     104        }
     105        free (start);
     106        free (stop);
     107      }
    80108      if (tasks[i][0].host == NULL) {
    81109        gprint (GP_LOG, "    task runs locally\n");
     
    99127int ShowTask (char *name) {
    100128
    101   int i;
     129  int i, j;
     130  char *start, *stop
    102131  Task *task;
    103132
     
    138167periods:
    139168  gprint (GP_LOG, " time periods: exec: %f  poll: %f  timeout: %f\n",
    140            task[0].exec_period, task[0].poll_period, task[0].timeout_period);
     169          task[0].exec_period, task[0].poll_period, task[0].timeout_period);
     170
     171  for (j = 0; j < tasks[i][0].Nranges; j++) {
     172    switch (tasks[i][0].ranges[j].type) {
     173      case RANGE_ABS:
     174        start = sec_to_date (tasks[i][0].ranges[j].start);
     175        stop  = sec_to_date (tasks[i][0].ranges[j].stop);
     176        break;
     177      case RANGE_DAY:
     178        start = sec_to_hms (tasks[i][0].ranges[j].start);
     179        stop  = sec_to_hms (tasks[i][0].ranges[j].stop);
     180        break;
     181      case RANGE_WEEK:
     182        start = sec_to_day (tasks[i][0].ranges[j].start);
     183        stop  = sec_to_day (tasks[i][0].ranges[j].stop);
     184        break;
     185      default:
     186        abort ();
     187    }
     188    if (tasks[i][0].ranges[j].include) {
     189      gprint (GP_LOG, "     active : %s - %s", start, stop);
     190      if (tasks[i][0].ranges[j].Nmax) gprint (GP_LOG, " (%d of %d)", tasks[i][0].ranges[j].Nrun, tasks[i][0].ranges[j].Nmax);
     191      gprint (GP_LOG, "\n");
     192    } else {
     193      gprint (GP_LOG, "     avoid  : %s - %s\n", start, stop);
     194    }
     195    free (start);
     196    free (stop);
     197  }
    141198
    142199  gprint (GP_LOG, "\n pre-execute macro\n");
  • trunk/Ohana/src/opihi/pantasks/task.c

    r8129 r8192  
    2323  if ((N = get_argument (argc, argv, "-show"))) {
    2424    remove_argument (N, &argc, argv);
     25    if (argc != 2) goto usage;
    2526    ShowTask (argv[N]);
    2627    return (TRUE);
    2728  }
    2829
    29   if (argc != 2) {
    30     gprint (GP_ERR, "USAGE: task <name>\n");
    31     gprint (GP_ERR, "  (enter commands & task functions; end with the word 'END')\n");
    32     return (FALSE);
    33   }
     30  if (argc != 2) goto usage;
    3431
    3532  task = FindTask (argv[1]);
     
    108105    }
    109106  }
    110   /* cannot ever reach here */
     107
     108usage:
     109  gprint (GP_ERR, "USAGE: task -list\n");
     110  gprint (GP_ERR, "USAGE: task -longlist\n");
     111  gprint (GP_ERR, "USAGE: task -show (task)\n");
     112  gprint (GP_ERR, "USAGE: task <name>\n");
     113  gprint (GP_ERR, "  (enter commands & task functions; end with the word 'END')\n");
    111114  return (FALSE);
    112115}
  • trunk/Ohana/src/opihi/pantasks/task_trange.c

    r8191 r8192  
    77  TimeRange range;
    88
    9   /* add a -reset option?
    10   if (N = get_argument (argc, argv, "-reset")) {
     9  /* reset the tranges for the current task */
     10  if ((N = get_argument (argc, argv, "-reset"))) {
    1111    remove_argument (N, &argc, argv);
    12   } */
     12    if (argc != 1) goto usage;
     13
     14    task = GetNewTask ();
     15    if (task == NULL) {
     16      gprint (GP_ERR, "ERROR: not defining or running a task\n");
     17      return (FALSE);
     18    }
     19
     20    task[0].Nranges = 0;
     21    REALLOCATE (task[0].ranges, TimeRange, 1);
     22    return (TRUE);
     23  }
    1324
    1425  range.Nmax = 0;
    1526  range.Nrun = 0;
    16   if (N = get_argument (argc, argv, "-nmax")) {
     27  if ((N = get_argument (argc, argv, "-nmax"))) {
    1728    remove_argument (N, &argc, argv);
    1829    range.Nmax = atoi (argv[N]);
     
    2233  /* keep = true means the time range defines a valid time range
    2334     keep = false means the time range defines an invalid range */
    24   range.keep = TRUE;
     35  range.include = TRUE;
    2536  if ((N = get_argument (argc, argv, "-exclude"))) {
    2637    remove_argument (N, &argc, argv);
    27     range.keep = FALSE;
     38    range.include = FALSE;
    2839  }
    2940
     
    3849  /* test for Mon[@HH:MM:SS] - both must match */
    3950  if (day_to_sec (argv[1], &range.start)) {
    40     if (!day_to_sec (argv[2], &range.stop)) goto usage;
     51    if (!day_to_sec (argv[2], &range.stop)) {
     52      gprint (GP_ERR, "invalid day/time %s\n", argv[2]);
     53      goto usage;
     54    }
    4155    range.type = RANGE_WEEK;
    4256    goto valid;
     
    4559  /* test for HH:MM:SS */
    4660  if (hms_to_sec (argv[1], &range.start)) {
    47     if (!hms_to_sec (argv[2], &range.stop)) goto usage;
     61    if (!hms_to_sec (argv[2], &range.stop)) {
     62      gprint (GP_ERR, "invalid time %s\n", argv[2]);
     63      goto usage;
     64    }
    4865    range.type = RANGE_DAY;
    4966    goto valid;
     
    5370  /* test for YYYY/MM/DD - both must match */
    5471  if (str_to_time (argv[1], &range.start)) {
    55     if (!str_to_time (argv[2], &range.stop)) goto usage;
     72    if (!str_to_time (argv[2], &range.stop)) {
     73      gprint (GP_ERR, "invalid date/time %s\n", argv[2]);
     74      goto usage;
     75    }
    5676    range.type = RANGE_ABS;
    5777    goto valid;
     
    6888
    6989usage:
    70   gprint (GP_ERR, "USAGE: trange start end\n");
     90  gprint (GP_ERR, "USAGE: trange start end [-nmax N]\n");
     91  gprint (GP_ERR, "USAGE: trange -reset\n");
    7192  return (FALSE);
    7293}
Note: See TracChangeset for help on using the changeset viewer.