Add debugging Arduino code

This commit is contained in:
redfast00 2020-08-19 02:10:30 +02:00
parent f37452df46
commit 5d5ad2decd
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C
2 changed files with 39 additions and 5 deletions

View file

@ -3,6 +3,7 @@ from flask import Flask, jsonify, send_file
from time import sleep
from dataclasses import dataclass
from datetime import datetime
import serial
app = Flask(__name__)
shared_message_log = []
@ -78,11 +79,18 @@ class Message:
def serial_reader(messagelog):
while True:
sleep(5)
received = Message(b'\x00' * 8, 0b101000110, datetime.now(), len(messagelog))
messagelog.append(received.serialize())
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:])
received = Message(message, sender, datetime.now(), len(messagelog))
messagelog.append(received.serialize()
@app.route('/')
def index():

View file

@ -0,0 +1,26 @@
#include <mcp2515.h>
MCP2515 mcp2515(10);
void setup() {
Serial.begin(115200);
mcp2515.reset();
mcp2515.setBitrate(CAN_50KBPS);
mcp2515.setNormalMode();
Serial.println("begin");
}
void loop() {
char message[9];
message[8] = '\0';
struct can_frame receive_frame;
if (mcp2515.readMessage(&receive_frame) == MCP2515::ERROR_OK) {
Serial.print("message ");
Serial.print(receive_frame.can_id, DEC);
for (int i = 0; i < 8; i++) {
Serial.print(" ");
Serial.print(receive_frame.data[i], DEC);
}
Serial.print("\n");
}
}