71 #include <sys/types.h> 104 #define RX_PRIM priMAC[1] 106 #define RX_SEC secMAC[1] 148 InitializeCriticalSection(&(port->
tx_mutex));
149 InitializeCriticalSection(&(port->
rx_mutex));
163 *psock = pcap_open(ifname, 65536, PCAP_OPENFLAG_PROMISCUOUS |
164 PCAP_OPENFLAG_MAX_RESPONSIVENESS |
165 PCAP_OPENFLAG_NOCAPTURE_LOCAL, 0, NULL ,
errbuf);
168 printf(
"interface %s could not open with pcap\n", ifname);
193 DeleteCriticalSection(&(port->
tx_mutex));
194 DeleteCriticalSection(&(port->
rx_mutex));
216 bp->da0 = htons(0xffff);
217 bp->da1 = htons(0xffff);
218 bp->da2 = htons(0xffff);
219 bp->sa0 = htons(
priMAC[0]);
220 bp->sa1 = htons(
priMAC[1]);
221 bp->sa2 = htons(
priMAC[2]);
288 stack = &(port->
stack);
295 rval = pcap_sendpacket(*stack->
sock, (*stack->
txbuf)[idx], lp);
314 ehp->sa1 = htons(
priMAC[1]);
319 EnterCriticalSection( &(port->
tx_mutex) );
324 datagramP->index = idx;
326 ehp->sa1 = htons(
secMAC[1]);
329 LeaveCriticalSection( &(port->
tx_mutex) );
345 struct pcap_pkthdr *
header;
346 unsigned char const * pkt_data;
351 stack = &(port->
stack);
359 res = pcap_next_ex(*stack->
sock, &header, &pkt_data);
365 bytesrx = header->len;
370 memcpy(*stack->
tempbuf, pkt_data, bytesrx);
372 return (bytesrx > 0);
403 stack = &(port->
stack);
410 rxbuf = &(*stack->
rxbuf)[idx];
414 l = (*rxbuf)[0] + ((
uint16)((*rxbuf)[1] & 0x0f) << 8);
416 rval = ((*rxbuf)[l] + ((
uint16)(*rxbuf)[l + 1] << 8));
422 EnterCriticalSection(&(port->
rx_mutex));
432 l =
etohs(ecp->elength) & 0x0fff;
440 rval = ((*rxbuf)[l] + ((
uint16)((*rxbuf)[l + 1]) << 8));
444 (*stack->
rxsa)[idx] = ntohs(ehp->sa1);
451 rxbuf = &(*stack->
rxbuf)[idxf];
456 (*stack->
rxsa)[idxf] = ntohs(ehp->sa1);
465 LeaveCriticalSection( &(port->
rx_mutex) );
529 if ( ((primrx == 0) && (secrx ==
RX_SEC)) ||
631 int ec_setupnic(
const char *ifname,
int secondary)
636 int ec_closenic(
void)
641 int ec_getindex(
void)
646 void ec_setbufstat(
int idx,
int bufstat)
651 int ec_outframe(
int idx,
int stacknumber)
656 int ec_outframe_red(
int idx)
661 int ec_inframe(
int idx,
int stacknumber)
666 int ec_waitinframe(
int idx,
int timeout)
671 int ec_srconfirm(
int idx,
int timeout)
int ecx_getindex(ecx_portt *port)
void ec_setupheader(void *p)
int txbuflength[EC_MAXBUF]
static int ecx_recvpkt(ecx_portt *port, int stacknumber)
int ecx_outframe_red(ecx_portt *port, int idx)
static char errbuf[PCAP_ERRBUF_SIZE]
int(* txbuflength)[EC_MAXBUF]
PACKED_BEGIN struct PACKED ec_etherheadert
int ecx_srconfirm(ecx_portt *port, int idx, int timeout)
int ecx_setupnic(ecx_portt *port, const char *ifname, int secondary)
std_msgs::Header * header(M &m)
boolean osal_timer_is_expired(osal_timert *self)
General typedefs and defines for EtherCAT.
ec_bufT(* rxbuf)[EC_MAXBUF]
int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
void ecx_setbufstat(ecx_portt *port, int idx, int bufstat)
int ecx_inframe(ecx_portt *port, int idx, int stacknumber)
ec_bufT(* txbuf)[EC_MAXBUF]
PACKED_BEGIN struct PACKED ec_comt
static int ecx_waitinframe_red(ecx_portt *port, int idx, osal_timert *timer)
void osal_timer_start(osal_timert *self, uint32 timeout_us)
pthread_mutex_t getindex_mutex
int ecx_closenic(ecx_portt *port)
uint8 ec_bufT[EC_BUFSIZE]
int ecx_waitinframe(ecx_portt *port, int idx, int timeout)
int(* rxbufstat)[EC_MAXBUF]