Page 1 of 1

TX_SETUP; Low Level CAN Framework; Broadcast Manager

Posted: Tue 10. May 2016, 11:48
by stahlstngel
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;
}

Re: TX_SETUP; Low Level CAN Framework; Broadcast Manager

Posted: Wed 11. May 2016, 08:40
by PEAK-Support
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?

Re: TX_SETUP; Low Level CAN Framework; Broadcast Manager

Posted: Wed 11. May 2016, 11:38
by stahlstngel
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;
}

Re: TX_SETUP; Low Level CAN Framework; Broadcast Manager

Posted: Wed 11. May 2016, 17:54
by O.Hartkopp
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