Changeset 3293
- Timestamp:
- 08/02/08 02:00:19 (5 years ago)
- Files:
-
- 1 modified
-
branch/UMPA/umpa/packets.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branch/UMPA/umpa/packets.py
r3193 r3293 20 20 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 21 22 import struct 23 24 import umpa.utils.bits 25 from umpa.protocols._consts import BYTE 26 22 27 class Packet(object): 23 28 """You have to use this class to build a completely packets. … … 31 36 self.protos = [] 32 37 self._add_new_protocols(protos) 38 self.raw = None 39 self.bits = 0 33 40 34 41 def __str__(self): … … 46 53 self._add_new_protocols(protos) 47 54 48 def _add_new_protocols(self, *protos):55 def _add_new_protocols(self, protos): 49 56 for p in protos: 50 57 self.protos.append(p) … … 52 59 def get_raw(self): 53 60 """Return raw packet, in bit-mode (big-endian).""" 54 # TODO: calling method to pack it for each protocols 55 print "Not implemented yet." 61 62 self.raw = 0 63 self.bits = 0 64 proto_id = 0 65 for proto in reversed(self.protos): 66 raw_proto, bit_proto = proto.get_raw(tuple(self.protos), self.bits) 67 self.raw |= raw_proto << self.bits 68 self.bits += bit_proto 69 # split into chunks 70 # we make it because we need string for socket object 71 # so after that we pack it by struct module.pack() 72 byte_chunks = umpa.utils.bits.split_into_chunks(self.raw, self.bits) 73 return struct.pack('!' + 'B'*(self.bits/BYTE), *byte_chunks)
