iamalive.cpp 1.54 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
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

// 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];
  int i;
  struct watchdog_info ident;
  int fd, ret;
  int timeout = 0;
  int timeslice=10;
  int retfinal;
 printf("Entrado en iamlive....\r\n");
    while (1) {

    sleep (timeslice);


    time_t t = time(NULL);
    struct tm tm = *localtime(&t);
    fprintf(stdout, "alive: %d-%02d-%02d %02d:%02d:%02d  Temp:", 
           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);
   
    }
    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;
}