From 5cbc1bcd61ccd50b3c37f3f70083afca13c9a175 Mon Sep 17 00:00:00 2001 From: Gergő J. Miklós Date: Sat, 11 May 2019 03:27:13 +0200 Subject: some debugging + read --- Makefile | 4 +-- run.sh | 17 ++++++++++++ src/hih61xx.c | 2 +- src/lm75.c | 85 +++++++++++++++++++++++++++++++++-------------------------- src/lm75.h | 2 +- src/main.c | 34 +++++++++++++----------- 6 files changed, 87 insertions(+), 57 deletions(-) create mode 100644 run.sh diff --git a/Makefile b/Makefile index a1bfd3a..d3f01f7 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,8 @@ main: clean: - rm -f build/i2sensors* + rm -f build/i2sensors* copy: - mkdir -p build/bin/ + echo \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..c78d362 --- /dev/null +++ b/run.sh @@ -0,0 +1,17 @@ +#!/bin/bash + + + + + +make + +#rsync -aHv -q -e "ssh" build/i2sensors-arm root@cb2:/tmp/i2sensors +scp build/i2sensors-armhf root@cb2:/tmp/i2sensors + +ssh root@cb2 '/tmp/i2sensors read_one 1 lm75 0x49 0,111.1' +echo +ssh root@cb2 '/tmp/i2sensors read_all 1 lm75 0x49 ' +#ssh root@cb2 '/tmp/i2sensors list_all 1 lm75 0x49' + +exit 0 \ No newline at end of file diff --git a/src/hih61xx.c b/src/hih61xx.c index b68b653..221f2b2 100644 --- a/src/hih61xx.c +++ b/src/hih61xx.c @@ -14,7 +14,7 @@ extern void print_help(void); unsigned char buf[5]; - + void hih61xx_list_all(void) { diff --git a/src/lm75.c b/src/lm75.c index fac61c2..b2155ad 100644 --- a/src/lm75.c +++ b/src/lm75.c @@ -12,7 +12,7 @@ extern int file; extern void bus_err(int ern); extern void print_help(void); unsigned char buf[5]; - + void lm75_list_all(void) { @@ -26,15 +26,13 @@ void lm75_list_all(void) -void lm75_get_data(void) -{ - if(write(file, buf, 1) != 1) - { +void lm75_get_data(void){ + + if(write(file, buf, 1) != 1){ bus_err(errno); } - if(read(file, buf, 2) != 2) - { + if(read(file, buf, 2) != 2) { bus_err(errno); } } @@ -118,14 +116,14 @@ char lm75_read_conf(void) void lm75_read_all(const char *opts) { - if(opts != NULL) - { - printf("00:%f\n", lm75_read_temp(strtof(opts, NULL))); - } - else - { + // if(opts != NULL) + // { + // printf("00:%f\n", lm75_read_temp(strtof(opts, NULL))); + // } + // else + // { printf("00:%f\n", lm75_read_temp(0.0)); - } + // } printf("01:0x%x\n", lm75_read_conf()); printf("02:%f\n", lm75_read_tos()); @@ -136,28 +134,41 @@ void lm75_read_all(const char *opts) void lm75_read_one(const char *opts) { - int id; - char *ptr; - - id = strtol (opts,&ptr,0); //all format allowed - ptr++; //one separator allowed - - switch (id) - { - case 0x00: - printf("00:%f\n", lm75_read_temp(strtof(ptr, NULL))); - break; - case 0x01: - printf("01:0x%x\n", lm75_read_conf()); - break; - case 0x02: - printf("02:%f\n", lm75_read_tos()); - break; - case 0x03: - printf("03:%f\n", lm75_read_thys()); - break; - default: - print_help(); - } + int id,i; + //char *ptr; + char temp[256]; + + if(opts != NULL){ + for(i = 0; i < strlen(opts); i++){ + if (*(opts+i) == ','){ + break; + } + temp[i] = *(opts+i); + temp[i+1] = '\0'; + } + + id = atoi(temp); + strncpy(temp, opts+i+1, 255); + // id = strtol (opts,&ptr,0); //all format allowed + // ptr++; //one separator allowed + + switch (id) + { + case 0x00: + printf("00:%f\n", lm75_read_temp(atof(temp))); + break; + case 0x01: + printf("01:0x%x\n", lm75_read_conf()); + break; + case 0x02: + printf("02:%f\n", lm75_read_tos()); + break; + case 0x03: + printf("03:%f\n", lm75_read_thys()); + break; + default: + print_help(); + } + } } diff --git a/src/lm75.h b/src/lm75.h index ff31c6a..3f21ff5 100644 --- a/src/lm75.h +++ b/src/lm75.h @@ -11,7 +11,7 @@ void lm75_list_all(void); void lm75_get_data(void); float lm75_read_temp(float offset); float lm75_read_tos(void); -float lm75_read_thys(void); +float lm75_read_thys(void); char lm75_read_conf(void); void lm75_read_all(const char *opts); void lm75_read_one(const char *opts); diff --git a/src/main.c b/src/main.c index c71c872..ee3ec67 100644 --- a/src/main.c +++ b/src/main.c @@ -24,16 +24,17 @@ extern void hih61xx_read_all(const char *opts); extern void hih61xx_read_one(const char *opts); -int file; +int file; +char temp[256]; void (*list_all)(void) = NULL; void (*read_all)(const char *opts) = NULL; void (*read_one)(const char *opts) = NULL; void print_help(void) -{ +{ printf ("Usage:\n" - " i2sensor ()\n" + " i2sensor ()\n" "Aviable options: \n" " list_all -- list all measured parameters off device\n" " read_all -- read all measured parameters from device\n" @@ -41,9 +42,11 @@ void print_help(void) "Exmples:\n" " i2sensor read_all
\n" " i2sensor read_one
\n" - " i2sensor read_all 1 lm75 0x4f -1.35,\n" - " i2sensor read_one 1 lm75 0x4f 01,-1.35\n" - "" "\n"); + " i2sensor read_all 1 lm75 0x4f ---,\n" + " i2sensor read_one 1 lm75 0x4f 00,-1.35\n" + "" ""); + printf ("Build: %s %s\n\n",__DATE__,__TIME__); + } void bus_err(int ern) @@ -84,7 +87,7 @@ int main(int argc, char *argv[]) // ...set_reg... , - if(4 < argc && 7 > argc) //Minimal 5 argument passed + if(4 < argc && argc < 10) //Minimal 5 argument passed { char filename[32]; @@ -100,22 +103,20 @@ int main(int argc, char *argv[]) exit (EXIT_FAILURE); } } - snprintf(filename, 31, "/dev/i2c-%s", argv[2]); //Open i2c bus file = open(filename, O_RDWR); if (file < 0) { - printf("\n\tCan't open i2c BUS, are you root?\n\n"); + printf("\n\tCan't open i2c BUS. Have you any permission?\n\n"); print_help(); exit (EXIT_FAILURE); } - if(argv[4][0]=='0' && argv[4][1]=='x') //? - { - - int addr = (int)strtol(argv[4], NULL, 0); //Open i2c device + if(argv[4][0]=='0' && argv[4][1]=='x'){ // Hexadecimal device address + + long addr = (int)strtol(argv[4], NULL, 0); //# strtol() is working with hex string if (ioctl(file, I2C_SLAVE, addr) < 0) { @@ -139,15 +140,16 @@ int main(int argc, char *argv[]) } else if(!strcmp("read_all",argv[1]) && read_all != NULL) { - read_all(argv[5]); + // read_all(argv[5]); + read_all(NULL); } - else if(!strcmp("read_one",argv[1]) && read_one != NULL && argc == 5) + else if(!strcmp("read_one",argv[1]) && read_one != NULL && argc > 5) { read_one(argv[5]); } else { - // print_help(); + print_help(); } close(file); -- cgit v1.2.3