Skip to content

Commit 79aaeb8

Browse files
committed
Elimino el bug que hacía que hubiera un byte inválido entre lecturas.
Se agrega el id de puerto en la respuesta (otro bug). Modifico el poc para que muestre la cantidad de operaciones que puede realizar con una configuración básica. En mi sistema obtuve más de alrededor de 5k de operaciones, por lo que estamos bastante bien! Igual, voy a realizar un test que haga reportar a todos los puertos analógicos y que actúe sobre más puertos.
1 parent 0874e90 commit 79aaeb8

File tree

3 files changed

+35
-14
lines changed

3 files changed

+35
-14
lines changed

MLC/arduino/Firmware/Firmware.ino

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

2-
#define DEBUG 1
3-
4-
#ifdef DEBUG
2+
#define DEBUG 0
3+
#if DEBUG
54
#define LOG(x,y) Serial.print(x); Serial.println(y);
5+
#else
6+
#define LOG(x,y)
67
#endif
78

89
// defines ahorran ROM... aunque nos sobra de eso XD -- Verificar que los const vayan a la rom!
@@ -140,34 +141,36 @@ int actuate(const char* data)
140141
byte len = 1; // Inicia en 1 para evitar pisar el id de comando
141142
for (int i = 1; i <= byte(INPUT_PORTS[0]); i++)
142143
{
144+
response[len + 1] = INPUT_PORTS[i];
143145
if ( INPUT_PORTS[i] >= A0 )
144146
{
145147
int data = analogRead(INPUT_PORTS[i]-A0);
146-
response[len + 1] = byte((data & 0xFF00) >> 8); // Se guarda el msb en el buffer
147-
response[len + 2] = byte(data & 0xFF); // Se guarda el lsb en el buffer
148+
response[len + 2] = byte((data & 0xFF00) >> 8); // Se guarda el msb en el buffer
149+
response[len + 3] = byte(data & 0xFF); // Se guarda el lsb en el buffer
148150

149-
len += 2; // Cada lectura de un recurso analógico ocupa dos bytes. FIXME: se puede optimizar con bajas resoluciones
151+
len += 3; // Cada lectura de un recurso analógico ocupa dos bytes. FIXME: se puede optimizar con bajas resoluciones
150152
LOG("Analog pin read: ", INPUT_PORTS[i]);
151153
} else
152154
{
153155
int data = digitalRead(INPUT_PORTS[i]);
154-
response[len + 1] = byte(data);
155-
156-
len += 1;
156+
response[len + 2] = byte(data);
157+
len += 2;
157158
LOG("Digital pin read: ", INPUT_PORTS[i]);
158159
}
159-
}
160+
};
161+
160162

163+
LOG("Reporting actuate results ", len - 1);
161164
response[1] = len - 1;
162-
SerialUSB.write(response, len + 2); // 2 bytes extras por el id de comando y la longitud
165+
SerialUSB.write(response, len + 1); // 2 bytes extras por el id de comando y la longitud y -1 por el padding
163166

164167
return offset + 2;
165168
}
166169

167170
void setup() {
168171
SerialUSB.begin(115200);
169172

170-
#ifdef DEBUG
173+
#if DEBUG
171174
Serial.begin(115200);
172175
#endif
173176

MLC/arduino/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def actuate(self, data):
107107
raise Exception("Actuate error. Code: %s" % response)
108108

109109
if response <> _PROTOCOL_CMDS["ACTUATE_REPORT"]:
110-
raise Exception("Actuate error. Unknown response %s after actuate operation" % response)
110+
raise Exception("Actuate error. Unknown response %s after actuate operation" % ord(response))
111111

112112
length = ord(self._connection.recv(1))
113113
data = self._connection.recv(length)

tests/pocs/test_connection.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,31 @@
33
from MLC.arduino.protocol import ArduinoInterface
44
from MLC.arduino import boards
55
import sys
6+
import time
67

78
def actuate(terminal):
89
connection = SerialConnection(port=terminal)
910
arduinoDue = ArduinoInterface(connection, boards.Due)
1011

1112
arduinoDue.add_output(40)
12-
arduinoDue.actuate([(40,1)])
13+
arduinoDue.add_input(64)
14+
15+
last_time = time.time()
16+
start_time = last_time
17+
read_c = 0
18+
19+
for i in range(0, 100000):
20+
arduinoDue.actuate([(40,1)])
21+
read_c = read_c + 1
22+
new_time = time.time()
23+
24+
if (new_time - start_time) > 1:
25+
print str(read_c-1) # The current read was out of the period
26+
read_c = 1
27+
start_time = new_time
28+
29+
last_time = new_time
30+
1331

1432
if __name__ == "__main__":
1533
if (len(sys.argv) < 2):

0 commit comments

Comments
 (0)