Skip to content

Commit

Permalink
working integration with param webserver on TCU
Browse files Browse the repository at this point in the history
  • Loading branch information
RCMast3r committed May 12, 2024
1 parent 30b29e2 commit c78978e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 26 deletions.
13 changes: 8 additions & 5 deletions include/InterfaceParams.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
#ifndef INTERFACEPARAMS
#define INTERFACEPARAMS
#include "NativeEthernet.h"
// #include "NativeEthernet.h"
#include <QNEthernet.h>

namespace EthParams
{
using namespace qindesign::network;

uint8_t default_MCU_MAC_address[6] =
{0x04, 0xe9, 0xe5, 0x10, 0x1f, 0x22};

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

const uint16_t default_protobuf_send_port = 2001;
const uint16_t default_protobuf_recv_port = 2000;
const uint16_t default_protobuf_send_port = 20001;
const uint16_t default_protobuf_recv_port = 20000;

const IPAddress default_netmask(255, 255, 255, 0);
const IPAddress default_gateway(192, 168, 0, 1);

const uint16_t default_buffer_size = 512;
const uint16_t default_buffer_size = 1024;
}
#endif
16 changes: 9 additions & 7 deletions lib/interfaces/include/ProtobufMsgInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#include "pb_common.h"
#include "ParameterInterface.h"
#include "circular_buffer.h"
#include "NativeEthernet.h"
// #include "NativeEthernet.h"
#include "QNEthernet.h"
#include "MCU_rev15_defs.h"

namespace qn = qindesign::network;

struct ETHInterfaces
{
Expand All @@ -19,22 +21,22 @@ struct ETHInterfaces
using recv_function_t = void (*)(const uint8_t* buffer, size_t packet_size, ETHInterfaces& interfaces);

// this should be usable with arbitrary functions idk something
void handle_ethernet_socket_receive(EthernetUDP* socket, recv_function_t recv_function, ETHInterfaces& interfaces)
void handle_ethernet_socket_receive(qn::EthernetUDP* socket, recv_function_t recv_function, ETHInterfaces& interfaces)
{
int packet_size = socket->parsePacket();
if(packet_size > 0)
{
Serial.println("packet size");
Serial.println(packet_size);
// Serial.println("packet size");
// Serial.println(packet_size);
uint8_t buffer[EthParams::default_buffer_size];
size_t read_bytes = socket->read(buffer, sizeof(buffer));
socket->read(buffer, UDP_TX_PACKET_MAX_SIZE);
socket->read(buffer, EthParams::default_buffer_size);
recv_function(buffer, read_bytes, interfaces);
}
}

template <typename pb_struct>
bool handle_ethernet_socket_send_pb(EthernetUDP* socket, const pb_struct& msg, const pb_msgdesc_t* msg_desc)
bool handle_ethernet_socket_send_pb(qn::EthernetUDP* socket, const pb_struct& msg, const pb_msgdesc_t* msg_desc)
{
socket->beginPacket(EthParams::default_TCU_ip, EthParams::default_protobuf_send_port);

Expand All @@ -57,7 +59,7 @@ void recv_pb_stream_union_msg(const uint8_t *buffer, size_t packet_size, ETHInte
HT_ETH_Union msg = HT_ETH_Union_init_zero;
if (pb_decode(&stream, HT_ETH_Union_fields, &msg))
{
Serial.println("decoded!");
// Serial.println("decoded!");

switch (msg.which_type_union)
{
Expand Down
4 changes: 3 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ board = teensy41
framework = arduino
upload_protocol = teensy-cli
extra_scripts = pre:extra_script.py
lib_compat_mode=strict

lib_deps =
SPI
Nanopb
https://github.com/vjmuzik/NativeEthernet.git
https://github.com/ssilverman/QNEthernet#v0.27.0
https://github.com/hytech-racing/HT_params/releases/download/2024-05-07T06_59_33/ht_eth_pb_lib.tar.gz
https://github.com/hytech-racing/shared_firmware_interfaces.git
https://github.com/hytech-racing/shared_firmware_systems.git
Expand Down
27 changes: 14 additions & 13 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "FlexCAN_T4.h"
#include "HyTech_CAN.h"
#include "MCU_rev15_defs.h"
#include "NativeEthernet.h"

// #include "NativeEthernet.h"
#include <QNEthernet.h>
// /* Interfaces */

#include "HytechCANInterface.h"
Expand Down Expand Up @@ -89,9 +89,10 @@ const PedalsParams brake_params = {
/*
DATA SOURCES
*/

EthernetUDP protobuf_send_socket;
EthernetUDP protobuf_recv_socket;
// using namespace qindesign::network;
namespace qn = qindesign::network;
qn::EthernetUDP protobuf_send_socket;
qn::EthernetUDP protobuf_recv_socket;

/* Two CAN lines on Main ECU rev15 */
FlexCAN_T4<CAN2, RX_SIZE_256, TX_SIZE_16> INV_CAN; // Inverter CAN (now both are on same line)
Expand Down Expand Up @@ -250,14 +251,14 @@ void setup()
// initialize CAN communication
init_all_CAN_devices();

// Ethernet.begin(EthParams::default_MCU_MAC_address, EthParams::default_MCU_ip);
// protobuf_send_socket.begin(EthParams::default_protobuf_send_port);
// protobuf_recv_socket.begin(EthParams::default_protobuf_recv_port);
qn::Ethernet.begin(EthParams::default_MCU_ip, EthParams::default_netmask, EthParams::default_gateway);
protobuf_send_socket.begin(EthParams::default_protobuf_send_port);
protobuf_recv_socket.begin(EthParams::default_protobuf_recv_port);

/* Do this to send message VVV */
// protobuf_socket.beginPacket(EthParams::default_TCU_ip, EthParams::default_protobuf_port);
// protobuf_socket.write(buf, len);
// protobuf_socker.endPacket();
// /* Do this to send message VVV */
// // protobuf_socket.beginPacket(EthParams::default_TCU_ip, EthParams::default_protobuf_port);
// // protobuf_socket.write(buf, len);
// // protobuf_socker.endPacket();

SPI.begin();
a1.init();
Expand Down Expand Up @@ -319,7 +320,7 @@ void loop()
// get latest tick from sys clock
SysTick_s curr_tick = sys_clock.tick(micros());

// handle_ethernet_interface_comms();
handle_ethernet_interface_comms();

// process received CAN messages
process_ring_buffer(CAN2_rxBuffer, CAN_receive_interfaces, curr_tick.millis);
Expand Down

0 comments on commit c78978e

Please sign in to comment.