Add ability to send in debugger module
This commit is contained in:
parent
7c65a3a8f0
commit
ccfcea08b1
2 changed files with 31 additions and 14 deletions
|
@ -6,6 +6,7 @@ from datetime import datetime
|
||||||
import serial
|
import serial
|
||||||
import uuid
|
import uuid
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
import sys
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@ -108,16 +109,16 @@ class Message:
|
||||||
|
|
||||||
|
|
||||||
def serial_reader(shared_data):
|
def serial_reader(shared_data):
|
||||||
with serial.Serial('/dev/ttyACM0', 115200, timeout=10) as ser:
|
with serial.Serial('/dev/ttyUSB0', 115200, timeout=10) as ser:
|
||||||
while True:
|
while True:
|
||||||
line = ser.readline()
|
line = ser.readline()
|
||||||
print(line.decode('ascii'))
|
print(line)
|
||||||
if line.startswith(b"message"):
|
if len(line) == 12:
|
||||||
line = line.decode('ascii')
|
if line == b'BEGIN START\n':
|
||||||
line = line.strip()
|
continue
|
||||||
parts = line.split(' ')
|
sender = int(line[0] << 8 + line[1])
|
||||||
sender = int(parts[1])
|
size = int(line[2])
|
||||||
message = bytes(int(p) for p in parts[2:])
|
message = line[3:3+size]
|
||||||
received = Message(message, sender, datetime.now(), len(shared_data.messages))
|
received = Message(message, sender, datetime.now(), len(shared_data.messages))
|
||||||
shared_data.messages.append(received.serialize())
|
shared_data.messages.append(received.serialize())
|
||||||
shared_data.last_message_index += 1
|
shared_data.last_message_index += 1
|
||||||
|
|
|
@ -8,7 +8,7 @@ void setup() {
|
||||||
mcp2515.setBitrate(CAN_50KBPS);
|
mcp2515.setBitrate(CAN_50KBPS);
|
||||||
mcp2515.setNormalMode();
|
mcp2515.setNormalMode();
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
Serial.println("begin");
|
Serial.print("BEGIN START\n"); // 11 bytes plus newline
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,28 @@ void setup() {
|
||||||
void loop() {
|
void loop() {
|
||||||
struct can_frame receive_frame;
|
struct can_frame receive_frame;
|
||||||
if (mcp2515.readMessage(&receive_frame) == MCP2515::ERROR_OK) {
|
if (mcp2515.readMessage(&receive_frame) == MCP2515::ERROR_OK) {
|
||||||
Serial.print("message ");
|
Serial.write((byte) (receive_frame.can_id >> 8));
|
||||||
Serial.print(receive_frame.can_id, DEC);
|
Serial.write((byte) (receive_frame.can_id & 0xff));
|
||||||
|
Serial.write((byte) receive_frame.can_dlc);
|
||||||
for (int i = 0; i < receive_frame.can_dlc; i++) {
|
for (int i = 0; i < receive_frame.can_dlc; i++) {
|
||||||
Serial.print(" ");
|
Serial.write((byte) receive_frame.data[i]);
|
||||||
Serial.print(receive_frame.data[i], DEC);
|
|
||||||
}
|
}
|
||||||
Serial.print("\n");
|
for (int i = 0; i < (8 - receive_frame.can_dlc); i++) {
|
||||||
|
Serial.write('\0');
|
||||||
|
}
|
||||||
|
Serial.write('\n');
|
||||||
|
}
|
||||||
|
if (Serial.available()) {
|
||||||
|
byte readbuffer[12];
|
||||||
|
if ((Serial.readBytes(readbuffer, 12) != 12) || readbuffer[11] != '\n') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct can_frame send_frame;
|
||||||
|
send_frame.can_id = (((uint32_t) readbuffer[0]) << 8) | (readbuffer[1]);
|
||||||
|
send_frame.can_dlc = readbuffer[2];
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
send_frame.data[i] = readbuffer[3+i];
|
||||||
|
}
|
||||||
|
mcp2515.sendMessage(&send_frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue