]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
first revision
authorhadaq <hadaq>
Thu, 17 Sep 2009 21:19:37 +0000 (21:19 +0000)
committerhadaq <hadaq>
Thu, 17 Sep 2009 21:19:37 +0000 (21:19 +0000)
trbrich/trbrichcmd.c [new file with mode: 0644]

diff --git a/trbrich/trbrichcmd.c b/trbrich/trbrichcmd.c
new file mode 100644 (file)
index 0000000..1cbe6b9
--- /dev/null
@@ -0,0 +1,163 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libgen.h>
+#include <unistd.h>
+#include <stdint.h>
+#include <trbnet.h>
+#include <trberror.h>
+
+#define BUFFER_SIZE (64 * 5 * 6)
+
+static const char trb_i2c_version[] = "$Revision: 1.1 $"; 
+
+static const uint16_t adcm_uid_register = 0xc000;
+
+void usage(const char *progName)
+{
+  printf("Usage: %s [-h] [-V] <COMMAND>\n", progName);
+  printf("Options:\n");
+  printf("  -h    give this help\n");
+  printf("  -V    Version number\n");
+  printf("\nCommands:\n");
+  printf("   uid <trb_address>     -> read uids from APV-FrondEnds\n");
+}
+
+/* ------ MAIN ---------------------------------------------------------- */
+
+int main(int argc, char** argv)
+{
+  int i;
+  
+  trb_debug = 0;
+  
+  /* Parse Arguments */
+  while ((i = getopt(argc, argv, "+hd:V")) != -1) {
+    switch (i) {
+    case '?':
+      usage(basename(argv[0]));
+      exit(EXIT_FAILURE);
+    case 'h':
+      usage(basename(argv[0]));
+      exit(EXIT_SUCCESS);
+    case 'd':
+      trb_debug = strtoul(optarg, NULL, 0);
+      break;
+    case 'V':
+      printf("%s %s, using libtrbnet %s\n",
+             basename(argv[0]), trb_i2c_version, trbnet_version);
+      exit(EXIT_SUCCESS);
+      break;
+    default:
+      break;
+    }
+  }
+  
+  if (optind >= argc) {
+    usage(basename(argv[0]));
+    exit(EXIT_FAILURE);
+  }
+        
+  /* Open port */
+  init_ports();
+  
+  if (strcmp(argv[optind], "w") == 0) {
+    
+    /*************************************************/
+    /* Read UIDs                                     */
+    /*************************************************/
+
+    uint32_t *buffer = NULL;
+    uint32_t *tmp = NULL;
+    uint32_t *end = NULL;
+    uint16_t trb_address = 0;
+    int status = 0;
+    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 (trb_register_write(trb_address, adcm_uid_register, 0) == -1) {
+      trb_error("Error read temperature");
+      exit(EXIT_FAILURE);
+    }
+    
+    status = trb_register_read_mem(trb_address, adcm_uid_register, 0, 64, 
+                                   buffer, BUFFER_SIZE);
+    if (status == -1) {
+      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);
+      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]);       
+      }
+    }
+            
+  } else if (strcmp(argv[optind], "r") == 0) {
+    
+    /*************************************************/
+    /* Read Temperatures                             */
+    /*************************************************/
+    
+    uint32_t *buffer = NULL;
+    uint32_t *tmp = NULL;
+    uint32_t *end = NULL;
+    int status = 0;
+    uint16_t trb_address = 0;
+    
+    if (argc - optind != 4) {
+      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 (trb_register_write(trb_address, adcm_uid_register, 0) == -1) {
+      trb_error("Error read temperature");
+      exit(EXIT_FAILURE);
+    }
+    
+    status = trb_register_read_mem(trb_address, adcm_uid_register, 0, 64, 
+                                   buffer, BUFFER_SIZE);
+    if (status == -1) {
+      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);
+      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]);
+      }
+    }
+    
+  } else {
+    usage(basename(argv[0]));
+    exit(EXIT_FAILURE);
+  }
+  
+  exit(EXIT_SUCCESS);
+}