#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;
printf(" -V Version number\n");
printf("\nCommands:\n");
printf(" uid <trb_address> -> read uids from APV-FrondEnds\n");
+ printf(" temp <trb_address> -> read temperatures from APV-FrondEnds\n");
}
/* ------ MAIN ---------------------------------------------------------- */
/* Open port */
init_ports();
- if (strcmp(argv[optind], "w") == 0) {
+ if (strcmp(argv[optind], "uid") == 0) {
/*************************************************/
/* Read UIDs */
}
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);
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 */
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);
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);
+ }
}
}