
SENSOR LIBRARYSection: Rutgers DarkLab Tools (1)Updated: 2006-08-23 Index Return to Main Contents NAMEopensensor, readsensor, closesensor - temperature emulator routinesSYNOPSIS#include <sensor/sensor.h>
int opensensor(char *sensorserver, int port, char *whichcomponent);
DESCRIPTIONSensor library. Applications and system software can use Mercury through a simple run-time library API comprised by three calls: opensensor(), readsensor(), and closesensor(). The call opensensor() takes as parameters the address of the machine running the solver, the port number at that machine, and the component of which we want the temperature. It returns a file descriptor that can then be read with readsensor(). The read call involves communication with the solver to get the emulated sensor reading. The call closesensor() closes the sensor. With this interface, the programmer can treat Mercury as a regular, local sensor device. The theory works as follows: there is a machine which has components that you are interested in monitoring the temperatures. There is also a machine which has a model of the entire cluster, and is running emulator(1); To get reliable readings, you also need to be running monitord(1); , which is a daemon that updates usage information to the emulator server. To use these function, one first uses opensensor() to choose which sensor is being read with sensorserver and port being the name of the server that has the emulator running on it and the port that it is running on, respectively. whichcomponent is the name of the component that will be measured using this particular sensorfd. This component name should match up with a component name in the machine specification given to emulator. openremotesensor() is the same as opensensor() , except that it will read a value from machine machineID . For now, this machineID is the same as the host identifier of the IP address for the machine in question. Both openremotesensor() and opensensor() return a sensorfd, which is then used as an argument into readsensor() which then returns the temperature in Celsius as a floating point value. This call is blocking, and requires a UDP 128-byte send and recv (done by the comm library, internally). closesensor() closes the sensor for further use. It does not stop monitord .
RETURN VALUEOn success, opensensor and openremotesensor return a sensorfd, which is greater than or equal to zero. On error, -1 is returned, and errno is set appropriately.ERRORS
EXAMPLE 1The program code below illustrates the use of opensensor(), readsensor() and closesensor() to read the temperature of the local disk.
int sd;
float temp;
sd = opensensor("solvermachine", 8367, "disk");
temp = readsensor(sd);
closesensor(sd);
EXAMPLE 2This is a complete program that you can use to query any component by providing arguments in command line.
#include <stdio.h> #include <emulator/emulator.h> int main(int argc, char *argv[]) { /* Read the named sensor every second forever. */ /* Called as ./sensorread servername port sensorname */ int sensorfd; float temperature; sensorfd=opensensor(argv[1],atoi(argv[2]),argv[3]); for(;;){ temperature=readsensor(sensorfd); printf("%.1fC,temperature); sleep(1); } close(sensorfd); return 0; } gcc -o sensorread sensorread.c -lsensor NOTESWithout monitord running, sensor readings are likely to be the fictional inlet temperatures provided by the emulator server.BUGSThese commands are not thread safe. Accuracy is also an open question.SEE ALSOemulator(1); monitord(1); fiddle(1);
IndexThis document was created by man2html using the manual pages. Time: 03:06:29 GMT, September 04, 2006 |