This repository has been archived by the owner on Aug 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
net.h
124 lines (93 loc) · 3.5 KB
/
net.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* net.h
*/
#include "main.h"
#define DATALINK_SEND_FREQUENCY 0.2 //Time in seconds
#define BLOCKING_MODE 0
#define OUTBOUND_QUEUE_SIZE 20
#define INBOUND_QUEUE_SIZE 100
#define MAX_PACKET_SIZE 20
#define EDIT_NONE 0
#define EDIT_PITCH_GAIN 1
#define EDIT_ROLL_GAIN 2
#define EDIT_YAW_GAIN 3
#define API_HEADER_LENGTH 17
#define API_HEADER_PREFIX 3
#define RECEIVER_ADDRESS 0x0013A20040B47E6B
#define INCREMENT_DATA_FRAME 0x00
#define OPTION_BYTE 0x01 //Disables ACK
//FRAME TYPE
#define TX_PACKET 0x10
#define BROADCAST_RADIUS 1 //0 is infinite number of hops to reach target
#define RAW_PACKET_BUFFER_SIZE 16 // Number of buffer regions to allow for incoming commands
#define HEARTBEAT_TIMEOUT 10000 //In Milliseconds
#define GPS_TIMEOUT 30000 //In Milliseconds
#define HEARTBEAT_KILL_TIMEOUT 120000 //In Milliseconds
struct telem_block {
long double lat, lon; // Latitude and longitude from gps // 8Byte
float millis; // Timestamp UTC // 4Byte
float groundSpeed;
int heading;
int lastCommandSent;
unsigned int errorCodes;
char gpsStatus; // 1Byte
char steeringSetpoint;
char throttleSetpoint;
char steeringOutput;
char throttleOutput;
// TODO: Add additional telemetry to be sent here
};
struct telem_buffer {
unsigned int sendIndex; // index into telemetry to send
unsigned char header[API_HEADER_LENGTH]; // The header for the telem
union {
struct telem_block *asStruct; // The telemetry block being sent
unsigned char *asArray; // The telemetry intepreted as an array
} telemetry;
unsigned char checksum; // The checksum so far
};
struct command {
unsigned char cmd;
unsigned char data_length;
unsigned char data[101];
};
// Initialize the data link
int initDataLink(void);
// Create a telemetry block to use for debugging, only creates one instance
struct telem_block *getDebugTelemetryBlock(void);
// Create a telem block returns null if fails
struct telem_block *createTelemetryBlock(void);
// Destroy a dataBlock
void destroyTelemetryBlock(struct telem_block *data);
// Add a telem_block to the outbound data queue
// Returns the position in the queue or -1 if no room in queue
int pushOutboundTelemetryQueue(struct telem_block *data);
// Get the number of items waiting to be sent
int getOutboundQueueLength(void);
// Clear all telem blocks waiting to be sent
int clearOutboundTelemetryQueue(void);
// Pop next telem_block from incoming buffer, null if no data
struct telem_block *popOutboundTelemetryQueue(void);
// generate the header for the a telemetry block
unsigned int generateApiHeader(unsigned char *apiString, char dataFrame);
// Stage the given telemetry block
void stageTelemetryBlock(struct telem_block *telem);
// Do outbound buffer maintenance
void outboundBufferMaintenance(void);
// Send a block of telemetry immediately, probably shouldn't call this directly
int sendTelemetryBlock(struct telem_block *telem);
/****************************************************************************
* Inbound relevant functions
*/
// Clean up the command
void destroyCommand( struct command* cmd );
// Get the next command
struct command* popCommand();
// Queue up another command
int pushCommand(struct command* cmd);
// Create a new command struct
struct command* createCommand( char* rawPacket );
// Check and make sure the char array is a valid packet
int checkPacket( char* rawPacket);
// Handle the inbound buffer
void inboundBufferMaintenance(void);