Exemple #1
0
 def __init__(self, CallName='', LH='L', Dict=None):
     self.LHdict = iad({0:'L', 1:'H'})
     Bit.__init__(self, CallName=CallName, BitLen=1, Dict=Dict, Repr='hum')
     if LH not in ('L', 'H'): LH = 'L'
     self.LH = LH
     self.Pt = 0
     self.PtFunc = self.__lh_val
Exemple #2
0
 def _append_csn1_field(self, field):
     if isinstance(field, LHFlag):
         #print self._offset
         if self.L[self._offset%8] == 1:
             field.LHdict = iad({1:'L', 0:'H'})
     if isinstance(field, CSN1):
         # initialize the field without building it any specific way
         f = field.__class__(False, None)
         # and then call build() in order to pass the _offset attribute
         path = self._cur_path if hasattr(self, '_cur_path') else None
         f.build(f.csn1List, self._offset, path)
         #
         if self.dbg >= DBG:
             log(DBG, '(_append_csn1_field) field %s with path %s'\
                 % (f.CallName, path))
         self.append(f)
         self._offset += f.bit_len()
         #
     else:
         self.append(field)
         self._offset += field.bit_len()
Exemple #3
0
 def _append_map_csn1_field(self, csn1f):
     # ensure there is still enough buffer to map on new fields
     if hasattr(csn1f, 'bit_len') \
     and csn1f.bit_len() > (self._buflen - (self._consumed+self._offset)):
         if self.dbg >= WNG:
             log(WNG, '(CSN1.map - %s) buffer not long enough for field: ' \
                      '%s from csn1List' % (self.__class__, csn1f.CallName))
         self._map_exit = True
         return
     # append the field to the layer
     if self.dbg >= DBG:
         log(DBG, '(CSN1._append_map_csn1_field) appending csn1 field: %s' \
             % csn1f.CallName)
     #
     # map the BUF on the element: this solves its bit length
     # moreover, we transmit the byte offset, for solving correctly L|H flags
     if type(csn1f) == type and issubclass(csn1f, CSN1):
         self.append(csn1f().clone())
     else:
         self.append(csn1f)
     #
     if isinstance(self[-1], CSN1):
         self[-1].map(self.BUF, (self._consumed+self._offset)%8)
         bitlen = self[-1].bit_len()
     else:
         self[-1].map(self.BUF)
         bitlen = self[-1].bit_len()
         # check if LHFlag to possibly update its LH dictionnary
         if isinstance(self[-1], LHFlag):
             l = self.L[(self._consumed+self._offset)%8]
             h = (1, 0)[l]
             self[-1].LHdict = iad({l:'L', h:'H'})
     #
     # update global BUFFER and consumed bit length 
     self.BUF = self.BUF << bitlen
     self._consumed += bitlen