-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:eagletrt/micro-libs into mcp23017…
…-driver-update
- Loading branch information
Showing
7 changed files
with
485 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "../can_manager.h" | ||
|
||
void consume_primary_rx_queue(can_manager_message_t *msg) { | ||
printf("RECEIVED can: primary, "); | ||
print_message(msg); | ||
} | ||
|
||
void consume_secondary_rx_queue(can_manager_message_t *msg) { | ||
printf("RECEIVED can: secondary, "); | ||
print_message(msg); | ||
} | ||
|
||
int main() { | ||
CAN_HandleTypeDef primary_can_handle; | ||
CAN_HandleTypeDef secondary_can_handle; | ||
primary_can_handle.name = "primary"; | ||
secondary_can_handle.name = "secondary"; | ||
|
||
int can_primary_id = can_init(&primary_can_handle, consume_primary_rx_queue, 0, 0); | ||
int can_secondary_id = can_init(&secondary_can_handle, consume_secondary_rx_queue, 0, 0); | ||
|
||
can_manager_message_t msg1 = {.id = 1, .size = 8, .data = {4, 6, 2, 8, 2, 4, 8, 6}}; | ||
can_manager_message_t msg2 = {.id = 2, .size = 3, .data = {9, 1, 0, 0, 3, 2, 5, 4}}; | ||
can_manager_message_t msg3 = {.id = 3, .size = 7, .data = {8, 2, 3, 4, 5, 6, 7, 1}}; | ||
can_manager_message_t msg4 = {.id = 4, .size = 5, .data = {3, 7, 3, 6, 9, 5, 8, 5}}; | ||
|
||
add_to_tx_queue(can_primary_id, &msg1); | ||
add_to_rx_queue(can_secondary_id, &msg2); | ||
add_to_tx_queue(can_primary_id, &msg3); | ||
add_to_rx_queue(can_secondary_id, &msg4); | ||
|
||
while (consume_rx_queue(can_primary_id)) | ||
; | ||
|
||
printf("sent %d messages primary\n", flush_tx_queue(can_primary_id)); | ||
|
||
while (consume_rx_queue(can_secondary_id)) | ||
; | ||
|
||
printf("sent %d messages secondary\n", flush_tx_queue(can_secondary_id)); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Candump to Serial | ||
|
||
Simple tool to replay old candump log files on mcu via uart. Run [candump_to_serial.py](./candump_to_serial.py) to send data via serial. Regarding the MCU part, please refer to the [example](./candump_to_serial_example.c). Remember only to activate the UART interrupt in CubeMX. | ||
|
||
Authors: | ||
Giacomo Mazzucchi | ||
Antonio Gelain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
""" | ||
# PSEUDOCODE IDEA | ||
producer | ||
open file and serial | ||
for line | ||
parse line | ||
timestamp interface id#content | ||
(0.000000) secondary 4EC#00140000FFFF0000 | ||
send interface, id and content | ||
consumer | ||
while(true) { | ||
riceve interface, id and content | ||
} | ||
""" | ||
|
||
import sys | ||
import serial | ||
import datetime | ||
import time | ||
|
||
DEFAULT_DELAY = 0.1 | ||
|
||
|
||
def delta_us(ctime, ptime): | ||
delta = ctime - ptime | ||
return delta.total_seconds() * 1e6 | ||
|
||
|
||
def send_message(si, mint, mid, mdata): | ||
smsg = 0 if (mint == "primary") else 1 | ||
msg = f"{smsg}&{mid}&{mdata}$".ljust(23, "0") | ||
si.write(str.encode(msg)) | ||
sys.stdout.write(f"Sent message: {str.encode(msg)}\n") | ||
|
||
|
||
if __name__ == "__main__": | ||
argc = len(sys.argv) | ||
if argc < 3: | ||
sys.stderr.write( | ||
"Usage: python3 candump_to_serial.py <candump_file_path> <serial_port>\n" | ||
) | ||
exit(1) | ||
candump_file_path = sys.argv[1] | ||
serial_port = sys.argv[2] | ||
try: | ||
serial_interface = serial.Serial( | ||
port=serial_port, | ||
baudrate=115200, | ||
parity=serial.PARITY_NONE, | ||
stopbits=serial.STOPBITS_ONE, | ||
bytesize=serial.EIGHTBITS, | ||
) | ||
except OSError: | ||
sys.stderr.write(f"Usage: could not open the serial port {serial_port}\n") | ||
exit(1) | ||
try: | ||
candump_file = open(candump_file_path, "r") | ||
except OSError: | ||
sys.stderr.write(f"Could not open/read file: {candump_file_path}\n") | ||
exit(1) | ||
|
||
ptime = datetime.datetime.now() | ||
ploggingtime = datetime.datetime.now() | ||
pdelta = 0 | ||
|
||
with candump_file: | ||
for row in candump_file.readlines(): | ||
message_contents = row.split() | ||
message_delta = float(str.strip(message_contents[0].strip("()"))) | ||
message_interface = message_contents[1] | ||
msg_tmp = str.split(message_contents[2], "#") | ||
message_id = msg_tmp[0] | ||
message_data = msg_tmp[1] | ||
while delta_us(datetime.datetime.now(), ptime) < (message_delta - pdelta): | ||
pass | ||
send_message(serial_interface, message_interface, message_id, message_data) | ||
ptime = datetime.datetime.now() | ||
pdelta += message_delta | ||
time.sleep(DEFAULT_DELAY) | ||
|
Oops, something went wrong.