summaryrefslogtreecommitdiff
path: root/hpiutil/hpievent.c
blob: 56a5930255da15c64a1d571933345614d46359c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/*
 * hpievent.c
 *
 * Author:  Bill Barkley
 * Copyright (c) 2003 Intel Corporation.
 *
 * 05/14/03 
 * 06/06/03 - complete working version
 * 06/20/03 ARCress - added option for Mullins w default=Langley-type sensor
 *                    added progver
 * 02/26/04 ARCress - added general search for any Fan sensor.
 * 03/17/04 ARCress - changed to Temp sensor (always has Lower Major)
 * 03/30/04 ARCress - fixed rv with saHpiSensorThresholdsSet
 * 01/03/05 ARCress - some edits for HPI_A/B
 * 01/07/05 ARCress - clean compile for HPI B, but ThresholdGet returns -1006
 * 04/01/05 ARCress - set UpMajor if not fFan
 */
/*M*
Copyright (c) 2003, Intel Corporation
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

  a.. Redistributions of source code must retain the above copyright notice, 
      this list of conditions and the following disclaimer. 
  b.. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation 
      and/or other materials provided with the distribution. 
  c.. Neither the name of Intel Corporation nor the names of its contributors 
      may be used to endorse or promote products derived from this software 
      without specific prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *M*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include "SaHpi.h"

char progname[] = "hpievent";
char progver[] = "1.2";
char s_name[] = "80mm Sys Fan (R)";  /*TSRLT2, default*/
char sm_name[] = "Baseboard Fan 2";  /*TSRMT2, Mullins*/
int fFan = 1;
char s_pattn[] = "Temp";  /* else use the first temperature SDR found */
char *sensor_name;
int sensor_name_len = 0;
int fdebug = 0;
int fxdebug = 0;
int fsensor = 0;
int slist = 0;
int i,j,k = 0;
char inbuff[1024];
char outbuff[256];
SaHpiUint32T buffersize;
SaHpiUint32T actualsize;
SaHpiTextBufferT *strptr;
#ifdef HPI_A
SaHpiInventoryDataT *inv;
SaHpiInventGeneralDataT *dataptr;
SaHpiSensorEvtEnablesT enables1;
SaHpiSensorEvtEnablesT enables2;
#endif

char *rdrtypes[5] = {
	"None    ",
	"Control ",
	"Sensor  ",
	"Invent  ",
	"Watchdog"};

#define HPI_NSEC_PER_SEC 1000000000LL
#define NSU   32
char *units[NSU] = {
	"units", "deg C",     "deg F",     "deg K",     "volts", "amps",
	"watts", "joules",    "coulombs",  "va",        "nits",  "lumen",
	"lux",   "candela",   "kpa",       "psi",     "newton",  "cfm",
	"rpm",   "Hz",        "us",        "ms",      "sec",     "min",
	"hours", "days",      "weeks",     "mil",     "in",     "ft",
	"mm",    "cm"
};

#ifdef NOT
void
fixstr(SaHpiTextBufferT *strptr)
{ 
	size_t datalen;
	outbuff[0] = 0;
	if (strptr == NULL) return;
	datalen = strptr->DataLength;
	if (datalen != 0) {
		strncpy ((char *)outbuff, (char *)strptr->Data, datalen);
		outbuff[datalen] = 0;
	}
}
#endif

