Skip to content

Commit

Permalink
more jank testing
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtzhang committed Dec 1, 2024
1 parent 44eac12 commit d4bd0f3
Show file tree
Hide file tree
Showing 9 changed files with 591,269 additions and 147 deletions.
2,349 changes: 2,246 additions & 103 deletions Ethernet.ipynb

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions include/InterfaceParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ namespace EthParams
{
uint8_t default_MCU_MAC_address[6] =
{0x04, 0xe9, 0xe5, 0x10, 0x1f, 0x22};
uint8_t default_VCR_MAC_address[6] =
{0x04, 0xe9, 0xe5, 0x10, 0x1f, 0x23};

const IPAddress default_MCU_ip(192, 168, 1, 30);
const IPAddress default_VCR_ip(192, 168, 1, 37);
const IPAddress default_TCU_ip(192, 168, 1, 69);

const uint16_t default_protobuf_send_port = 2001;
Expand Down
86 changes: 86 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,92 @@ lib_deps =
https://github.com/RCMast3r/hytech_can#testing_new_inv_ids
https://github.com/hytech-racing/HT_CAN/releases/download/127/can_lib.tar.gz

[env:teensy41_eth_udp_tx]
; Testing variables
test_framework=unity
test_ignore=test_systems*
lib_ignore =
mock_interfaces
mock_systems


; including only the current main file for compiling to keep old main still around for now while
; refactoring
build_src_filter =
-<**/*.cpp>
+<ethtest_udp_tx.cpp>
build_unflags = -std=gnu++11
build_flags =
-std=c++17
-D TEENSY_OPT_SMALLEST_CODE
; -D ENABLE_DEBUG_PRINTS
check_tool = clangtidy
check_src_filters =
+<include/*>
+<lib/*>
+<src/*>
-<src/old_main.cpp>

platform = teensy
board = teensy41
framework = arduino
monitor_speed = 115200
upload_protocol = teensy-cli
extra_scripts = pre:extra_script.py
lib_deps =
${common.lib_deps_shared}
Nanopb
SPI
https://github.com/hytech-racing/shared_firmware_interfaces.git#shared_types
https://github.com/tonton81/FlexCAN_T4
https://github.com/ssilverman/QNEthernet#v0.26.0
https://github.com/RCMast3r/hytech_can#testing_new_inv_ids
https://github.com/hytech-racing/HT_CAN/releases/download/127/can_lib.tar.gz


[env:teensy41_eth_udp_rx]
; Testing variables
test_framework=unity
test_ignore=test_systems*
lib_ignore =
mock_interfaces
mock_systems


; including only the current main file for compiling to keep old main still around for now while
; refactoring
build_src_filter =
-<**/*.cpp>
+<ethtest_udp_rx.cpp>
build_unflags = -std=gnu++11
build_flags =
-std=c++17
-D TEENSY_OPT_SMALLEST_CODE
; -D ENABLE_DEBUG_PRINTS
check_tool = clangtidy
check_src_filters =
+<include/*>
+<lib/*>
+<src/*>
-<src/old_main.cpp>

platform = teensy
board = teensy41
framework = arduino
monitor_speed = 115200
upload_protocol = teensy-cli
extra_scripts = pre:extra_script.py
lib_deps =
${common.lib_deps_shared}
Nanopb
SPI
https://github.com/hytech-racing/shared_firmware_interfaces.git#shared_types
https://github.com/tonton81/FlexCAN_T4
https://github.com/ssilverman/QNEthernet#v0.26.0
https://github.com/RCMast3r/hytech_can#testing_new_inv_ids
https://github.com/hytech-racing/HT_CAN/releases/download/127/can_lib.tar.gz


[env:test_can_on_teensy]
lib_ignore =
mock_interfaces
Expand Down
16 changes: 16 additions & 0 deletions src/ethtest_raw_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ void runTests() {
send_timer.reset(); // Reset the timer
testnum++;
}
/*
const int intervals[] = {10, 15, 20, 25, 30, 40, 50, 100, 150, 200, 300, 400, 500, 1000};
if (testnum < sizeof(intervals) / sizeof(intervals[0]) && done)
{
frameSize = 50; // Set the current test frame size
numFrames = 10000; // Set the number of frames to send
send_timer.interval(intervals[testnum]); // Set 200 microseconds interval
framesSent = 0; // Reset the number of frames sent
done = 0;
Serial.printf("Running test with interval: %d us\n", intervals[testnum]);
send_timer.reset(); // Reset the timer
testnum++;
}
*/
}

void readSerial() {
Expand Down
27 changes: 9 additions & 18 deletions src/ethtest_udp_rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QNEthernet.h>

#include "ethtest.h"
#include "InterfaceParams.h"

using namespace qindesign::network;

Expand All @@ -14,6 +15,8 @@ unsigned char src[] = {0x0, 0xe0, 0x4c, 0xef, 0xf8, 0x6};
// Custom EtherType constant
constexpr uint16_t kCustomEtherType = 0x8001;

EthernetUDP socket(256);

// Main program setup.
void setup()
{
Expand Down Expand Up @@ -63,29 +66,17 @@ void setup()
// Initialize Ethernet
printf("Starting Ethernet%s...\r\n",
Ethernet.isDHCPEnabled() ? " with DHCP" : "");
if (!Ethernet.begin())
{
printf("Failed to start Ethernet\r\n");
return;
}
EthernetFrame.setReceiveQueueSize(256);
Ethernet.begin(EthParams::default_VCR_MAC_address,EthParams::default_VCR_ip);
socket.beginWithReuse(2000);
}

void readFrame()
{

int size = EthernetFrame.parseFrame();
if (size <= 0)
{
return; // No frame received
int packetSize = socket.parsePacket();
if (packetSize >= 0) { // non_negative_value >= 0
digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN) ? 0 : 1);
socket.send(EthParams::default_MCU_ip, 2000, socket.data(), packetSize);
}

// Access the frame's data directly
const uint8_t *buf = EthernetFrame.data();

// Retransmit the frame
digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN) ? 0 : 1);
EthernetFrame.send(buf, size);
}

