From 04d0e0abb008b859bb8d2b91295b033f190687f8 Mon Sep 17 00:00:00 2001 From: hadaq Date: Fri, 18 Sep 2009 23:29:11 +0000 Subject: [PATCH] update --- trbrich/trbrichcmd.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/trbrich/trbrichcmd.c b/trbrich/trbrichcmd.c index 1cbe6b9..cac526c 100644 --- a/trbrich/trbrichcmd.c +++ b/trbrich/trbrichcmd.c @@ -11,7 +11,9 @@ #define BUFFER_SIZE (64 * 5 * 6) -static const char trb_i2c_version[] = "$Revision: 1.1 $"; +#define TEMP_RESOLUTION 0.0625 + +static const char trb_i2c_version[] = "$Revision: 1.2 $"; static const uint16_t adcm_uid_register = 0xc000; @@ -23,6 +25,7 @@ void usage(const char *progName) printf(" -V Version number\n"); printf("\nCommands:\n"); printf(" uid -> read uids from APV-FrondEnds\n"); + printf(" temp -> read temperatures from APV-FrondEnds\n"); } /* ------ MAIN ---------------------------------------------------------- */ @@ -63,7 +66,7 @@ int main(int argc, char** argv) /* Open port */ init_ports(); - if (strcmp(argv[optind], "w") == 0) { + if (strcmp(argv[optind], "uid") == 0) { /*************************************************/ /* Read UIDs */ @@ -81,9 +84,11 @@ int main(int argc, char** argv) } trb_address = (uint16_t)strtoul(argv[optind + 1], NULL, 0); - exit(0); - if ((buffer = (uint32_t*)malloc(sizeof(uint32_t) * BUFFER_SIZE)) == NULL) abort(); + if ((buffer = (uint32_t*)malloc(sizeof(uint32_t) * BUFFER_SIZE)) == NULL) { + abort(); + } + if (trb_register_write(trb_address, adcm_uid_register, 0) == -1) { trb_error("Error read temperature"); exit(EXIT_FAILURE); @@ -95,21 +100,23 @@ int main(int argc, char** argv) trb_error("Error read temperature"); exit(EXIT_FAILURE); } - + tmp = buffer; end = buffer + status; while (tmp < end) { unsigned int ctr; unsigned int i; unsigned int len = *tmp >> 16; - printf("0x%04x:\n", *tmp & 0xffff); + printf("EndPoint: 0x%04x\n", *tmp & 0xffff); tmp++; for (i = 0, ctr = 0; (i < len) && (tmp < end); i += 4, tmp += 4, ctr++) { - printf("%d 0x%04x%04x\n", ctr, tmp[0], tmp[1]); + if ((tmp[2] & 0x8000) > 0 ) { + printf("%02d 0x%08x%08x\n", ctr, tmp[1], tmp[0]); + } } } - } else if (strcmp(argv[optind], "r") == 0) { + } else if (strcmp(argv[optind], "temp") == 0) { /*************************************************/ /* Read Temperatures */ @@ -121,14 +128,17 @@ int main(int argc, char** argv) int status = 0; uint16_t trb_address = 0; - if (argc - optind != 4) { + if (argc - optind != 2) { usage(argv[0]); exit(EXIT_FAILURE); } trb_address = (uint16_t)strtoul(argv[optind + 1], NULL, 0); - exit(0); - if ((buffer = (uint32_t*)malloc(sizeof(uint32_t) * BUFFER_SIZE)) == NULL) abort(); + + if ((buffer = (uint32_t*)malloc(sizeof(uint32_t) * BUFFER_SIZE)) == NULL) { + abort(); + } + if (trb_register_write(trb_address, adcm_uid_register, 0) == -1) { trb_error("Error read temperature"); exit(EXIT_FAILURE); @@ -147,10 +157,17 @@ int main(int argc, char** argv) unsigned int ctr; unsigned int i; unsigned int len = *tmp >> 16; - printf("0x%04x:\n", *tmp & 0xffff); + printf("EndPoint: 0x%04x\n", *tmp & 0xffff); tmp++; for (i = 0, ctr = 0; (i < len) && (tmp < end); i += 4, tmp += 4, ctr++) { - printf("%d %x %x\n", i, tmp[2], tmp[3]); + if ((tmp[2] & 0x8000) > 0 ) { + int16_t temperature = tmp[2] & 0x7fff; + temperature = 0x8e37 & 0x7fff; + temperature = (temperature & 0x0800) == 0 + ? temperature + : temperature | 0xf000; + printf("%02d %.04f\n", ctr, temperature * TEMP_RESOLUTION); + } } } -- 2.43.0