]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
unpack_mvd: better integration of scurve frames
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Wed, 29 Oct 2014 16:15:38 +0000 (17:15 +0100)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Wed, 29 Oct 2014 16:15:38 +0000 (17:15 +0100)
tools/python_mvd_unpacker/mvd_unpacker/unpacker.py
tools/python_mvd_unpacker/mvd_unpacker/utils.py
tools/python_mvd_unpacker/scripts/unpack_mvd

index 1a94c66a85faeab854c2987adab2450d71f9af03..0ad81873f59702b71fe7260530ad40912620d5ab 100644 (file)
@@ -10,7 +10,7 @@ import struct
 import pdb
 import io
 
-from .utils import split_by_n, str_32bit_chunks
+from .utils import split_by_n, str_32bit_chunks, bits_set_count
 
 #### ------ Definitions for M-26 data ------ ####
 
@@ -82,10 +82,14 @@ class FrameMessage(object):
         self.data_type = data_type
         self.data_bytes = data_bytes
         self._interpret()
+        self._check()
 
     def _interpret(self):
         pass
 
+    def _check(self):
+        pass
+
 class Frame_Message_01(FrameMessage):
 
     def _interpret(self):
@@ -119,17 +123,25 @@ class Frame_Message_C0(FrameMessage):
         # everything else is testmode data
         self.sensor_data = self.data_bytes[2*4:]
 
+    def _check(self):
+        if self.occupancy > 1.0: pdb.set_trace()
+
+    @property
+    def occupancy(self):
+        try:
+            return self._occupancy
+        except:
+            self._occupancy = bits_set_count(self.sensor_data) / (len(self.sensor_data) * 8.0) * 4.0
+            return self._occupancy
+
     def __str__(self):
-        fmt = "static init: 0x{:08x}  format version: 0x{:04x}  testmode: 0x{:04x}\n"
-        out = fmt.format(self.init, self.format_version, self.testmode)
-        fmt = "id: 0x{:08x}  status:   0x{:08x}  h5:        0x{:08x}\n"
-        out += fmt.format(self.id, self.status, self.h5)
-        #fmt = "h6: 0x{:08x}  external: 0x{:08x}  frame_num: 0x{:08x}\n"
-        #out += fmt.format(self.h6, self.external, self.frame_num)
-        fmt = "h6: 0x{:08x}  threshold: 0x{:04x}  run: 0x{:04x}  row: 0x{:04x}\n"
-        out += fmt.format(self.h6, self.threshold, self.run, self.row)
+        fmt = "frame length: 0x{:04x}  sensor id: 0x{:02x}\n"
+        out = fmt.format(self.frame_length, self.sensor_id)
+        fmt = "bank: {}  row: {}  threshold: {}  run: {}\n"
+        out += fmt.format(self.bank, self.row, self.threshold, self.run)
         out += "\n"
-        out += str_32bit_chunks(self.payload_bytes)
+        out += "Occupancy: {:.2f}".format(self.occupancy)
+        #out += str_32bit_chunks(self.sensor_data)
         out += "\n"
         return out
 
index 93057fbaabec2fcf66b281c3d03fbe7a10aea547..8682cfd475e24f123f25bbb8de282615b64c78a9 100644 (file)
@@ -28,3 +28,17 @@ def str_32bit_chunks(data):
         i += int(wordlength/2) * words_per_line
     return out
 
+def bits_set_count(x):
+    """
+    Accepts bytes as input and returns the number of bits set in the bytes.
+    """
+    if type(x) == bytes:
+        sum = 0
+        for b in x:
+            sum += bin(b).count('1')
+        return sum
+    if type(x) == int:
+        return bin(x).count('1')
+    else:
+        raise TypeError()
+
index a1fac8f554a5d8e7af8f2af162dfd7d3343eaf39..b6e0315a6a4091dd6663eb36ce6c9b0ab3701fa2 100644 (file)
@@ -15,16 +15,19 @@ def main():
           help='HLD file with M26 data to unpack')
     args = parser.parse_args()
 
+    frame_count = 0
     for event in read(args.hldfile):
         for subevent in event.subevents:
             for subsubevent in subevent.subsubevents:
                 if not len(subsubevent.payload_bytes): continue
                 if subsubevent.address == 0x5555: continue
                 roc_message = read_ROC_Message(subsubevent.payload_bytes)
-                print(roc_message.payload_bytes)
                 try:
                     roc_message = read_ROC_Message(subsubevent.payload_bytes)
-                    print(roc_message.frames)
+                    for frame in roc_message.frames:
+                        if not (frame_count % 10000):
+                            print(frame)
+                        frame_count += 1
                 except:
                     print("Not a ROC message (?):")
                     print(str_32bit_chunks(subsubevent.payload_bytes))