コード例 #1
0
ファイル: komodo_if.py プロジェクト: seftiz/V2X-ATE
    def receive(self, interface):
        """
        receive - 
        receive CAN frame
        """
        self.check_interface_range(interface)
        if self.port[interface] is None:
            raise Exception(
                "Port number {0} is not configured".format(interface))

        info = komodo_drv.km_can_info_t()
        komodo_pkt = komodo_drv.km_can_packet_t()
        data_in = array('B', '\0' * 8)
        komodo_rc = 0
        rc = 1
        self.lock.acquire()
        komodo_rc, info, komodo_pkt, data_in = komodo_drv.km_can_read(
            self.port[interface], data_in)
        self.lock.release()
        if komodo_rc:
            # pkt.can_id = komodo_pkt.id
            # pkt.dlc = komodo_pkt.dlc
            # pkt.data = data_in
            # flags = (pkt.extend_addr << EXTENDED_CAN_ID_LEN) | (pkt.remote_req << CAN_ID_RTR_BIT)
            # pkt.is_extended = pkt.extend_addr
            # pkt.rtr_f =  pkt.remote_req
            # rc = 0
            return globals.canBusFrame(
                komodo_pkt.id, komodo_pkt.dlc, data_in,
                (komodo_pkt.extend_addr << globals.EXTENDED_CAN_ID_LEN) |
                (komodo_pkt.remote_req << globals.CAN_ID_RTR_BIT))

        return str(rc)
コード例 #2
0
ファイル: komodo_if.py プロジェクト: seftiz/V2X-ATE
    def get_frame(self, interface, timeout_sec=60):
        self._check_interface_range(interface)
        if not self._is_power_up:
            raise Exception("Could not get frame - CAN Port is not powered up")

        if self._port[interface] is None:
            raise Exception(
                "Could not get frame - Port number {0} is not configured".
                format(interface))

        info = komodo_drv.km_can_info_t()
        pkt = komodo_drv.km_can_packet_t()
        ret = 0
        data_in = array('B', '\0' * 8)

        start_time = time.time()

        # When a frame is received info.status changes to 0 and info.events should be 0.
        while ((info.status != 0) or (info.events != 0)):
            ret, info, pkt, data_in = komodo_drv.km_can_read(
                self._port[interface], data_in)
            #            log.debug("Inside Komodo read loop - status={0}, events={1}, id={2}, dlc={3}".format(info.status, info.events, pkt.id, pkt.dlc))
            if (time.time() - start_time > timeout_sec):
                raise Exception(
                    "Get frame didn't receive any frame for {} seconds".format(
                        timeout_sec))

        # can_frame = canbus_manager.CanFrame(pkt.id, pkt.extend_addr, pkt.remote_req, pkt.dlc, data_in.tolist())
        return can_frame
コード例 #3
0
ファイル: komodo_if.py プロジェクト: seftiz/V2X-ATE
    def transmit(self, interface, can_frame):

        self.check_interface_range(interface)
        if not self.is_power_up:
            raise Exception(
                "Could not send frame - CAN Port is not powered up")

        if self.port[interface] is None:
            raise Exception(
                "Could not send frame - Port number {0} is not configured".
                format(interface))

        pkt = komodo_drv.km_can_packet_t()
        pkt.id = can_frame.can_id
        pkt.dlc = can_frame.dlc
        pkt.extend_addr = can_frame.ide_f
        pkt.remote_req = can_frame.rtr_f

        # Convert data of type list to array for the komodo driver
        data = array('B', can_frame.data)

        self.lock.acquire()
        ret, bytes = komodo_drv.km_can_write(self.port[interface], interface,
                                             0, pkt, data)
        self.lock.release()
        if ret < 0:
            raise Exception("Could not send frame, error {0}".format(ret))