def dictify(sdict, byteStr): """ Returns a dictionary of the byteStr """ res = seq_dict() for key in sdict: packStr = sdict[key][0] size = calcsize(packStr) current, byteStr = byteStr[:size], byteStr[size:] res[key] = (packStr, unpack(packStr, current)[0]) return res
_ourpid = getpid() _request_number = 0x0000 # these two dictionaries should be read in the order defined by # their respective _fields lists # the format they follow is Key:["packstring", initial value] ecp_rcvd_packStr = 'HHH' ecp_header_fields = ('llcDestinationLsap', 'llcSourceLsap', 'llcControl', 'llcStatus', 'pseudoLlc3Control', 'pseudoLlc3Status', 'frameType', 'requestNumber', 'crateNumber', 'hostId', 'hostPid', 'hostAccessId', 'flags', 'status',) ecp_rcvd = seq_dict(dict(zip(('nwords', 'data', 'qresp'), ecp_rcvd_packStr)), ('nwords', 'data', 'qresp')) ecp_COR_fields = ('modifier', 'cmd', 'lo', 'hi') _ecp_header_defaults = ( # would be dictionary but order is important ['B', 0x60], # LSAP dest ['B', 0x60], # LSAP src ['B', 0xF7], # llc control - changes for every send/recv pair ['B', 0x00], # llc status ['B', 0x03], # llc3 ctrl ['B', 0x00], # llc3 status ['H', 0x0007], # frame type - 0x07 = UI_frame ['H', _request_number], # request No should increment ['H', 0x0001], # crate No ['H', 0xFFFF], # host id ['I', _ourpid], # pid