static void ShowThresh(
   SaHpiSensorThresholdsT *sensbuff, SaHpiSensorThdMaskT ReadThold)
{
      printf( "    Supported Thresholds:\n");
#ifdef HPI_A
      if (sensbuff->LowCritical.ValuesPresent & SAHPI_SRF_INTERPRETED)
         printf( "      Lower Critical Threshold: %5.2f\n",
               sensbuff->LowCritical.Interpreted.Value.SensorFloat32);
      if (sensbuff->LowMajor.ValuesPresent & SAHPI_SRF_INTERPRETED)
         printf( "      Lower Major Threshold: %5.2f\n",
               sensbuff->LowMajor.Interpreted.Value.SensorFloat32);
      if (sensbuff->LowMinor.ValuesPresent & SAHPI_SRF_INTERPRETED)
         printf( "      Lower Minor Threshold: %5.2f\n",
               sensbuff->LowMinor.Interpreted.Value.SensorFloat32);

      if (sensbuff->UpCritical.ValuesPresent & SAHPI_SRF_INTERPRETED)
         printf( "      Upper Critical Threshold: %5.2f\n",
               sensbuff->UpCritical.Interpreted.Value.SensorFloat32);
      if (sensbuff->UpMajor.ValuesPresent & SAHPI_SRF_INTERPRETED)
         printf( "      Upper Major Threshold: %5.2f\n",
               sensbuff->UpMajor.Interpreted.Value.SensorFloat32);
      if (sensbuff->UpMinor.ValuesPresent & SAHPI_SRF_INTERPRETED)
         printf( "      Upper Minor Threshold: %5.2f\n",
               sensbuff->UpMinor.Interpreted.Value.SensorFloat32);

      if (sensbuff->PosThdHysteresis.ValuesPresent & SAHPI_SRF_RAW)
         printf( "      Positive Threshold Hysteresis in RAW\n");
      if (sensbuff->PosThdHysteresis.ValuesPresent & SAHPI_SRF_INTERPRETED)
         printf( "      Positive Threshold Hysteresis: %5.2f\n",
               sensbuff->PosThdHysteresis.Interpreted.Value.SensorFloat32);
      if (sensbuff->NegThdHysteresis.ValuesPresent & SAHPI_SRF_RAW)
         printf( "      Negative Threshold Hysteresis in RAW\n");
      if (sensbuff->NegThdHysteresis.ValuesPresent & SAHPI_SRF_INTERPRETED)
         printf( "      Negative Threshold Hysteresis: %5.2f\n",
               sensbuff->NegThdHysteresis.Interpreted.Value.SensorFloat32);
#else
      if ( ReadThold & SAHPI_STM_LOW_CRIT ) {
         printf( "      Lower Critical Threshold: %5.2f\n",
               sensbuff->LowCritical.Value.SensorFloat64);
	}
      if ( ReadThold & SAHPI_STM_LOW_MAJOR ) {
         printf( "      Lower Major Threshold: %5.2f\n",
               sensbuff->LowMajor.Value.SensorFloat64);
	}
      if ( ReadThold & SAHPI_STM_LOW_MINOR ) {
         printf( "      Lower Minor Threshold: %5.2f\n",
               sensbuff->LowMinor.Value.SensorFloat64);
	}

      if ( ReadThold & SAHPI_STM_UP_CRIT ) {
         printf( "      Upper Critical Threshold: %5.2f\n",
               sensbuff->UpCritical.Value.SensorFloat64);
	}
      if ( ReadThold & SAHPI_STM_UP_MAJOR ) {
         printf( "      Upper Major Threshold: %5.2f\n",
               sensbuff->UpMajor.Value.SensorFloat64);
	}
      if ( ReadThold & SAHPI_STM_UP_MINOR ) {
         printf( "      Upper Minor Threshold: %5.2f\n",
               sensbuff->UpMinor.Value.SensorFloat64);
	}

      if ( ReadThold & SAHPI_STM_UP_HYSTERESIS ) {
         printf( "      Positive Threshold Hysteresis: %5.2f\n",
               sensbuff->PosThdHysteresis.Value.SensorFloat64);
	}
      if ( ReadThold & SAHPI_STM_LOW_HYSTERESIS ) {
         printf( "      Negative Threshold Hysteresis: %5.2f\n",
               sensbuff->NegThdHysteresis.Value.SensorFloat64);
	}
#endif
      printf( "\n");
}

