TX_SETUP; Low Level CAN Framework; Broadcast Manager

This forum covers PCAN-Linux and Linux development issues concerning our products
Post Reply
stahlstngel
Posts: 10
Joined: Thu 28. Apr 2016, 18:24

TX_SETUP; Low Level CAN Framework; Broadcast Manager

Post by stahlstngel » Tue 10. May 2016, 11:48

I'm working on the "Low Level CAN Framework" with the PCAN-USB FD to setup a cyclic transmission per "Broadcast Manager".

I followed the expamle here: http://www.brownhat.org/docs/socketcan/ ... 0000000000

But when i start my program it only sends the frame once. But i want to send the same message in 100ms again and again.

Can please anybody tell me what i doing wrong.


can0:

Code: Select all

$ ip -details -statistics link show can0
3: can0: <NOARP,UP,LOWER_UP> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE restart-ms 0 
	  bitrate 125000 sample-point 0.875 
	  tq 125 prop-seg 27 phase-seg1 28 phase-seg2 8 sjw 1
	  pcan: tseg1 1..64 tseg2 1..16 sjw 1..16 brp 1..1024 brp-inc 1
	  pcan: dtseg1 1..16 dtseg2 1..8 dsjw 1..4 dbrp 1..1024 dbrp-inc 1
	  clock 80000000

My program:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <linux/can.h>
#include <linux/can/bcm.h>

int main(void)
{
        int s;
        int nbytes;
        struct sockaddr_can addr;
        struct ifreq ifr;
        struct {
                struct bcm_msg_head msg_head;
                struct can_frame frame[1];
        } msg;

        if((s = socket(PF_CAN, SOCK_DGRAM, CAN_BCM)) < 0) {
                perror("Error while opening socket");
                return -1; }

        addr.can_family = AF_CAN;
        strcpy(ifr.ifr_name, "can0");
        ioctl(s, SIOCGIFINDEX, &ifr);
        addr.can_ifindex = ifr.ifr_ifindex;

        if(connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
                perror("Error in socket connect");
                return -2; }

// cyclic transmission
    msg.msg_head.opcode  = TX_SETUP;
    msg.msg_head.can_id  = 0x123;
    msg.msg_head.flags   = SETTIMER|STARTTIMER|TX_CP_CAN_ID;
    msg.msg_head.nframes = 1;
    msg.msg_head.count = 0;
    msg.msg_head.ival1.tv_sec = 0;
    msg.msg_head.ival1.tv_usec = 0;
    msg.msg_head.ival2.tv_sec = 0;
    msg.msg_head.ival2.tv_usec = 100000;
//    msg.frame[0].can_id    = 0x123; /* obsolete when using TX_CP_CAN_ID */
    msg.frame[0].can_dlc   = 3;
    msg.frame[0].data[0]   = 0x52;
    msg.frame[0].data[1]   = 0x53;
    msg.frame[0].data[2]   = 0x53;

        write(s, &msg, sizeof(msg));

        return 0;
}

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: TX_SETUP; Low Level CAN Framework; Broadcast Manager

Post by PEAK-Support » Wed 11. May 2016, 08:40

The Framework is not from PEAK, so please contact the Developers / Community.

But for me it looks like you end your software directly after calling the Send Message function...so your created socket will be also deleted. Who should from this point take care od sending the cycle message? Have you try to insert a loop with some delay at the end of your SW to check if the sending in background works?
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

stahlstngel
Posts: 10
Joined: Thu 28. Apr 2016, 18:24

Re: TX_SETUP; Low Level CAN Framework; Broadcast Manager

Post by stahlstngel » Wed 11. May 2016, 11:38

Thanks a lot. I'm completely new to this topic and yes i just need to keep the program running.

A simple getchar() worked (see code).

Thanks again and thanks for your time.

Code: Select all

...
        write(s, &msg, sizeof(msg));

        printf("To end the transmission hit a key: ");
        getchar();
        printf("\n");

        return 0;
}

User avatar
O.Hartkopp
Posts: 40
Joined: Fri 22. Nov 2013, 19:47

Re: TX_SETUP; Low Level CAN Framework; Broadcast Manager

Post by O.Hartkopp » Wed 11. May 2016, 17:54

stahlstngel wrote:I'm working on the "Low Level CAN Framework" with the PCAN-USB FD to setup a cyclic transmission per "Broadcast Manager".

I followed the expamle here: http://www.brownhat.org/docs/socketcan/ ... 0000000000
Questions related to SocketCAN (former LLCF) network layer should be directed to the linux-can mailing list.

Subscription see: http://vger.kernel.org/vger-lists.html#linux-can
For discussions just send a mail to linux-can@vger.kernel.org
Mail archives: http://marc.info/?l=linux-can

Regards,
Oliver

Post Reply