This repository has been archived by the owner on Oct 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduinocomm.h
66 lines (52 loc) · 1.98 KB
/
arduinocomm.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
//Header guard
#ifndef ARDUINOCOMM_H
#define ARDUINOCOMM_H
#include "Arduino.h"
class Arduinocomm{
private:
static const uint8_t START_DATA = 0x80;
static const uint8_t END_DATA = 0xFF;
void writebyte(uint8_t);
void writeuint16(uint16_t value);
void writeuint32(uint32_t);
uint8_t readbyte(unsigned int position);
static const uint16_t MAX_BUFFER = 25;
uint8_t input_buffer[MAX_BUFFER];
uint8_t temp_buffer[MAX_BUFFER];
uint8_t output_buffer[MAX_BUFFER];
void process();
void writecommand(uint8_t byte);
uint16_t packet_length;
bool reading_packet = false;
uint8_t input_position = 0;
uint8_t input_size = 0;
//void handlepacket(uint8_t (&packet)[MAX_BUFFER], uint8_t);
uint8_t CRC8(const uint8_t *data, uint8_t len, uint8_t start);
uint8_t *bytes = 0;
uint8_t byte_position = 0;
public:
byte debug = 0;
void update();
Arduinocomm();
void write_ok();
void write_line_position(uint16_t position);
//void writeDriveCompleted();
void stop();
void sendcustombyte(uint8_t byte);
uint8_t packet_buffer[MAX_BUFFER];
uint8_t packet_position = 0;
uint8_t packet_size = 0;
bool packet_ready = false;
//uint32_t read_uint32(uint8_t (&packet)[MAX_BUFFER],unsigned int);
//uint16_t read_uint16(uint8_t (&packet)[MAX_BUFFER],unsigned int);
//
//Packet definitions
static const uint8_t OK = 0x01;//Acknowledge packet
static const uint8_t DRIVE = 0x02;//Contains specific engine speeds to be sendt to robot
static const uint8_t DEBUG = 0x03;
static const uint8_t DRIVE_DISTANCE = 0x04;//Drive straight for duration
static const uint8_t DRIVE_COMPLETED = 0x05;//Drive straight for duration
static const uint8_t LINE_POSITION = 0x06;//Drive straight for duration
};
//End header guard
#endif