static
SaErrorT DoEvent(
   SaHpiSessionIdT sessionid,
   SaHpiResourceIdT resourceid,
   SaHpiSensorRecT *sensorrec )
{
   SaHpiSensorNumT sensornum;
   SaHpiSensorReadingT reading;
   SaHpiSensorThresholdsT senstbuff1;
   SaHpiSensorThresholdsT senstbuff2;
   SaErrorT rv, rv2;
#ifdef HPI_A
   SaHpiSensorReadingT conv_reading;
#else
   SaHpiEventStateT  evtstate; 
#endif

   SaHpiTimeoutT timeout = (SaHpiInt64T)(12 * HPI_NSEC_PER_SEC); /* 12 seconds*/
   SaHpiEventT event;
   SaHpiRptEntryT rptentry;
   SaHpiRdrT rdr;
   char *unit;
   int eventflag = 0;
   int i;

   sensornum = sensorrec->Num;

/* Get current sensor reading */
#ifdef HPI_A
   rv = saHpiSensorReadingGet( sessionid, resourceid, sensornum, &reading);
#else
   rv = saHpiSensorReadingGet(sessionid,resourceid, sensornum, &reading,&evtstate);
#endif
   if (rv != SA_OK)  {
	printf( "saHpiSensorReadingGet error %d\n",rv);
/*	printf("ReadingGet ret=%d\n", rv); */
	return(rv);
   }

#ifdef HPI_A
   /* HPI A has both interpreted and raw.  HPI B has only interpreted. */
   if ((reading.ValuesPresent & SAHPI_SRF_INTERPRETED) == 0 &&
       (reading.ValuesPresent & SAHPI_SRF_RAW)) {
        /* only try convert if intrepreted not available. */
        rv = saHpiSensorReadingConvert(sessionid, resourceid, sensornum,
					&reading, &conv_reading);
        if (rv != SA_OK) {
		printf("raw=%x conv_ret=%d\n", reading.Raw, rv);
	     /* printf("conv_rv=%s\n", decode_error(rv)); */
		return(rv);
        } else {
	   reading.Interpreted.Type = conv_reading.Interpreted.Type;
	   reading.Interpreted.Value.SensorUint32 = 
		   conv_reading.Interpreted.Value.SensorUint32;
	}
   }
#endif

   /* Determine units of interpreted reading */
   i = sensorrec->DataFormat.BaseUnits;
   if (i > NSU) i = 0;
   unit = units[i];
   /* We know that reading.Type is float for the chosen sensor. */
#ifdef HPI_A
   printf(" = %05.2f %s \n", 
	reading.Interpreted.Value.SensorFloat32, unit);
#else
   printf(" = %05.2f %s \n", reading.Value.SensorFloat64, unit);
#endif

/* Retrieve current threshold setings, twice */
/* once for backup and once for modification */

   /* Get backup copy */
   rv = saHpiSensorThresholdsGet(
	sessionid, resourceid, sensornum, &senstbuff1);
   if (rv != SA_OK) {
	printf( "saHpiSensorThresholdsGet error %d\n",rv); return(rv); }
	/* OpenHPI 2.0.0 ipmi plugin returns -1006 timeout here, why ???? */

   /* Get modification copy */
   rv = saHpiSensorThresholdsGet(
	sessionid, resourceid, sensornum, &senstbuff2);
   if (rv != SA_OK) {
	printf( "saHpiSensorThresholdsGet error %d\n",rv); return(rv); }

   /* Display current thresholds */ 
   if (rv == SA_OK) {
     printf( "   Current\n");
     ShowThresh( &senstbuff2, sensorrec->ThresholdDefn.ReadThold);
   }

/* Set new threshold to current reading + 10% */
#ifdef HPI_A
   if (fFan) {
      senstbuff2.LowMajor.Interpreted.Value.SensorFloat32 =
           reading.Interpreted.Value.SensorFloat32 * (SaHpiFloat32T)1.10;
   } else {
      senstbuff2.UpMinor.Interpreted.Value.SensorFloat32 =
           reading.Interpreted.Value.SensorFloat32 * (SaHpiFloat32T)0.90;
      senstbuff2.UpMajor.Interpreted.Value.SensorFloat32 =
           reading.Interpreted.Value.SensorFloat32 * (SaHpiFloat32T)0.05;
   }
   if (fdebug) {
	printf( "ValuesPresent = %x\n", senstbuff2.LowMajor.ValuesPresent);
	printf( "Values Mask   = %x\n", (SAHPI_SRF_RAW));
   }
   senstbuff2.LowMajor.ValuesPresent =
        senstbuff2.LowMajor.ValuesPresent ^ (SAHPI_SRF_RAW);
   if (fdebug) 
	printf( "ValuesPresent = %x\n", senstbuff2.LowMajor.ValuesPresent);
#else
   /* If fan type, set LowMajor, if temp type, set HighMinor. */
   if (fFan) {
      senstbuff2.LowMajor.Value.SensorFloat64 =
		   reading.Value.SensorFloat64 * (SaHpiFloat64T)1.10; 
   } else {  /* usually Temperature sensor */
      senstbuff2.UpMinor.Value.SensorFloat64 =
		   reading.Value.SensorFloat64 * (SaHpiFloat64T)0.90;
      senstbuff2.UpMajor.Value.SensorFloat64 =
		   reading.Value.SensorFloat64 * (SaHpiFloat64T)0.95;
   }
#endif

   /* Display new current thresholds */ 
   if (rv == SA_OK) {
      printf( "   New\n");
      ShowThresh( &senstbuff2, sensorrec->ThresholdDefn.ReadThold);
   }

#ifdef HPI_A
   /* See what Events are Enabled */
   rv = saHpiSensorEventEnablesGet(
		sessionid, resourceid, sensornum, &enables1);
   if (rv != SA_OK) {
	printf( "saHpiSensorEventEnablesGet error %d\n",rv); return(rv); }

   printf( "Sensor Event Enables: \n");
   printf( "  Sensor Status = %x\n", enables1.SensorStatus);
   printf( "  Assert Events = %x\n", enables1.AssertEvents);
   printf( "  Deassert Events = %x\n", enables1.DeassertEvents);
#endif

/* 
   enables1.AssertEvents = 0x0400;
   enables1.DeassertEvents = 0x0400;
   rv = saHpiSensorEventEnablesSet(
		sessionid, resourceid, sensornum, &enables1);
   if (rv != SA_OK) return(rv);
*/


/************************
   Temporary exit */
/*
 return(rv);
*/

/* Subscribe to New Events, only */
printf( "Subscribe to events\n");
#ifdef HPI_A
   rv = saHpiSubscribe( sessionid, (SaHpiBoolT)0 );
#else
   rv = saHpiSubscribe( sessionid );
#endif
   if (rv != SA_OK) {
	printf( "saHpiSubscribe error %d\n",rv); return(rv); }

/* Set new thresholds */
printf( "Set new thresholds\n");

   rv = saHpiSensorThresholdsSet(
	sessionid, resourceid, sensornum, &senstbuff2);
   if (rv != SA_OK) {
	printf( "saHpiSensorThresholdsSet error %d\n",rv); 
	/* rv2 = saHpiUnsubscribe( sessionid ); 
        if (fxdebug) printf("saHpiUnsubscribe, rv = %d\n",rv2);
	return(rv); */
	}

/* Go wait on event to occur */
printf( "Go and get the event\n");
   eventflag = 0;
   while ( eventflag == 0) {
#ifdef HPI_A
     rv = saHpiEventGet( sessionid, timeout, &event, &rdr, &rptentry );
#else
     timeout = SAHPI_TIMEOUT_BLOCK;
     timeout = SAHPI_TIMEOUT_IMMEDIATE;  /* use this if not threaded */
     rv = saHpiEventGet( sessionid, timeout, &event, &rdr, &rptentry, NULL);
#endif
     if (rv != SA_OK) { 
	if (rv == SA_ERR_HPI_TIMEOUT) {
	  printf( "Time expired during EventGet - Test FAILED\n");
            /* Reset to the original thresholds */
            printf( "Reset thresholds\n");
               rv = saHpiSensorThresholdsSet(
                    sessionid, resourceid, sensornum, &senstbuff1);
               if (rv != SA_OK) return(rv);

            /* Re-read threshold values */
               rv = saHpiSensorThresholdsGet(
                    sessionid, resourceid, sensornum, &senstbuff2);
               if (rv != SA_OK) return(rv);
	  return(rv);
        } else {
	  printf( "Error %d during EventGet - Test FAILED\n",rv);
	  return(rv);
	}
     }

/* Decode the event information */
printf( "Decode event info\n");
     if (event.EventType == SAHPI_ET_SENSOR) {
       printf( "Sensor # = %2d  Severity = %2x\n", 
	    event.EventDataUnion.SensorEvent.SensorNum, event.Severity );
       if (event.EventDataUnion.SensorEvent.SensorNum == sensornum) {
	 eventflag = 1;
	 printf( "Got it - Test PASSED\n");
       }
     }
   }
/* Reset to the original thresholds */
printf( "Reset thresholds\n");
   rv = saHpiSensorThresholdsSet(
	sessionid, resourceid, sensornum, &senstbuff1);
   if (rv != SA_OK) {
	printf( "saHpiSensorThresholdsSet error %d\n",rv); 
        rv2 = saHpiUnsubscribe( sessionid );
        if (fxdebug) printf("saHpiUnsubscribe, rv = %d\n",rv2);
	return(rv);
   } else {
	/* Re-read threshold values */
	rv = saHpiSensorThresholdsGet( sessionid, resourceid, sensornum, 
					&senstbuff2);
	if (rv != SA_OK) {
	   printf( "saHpiSensorThresholdsGet error %d\n",rv); 
	} else {  /* rv == SA_OK */
	   /* Display reset thresholds */ 
           printf( "   Reset\n");
	   ShowThresh( &senstbuff2, sensorrec->ThresholdDefn.ReadThold);
	}
   }  /*end-else SA_OK*/

/* Unsubscribe to future events */
printf( "Unsubscribe\n");
   rv2 = saHpiUnsubscribe( sessionid );
   if (fxdebug) printf("saHpiUnsubscribe, rv = %d\n",rv2);

   return(rv);
}  /*end DoEvent*/

