From 54f0853f68210475394083b26505d9bf454f6f8c Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Thu, 2 Jul 2015 00:39:44 +0200
Subject: [PATCH] added handler callbacks to python decoder

---
 lib/python/labcomm2014/LabComm.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/lib/python/labcomm2014/LabComm.py b/lib/python/labcomm2014/LabComm.py
index 4b536ac..9898127 100644
--- a/lib/python/labcomm2014/LabComm.py
+++ b/lib/python/labcomm2014/LabComm.py
@@ -874,7 +874,11 @@ class Decoder(Codec):
         super(Decoder, self).__init__()
         self.reader = reader
         self.version = version
-        
+        self.handlers = {}
+
+    def register_handler(self, sig, handler):
+        self.handlers[str(sig)] = handler
+
     def unpack(self, format):
         size = packer.calcsize(format)
         data = ""
@@ -903,6 +907,17 @@ class Decoder(Codec):
         else:    
             raise Exception("Invalid type index %d" % index)
 
+    def runOne(self):
+        data,decl = self.decode()
+        if decl:
+            if data:
+                if str(decl) in self.handlers:
+                    handler = self.handlers[str(decl)]
+                    handler(data)
+                else:
+                    print ("No handler for %s" % decl.name )
+
+
     def decode(self):
         while True:
             index = self.decode_type_number()
-- 
GitLab