예제 #1
0
    def _process_incoming_message(self, msg):
        logger.info("PI01: Processing incoming message: instance={}, msg=  {}".format(self, msg))
        arbitration_id = ArbitrationID()
        arbitration_id.can_id = msg.arbitration_id
        if arbitration_id.pgn.is_destination_specific:
            arbitration_id.pgn.value -= arbitration_id.pgn.pdu_specific

        pdu = self._pdu_type(timestamp=msg.timestamp, data=msg.data, info_strings=[])
        pdu.arbitration_id.can_id = msg.arbitration_id
        pdu.info_strings = []
        pdu.radix = 16

        logger.debug("PI02a: arbitration_id.pgn.value = 0x{:04x} ({})".format(arbitration_id.pgn.value, arbitration_id.pgn.value))
        logger.debug("PI02b: PGN_TP_SEED_REQUEST = {}".format(PGN_TP_SEED_REQUEST)) 

        logger.debug("PI02c: self._key_generation_fcn = {}".format(self._key_generation_fcn)) 

        if arbitration_id.pgn.value == PGN_TP_CONNECTION_MANAGEMENT:
            logger.info("PGN_TP_CONNECTION_MANAGEMENT")
            retval = self._connection_management_handler(pdu)
        elif arbitration_id.pgn.value == PGN_TP_DATA_TRANSFER:
            logger.info("PGN_TP_DATA_TRANSFER")
            retval = self._data_transfer_handler(pdu)
        elif (arbitration_id.pgn.value == PGN_TP_SEED_REQUEST) and (self._key_generation_fcn is not None):
            logger.info("PGN_TP_SEED_REQUEST")
            retval = self._send_key_response(pdu)
        else:
            logger.info("PGN_PDU generic")
            retval = pdu

        logger.info("_process_incoming_message: returning %s" % (retval))
        return retval
예제 #2
0
    def notification(self, inboundMessage):
        #self.rx_can_message_queue.put(inboundMessage)

        if isinstance(inboundMessage, Message):
            logger.info('Got a Message from CAN: %s' % inboundMessage)
            if inboundMessage.id_type:
                # Extended ID
                # Only J1939 messages (i.e. 29-bit IDs) should go further than this point.
                # Non-J1939 systems can co-exist with J1939 systems, but J1939 doesn't care
                # about the content of their messages.
                logger.info('Message is j1939 msg')

                #
                # Need to determine if it's a broadcase message or 
                # limit to listening nodes only
                #
                arbitration_id = ArbitrationID()
                arbitration_id.can_id = inboundMessage.arbitration_id

                # redirect the AC stuff to the node processors. the rest can go 
                # to the main queue.
                for (node, l_notifier) in self.node_queue_list:
                    logger.info("node=%s, notifier=%s" % (node, l_notifier))
                    if node and (arbitration_id.pgn in [PGN_AC_ADDRESS_CLAIMED, PGN_AC_COMMANDED_ADDRESS, PGN_REQUEST_FOR_PGN]):
                        logger.info("sending to notifier queue")
                        # send the PDU to the node processor.
                        l_notifier.queue.put(inboundMessage)
                    elif node==None:
                        # always send the message to the logging queue
                        logger.info("sending to logging queue")
                        rx_pdu = self._process_incoming_message(inboundMessage)
                        self.queue.put(rx_pdu)

            else:
                logger.info("Received non J1939 message (ignoring)")
