Skip to content

Commit 21cad55

Browse files
committed
started receive part of multicasting
1 parent ebd4d0c commit 21cad55

File tree

4 files changed

+206
-40
lines changed

4 files changed

+206
-40
lines changed

lib/interfaces/src/VCREthernetInterface.cpp

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,53 +19,87 @@ hytech_msgs_VCRSystemData_s VCREthernetInterface::make_vcrsystemdata_msg(const V
1919
out.pedals_system_data.brake_percent;
2020
out.pedals_system_data.regen_percent;
2121

22-
out.rear_loadcells_filtered = {shared_state.pedals_system_data.accel_is_implausible,
22+
out.pedals_system_data = {shared_state.pedals_system_data.accel_is_implausible,
2323
shared_state.pedals_system_data.brake_is_implausible,
2424
shared_state.pedals_system_data.brake_is_pressed,
2525
shared_state.pedals_system_data.accel_is_pressed,
2626
shared_state.pedals_system_data.mech_brake_is_active,
2727
shared_state.pedals_system_data.brake_and_accel_pressed_implausibility_high,
2828
shared_state.pedals_system_data.implausibility_has_exceeded_max_duration,
29-
shared_state.pedals_system_accel_percent,
29+
shared_state.pedals_system_data.accel_percent,
3030
shared_state.pedals_system_data.brake_percent,
3131
shared_state.pedals_system_data.regen_percent};
3232

3333

34-
//FrontLoadCellsFiltered_s
35-
out.front_loadcells_filtered.FL_loadcell_filtered_pounds;
36-
out.front_loadcells_filtered.FR_loadcell_filtered_pounds;
37-
out.front_loadcells_filtered.front_loadcell_FIR_is_saturated;
34+
//DashInputState_s
35+
36+
out.dash_input_state.dim_btn_is_pressed;
37+
out.dash_input_state.preset_btn_is_pressed;
38+
out.dash_input_state.mc_reset_btn_is_pressed;
39+
out.dash_input_state.mode_btn_is_pressed;
40+
out.dash_input_state.start_btn_is_pressed;
41+
out.dash_input_state.data_btn_is_pressed;
42+
out.dash_input_state.left_paddle_is_pressed;
43+
out.dash_input_state.right_paddle_is_pressed;
44+
out.dash_input_state.dial_state;
45+
46+
3847

39-
out.front_loadcells_filtered = {shared_state.front_loadcells_filtered.FL_loadcell_filtered_pounds,
40-
shared_state.front_loadcells_filtered.FR_loadcell_filtered_pounds,
41-
shared_state.front_loadcells_filtered.front_loadcell_FIR_is_saturated};
48+
out.dash_input_state = {shared_state.dash_input_state.dim_btn_is_pressed,
49+
shared_state.dash_input_state.preset_btn_is_pressed,
50+
shared_state.dash_input_state.mc_reset_btn_is_pressed,
51+
shared_state.dash_input_state.mode_btn_is_pressed,
52+
shared_state.dash_input_state.start_btn_is_pressed,
53+
shared_state.dash_input_state.data_btn_is_pressed,
54+
shared_state.dash_input_state.left_paddle_is_pressed,
55+
shared_state.dash_input_state.right_paddle_is_pressed,
56+
shared_state.dash_input_state.dial_state};
4257

4358

4459

45-
//FrontSusPotsFiltered_s
46-
out.front_suspots_filtered.FL_sus_pot_filtered_analog;
47-
out.front_suspots_filtered.FR_sus_pot_filtered_analog;
48-
out.front_suspots_filtered.front_loadcell_FIR_is_saturated;
60+
//DrivetrainDynamicReport_s
4961

50-
out.front_suspots_filtered = {shared_state.front_suspots_filtered.FL_sus_pot_filtered_analog,
51-
shared_state.front_suspots_filtered.FR_sus_pot_filtered_analog,
52-
shared_state.front_suspots_filtered.front_loadcell_FIR_is_saturated};
5362

5463

55-
//SteeringFiltered_s
56-
out.steering_filtered.steering_filtered_degrees;
57-
out.steering_filtered.steering_FIR_is_saturated;
64+
out.drivetrain_data.measuredInverterFLPackVoltage;
65+
out.drivetrain_data.measuredSpeeds[4];
66+
out.drivetrain_data.measuredTorques[4];
67+
out.drivetrain_data.measuredTorqueCurrents[4];
68+
out.drivetrain_data.measuredMagnetizingCurrents[4];
69+
5870

59-
out.steering_filtered = {shared_state.steering_filtered.steering_filtered_degrees,
60-
shared_state.steering_filtered.steering_FIR_is_saturated};
71+
out.drivetrain_data = {shared_state.drivetrain_data.measuredInverterFLPackVoltage,
72+
shared_state.drivetrain_data.measuredSpeeds[4],
73+
shared_state.drivetrain_data.measuredTorques[4],
74+
shared_state.drivetrain_data.measuredTorqueCurrents[4],
75+
shared_state.drivetrain_data.measuredMagnetizingCurrents[4]};
76+
77+
78+
//AMSSystemData_s
79+
out.ams_data.min_cell_voltage;
80+
out.ams_data.average_cell_voltage;
81+
out.ams_data.max_cell_voltage;
82+
out.ams_data.min_temp;
83+
out.ams_data.average_temp;
84+
out.ams_data.max_temp;
85+
86+
out.ams_data = {shared_state.ams_data.min_cell_voltage,
87+
shared_state.ams_data.average_cell_voltage,
88+
shared_state.ams_data.max_cell_voltage,
89+
shared_state.ams_data.min_temp,
90+
shared_state.ams_data.average_temp,
91+
shared_state.ams_data.max_temp};
6192

6293

6394
//DashDisplayState_s
64-
out.dash_display.dash_data;
65-
out.dash_display = {shared_state.dash_display.dash_data};
95+
out.buzzer_is_active = shared_state.buzzer_is_active;
96+
6697

6798
return out;
6899

100+
/* EXAMPLE UPDATED 02/04/2025 */
101+
/* WILL NOT UPDATE FUNCTIONS PAST THIS POINT */
102+
69103
}
70104

71105
hytech_msgs_VCRInterfaceData_s VCREthernetInterface::make_vcrinterfacedata_msg(const VCRInterfaceData_s &shared_state)

platformio.ini

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
; HT09 VCR PlatformIO configuration file.
1+
; HT09 VCF PlatformIO configuration file.
22
;
33
; Please visit documentation for the other options and examples
44
; https://docs.platformio.org/page/projectconf.html
55

66
[common]
77
lib_deps_shared =
8-
Nanopb
9-
https://github.com/hytech-racing/shared_firmware_systems.git
10-
https://github.com/hytech-racing/shared_firmware_types
11-
https://github.com/ssilverman/QNEthernet#v0.26.0
8+
https://github.com/hytech-racing/shared_firmware_systems.git#af96a63
9+
https://github.com/hytech-racing/shared_firmware_types.git#
10+
1211
https://github.com/hytech-racing/HT_SCHED
13-
https://github.com/hytech-racing/HT_proto/releases/download/2024-10-20T18_54_37/hytech_msgs_pb_lib.tar.gz
14-
Embedded Template Library@^20.39.4
1512

1613
; Teensy41 Environment. This environment is the primary environment for uploading code to the car.
1714
; * Build to verify the on-car software.
@@ -24,10 +21,16 @@ check_flags =
2421
check_severity = medium, high
2522
test_framework=googletest
2623
build_unflags = -std=gnu++11
24+
build_src_filter =
25+
+<test_ethernet_main.cpp>
2726
build_flags =
2827
-std=c++17
2928
-D TEENSY_OPT_SMALLEST_CODE
30-
29+
check_src_filters =
30+
+<include/*>
31+
+<lib/*>
32+
+<src/*>
33+
-<src/old_main.cpp>
3134

3235
platform = teensy
3336
board = teensy41
@@ -39,8 +42,8 @@ test_ignore =
3942
test_systems
4043
lib_deps =
4144
${common.lib_deps_shared}
45+
https://github.com/ssilverman/QNEthernet#v0.26.0
4246
https://github.com/hytech-racing/shared_firmware_interfaces.git
43-
4447

4548
; Test Systems Environment. This is only for compiling and uploading the hardware-abstracted code.
4649
; * BUILD to verify the SYSTEMS compile.
@@ -49,13 +52,10 @@ lib_deps =
4952
[env:test_systems_env]
5053
platform = native
5154
test_framework = googletest
52-
; test_build_src = yes
5355
build_src_filter =
54-
-<VCR_Globals.cpp>
55-
-<VCR_Tasks.cpp>
56-
-<main.cpp>
57-
+<VCR_Constants.cpp>
58-
+<../test/test_systems/test_systems.cpp>
56+
-<**/*.c>
57+
-<**/*.cpp>
58+
5959
build_unflags = -std=gnu++11
6060
build_flags =
6161
-std=c++17
@@ -65,5 +65,36 @@ lib_ignore =
6565
test_ignore=
6666
test_interfaces*
6767
lib_deps =
68-
google/googletest@^1.15.2
69-
${common.lib_deps_shared}
68+
${common.lib_deps_shared}
69+
70+
[env:ethernet_testing]
71+
check_tool = clangtidy
72+
check_flags =
73+
clangtidy: --config-file=./.clang-tidy
74+
check_severity = medium, high
75+
test_framework=googletest
76+
build_unflags = -std=gnu++11
77+
build_flags =
78+
-std=c++17
79+
-D TEENSY_OPT_SMALLEST_CODE
80+
check_src_filters =
81+
+<include/*>
82+
+<lib/*>
83+
+<src/*>
84+
-<src/old_main.cpp>
85+
build_src_filter =
86+
-<main.cpp>
87+
+<test_ethernet_main.cpp>
88+
platform = teensy
89+
board = teensy41
90+
framework = arduino
91+
monitor_speed = 115200
92+
upload_protocol = teensy-cli
93+
test_ignore =
94+
test_interfaces
95+
test_systems
96+
lib_deps =
97+
${common.lib_deps_shared}
98+
https://github.com/ssilverman/QNEthernet#v0.26.0
99+
https://github.com/hytech-racing/shared_firmware_interfaces.git
100+

src/test_ethernet_main.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include <Arduino.h>
2+
#include <cstdint>
3+
#include <QNEthernet.h>
4+
5+
#include <array>
6+
#include <cstring>
7+
8+
using namespace qindesign::network;
9+
EthernetUDP socket;
10+
//EthernetUDP recv_socket;
11+
// ParameterInterface params = ParameterInterface();
12+
// ETHInterfaces ethernet_interfaces = {&params};
13+
14+
const IPAddress default_VCR_ip(192, 168, 1, 30);
15+
//const IPAddress default_PC_ip(192, 168, 1, 31);
16+
const IPAddress multicast_ip1(239, 1, 1, 1); // First multicast group
17+
const IPAddress multicast_ip2(239, 1, 1, 2); // Second multicast group
18+
const IPAddress default_dns(192, 168, 1, 1);
19+
const IPAddress default_gateway(192, 168, 1, 1);
20+
const IPAddress car_subnet(255, 255, 255, 0);
21+
uint16_t my_port = 5555;
22+
23+
// uint8_t default_MCU_MAC_address[6] =
24+
// {0x04, 0xe9, 0xe5, 0x10, 0x1f, 0x22};
25+
26+
void init_ethernet_device()
27+
{
28+
Ethernet.begin(default_VCR_ip, default_dns, default_gateway, car_subnet);
29+
30+
//for receiving
31+
socket.begin(my_port); //binds socket to specific port
32+
Ethernet.joinGroup(multicast_ip1);
33+
Ethernet.joinGroup(multicast_ip2);
34+
35+
//can also call this several times for each ip address beginMulticast(ip, port)
36+
//send_socket.begin(4444);
37+
//recv_socket.begin(5555);
38+
}
39+
40+
void test_ethernet()
41+
{
42+
/*
43+
int packet_size = recv_socket.parsePacket();
44+
if (packet_size > 0)
45+
{
46+
float read_float;
47+
// uint8_t buffer[4];
48+
std::array<uint8_t, 4> buffer;
49+
recv_socket.read(buffer.data(), sizeof(float));
50+
51+
// read_float = buffer[0] | buffer[1]
52+
memcpy(&read_float, buffer.data(), sizeof(float));
53+
Serial.print("got float: ");
54+
Serial.println(read_float);
55+
}
56+
float send_float = 6969.2;
57+
std::array<uint8_t, 4> data;
58+
memcpy(data.data(), &send_float, sizeof(float));
59+
send_socket.send(default_PC_ip, 4444, data.data(), sizeof(float));
60+
*/
61+
62+
//will receive any messages sent from another device to the given IP addresses
63+
64+
int packet_size = socket.parsePacket();
65+
if (packet_size > 0) {
66+
float read_float;
67+
std::array<uint8_t, 4> buffer;
68+
IPAddress sender_ip = socket.remoteIP();
69+
socket.read(buffer.data(), sizeof(float));
70+
memcpy(&read_float, buffer.data(), sizeof(float));
71+
72+
Serial.print("Received multicast float: ");
73+
Serial.print(read_float);
74+
Serial.print(" from ");
75+
Serial.println(sender_ip);
76+
}
77+
}
78+
79+
void setup()
80+
{
81+
init_ethernet_device();
82+
}
83+
84+
void loop()
85+
{
86+
test_ethernet();
87+
Serial.println("loopin");
88+
}

test/test_scripts/receive.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import socket
2+
import struct
3+
4+
MCAST_GRP = '239.1.1.1' # Multicast IP matching the Teensy's group
5+
MCAST_PORT = 5000 # Port matching the Teensy's receiver
6+
7+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
8+
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
9+
10+
# Send a float value
11+
import struct
12+
data = struct.pack('f', 42.42) # Convert float to bytes
13+
sock.sendto(data, (MCAST_GRP, MCAST_PORT))

0 commit comments

Comments
 (0)