iamalive.cpp 1.63 KB
Newer Older
German Leon's avatar
German Leon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

// iisalive.cpp
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h> // for watchdog timer
#include <unistd.h> // needed only if close() is used to close watchdog timer
#include <sys/ioctl.h> // for watchdog timer
#include <linux/watchdog.h> // for watchdog timer
#include <time.h>

int main(int argc, char*argv[]) {
  FILE *fdf;
  int valor,millamperes;
  char buffer[100];
  char name[50];
German Leon's avatar
German Leon committed
17
  char *nom;
German Leon's avatar
German Leon committed
18
19
20
21
22
23
  int i;
  struct watchdog_info ident;
  int fd, ret;
  int timeout = 0;
  int timeslice=10;
  int retfinal;
German Leon's avatar
German Leon committed
24
25
26
 nom=getenv( "HOSTNAME" );
 printf("Entrado en iamlive...%s.\r\n",nom);

German Leon's avatar
German Leon committed
27
28
29
30
31
32
33
    while (1) {

    sleep (timeslice);


    time_t t = time(NULL);
    struct tm tm = *localtime(&t);
German Leon's avatar
German Leon committed
34
    fprintf(stdout, "alive(%s): %d-%02d-%02d %02d:%02d:%02d  Temp:", getenv("HOSTNAME"), 
German Leon's avatar
German Leon committed
35
36
37
38
39
40
41
           tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);

    for(i=0; i<6;i++) {
      sprintf(buffer,"/sys/devices/virtual/thermal/thermal_zone%d/temp",i);
      fdf=fopen(buffer,"r");
      fscanf (fdf,"%d",&valor);
      fprintf(stdout,"%.1f,",valor/1000.0);
German Leon's avatar
German Leon committed
42
      fclose(fdf);
German Leon's avatar
German Leon committed
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
   
    }
    for(i=0; i<3;i++) {
      sprintf(buffer,"/sys/bus/i2c/drivers/ina3221x/6-0040/iio:device0/rail_name_%d",i);
     
      fdf=fopen(buffer,"r");
      fscanf (fdf,"%s",name);
      fclose(fdf);

      sprintf(buffer,"/sys/bus/i2c/drivers/ina3221x/6-0040/iio:device0/in_power%d_input",i);
      
      fdf=fopen(buffer,"r");
      fscanf (fdf,"%d",&millamperes);
      fclose(fdf);
    
  
      fprintf(stdout,"%s:%.3fW ",name+7,((float)millamperes)/1.0e3);
   
    }
    fprintf (stdout,"\r\n");

   } // end while


  return 0;
}