Skip to content

Feature comms refactor #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 101 commits into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from 99 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
f27ce75
copy paste (mostly) from hive to bring over comms stuff (mostly). doe…
ashleycody345 Jan 11, 2025
039c946
added RobotState data, it compiles now WOOOOO
ashleycody345 Jan 11, 2025
b01360e
comms_layer.cpp prototype, along with RobotState vector struct templa…
ashleycody345 Jan 11, 2025
45cd458
minor changes to include CommsLayer in main (can be reverted, just fo…
ashleycody345 Jan 11, 2025
c263695
integrate comms layer into main loop
ashleycody345 Jan 12, 2025
2b180eb
why did this work??????
ashleycody345 Jan 12, 2025
36e9b8d
Merge remote-tracking branch 'origin/main' into feature-comms-refactor
ashleycody345 Jan 13, 2025
32fa669
packet receiving and managing
ashleycody345 Jan 13, 2025
d2588f7
missed part of invalid packet function
ashleycody345 Jan 13, 2025
02bfb2a
removed EthernetPayload (to be later replaced with internal packet pr…
ashleycody345 Jan 14, 2025
55a20c2
Merge remote-tracking branch 'origin/feature-hot-reload' into feature…
ashleycody345 Jan 14, 2025
f8457d6
Merge remote-tracking branch 'origin/main' into feature-comms-refactor
ashleycody345 Jan 14, 2025
499969e
Merge remote-tracking branch 'origin/main' into feature-comms-refactor
ashleycody345 Jan 18, 2025
e99cc96
removed interfacing with old config layer for ethernet config
ashleycody345 Jan 18, 2025
abd9dd3
renaming and changing types of misc
ashleycody345 Jan 18, 2025
b117160
Merge remote-tracking branch 'origin/main' into feature-comms-refactor
ashleycody345 Jan 26, 2025
f5a2a2c
ngl i dont really rememebr skull ejomi
ashleycody345 Jan 31, 2025
a4de226
cleanup for my own sanity
ashleycody345 Jan 31, 2025
b05df9c
defined send, receive, loop functions
ashleycody345 Feb 1, 2025
3f23541
very simple encode
ashleycody345 Feb 1, 2025
8ef72ba
prototype send and receive for toy string struct
ashleycody345 Feb 1, 2025
2cf31cf
comms layer can send stuff now (!!!)
ashleycody345 Feb 1, 2025
a787cc2
Merge remote-tracking branch 'origin/main' into feature-comms-refactor
ashleycody345 Feb 9, 2025
bc700e0
move over everything from hive (big commit sorry)
ashleycody345 Feb 9, 2025
5b10075
sample data is sent correctly WOOOOOO
ashleycody345 Feb 9, 2025
b2ba351
trying to fix the send errors
ashleycody345 Feb 9, 2025
90f1f19
changes
Pandabear1125 Feb 16, 2025
cfe055b
Fresh slate
Pandabear1125 Feb 16, 2025
d838e29
Merged config updates from main. Adds a timeout for ethernet warmup
Pandabear1125 Feb 17, 2025
3b95cd8
Adds hive's comms stuff
Pandabear1125 Feb 19, 2025
c13bf81
Updates comms data files
Pandabear1125 Feb 20, 2025
e8cedc2
Whoops
Pandabear1125 Feb 20, 2025
769eebb
Disables IGMP, ICMP, DHCP from QNEthernet
Pandabear1125 Feb 22, 2025
d1a79d7
Added CommsLayer, integrated it
Pandabear1125 Feb 22, 2025
fd83269
Merge from main
Pandabear1125 Feb 25, 2025
834bcd6
comments tof read and sensor prints
Pandabear1125 Feb 25, 2025
3cf5cb2
Add clangd stuff to gitignore
Pandabear1125 Feb 25, 2025
35bafde
Merge branch 'main' into feature-comms-refactor
Pandabear1125 Feb 25, 2025
195aded
encoder merge
Pandabear1125 Feb 27, 2025
8db476e
Ethernet adapted to use sendReceive function
Pandabear1125 Feb 27, 2025
94c3db9
Initialize and use packet payloads
Pandabear1125 Feb 27, 2025
9944d7d
consolidated data structs from sensors into data_structs.hpp and made…
guywithhat99 Mar 5, 2025
00fdfe0
learned what Include gards do...
guywithhat99 Mar 8, 2025
faa008b
fixed bitfield form
guywithhat99 Mar 8, 2025
840b777
middle mouse button did a thing
guywithhat99 Mar 8, 2025
974b73f
Puts a cap on the size of payload queues to not exhaust memory
Pandabear1125 Mar 8, 2025
dbd9ec0
Makes comms layer global, implements firmware to hive sending over et…
Pandabear1125 Mar 8, 2025
f129d0f
Implements hive_data
Pandabear1125 Mar 8, 2025
1a8b4fb
Implements sendable
Pandabear1125 Mar 8, 2025
dc1514b
Bruh
Pandabear1125 Mar 8, 2025
567fed9
Copy paste error
Pandabear1125 Mar 11, 2025
99e3a9e
Moved data structs. Added a temp state struct
Pandabear1125 Mar 11, 2025
6c081e8
Adds and sends temp state struct
Pandabear1125 Mar 11, 2025
c0fb572
Fills in dr16 data struct, sends it
Pandabear1125 Mar 11, 2025
4f725ce
Data parity from hive
Pandabear1125 Mar 13, 2025
2a1b923
Parity and include comment consistency
Pandabear1125 Mar 13, 2025
7f278eb
Implemented receiving hive target state
Pandabear1125 Mar 13, 2025
052287a
Merge from main
Pandabear1125 Mar 14, 2025
037f6c6
untested logging data stuff
Pandabear1125 Mar 14, 2025
8635eee
Added send_sensor_data_to_comms() for sensorManager. Correct data sen…
guywithhat99 Mar 19, 2025
d4407d3
Enforces regulation time for ethernet
cu-boulder-robotics Mar 21, 2025
f2a4231
adds estimated, target, and override state structs
Pandabear1125 Mar 22, 2025
6278ae5
Removes double print
Pandabear1125 Mar 22, 2025
cd6327f
Updates from hive
Pandabear1125 Mar 23, 2025
cff858a
Seperates sending logic into individual functions
Pandabear1125 Mar 23, 2025
ff12276
Hive changes
Pandabear1125 Mar 23, 2025
8e05393
Makes hive data not global
Pandabear1125 Mar 24, 2025
667c241
Makes config use ConfigSection rather than random array indicies
Pandabear1125 Mar 24, 2025
2f4e4e5
Maybe hid config integration
Pandabear1125 Mar 24, 2025
2b2e284
Standardizes HID packet payload stuff
Pandabear1125 Mar 25, 2025
3d91163
Adds size check on re-routing
Pandabear1125 Mar 26, 2025
72bb466
Adds lidar data struct for comms
Pandabear1125 Mar 26, 2025
9e3f617
Added ref data
Pandabear1125 Mar 26, 2025
0f99191
Optimizes lidar data packets
Pandabear1125 Mar 26, 2025
c76f27d
Hive parity
Pandabear1125 Mar 26, 2025
af6902e
Whoops
Pandabear1125 Mar 26, 2025
6751a01
Bruh
cu-boulder-robotics Mar 27, 2025
d1f7e21
Hive parity
Pandabear1125 Mar 29, 2025
9f25aa7
stops adding lidar data on firmware
Pandabear1125 Mar 29, 2025
e801716
Fixes weird assignment bug
Pandabear1125 Mar 29, 2025
87bacee
Fixes issue with reconfig with too short watchdog timer
cu-boulder-robotics Mar 30, 2025
5df5883
Trims down HID, implements override state
Pandabear1125 Mar 30, 2025
bac5b8d
Restructures HID packet
Pandabear1125 Apr 1, 2025
1cffee2
Fixes up ethernet connection logic
Pandabear1125 Apr 1, 2025
9f1a2b8
Upgraded to c++ 23
Pandabear1125 Apr 1, 2025
389a1e3
Todos
Pandabear1125 Apr 1, 2025
fd01167
Hive parity
Pandabear1125 Apr 1, 2025
d36acaf
Improves comms prints
cu-boulder-robotics Apr 1, 2025
87130a2
Merge from main
Pandabear1125 Apr 4, 2025
aeff2a0
HIve parity
Pandabear1125 Apr 10, 2025
e05a377
Merge branch 'main' into feature-comms-refactor
Pandabear1125 Apr 12, 2025
ace3d74
Comms trimmed down
Pandabear1125 Apr 12, 2025
cf81a8d
Include/code cleanup
Pandabear1125 Apr 12, 2025
2fbf0dd
Safety check enabled
Pandabear1125 Apr 12, 2025
0815fe0
Docs
Pandabear1125 Apr 12, 2025
0ff56fb
Removes sensor_constants
Pandabear1125 Apr 12, 2025
9455646
Ethernet fix, naming correction
Pandabear1125 Apr 14, 2025
cb9abb3
Me when safety check
Pandabear1125 Apr 14, 2025
67bb5e7
priority queue fallthrough
Pandabear1125 Apr 15, 2025
dd37843
Review comments
Pandabear1125 Apr 23, 2025
83131e2
Hive parity
Pandabear1125 Apr 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ build/
*.a
*.tar.xz

# Ignore clangd files
compile_commands.json
.cache/
.clangd
.clang-format

# Ignore any tools/ directory artifacts
tools/*.txt
tools/*.out
Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ SRC_INC_FLAGS := $(addprefix -I,$(SRC_INC_DIRS))
INCLUDE_FLAGS := $(TEENSY_INC_FLAGS) $(LIBRARY_INC_FLAGS) $(SRC_INC_FLAGS)

# Compiler flags specific to Teensy 4.1
TEENSY4_FLAGS = -DF_CPU=600000000 -DUSB_CUSTOM -DLAYOUT_US_ENGLISH -D__IMXRT1062__ -DTEENSYDUINO=159 -DARDUINO_TEENSY41 -DARDUINO=10813
TEENSY4_FLAGS = -DF_CPU=600000000 -DUSB_CUSTOM -DLAYOUT_US_ENGLISH -D__IMXRT1062__ -DTEENSYDUINO=159 -DARDUINO_TEENSY41 -DARDUINO=10813 -DFIRMWARE

# CPU flags to optimize code for the Teensy processor
CPU_CFLAGS = -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-d16 -mthumb
Expand All @@ -70,9 +70,10 @@ CPPFLAGS := $(INCLUDE_FLAGS) $(DEFINES) -MMD -MP -ffunction-sections -fdata-sect
CFLAGS := $(CPU_CFLAGS)

# Compiler flags for C++ files
CXXFLAGS := $(CPU_CFLAGS) -std=gnu++17 \
CXXFLAGS := $(CPU_CFLAGS) -std=gnu++23 \
-felide-constructors -fno-exceptions -fpermissive -fno-rtti \
-Wno-error=narrowing -Wno-trigraphs -Wno-comment -Wall -Werror
-Wno-error=narrowing -Wno-trigraphs -Wno-comment -Wall -Werror \
-Wno-volatile

# Linker flags, including Teensy-specific linker script
# --gc-sections: Remove unused sections to reduce binary size
Expand Down
1 change: 1 addition & 0 deletions libraries/QNEthernet/src/QNEthernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ bool isDHCP = (ip == INADDR_NONE) &&
dhcpActive_ = false;
}
#endif // LWIP_DHCP
(void)isDHCP; // Avoid unused variable warning
}
#else
LWIP_UNUSED_ARG(ip);
Expand Down
12 changes: 6 additions & 6 deletions libraries/QNEthernet/src/lwipopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void qnethernet_hal_check_core_locking(const char *file, int line,
#define MEMP_NUM_UDP_PCB 8 /* 4 */
#endif // !MEMP_NUM_UDP_PCB
#ifndef MEMP_NUM_TCP_PCB
#define MEMP_NUM_TCP_PCB 8 /* 5 */
#define MEMP_NUM_TCP_PCB 0 /* 5 */
#endif // !MEMP_NUM_TCP_PCB
#ifndef MEMP_NUM_TCP_PCB_LISTEN
// #define MEMP_NUM_TCP_PCB_LISTEN 8
Expand All @@ -75,7 +75,7 @@ void qnethernet_hal_check_core_locking(const char *file, int line,
// #define MEMP_NUM_FRAG_PBUF 15
// #define MEMP_NUM_ARP_QUEUE 30
#ifndef MEMP_NUM_IGMP_GROUP
#define MEMP_NUM_IGMP_GROUP 9 /* 8 */
#define MEMP_NUM_IGMP_GROUP 0 /* 8 */
#endif // !MEMP_NUM_IGMP_GROUP
/* #define LWIP_NUM_SYS_TIMEOUT_INTERNAL \
(LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_ACD + \
Expand Down Expand Up @@ -135,7 +135,7 @@ void qnethernet_hal_check_core_locking(const char *file, int line,

// ICMP options
#ifndef LWIP_ICMP
#define LWIP_ICMP LWIP_IPV4 /* 1 */
#define LWIP_ICMP 0 /* 1 */
#endif // LWIP_ICMP
// #define ICMP_TTL IP_DEFAULT_TTL
// #define LWIP_BROADCAST_PING 0
Expand All @@ -147,7 +147,7 @@ void qnethernet_hal_check_core_locking(const char *file, int line,

// DHCP options
#ifndef LWIP_DHCP
#define LWIP_DHCP (LWIP_IPV4 && LWIP_UDP) /* 0 */
#define LWIP_DHCP 0 /* 0 */
#endif // !LWIP_DHCP
#define LWIP_DHCP_DOES_ACD_CHECK 0 /* LWIP_DHCP */
// #define LWIP_DHCP_BOOTP_FILE 0
Expand Down Expand Up @@ -181,7 +181,7 @@ void qnethernet_hal_check_core_locking(const char *file, int line,

// IGMP options
#ifndef LWIP_IGMP
#define LWIP_IGMP LWIP_IPV4 /* 0 */
#define LWIP_IGMP 0 /* 0 */
#endif // !LWIP_IGMP

// DNS options
Expand Down Expand Up @@ -216,7 +216,7 @@ void qnethernet_hal_check_core_locking(const char *file, int line,
// TCP options

#ifndef LWIP_TCP
#define LWIP_TCP (LWIP_IPV4 || LWIP_IPV6) /* 1 */
#define LWIP_TCP 0 /* 1 */
#endif // !LWIP_TCP
// #define TCP_TTL IP_DEFAULT_TTL
// #define TCP_MAXRTX 12
Expand Down
6 changes: 3 additions & 3 deletions libraries/QNEthernet/src/qnethernet_opts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

// Enables the 'altcp_tls_adapter' functions for easier TLS library integration.
// It's set, by default here, to be enabled if MbedTLS is enabled.
#ifndef QNETHERNET_ALTCP_TLS_ADAPTER
#define QNETHERNET_ALTCP_TLS_ADAPTER LWIP_ALTCP_TLS_MBEDTLS
#endif
// #ifndef QNETHERNET_ALTCP_TLS_ADAPTER
// #define QNETHERNET_ALTCP_TLS_ADAPTER LWIP_ALTCP_TLS_MBEDTLS
// #endif

// Put the RX and TX buffers into RAM1. (Teensy 4)
#ifndef QNETHERNET_BUFFERS_IN_RAM1
Expand Down
4 changes: 2 additions & 2 deletions src/comms/SDManager.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef SD_WRAP
#define SD_WRAP

#include "../../libraries/SD/SD.h"
#include "../../libraries/SPI/SPI.h"
#include <SD/SD.h>
#include <SPI/SPI.h>

#define SD_DIR_LENGTH 256

Expand Down
170 changes: 170 additions & 0 deletions src/comms/comms_layer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#include "comms_layer.hpp"

namespace Comms {

CommsLayer::CommsLayer() {
Serial.printf("CommsLayer: constructed\n");
};

CommsLayer::~CommsLayer() {
Serial.printf("CommsLayer: destructed\n");
};

int CommsLayer::init() {
Serial.printf("CommsLayer: initializing\n");

// hid failing is a fatal error
bool hid_init = initialize_hid();
if (!hid_init) {
Serial.printf("CommsLayer: HIDComms init failed\n");
return -1;
}

// ethernet init failing is not a fatal error
bool ethernet_init = initialize_ethernet();
if (!ethernet_init) {
Serial.printf("CommsLayer: EthernetComms init failed\n");
}

Serial.printf("CommsLayer: initialized\n");

return 0;
};

int CommsLayer::run() {
// read packets from the physical layers
recv_packets();

// write packets to the physical layers
send_packets();

return 0;
};

void CommsLayer::queue_data(CommsData* data) {
switch (data->physical_medium) {
case PhysicalMedium::HID:
if (!is_hid_connected()) {
// discard attempt to send
Serial.printf("Attempting to re-route %s to HID but HID is not connected\n", to_string(data->type_label).c_str());
break;
}
m_hid_payload.add(data);
break;
case PhysicalMedium::Ethernet:
// if ethernet is down and it is a small enough packet, route it through HID instead
if (!is_ethernet_connected() && data->size < HID_PACKET_PAYLOAD_SIZE) {
m_hid_payload.add(data);
break;
} else if (data->size > HID_PACKET_PAYLOAD_SIZE) {
// discard attempt to send
Serial.printf("Attempting to re-route %s to HID but packet is too large\n", to_string(data->type_label).c_str());
break;
}

m_ethernet_payload.add(data);
break;
default:
assert(false && "Invalid PhysicalMedium");
}
};

void CommsLayer::send_packets() {
// prepare and send a HID packet
m_hid_payload.construct_data();
memcpy(m_hid_outgoing.payload(), m_hid_payload.data(), HID_PACKET_PAYLOAD_SIZE);
m_hid.send_packet(m_hid_outgoing);

// prepare and send an ethernet packet
m_ethernet_payload.construct_data();
memcpy(m_ethernet_outgoing.payload(), m_ethernet_payload.data(), ETHERNET_PACKET_PAYLOAD_SIZE);
m_ethernet.send_packet(m_ethernet_outgoing);
};

void CommsLayer::recv_packets() {
// defaulted to true so tests can run without physical layers
bool hid_recv = true;
bool ethernet_recv = true;

// receive packets from the appropriate physical layer
if (m_hid.is_initialized()) {
hid_recv = m_hid.recv_packet(m_hid_incoming);
}
if (m_ethernet.is_initialized()) {
ethernet_recv = m_ethernet.recv_packet(m_ethernet_incoming);
}

// process packets
if (hid_recv) {
m_hid_payload.deconstruct_data(m_hid_incoming.payload(), HID_PACKET_PAYLOAD_SIZE);
}
if (ethernet_recv) {
m_ethernet_payload.deconstruct_data(m_ethernet_incoming.payload(), ETHERNET_PACKET_PAYLOAD_SIZE);
}
};

bool CommsLayer::is_ethernet_connected() {
return m_ethernet.is_initialized() && m_ethernet.is_connected();
};

bool CommsLayer::is_hid_connected() {
return m_hid.is_initialized() && m_hid.is_connected();
};

void CommsLayer::clear_outgoing_buffers() {
m_hid_payload.clear_queues();
m_ethernet_payload.clear_queues();
};

EthernetPacket CommsLayer::get_ethernet_outgoing() {
return m_ethernet_outgoing;
};

HIDPacket CommsLayer::get_hid_outgoing() {
return m_hid_outgoing;
};

void CommsLayer::set_ethernet_incoming(EthernetPacket&& packet) {
m_ethernet_incoming = packet;
};

void CommsLayer::set_hid_incoming(HIDPacket&& packet) {
m_hid_incoming = packet;
};

HiveData& CommsLayer::get_hive_data() {
return m_hive_data;
};

void CommsLayer::set_hive_data(HiveData& data) {
m_hive_data = data;
};

FirmwareData& CommsLayer::get_firmware_data() {
return m_firmware_data;
};

void CommsLayer::set_firmware_data(FirmwareData& data) {
m_firmware_data = data;
};

bool CommsLayer::initialize_hid() {
// Initialize the HID physical layer
m_hid.init();

return true;
};

bool CommsLayer::initialize_ethernet() {
// Initialize the Ethernet physical layer
if (!m_ethernet.init()) {
Serial.println("Ethernet initialization failed");
return false;
}

Serial.println("Ethernet initialized successfully");

return true;
};

} // namespace Comms
Loading