Add ability to send in debugger module

This commit is contained in:
redfast00 2022-01-17 18:52:39 +01:00
parent 7c65a3a8f0
commit ccfcea08b1
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
2 changed files with 31 additions and 14 deletions

View file

@ -6,6 +6,7 @@ from datetime import datetime
import serial
import uuid
from collections import deque
import sys
app = Flask(__name__)
@ -108,16 +109,16 @@ class Message:
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:
line = ser.readline()
print(line.decode('ascii'))
if line.startswith(b"message"):
line = line.decode('ascii')
line = line.strip()
parts = line.split(' ')
sender = int(parts[1])
message = bytes(int(p) for p in parts[2:])
print(line)
if len(line) == 12:
if line == b'BEGIN START\n':
continue
sender = int(line[0] << 8 + line[1])
size = int(line[2])
message = line[3:3+size]
received = Message(message, sender, datetime.now(), len(shared_data.messages))
shared_data.messages.append(received.serialize())
shared_data.last_message_index += 1

View file

@ -8,7 +8,7 @@ void setup() {
mcp2515.setBitrate(CAN_50KBPS);
mcp2515.setNormalMode();
for (int i = 0; i < 5; i++) {
Serial.println("begin");
Serial.print("BEGIN START\n"); // 11 bytes plus newline
delay(1000);
}
}
@ -16,12 +16,28 @@ void setup() {
void loop() {
struct can_frame receive_frame;
if (mcp2515.readMessage(&receive_frame) == MCP2515::ERROR_OK) {
Serial.print("message ");
Serial.print(receive_frame.can_id, DEC);
Serial.write((byte) (receive_frame.can_id >> 8));
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++) {
Serial.print(" ");
Serial.print(receive_frame.data[i], DEC);
Serial.write((byte) receive_frame.data[i]);
}
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);
}
}