From db39453953d8acafc2da3f3f346ebd3c8e9884a2 Mon Sep 17 00:00:00 2001 From: Sven Gestegard Robertz <sven.robertz@cs.lth.se> Date: Mon, 10 Nov 2014 14:24:14 +0100 Subject: [PATCH] started adding (hierarchical) type def functionality. for now: skip them --- lib/c/labcomm_decoder.c | 2 +- lib/java/se/lth/control/labcomm/Constant.java | 2 + .../lth/control/labcomm/DecoderChannel.java | 27 +++++++++--- lib/python/labcomm/LabComm.py | 43 +++++++++++++++++++ 4 files changed, 67 insertions(+), 7 deletions(-) diff --git a/lib/c/labcomm_decoder.c b/lib/c/labcomm_decoder.c index aa33d13..9d760e8 100644 --- a/lib/c/labcomm_decoder.c +++ b/lib/c/labcomm_decoder.c @@ -267,7 +267,7 @@ out: static int decoder_skip(struct labcomm_decoder *d, int len, int tag) { int i; - printf("skipping %d bytes\n", len); + printf("got tag 0x%x, skipping %d bytes\n", tag, len); for(i = 0; i <len; i++){ labcomm_read_byte(d->reader); if (d->reader->error < 0) { diff --git a/lib/java/se/lth/control/labcomm/Constant.java b/lib/java/se/lth/control/labcomm/Constant.java index e2c88c9..3d6d53a 100644 --- a/lib/java/se/lth/control/labcomm/Constant.java +++ b/lib/java/se/lth/control/labcomm/Constant.java @@ -12,6 +12,8 @@ public class Constant { */ public static final int VERSION = 0x01; public static final int SAMPLE_DEF = 0x02; + public static final int TYPE_DEF = 0x03; + public static final int TYPE_BINDING = 0x04; public static final int PRAGMA = 0x3f; public static final int FIRST_USER_INDEX = 0x40; /* ..0xffffffff */ diff --git a/lib/java/se/lth/control/labcomm/DecoderChannel.java b/lib/java/se/lth/control/labcomm/DecoderChannel.java index b4b561e..2539fa6 100644 --- a/lib/java/se/lth/control/labcomm/DecoderChannel.java +++ b/lib/java/se/lth/control/labcomm/DecoderChannel.java @@ -30,6 +30,21 @@ public class DecoderChannel implements Decoder { registry.add(index, name, signature); } + + private void processTypeDef(int len) throws IOException { + System.out.println("Got TypeDef: skipping "+len+" bytes"); + for(int i=0; i<len; i++) { + decodeByte(); + } + } + + private void processTypeBinding(int len) throws IOException { + System.out.println("Got TypeBinding: skipping "+len+" bytes"); + for(int i=0; i<len; i++) { + decodeByte(); + } + } + private void processPragma(int len) throws IOException { // String pt = decodeString(); // System.out.println("Pragma["+pt+"]: skipping "+plen+" bytes"); @@ -77,14 +92,14 @@ public class DecoderChannel implements Decoder { case Constant.SAMPLE_DEF: { processSampleDef(); } break; + case Constant.TYPE_DEF: { + processTypeDef(length); + } break; + case Constant.TYPE_BINDING: { + processTypeBinding(length); + } break; case Constant.PRAGMA: { processPragma(length); - // String pt = decodeString(); - // int plen = length - pt.length()-1; - // System.out.println("Pragma["+pt+"]: skipping "+plen+" bytes"); - // for(int i=0; i<plen; i++) { - // decodeByte(); - // } } break; default: { DecoderRegistry.Entry e = registry.get(tag); diff --git a/lib/python/labcomm/LabComm.py b/lib/python/labcomm/LabComm.py index 7b38330..019559c 100644 --- a/lib/python/labcomm/LabComm.py +++ b/lib/python/labcomm/LabComm.py @@ -29,6 +29,37 @@ # | ... # +----+-- # +# LabComm220141009 TYPE_DEF: (as SAMPLE_DEF, but signatures are hierarchical, +# i.e., may contain references to other types +# +# +----+----+----+----+ +# | id = 0x03 (packed32) +# +----+----+----+----+ +# | length (packed32) +# +----+----+----+----+ +# | type number (packed32) +# +----+----+----+----+ +# | type name (UTF8) +# | ... +# +----+----+----+----+ +# | signature length (packed32) +# +----+----+----+----+ +# | type signature +# | ... +# +----+-- +# +# LabComm220141009 TYPE_BINDING +# +# +----+----+----+----+ +# | id = 0x04 (packed32) +# +----+----+----+----+ +# | length (packed32) +# +----+----+----+----+ +# | sample number (packed32) +# +----+----+----+----+ +# | type number (packed32) +# +----+----+----+----+ +# # LabComm20141009 User data: # # +----+----+----+----+ @@ -125,6 +156,8 @@ DEFAULT_VERSION = "LabComm20141009" # Allowed packet tags i_VERSION = 0x01 i_SAMPLE_DEF = 0x02 +i_TYPE_DEF = 0x03 +i_TYPE_BINDING= 0x04 i_PRAGMA = 0x3f i_USER = 0x40 # ..0xffffffff @@ -693,6 +726,10 @@ class Decoder(Codec): raise Exception('Should not be used') return result + def skip(self, length): + for _ in xrange(length): + self.decode_byte() + def decode(self): while True: index = self.decode_type_number() @@ -708,6 +745,12 @@ class Decoder(Codec): if index == i_SAMPLE_DEF: decl = self.index_to_decl[index].decode_decl(self) value = None + elif index == i_TYPE_DEF: + print "Got type_def, skipping %d bytes" % length + self.skip(length) + elif index == i_TYPE_BINDING: + print "Got type_binding, skipping %d bytes" % length + self.skip(length) else: decl = self.index_to_decl[index] value = decl.decode(self) -- GitLab