From 5251988106ba26e51cfd7c8493dad84c0ace7bce Mon Sep 17 00:00:00 2001
From: Erik von Reis <evonreis@caltech.edu>
Date: Fri, 30 Apr 2021 11:25:54 -0700
Subject: [PATCH] awgptan: build working with explicit sized integers.  mbuf
 analyze improved to show the first working awg slot.

---
 src/drv/mbuf/mbuf_probe/analyze_awg_data.cc | 40 ++++++++++++++++++---
 src/gds/awgtpman/shared_memory.h            |  2 ++
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/src/drv/mbuf/mbuf_probe/analyze_awg_data.cc b/src/drv/mbuf/mbuf_probe/analyze_awg_data.cc
index 330cde5e3..e3bd68970 100644
--- a/src/drv/mbuf/mbuf_probe/analyze_awg_data.cc
+++ b/src/drv/mbuf/mbuf_probe/analyze_awg_data.cc
@@ -16,21 +16,53 @@ namespace analyze
 
     void dump_awg_data(volatile AWG_DATA *awg_data)
     {
+        int hunt_state = 0;
+        int slot = 0;
+
         auto detected_type = analyze_header(awg_data);
         if(detected_type != MBUF_AWG_DATA)
         {
             cout << "WARNING: attempting to analyze AWG_DATA structure, but structure was of type " << detected_type << endl;
         }
-        volatile AWG_DATA_PAGE * page = &awg_data->page[0];
+
         while(true)
         {
-            printf("status: %4x d: ", page->status);
-            for ( int i = 0; i < 8; ++i )
+            int page_index = FIND_PAGE_INDEX(slot,0);
+            volatile AWG_DATA_PAGE * page = & awg_data->page[page_index];
+
+            printf("slot: %1d status: %4x d: ", slot, page->status);
+            for ( int i = 0; i < 4; ++i )
             {
-                printf("%8.5f ", page->buf[i]);
+                printf("%12.5g", page->buf[i]);
             }
             cout << "\r" << flush;
 
+            // update slot if necessary to look for active slots
+            switch(hunt_state)
+            {
+            case 1:
+            case 0:
+                if(page->status != 0)
+                {
+                    ++hunt_state;
+                }
+                else
+                {
+                    hunt_state = 0;
+                }
+                break;
+            case 2:
+                if(page->status != 0)
+                {
+                    slot = (++slot) % AWG_SLOTS;
+                }
+                else
+                {
+                    hunt_state = 0;
+                }
+
+            }
+
             usleep(20000);
         }
     }
diff --git a/src/gds/awgtpman/shared_memory.h b/src/gds/awgtpman/shared_memory.h
index 0be34e8fa..37ae79f49 100644
--- a/src/gds/awgtpman/shared_memory.h
+++ b/src/gds/awgtpman/shared_memory.h
@@ -6,6 +6,8 @@
 #ifndef DAQD_TRUNK_SHARED_MEMORY_H
 #define DAQD_TRUNK_SHARED_MEMORY_H
 
+#include <stdint.h>
+
 #include "shmem_awg.h"
 
 extern volatile AWG_DATA *shmemAwgData;
-- 
GitLab