I solved the problem this way:
I modified the th03shm.c program, so that it:
- Takes a parameter (0, 1 or 2), that specifies what temperature we want to read
- Exits with an error code and an error message if temperature is zero.
- Otherwise, it reads the temperature and writes it to stdout
- At last it zeroes the temperature.
Our network monitoring application (
http://www.sysorb.com/) then queries the temperature once each minute. This is enough to ensure that the temperature is rewritten by th03lnx before the next measurement, and if th03lnx should fail to write new temperature measurements into share memory, then sysorb will issue an alert. Works perfectly...
Here is the modified source-code of th03shm.c:
- Code: Select all
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <syslog.h>
#include "th03lnx.h"
#define FALSE 0
#define TRUE 1
int main (int argc, char * const * argv)
{
int i;
int c;
int sm;
int found;
int idx;
TH03_SHARED * sm_ptr;
sm = shmget (TH03_DEFAULT_KEY, sizeof (TH03_SHARED), 0);
if (sm < 0)
{
printf ("th03shm: Unable to find shared memory\n");
exit (1);
}
sm_ptr = (TH03_SHARED *) shmat (sm, (void *) 0, 0);
if (sm_ptr == (void *) -1)
{
printf ("th03shm: Unable to attach shared memory %d %X\n", sm, sm_ptr);
exit (2);
}
if (!sm_ptr->active)
{
printf ("th03shm: Th03 not active\n");
shmdt (sm_ptr);
exit (3);
}
// Check parameters
if (argc!=2) {
printf ("th03shm: No parameter specified. Specify 0, 1 or 2.\n");
shmdt (sm_ptr);
exit (4);
}
if (strcmp(argv[1],"0")==0) idx=0; else
if (strcmp(argv[1],"1")==0) idx=1; else
if (strcmp(argv[1],"2")==0) idx=2; else {
printf ("th03shm: Invalid parameter specified. Specify 0, 1 or 2.\n");
shmdt (sm_ptr);
exit (5);
}
// Wait until all of the temperatures goes non-zero
if (sm_ptr->channel_values[idx]==0) {
printf("FAILED - no measurement, yet\n");
shmdt (sm_ptr);
exit (6);
} else {
printf ("T%d=%.2f\n", idx, (float) sm_ptr->channel_values [idx] / 100);
sm_ptr->channel_values[idx]=0;
}
/* Use this line to kill the th03lnx driver
sm_ptr->active = FALSE;
*/
shmdt (sm_ptr);
}