You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 lines
2.2 KiB

/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007 - 2013
Copyright Stichting C.A. Muller Radioastronomiestation, 2007 - 2009
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _INCLUDE_EC_H_
#define _INCLUDE_EC_H_
#include <stdlib.h>
#include <inttypes.h>
#include <stdbool.h>
#if defined(__linux__)
#include <endian.h>
#else
#include <sys/endian.h>
#endif
#ifndef __packed
#define __packed __attribute__((packed))
#endif
#include <ec/canopen.h>
struct ec *ec_init(char *ifname, int nr_slaves, bool single_cycle);
int ec_slave_count(struct ec *ec);
int ec_slave_dc_count(struct ec *ec);
struct ec_dgram_addr {
enum {
EC_DGRAM_ADDR_AUTO_INC,
EC_DGRAM_ADDR_STATION,
EC_DGRAM_ADDR_LOGICAL,
EC_DGRAM_ADDR_BROADCAST,
} type;
union {
struct {
uint16_t pos;
uint16_t off;
} position;
struct {
uint16_t addr;
uint16_t off;
} node;
struct {
uint32_t addr;
} logical;
} addr;
} __attribute((__packed__));
#define ec_addr_set_auto_inc_nr(add, nr) \
do { \
(add)->type = EC_DGRAM_ADDR_AUTO_INC; \
(add)->addr.position.pos = 0x0000 - (nr); \
(add)->addr.position.off = 0x0000; \
} while (0)
ssize_t ec_datagram_read(struct ec*, struct ec_dgram_addr *addr, void *buffer, size_t len);
ssize_t ec_datagram_write(struct ec*, struct ec_dgram_addr *addr, void *buffer, size_t len);
int ec_rx_pdo_add(struct ec *ec, struct ec_dgram_addr *addr, unsigned char **data, size_t len);
int ec_tx_pdo_add(struct ec *ec, struct ec_dgram_addr *addr, unsigned char **data, size_t len);
int ec_tx_pdo(struct ec *ec);
int ec_rx_pdo(struct ec *ec);
void ec_timeout_set(struct ec *ec, double timeout_sec);
#endif /* _INCLUDE_EC_H_ */