/*
 * findmatch
 * returns offset of the match if found, or -1 if not found.
 */
static int
findmatch(char *buffer, int sbuf, char *pattern, int spattern, char figncase)
{
    int c, j, imatch;
    j = 0;
    imatch = 0;
    for (j = 0; j < sbuf; j++) {
        if (sbuf - j < spattern && imatch == 0) return (-1);
        c = buffer[j];
        if (c == pattern[imatch]) {
            imatch++;
            if (imatch == spattern) return (++j - imatch);
        } else if (pattern[imatch] == '?') {  /*wildcard char*/
            imatch++;
            if (imatch == spattern) return (++j - imatch);
        } else if (figncase == 1) {
            if ((c & 0x5f) == (pattern[imatch] & 0x5f)) {
                imatch++;
                if (imatch == spattern) return (++j - imatch);
            } else
                imatch = 0;
        } else
            imatch = 0;
    }
    return (-1);
}                               /*end findmatch */

int
main(int argc, char **argv)
{
  int c;
#ifdef HPI_A
  SaHpiVersionT hpiVer;
  SaHpiRptInfoT rptinfo;
#endif
  SaHpiSessionIdT sessionid;
  SaHpiRptEntryT rptentry;
  SaHpiEntryIdT rptentryid;
  SaHpiEntryIdT nextrptentryid;
  SaHpiEntryIdT entryid;
  SaHpiEntryIdT nextentryid;
  SaHpiResourceIdT resourceid;
  SaHpiRdrT rdr;
  int firstpass = 1;
  SaErrorT rv;

  printf("%s  ver %s\n", progname,progver);
  sensor_name = (char *)strdup(s_name);
  while ( (c = getopt( argc, argv,"ms:xz?")) != EOF )
  switch(c)
  {
    case 'z': fxdebug = 1; /* fall thru to include next setting */
    case 'x': fdebug = 1; break;
    case 'm': 
	      sensor_name = (char *)strdup(sm_name);
	      fFan = 0;  /*assume not a Fan */
	      break;
    case 's':
	  fsensor = 1;
          if (optarg) {
	    sensor_name = (char *)strdup(optarg);
	  }
          break;
    default:
          printf("Usage: %s [-xm] [-s sensor_descriptor]\n", progname);
          printf("   -s  Sensor descriptor\n");
          printf("   -m  use Mullins sensor descriptor\n");
          printf("   -x  Display debug messages\n");
          printf("   -z  Display extra debug messages\n");
          exit(1);
  }
#ifdef HPI_A
  inv = (SaHpiInventoryDataT *)&inbuff[0];

  rv = saHpiInitialize(&hpiVer);

  if (rv != SA_OK) {
    printf("saHpiInitialize error %d\n",rv);
    exit(-1);
  }
  rv = saHpiSessionOpen(SAHPI_DEFAULT_DOMAIN_ID,&sessionid,NULL);
  if (rv != SA_OK) {
    printf("saHpiSessionOpen error %d\n",rv);
    exit(-1);
  }
 
  if (fdebug) printf("Starting Discovery ...\n");
  rv = saHpiResourcesDiscover(sessionid);
  if (fdebug) printf("saHpiResourcesDiscover rv = %d\n",rv);

  rv = saHpiRptInfoGet(sessionid,&rptinfo);
  if (fxdebug) printf("saHpiRptInfoGet rv = %d\n",rv);
  if (fdebug) printf("RptInfo: UpdateCount = %x, UpdateTime = %lx\n",
         rptinfo.UpdateCount, (unsigned long)rptinfo.UpdateTimestamp);
 
#else
  rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID,&sessionid,NULL);
  if (rv != SA_OK) {
    printf("saHpiSessionOpen error %d\n",rv);
    exit(-1);
  }
  if (fdebug) printf("Starting Discovery ...\n");
  rv = saHpiDiscover(sessionid);
  if (fdebug) printf("saHpiResourcesDiscover rv = %d\n",rv);

  // rv = saHpiDomainInfoGet(sessionid,&rptinfo);
  {
        /*
         * If OpenHPI, we need to wait extra time before doing
         * ThresholdsGet because its discovery isn't really done.
         */
        sleep(5);
  }