// Main program loop.
Expand Down
66 changes: 40 additions & 26 deletions src/ethtest_udp_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,28 @@
#include <QNEthernet.h>
#include "MicroMetro.h"
#include "ethtest.h"
#include "InterfaceParams.h"

using namespace qindesign::network;

unsigned char src[] = {0x0, 0xe0, 0x4c, 0xef, 0xf8, 0x6};

EthernetUDP socket(256);

// Custom EtherType constant
constexpr uint16_t kCustomEtherType = 0x8001;
uint32_t counter;
EthernetPacket frame;
DataPacket data, rx_data;
int numFrames, framesSent, delayus, frameSize;
int done = 1;
unsigned int testnum=999;
MicroMetro send_timer(100);
int total_rx_time, total_tx_time;

// Main program setup.
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
while (!Serial && millis() < 4000)
{
Expand Down Expand Up @@ -68,18 +73,11 @@ void setup()
// Initialize Ethernet
printf("Starting Ethernet%s...\r\n",
Ethernet.isDHCPEnabled() ? " with DHCP" : "");
if (!Ethernet.begin())
{
printf("Failed to start Ethernet\r\n");
return;
}
EthernetFrame.setReceiveQueueSize(256);
Ethernet.begin(EthParams::default_MCU_MAC_address ,EthParams::default_MCU_ip);
socket.beginWithReuse(2000);

const uint8_t destinationMAC[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
const uint8_t sourceMAC[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01};
memcpy(frame.destinationMAC, destinationMAC, 6);
memcpy(frame.sourceMAC, sourceMAC, 6);
reverseEndianMemcpy(&(frame.ethertype), &kCustomEtherType, 2);
frameSize = 64; // Default frame size
}

Expand All @@ -88,34 +86,34 @@ void sendFrames()
{
while (framesSent < numFrames && send_timer.check())
{
int startTime = micros();
// Get the current time in microseconds
frame.data.timestamp = (uint32_t) micros();
frame.data.counter = counter++;
EthernetFrame.send((const uint8_t *)&frame, 14 + frameSize);
data.timestamp = (uint32_t) micros();
data.counter = counter++;
socket.send((EthParams::default_VCR_ip), (uint16_t) 2000, (const uint8_t*)&data, (size_t) frameSize);
framesSent++;
total_tx_time += micros() - startTime;
if (framesSent == numFrames)
{
Serial.printf("Done\n");
done = 1;
Serial.printf("Total Tx time: %d us, Total Rx time: %d us\n", total_tx_time, total_rx_time);
total_tx_time = 0;
total_rx_time = 0;
}
}
}

void readFrames()
{
int size = EthernetFrame.parseFrame();
if (size <= 0)
{
return;
int startTime = micros();
int packetSize = socket.parsePacket();
if (packetSize >= 0) { // non_negative_value >= 0
digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN) ? 0 : 1);
memcpy(&rx_data, socket.data(), packetSize);
total_rx_time += micros() - startTime;
printf("Frame[%d]: %d us\n", rx_data.counter, micros()-rx_data.timestamp);
}
if (size < EthernetFrame.minFrameLen() - 4)
{
printf("SHORT Frame[%d] \r\n", size);
return;
}

const EthernetPacket *pkt = (const EthernetPacket *) EthernetFrame.data();
printf("Frame[%d]: %d us\n", pkt->data.counter, micros()-pkt->data.timestamp);
}

// Add this new function to run the tests
Expand All @@ -129,14 +127,30 @@ void runTests() {
{
frameSize = sizes[testnum]; // Set the current test frame size
numFrames = 10000; // Set the number of frames to send
send_timer.interval(300); // Set 200 microseconds interval
send_timer.interval(200); // Set 200 microseconds interval
framesSent = 0; // Reset the number of frames sent
done = 0;
Serial.printf("Running test with frame size: %d bytes\n", frameSize);

send_timer.reset(); // Reset the timer
testnum++;
}
/*
const int intervals[] = {10, 15, 20, 25, 30, 40, 50, 100, 150, 200, 300, 400, 500, 1000};
if (testnum < sizeof(intervals) / sizeof(intervals[0]) && done)
{
frameSize = 50; // Set the current test frame size
numFrames = 10000; // Set the number of frames to send
send_timer.interval(intervals[testnum]); // Set 200 microseconds interval
framesSent = 0; // Reset the number of frames sent
done = 0;
Serial.printf("Running test with interval: %d us\n", intervals[testnum]);
send_timer.reset(); // Reset the timer
testnum++;
}
*/
}

void readSerial() {
Expand Down
Loading

0 comments on commit d4bd0f3

Please sign in to comment.