-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpacket_parser.h
94 lines (72 loc) · 2.16 KB
/
packet_parser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef PACKET_PARSER_H
#define PACKET_PARSER_H
#include "mbed.h"
#include "MODSERIAL.h"
#include "rtos.h"
#include "lib_crc.h"
#include "protocol.h"
/**
* Defines the number of packets in the incoming and outgoing buffers.
*/
#define PACKET_BUFFER_LENGTH 4
/**
* Thread flag to start work.
*/
#define START_THREAD_FLAG (1<<0)
#define DMA_COMPLETE_FLAG (1<<1)
class PacketParser {
public:
/**
* Constructor.
*
* Creates a packet parsing protocol on the USB serial connection.
*
*/
PacketParser(uint32_t baudrate, PinName tx_pin, PinName rx_pin, PinName tx_led, PinName rx_led);
/**
* Get a pointer to the next received packet, or NULL if there is no packet.
*/
packet_union_t* get_received_packet(void);
/**
* Return a received packet to the packet pool. Must be called after using
* a packet from get_received_packet.
*
* @param packet - pointer to packet to be freed.
*/
void free_received_packet(packet_union_t* packet);
/**
* Get a pointer to a packet to be sent. Will return NULL if there are no
* available outgoing packets.
*/
packet_union_t* get_send_packet(void);
/**
* Send the packet returned by get_send_packet via outgoing queue.
*
* @param packet - pointer to packet to be sent.
*/
void send_packet(packet_union_t* packet);
/**
* Blocking send the packet returned by get_send_packet.
*
* @param packet - pointer to packet to be sent.
*/
void send_blocking(packet_union_t* out_pkt);
/**
* Function to process outgoing queue; call in main loop.
*/
void send_worker(void);
private:
MODSERIAL pc_;
DigitalOut tx_led_;
uint32_t tx_sequence_;
Mail<packet_union_t, PACKET_BUFFER_LENGTH> out_box_;
packet_union_t* out_pkt_;
DigitalOut rx_led_;
Mail<packet_union_t, PACKET_BUFFER_LENGTH> in_box_;
packet_union_t* in_pkt_;
uint32_t in_pkt_idx_;
uint32_t in_pkt_len_;
uint8_t in_pkt_crc_;
void receive_callback(MODSERIAL_IRQ_INFO *q);
};
#endif