Exemplo n.º 1
0
 def recver(self):
     while True:
         frame = self.servant.recv()
         header, payload, _ = self.decompose(frame)
         header = self.unbuild(header)
         if header.acking:
             # sending frame ACKed
             if header.ack == self.sending_seq:
                 self.acked = True
                 self.sending_seq = (self.sending_seq + 1) % self.SEQ_SIZE
                 self.timer.stop()
         if payload:
             # is the expecting frame
             if header.seq == self.expecting_seq:
                 self.master.push(payload)
                 self.expecting_seq = (self.expecting_seq +
                                       1) % self.SEQ_SIZE
             else:
                 utils.put(self.host, 'drop',
                           struct.unpack('!B', payload)[0], 'at',
                           mint.now())
             # send ACK
             header = self.build(
                 acking=True,
                 ack=header.seq,  # ack the recved frame
                 seq=0)  # meaningless
             frame = self.compose(header)  # no payload
             self.servant.send(frame)
Exemplo n.º 2
0
 def recver(self):
     while True:
         frame = self.servant.recv()
         header, payload, _ = self.decompose(frame)
         header = self.unbuild(header)
         if header.acking:
             # sending frame ACKed
             if header.ack == self.sending_seq:
                 self.acked = True
                 self.sending_seq = (self.sending_seq + 1) % self.SEQ_SIZE
                 self.timer.stop()
         if payload:
             # is the expecting frame
             if header.seq == self.expecting_seq:
                 self.master.push(payload)
                 self.expecting_seq = (self.expecting_seq + 1) % self.SEQ_SIZE
             else:
                 utils.put(self.host, 'drop',
                         struct.unpack('!B', payload)[0], 'at', mint.now())
             # send ACK
             header = self.build(
                 acking=True,
                 ack=header.seq, # ack the recved frame
                 seq=0) # meaningless
             frame = self.compose(header) # no payload
             self.servant.send(frame)
Exemplo n.º 3
0
    def show(self, fmt='iioo'):
        def join(frame):
            return ''.join('1' if bit else '0' for bit in frame)

        if 'oo' in fmt:
            utils.put(self.host, 'os',
                      ' '.join(utils.format(f, 'bin') for f in self._oframes))
        if 'o' in fmt:
            utils.put(self.host, 'o ', join(self._oframe))
        if 'i' in fmt:
            utils.put(self.host, 'i ', join(self._iframe))
        if 'ii' in fmt:
            utils.put(self.host, 'is',
                      ' '.join(utils.format(f, 'bin') for f in self.iframes))
Exemplo n.º 4
0
    def show(self, fmt='iioo'):

        def join(frame):
            return ''.join('1' if bit else '0' for bit in frame)

        if 'oo' in fmt:
            utils.put(self.host, 'os', ' '.join(
                utils.format(f, 'bin') for f in self._oframes))
        if 'o' in fmt:
            utils.put(self.host, 'o ', join(self._oframe))
        if 'i' in fmt:
            utils.put(self.host, 'i ', join(self._iframe))
        if 'ii' in fmt:
            utils.put(self.host, 'is', ' '.join(
                utils.format(f, 'bin') for f in self.iframes))
Exemplo n.º 5
0
 def title(self):
     utils.put('=' * 25 + ' {}'.format(self.now))
Exemplo n.º 6
0
 def show(self):
     utils.put(self)
     utils.put('\to {}', self.osymbol)
     utils.put('\ti {}', self.isymbol)
Exemplo n.º 7
0
 def show(self):
     utils.put(self)
     utils.put('\to {}', self.osymbol)
     utils.put('\ti {}', self.isymbol)
Exemplo n.º 8
0
 def title(self):
     utils.put('=' * 25 + ' {}'.format(self.now))
Exemplo n.º 9
0
 def title(self):
     utils.put('=' * 25 + ' {} {}'.format(self.now, self.phase))
Exemplo n.º 10
0
 def show(self):
     utils.put(self)
     utils.put("\to {}", self.osymbol)
     utils.put("\ti {}", self.isymbol)
Exemplo n.º 11
0
 def title(self):
     utils.put('=' * 25 + ' {} {}'.format(self.now, self.phase))