(self, event)
Handle event broadcast by the SSE server

        Args:
            event : Event generated by the sseclient
Handle event broadcast by the SSE server
Handle event broadcast by the SSE server
def _handle_event(self, event):
        """Handle event broadcast by the SSE server

        Args:
            event : Event generated by the sseclient

        """
        # Parse the order corresponding to the event
        order = json.loads(event.data)

        # Debug
        logger.debug("Order: " + json.dumps(order, indent=4, sort_keys=True))

        # Proceed when the event matches the target Tx trigger event
        if (order["status"] != self.tx_event):
            return

        # Sequence number
        seq_num = order["tx_seq_num"]

        # If the sequence number has rolled back, maybe it is because the
        # server has restarted the sequence numbers (not uncommon on test
        # environments). In this case, restart the sequence.
        if (self.last_seq_num is not None and seq_num < self.last_seq_num):
            logger.warning("Tx sequence number rolled back from {} to "
                           "{}".format(self.last_seq_num, seq_num))
            self.last_seq_num = None

        rx_pending = True
        while (rx_pending):
            # Receive all messages until caught up
            if (self.last_seq_num is None):
                next_seq_num = seq_num
            else:
                next_seq_num = self.last_seq_num + 1

            # Keep track of the last processed sequence number
            self.last_seq_num = next_seq_num

            # Is this an interation to catch up with a sequence
            # number gap or a normal transmission iteration?
            if (seq_num == next_seq_num):
                rx_pending = False
            else:
                logger.info("Catch up with transmission %d" % (next_seq_num))

            logger.info("Message %-5d\tSize: %d bytes\t" %
                        (next_seq_num, order["message_size"]))

            # Get the API message data
            order = ApiOrder(self.server,
                             seq_num=next_seq_num,
                             tls_cert=self.tls_cert,
                             tls_key=self.tls_key)
            data = order.get_data()

            if (data is None):
                # Empty message. There is nothing else to do.
                continue

            # Split API message data into Blocksat packet(s)
            tx_handler = BlocksatPktHandler()
            tx_handler.split(data, next_seq_num, self.channel)
            pkts = tx_handler.get_frags(next_seq_num)

            logger.debug("Transmission is going to take: "
                         "{:6.2f} sec".format(len(data) * 8 / (self.kbps)))

            # Send the packet(s)
            self._send_pkts(pkts)

            # Send transmission confirmation to the server
            order.confirm_tx(self.regions)
def _handle_event ( self , event ) : # Parse the order corresponding to the event order = json . loads ( event . data ) # Debug logger . debug ( "Order: " + json . dumps ( order , indent = 4 , sort_keys = True ) ) # Proceed when the event matches the target Tx trigger event if ( order [ "status" ] != self . tx_event ) : return # Sequence number seq_num = order [ "tx_seq_num" ] # If the sequence number has rolled back, maybe it is because the # server has restarted the sequence numbers (not uncommon on test # environments). In this case, restart the sequence. if ( self . last_seq_num is not None and seq_num < self . last_seq_num ) : logger . warning ( "Tx sequence number rolled back from {} to " "{}" . format ( self . last_seq_num , seq_num ) ) self . last_seq_num = None rx_pending = True while ( rx_pending ) : # Receive all messages until caught up if ( self . last_seq_num is None ) : next_seq_num = seq_num else : next_seq_num = self . last_seq_num + 1 # Keep track of the last processed sequence number self . last_seq_num = next_seq_num # Is this an interation to catch up with a sequence # number gap or a normal transmission iteration? if ( seq_num == next_seq_num ) : rx_pending = False else : logger . info ( "Catch up with transmission %d" % ( next_seq_num ) ) logger . info ( "Message %-5d\tSize: %d bytes\t" % ( next_seq_num , order [ "message_size" ] ) ) # Get the API message data order = ApiOrder ( self . server , seq_num = next_seq_num , tls_cert = self . tls_cert , tls_key = self . tls_key ) data = order . get_data ( ) if ( data is None ) : # Empty message. There is nothing else to do. continue # Split API message data into Blocksat packet(s) tx_handler = BlocksatPktHandler ( ) tx_handler . split ( data , next_seq_num , self . channel ) pkts = tx_handler . get_frags ( next_seq_num ) logger . debug ( "Transmission is going to take: " "{:6.2f} sec" . format ( len ( data ) * 8 / ( self . kbps ) ) ) # Send the packet(s) self . _send_pkts ( pkts ) # Send transmission confirmation to the server order . confirm_tx ( self . regions )