#endif

  /* walk the RPT list */
  rptentryid = SAHPI_FIRST_ENTRY;
  while ((rv == SA_OK) && (rptentryid != SAHPI_LAST_ENTRY))
  {
    rv = saHpiRptEntryGet(sessionid,rptentryid,&nextrptentryid,&rptentry);
    if (rv == SA_OK)
    {
      /* walk the RDR list for this RPT entry */
      entryid = SAHPI_FIRST_ENTRY;
#ifdef HPI_A
      rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0;
#endif
      resourceid = rptentry.ResourceId;
      
      if (fdebug) printf("rptentry[%d] resourceid=%d\n", entryid,resourceid);

      printf("Resource Tag: %s\n", rptentry.ResourceTag.Data);
      while ((rv == SA_OK) && (entryid != SAHPI_LAST_ENTRY))
      {
        rv = saHpiRdrGet(sessionid,resourceid, entryid,&nextentryid, &rdr);

  	if (fxdebug) printf("saHpiRdrGet[%d] rv = %d\n",entryid,rv);

	if (rv == SA_OK)
	{
	  if (rdr.RdrType == SAHPI_SENSOR_RDR)
	  { 
	    /*type 2 includes sensor and control records*/
	    rdr.IdString.Data[rdr.IdString.DataLength] = 0;
#ifdef OLD
	    if (strncmp(rdr.IdString.Data, sensor_name,
		rdr.IdString.DataLength) == 0)
#else
	    if (findmatch(rdr.IdString.Data,rdr.IdString.DataLength,
		sensor_name, strlen(sensor_name),0) >= 0)
#endif
	    {
	      printf( "%02d %s\t", rdr.RecordId, rdr.IdString.Data);
	      rv = DoEvent( sessionid, resourceid, &rdr.RdrTypeUnion.SensorRec);
	      if (rv != SA_OK)
	        printf( "Returned Error from DoEvent: rv=%d\n", rv);
	      break;  /* done with rdr loop */
	    }
	  } 
	  if (rv != SA_OK)
	      printf( "Returned HPI Error: rv=%d\n", rv);
	  entryid = nextentryid;
        }
	if (firstpass && entryid == SAHPI_LAST_ENTRY) {
		/* Not found yet, so try again, looking for any Temp */
		sensor_name = s_pattn;
		entryid = SAHPI_FIRST_ENTRY;
		firstpass = 0;
		fFan = 0;  /*Temp not Fan*/
	}
      }  /*while rdr loop */
      rptentryid = nextrptentryid;
    }
  }  /*while rpt loop*/
  rv = saHpiSessionClose(sessionid);
#ifdef HPI_A
  rv = saHpiFinalize();
#endif
  exit(0);
}
 /* end hpievent.c */