예제 #3
0
    def notification(self, inboundMessage):
        #self.rx_can_message_queue.put(inboundMessage)
        if self.can_notifier._running is False:
            logger.info('{}: Aborting message {} bus is not running'.format(inspect.stack()[0][3], inboundMessage))
            # Should I return or throw exception here.

        if isinstance(inboundMessage, Message):
            logger.info('\n\n{}:  Got a Message from CAN: {}'.format(inspect.stack()[0][3],inboundMessage))
            if inboundMessage.id_type:
                # Extended ID
                # Only J1939 messages (i.e. 29-bit IDs) should go further than this point.
                # Non-J1939 systems can co-exist with J1939 systems, but J1939 doesn't care
                # about the content of their messages.
                logger.info('{}: Message is j1939 msg'.format(inspect.stack()[0][3]))

                #
                # Need to determine if it's a broadcast message or
                # limit to listening nodes only
                #
                arbitration_id = ArbitrationID()
                arbitration_id.can_id = inboundMessage.arbitration_id
                logger.info("{}: ArbitrationID = {}, inboundMessage.arbitration_id: 0x{:08x}".format(inspect.stack()[0][3],arbitration_id, inboundMessage.arbitration_id))

                for (node, l_notifier) in self.node_queue_list:
                    logger.debug("notification: node=%s" % (node))
                    logger.debug("              notifier=%s" % (l_notifier))
                    logger.debug("              arbitration_id.pgn=%s" % (arbitration_id.pgn))
                    logger.debug("              destination_address=%s" % (arbitration_id.destination_address))

                    # redirect the AC stuff to the node processors. the rest can go
                    # to the main queue.
                    if node and (arbitration_id.pgn in [PGN_AC_ADDRESS_CLAIMED, PGN_AC_COMMANDED_ADDRESS, PGN_REQUEST_FOR_PGN]):
                        logger.info("{}: sending to notifier queue".format(inspect.stack()[0][3]))
                        # send the PDU to the node processor.
                        l_notifier.queue.put(inboundMessage)

                    # if node has the destination address, do something with the PDU
                    elif node and (arbitration_id.destination_address in node.address_list):
                        logger.info("{}: sending to process_incoming_message".format(inspect.stack()[0][3]))
                        rx_pdu = self._process_incoming_message(inboundMessage)
                        if rx_pdu:
                            logger.info("WP02: notification: sent to general queue: %s QQ=%s" % (rx_pdu, self.queue))
                            self.queue.put(rx_pdu)
                    elif node and (arbitration_id.destination_address is None):
                        logger.info("{}: sending broadcast to general queue".format(inspect.stack()[0][3]))
                        rx_pdu = self._process_incoming_message(inboundMessage)
                        logger.info("WP01: notification: sent broadcast to general queue: %s QQ=%s" % (rx_pdu, self.queue))
                        self.queue.put(rx_pdu)
                    elif node is None:
                        # always send the message to the logging queue
                        logger.info("{}: sending to general queue".format(inspect.stack()[0][3]))
                        rx_pdu = self._process_incoming_message(inboundMessage)
                        logger.info("WP03: notification: sent pdu [%s] to general queue" % rx_pdu)
                        self.queue.put(rx_pdu)
                    else:
                        logger.info("WP04: notification: pdu dropped: %s\n\n" % inboundMessage)
            else:
                logger.info("Received non J1939 message (ignoring)")
예제 #4
0
    def _process_incoming_message(self, msg):
        logger.debug("Processing incoming message")
        logging.debug(msg)
        arbitration_id = ArbitrationID()
        arbitration_id.can_id = msg.arbitration_id
        if arbitration_id.pgn.is_destination_specific:
            arbitration_id.pgn.value -= arbitration_id.pgn.pdu_specific
        pdu = self._pdu_type(timestamp=msg.timestamp, data=msg.data, info_strings=[])
        pdu.arbitration_id.can_id = msg.arbitration_id
        pdu.info_strings = []

        if arbitration_id.pgn.value == PGN_TP_CONNECTION_MANAGEMENT:
            logger.debug("PGN_TP_CONNECTION_MANAGEMENT")
            retval = self._connection_management_handler(pdu)
        elif arbitration_id.pgn.value == PGN_TP_DATA_TRANSFER:
            logger.debug("PGN_TP_DATA_TRANSFER")
            retval = self._data_transfer_handler(pdu)
        else:
            logger.debug("PGN_PDU")
            retval = pdu

        logger.debug("\n")
        logging.debug(retval)
        return retval