forked from Churrosoft/OpenEFI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfazSerial.cpp
More file actions
126 lines (112 loc) · 2.34 KB
/
interfazSerial.cpp
File metadata and controls
126 lines (112 loc) · 2.34 KB
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
125
126
//el uso de esta libreria esta definido en el archivo .h
#include "interfazSerial.h"
interfazSerial::interfazSerial(byte d){
if(d == 2){
Serial.begin(11520);
}
Serial.begin(11520);
}
void interfazSerial::Enviar(byte code, String SubCode, String msg){
//este void caza todo, crea el mensaje y lo manda
temp = "";
temp += code;
temp += SubCode;
temp += msg;
Serial.println(temp);
}
void interfazSerial::Enviar(byte code, String SubCode, int msg) {
//este void caza todo, crea el mensaje y lo manda
temp = "";
temp += code;
temp += SubCode;
temp += msg;
Serial.println(temp);
}
int interfazSerial::Getcode(){
if (_msg) {
temp = msg;
temp.remove(3, 20);
//devuelvo codigo del ultimo mensaje recibido
return temp.toInt();
}
return -1;
}
String interfazSerial::GetSubCode(){
//devuelvo subcodigo del ultimo mensaje recibido
if (_msg) {
temp = msg;
temp.remove(0, 3);
temp.remove(4, 20);
return temp;
}
return "-1";
}
String interfazSerial::GetMSG(){
//devuelvo la info del ultimo mensaje
if (_msg) {
temp = msg;
temp.remove(0, 5);
return temp;
}
return "-1";
}
int interfazSerial::GetMSG_int() {
//devuelvo la info del ultimo mensaje
if (_msg) {
temp = msg;
temp.remove(0, 5);
return temp.toInt();
}
return -1;
}
void interfazSerial::loop(){
//loop para actualizar mensajes en cola
while (Serial.available()) {
char _T = (char)Serial.read();
msg += _T;
if (_T == '\n') {
_msg = true;
}
}
}
bool interfazSerial::MSG(){
return _msg;
}
void interfazSerial::MSG(bool op){
_msg = op;
}
bool interfazSerial::FXMD(bool val){
if (msg) {
if (interfazSerial::Getcode() == 004) {
if (interfazSerial::GetSubCode().startsWith("FXM_E")) {
return true;
}
if (interfazSerial::GetSubCode().startsWith("FXM_D")) {
return false;
}
}
}
return val;
}
int interfazSerial::FXMD(bool mode, int val) {
if (_msg) {
String temp2 = "";
if (interfazSerial::Getcode() == 004) {
if (interfazSerial::GetSubCode().startsWith("FXM_A")) {
if (!mode) {
//solo convierto el valor y retorno cuando corresponda
_msg = false;
return interfazSerial::GetMSG_int();
}
}
if (interfazSerial::GetSubCode().startsWith("FXM_I")) {
if (mode) {
//solo convierto el valor y retorno cuando corresponda
_msg = false;
return interfazSerial::GetMSG_int();
}
}
}
}
return val;
}