Pico Core
Loading...
Searching...
No Matches
harp_message.h
Go to the documentation of this file.
1#ifndef HARP_MESSAGE_H
2#define HARP_MESSAGE_H
3#include <reg_types.h>
4
5#define MAX_PACKET_SIZE (255) // unused?
6
7enum msg_type_t: uint8_t
8{
9 READ = 1,
10 WRITE = 2,
11 EVENT = 3,
13 WRITE_ERROR = 10
14};
15
16
17// Byte-align struct data so we can either:
18// memcopy it to struct or cast the rx buffer to struct
19#pragma pack(push, 1)
21{
23 uint8_t raw_length;
24 uint8_t address;
25 uint8_t port; // should default to 255.
27
28 // (Inline) Member functions:
30 {return bool(payload_type & HAS_TIMESTAMP);}
31
33 {return has_timestamp()? raw_length - 10: raw_length - 4;}
34
36 {return has_timestamp()? 11: 5;}
37
39 {return 2 + raw_length;}
40
41 uint8_t msg_size()
42 {return raw_length + 2;}
43};
44#pragma pack(pop)
45
46// Reference-only convenience classes.
47// The data needs to exist elsewhere (i.e: in the RX buffer).
48struct msg_t
49{
51 void* payload; // unknown type until we parse the header.
52 uint8_t& checksum;
53
54 // Custom reference-only constructor that refers to data in existing
55 // memory locations.
59
60 // (Inline) Member functions:
62 {return header.has_timestamp();}
63
65 {return header.payload_length();}
66};
67
69{
70 uint32_t& timestamp_sec;
71 uint16_t& timestamp_usec;
72
73 // Custom reference-only constructor that refers to data in existing
74 // memory locations.
81};
82
83#endif // HARP_MESSAGE_H
msg_type_t
Definition harp_message.h:8
@ READ_ERROR
Definition harp_message.h:12
@ EVENT
Definition harp_message.h:11
@ WRITE
Definition harp_message.h:10
@ WRITE_ERROR
Definition harp_message.h:13
@ READ
Definition harp_message.h:9
reg_type_t
Definition reg_types.h:11
#define HAS_TIMESTAMP
Definition reg_types.h:7
Definition harp_message.h:21
uint8_t checksum_index_offset()
Definition harp_message.h:38
bool has_timestamp()
Definition harp_message.h:29
uint8_t payload_length()
Definition harp_message.h:32
uint8_t payload_base_index_offset()
Definition harp_message.h:35
uint8_t port
Definition harp_message.h:25
uint8_t address
Definition harp_message.h:24
msg_type_t type
Definition harp_message.h:22
uint8_t raw_length
Definition harp_message.h:23
reg_type_t payload_type
Definition harp_message.h:26
uint8_t msg_size()
Definition harp_message.h:41
Definition harp_message.h:49
uint8_t payload_length()
Definition harp_message.h:64
bool has_timestamp()
Definition harp_message.h:61
void * payload
Definition harp_message.h:51
msg_t(msg_header_t &header, void *payload, uint8_t &checksum)
Definition harp_message.h:56
msg_header_t & header
Definition harp_message.h:50
uint8_t & checksum
Definition harp_message.h:52
Definition harp_message.h:69
uint32_t & timestamp_sec
Definition harp_message.h:70
timestamped_msg_t(msg_header_t &header, uint32_t &timestamp_sec, uint16_t &timestamp_usec, void *payload, uint8_t &checksum)
Definition harp_message.h:75
uint16_t & timestamp_usec
Definition harp_message.h:71