2016-05-25 18:37:40 +03:00
|
|
|
#ifndef SERIALQUEUE_H
|
|
|
|
#define SERIALQUEUE_H
|
|
|
|
|
|
|
|
#include "list.h" // struct list_head
|
|
|
|
|
|
|
|
#define MAX_CLOCK 0x7fffffffffffffff
|
|
|
|
|
|
|
|
#define MESSAGE_MIN 5
|
|
|
|
#define MESSAGE_MAX 64
|
|
|
|
#define MESSAGE_HEADER_SIZE 2
|
|
|
|
#define MESSAGE_TRAILER_SIZE 3
|
|
|
|
#define MESSAGE_POS_LEN 0
|
|
|
|
#define MESSAGE_POS_SEQ 1
|
|
|
|
#define MESSAGE_TRAILER_CRC 3
|
|
|
|
#define MESSAGE_TRAILER_SYNC 1
|
|
|
|
#define MESSAGE_PAYLOAD_MAX (MESSAGE_MAX - MESSAGE_MIN)
|
|
|
|
#define MESSAGE_SEQ_MASK 0x0f
|
|
|
|
#define MESSAGE_DEST 0x10
|
|
|
|
#define MESSAGE_SYNC 0x7E
|
|
|
|
|
|
|
|
struct queue_message {
|
|
|
|
int len;
|
|
|
|
uint8_t msg[MESSAGE_MAX];
|
|
|
|
union {
|
|
|
|
// Filled when on a command queue
|
|
|
|
struct {
|
|
|
|
uint64_t min_clock, req_clock;
|
|
|
|
};
|
|
|
|
// Filled when in sent/receive queues
|
|
|
|
struct {
|
|
|
|
double sent_time, receive_time;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
struct list_node node;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct queue_message *message_alloc_and_encode(uint32_t *data, int len);
|
|
|
|
|
|
|
|
struct pull_queue_message {
|
|
|
|
uint8_t msg[MESSAGE_MAX];
|
|
|
|
int len;
|
|
|
|
double sent_time, receive_time;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct serialqueue;
|
2016-07-11 18:41:49 +03:00
|
|
|
struct serialqueue *serialqueue_alloc(int serial_fd, int write_only);
|
2016-05-25 18:37:40 +03:00
|
|
|
void serialqueue_exit(struct serialqueue *sq);
|
|
|
|
struct command_queue *serialqueue_alloc_commandqueue(void);
|
|
|
|
void serialqueue_send_batch(struct serialqueue *sq, struct command_queue *cq
|
|
|
|
, struct list_head *msgs);
|
|
|
|
void serialqueue_send(struct serialqueue *sq, struct command_queue *cq
|
|
|
|
, uint8_t *msg, int len
|
|
|
|
, uint64_t min_clock, uint64_t req_clock);
|
|
|
|
void serialqueue_encode_and_send(struct serialqueue *sq, struct command_queue *cq
|
|
|
|
, uint32_t *data, int len
|
|
|
|
, uint64_t min_clock, uint64_t req_clock);
|
|
|
|
void serialqueue_pull(struct serialqueue *sq, struct pull_queue_message *pqm);
|
2016-07-11 18:41:49 +03:00
|
|
|
void serialqueue_set_baud_adjust(struct serialqueue *sq, double baud_adjust);
|
2016-05-25 18:37:40 +03:00
|
|
|
void serialqueue_set_clock_est(struct serialqueue *sq, double est_clock
|
|
|
|
, double last_ack_time, uint64_t last_ack_clock);
|
|
|
|
void serialqueue_flush_ready(struct serialqueue *sq);
|
|
|
|
void serialqueue_get_stats(struct serialqueue *sq, char *buf, int len);
|
|
|
|
int serialqueue_extract_old(struct serialqueue *sq, int sentq
|
|
|
|
, struct pull_queue_message *q, int max);
|
|
|
|
|
|
|
|
#endif // serialqueue.h
|