70 lines
1.6 KiB
C++
70 lines
1.6 KiB
C++
#ifndef INCLUDE_CAN_H_
|
|
#define INCLUDE_CAN_H_
|
|
|
|
#include <map>
|
|
#include <mutex>
|
|
#include <chrono>
|
|
#include <pthread.h>
|
|
|
|
#include <php.h>
|
|
#include <di/can.h>
|
|
|
|
#define DI_CAN_RX_FRAMES 32U
|
|
#define DI_CAN_MESSAGES 1024U
|
|
#define DI_CAN_MSG_SIZE 4096U
|
|
|
|
/**
|
|
* PHP DI-Net CAN context
|
|
*/
|
|
struct php_di_can_ctx {
|
|
int fd; /**< SocketCAN filedescriptor */
|
|
struct di_can_ctx ctx; /**< DI-Net CAN context */
|
|
std::mutex *lock;
|
|
pthread_t thr; /**< Background thread (recv, reassemble, periodic) */
|
|
bool running;
|
|
struct {
|
|
std::map<unsigned int, struct php_can_periodic_item> *queue;
|
|
unsigned int token;
|
|
} periodic;
|
|
struct {
|
|
struct di_can_frame_rx *di_can_frame_pool;
|
|
uint8_t *di_can_msg_buf_data;
|
|
struct di_buffer *di_can_msg_buf;
|
|
struct di_can_msg *di_can_msg_pool;
|
|
} mm;
|
|
};
|
|
|
|
/**
|
|
* PHP mapping of di_can_msg
|
|
*/
|
|
struct php_di_can_msg {
|
|
enum di_can_transfertype ttype;
|
|
uint16_t dtype;
|
|
bool rt;
|
|
enum di_can_ptypes ptype;
|
|
enum di_can_msgtype msgtype;
|
|
uint8_t *data;
|
|
zval data_zval;
|
|
size_t size;
|
|
uint32_t src_id;
|
|
uint32_t dst_id;
|
|
uint32_t canid;
|
|
struct di_can_msg msg;
|
|
};
|
|
|
|
struct php_can_periodic_item {
|
|
std::chrono::milliseconds interval;
|
|
std::chrono::system_clock::time_point deadline;
|
|
struct php_di_can_msg msg;
|
|
};
|
|
|
|
struct php_di_can_ctx *php_can_alloc(const char *iface);
|
|
void php_can_free(struct php_di_can_ctx **c);
|
|
void *php_can_thread_func(void *args);
|
|
|
|
void php_di_can_send_args_get(zval *arg, struct php_di_can_msg *msg, struct di_can_ctx *ctx);
|
|
void php_di_can_send_args_free(struct php_di_can_msg *msg);
|
|
void php_di_can_send_periodic_execute(struct php_di_can_ctx *ctx);
|
|
|
|
#endif /* INCLUDE_CAN_H_ */
|