-
Notifications
You must be signed in to change notification settings - Fork 0
/
EngineProtocol.h
92 lines (74 loc) · 2.17 KB
/
EngineProtocol.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
#pragma once
#define response_length 80
#include "arduino.h"
#include "Message.h"
#include "SoftwareSerial.h"
#define COMM_HARDWARE_0 1
#define COMM_HARDWARE_1 2
#define COMM_HARDWARE_2 4
#define COMM_HARDWARE_3 8
class Engine{
private:
//setup
char* m_address;
//timing
long m_current_time;
long m_last_time;
//communication
char m_response_0[response_length + 1];
int m_response_0_current_byte;
SoftwareSerial* m_comm_1;
uint8_t m_comms_enabled;
char m_response_1[response_length + 1];
int m_response_1_current_byte;
#ifdef __AVR_ATmega1280__
char m_response_2[response_length + 1];
int m_response_2_current_byte;
char m_response_3[response_length + 1];
int m_response_3_current_byte;
char m_response_4[response_length + 1];
int m_response_4_current_byte;
#endif // __AVR_ATmega1280__
//process commands
void (*m_processMessage)(char flags, String address_from, char type,char sub_type,String data);
void blinckLed();
void readComm0();
void readComm1();
#ifdef __AVR_ATmega1280__
void readComm2();
void readComm3();
void readComm4();
#endif //__AVR_ATmega1280__
void processSerialCommand(String command, uint8_t from_comm_port);
void sendACK(String message, uint8_t to_comm_port);
//Message queue
#define MESSAGE_QUEUE_SIZE 10
Message m_message_queue[MESSAGE_QUEUE_SIZE];
bool enqueMessage(String m);
void checkForResend(long time);
void ACKArrived(String message);
void resend(String m);
//codes
// 0 = normal
// 1 = continue
// 3 = break
char addToBuffer(char byte,uint8_t comm_port);
public:
Engine(char address[4]);
~Engine(void){}
bool isCommEnabled(uint8_t flag_serial_comm);
void setVirtualCommPort(SoftwareSerial* comm_1){
m_comm_1 = comm_1;
}
void enableHardWareCommPort(uint8_t flags){
m_comms_enabled = flags;
}
void transmitMessage(String message, uint8_t from_comm_port);
void setMessageProcessingFuction(void (*processMessage)(char flags, String address_from, char type,char sub_type,String data)){
m_processMessage = processMessage;
}
void sendMessage(String m);
void run();
void setup();
bool repeatWithPeriod(int period_millis);
};