From f582a36e4df16d5709943f7df17a900c8bcc12ab Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 25 May 2016 11:37:40 -0400 Subject: Initial commit of source code. Signed-off-by: Kevin O'Connor --- klippy/serialqueue.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 klippy/serialqueue.h (limited to 'klippy/serialqueue.h') diff --git a/klippy/serialqueue.h b/klippy/serialqueue.h new file mode 100644 index 00000000..229fb216 --- /dev/null +++ b/klippy/serialqueue.h @@ -0,0 +1,66 @@ +#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; +struct serialqueue *serialqueue_alloc(int serial_fd, double baud_adjust + , int write_only); +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); +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 -- cgit v1.2.3-70-g09d2